@@ -5,7 +5,16 @@ import './polyfills/buffer.js'
55
66import axios from '@nextcloud/axios'
77import { generateOcsUrl } from '@nextcloud/router'
8- import type { EditableField , FieldDefinition , FieldValueRecord } from './types'
8+ import type {
9+ CreateDefinitionPayload ,
10+ EditableField ,
11+ FieldDefinition ,
12+ FieldValueRecord ,
13+ UpdateDefinitionPayload ,
14+ UpdateOwnVisibilityPayload ,
15+ UpsertAdminUserValuePayload ,
16+ UpsertOwnValuePayload ,
17+ } from './types'
918
1019const jsonHeaders = {
1120 'OCS-APIRequest' : 'true' ,
@@ -22,14 +31,14 @@ export const listDefinitions = async(): Promise<FieldDefinition[]> => {
2231 return response . data . ocs . data
2332}
2433
25- export const createDefinition = async ( payload : Record < string , unknown > ) : Promise < FieldDefinition > => {
34+ export const createDefinition = async ( payload : CreateDefinitionPayload ) : Promise < FieldDefinition > => {
2635 const response = await axios . post < { ocs : { data : FieldDefinition } } > ( apiUrl ( '/api/v1/definitions' ) , payload , {
2736 headers : jsonHeaders ,
2837 } )
2938 return response . data . ocs . data
3039}
3140
32- export const updateDefinition = async ( id : number , payload : Record < string , unknown > ) : Promise < FieldDefinition > => {
41+ export const updateDefinition = async ( id : number , payload : UpdateDefinitionPayload ) : Promise < FieldDefinition > => {
3342 const response = await axios . put < { ocs : { data : FieldDefinition } } > ( apiUrl ( `/api/v1/definitions/${ id } ` ) , payload , {
3443 headers : jsonHeaders ,
3544 } )
@@ -49,17 +58,18 @@ export const listEditableFields = async(): Promise<EditableField[]> => {
4958 return response . data . ocs . data
5059}
5160
52- export const upsertOwnValue = async ( fieldDefinitionId : number , payload : Record < string , unknown > ) : Promise < FieldValueRecord > => {
61+ export const upsertOwnValue = async ( fieldDefinitionId : number , payload : UpsertOwnValuePayload ) : Promise < FieldValueRecord > => {
5362 const response = await axios . put < { ocs : { data : FieldValueRecord } } > ( apiUrl ( `/api/v1/me/values/${ fieldDefinitionId } ` ) , payload , {
5463 headers : jsonHeaders ,
5564 } )
5665 return response . data . ocs . data
5766}
5867
59- export const updateOwnVisibility = async ( fieldDefinitionId : number , currentVisibility : string ) : Promise < FieldValueRecord > => {
60- const response = await axios . put < { ocs : { data : FieldValueRecord } } > ( apiUrl ( `/api/v1/me/values/ ${ fieldDefinitionId } /visibility` ) , {
68+ export const updateOwnVisibility = async ( fieldDefinitionId : number , currentVisibility : UpdateOwnVisibilityPayload [ 'currentVisibility' ] ) : Promise < FieldValueRecord > => {
69+ const payload : UpdateOwnVisibilityPayload = {
6170 currentVisibility,
62- } , {
71+ }
72+ const response = await axios . put < { ocs : { data : FieldValueRecord } } > ( apiUrl ( `/api/v1/me/values/${ fieldDefinitionId } /visibility` ) , payload , {
6373 headers : jsonHeaders ,
6474 } )
6575 return response . data . ocs . data
@@ -72,7 +82,7 @@ export const listAdminUserValues = async(userUid: string): Promise<FieldValueRec
7282 return response . data . ocs . data
7383}
7484
75- export const upsertAdminUserValue = async ( userUid : string , fieldDefinitionId : number , payload : Record < string , unknown > ) : Promise < FieldValueRecord > => {
85+ export const upsertAdminUserValue = async ( userUid : string , fieldDefinitionId : number , payload : UpsertAdminUserValuePayload ) : Promise < FieldValueRecord > => {
7686 const response = await axios . put < { ocs : { data : FieldValueRecord } } > ( apiUrl ( `/api/v1/users/${ encodeURIComponent ( userUid ) } /values/${ fieldDefinitionId } ` ) , payload , {
7787 headers : jsonHeaders ,
7888 } )
0 commit comments