- constructor(serverApi: AxiosInstance, resourceType: string, actions: ApiActions) {
- super(serverApi, resourceType, actions);
+ constructor(serverApi: AxiosInstance, resourceType: string, actions: ApiActions, readOnlyFields: string[] = []) {
+ super(serverApi, resourceType, actions, readOnlyFields.concat([
+ 'uuid',
+ 'etag',
+ 'kind'
+ ]));
+ }
+
+ create(data?: Partial<T>) {
+ let payload: any;
+ if (data !== undefined) {
+ this.readOnlyFields.forEach( field => delete data[field] );
+ payload = {
+ [this.resourceType.slice(0, -1)]: CommonService.mapKeys(snakeCase)(data),
+ };
+ }
+ return super.create(payload);
+ }
+
+ update(uuid: string, data: Partial<T>, select?: string[]) {
+ let payload: any;
+ if (data !== undefined) {
+ this.readOnlyFields.forEach( field => delete data[field] );
+ payload = {
+ [this.resourceType.slice(0, -1)]: CommonService.mapKeys(snakeCase)(data),
+ };
+ if (select !== undefined && select.length > 0) {
+ payload.select = ['uuid', ...select.map(field => snakeCase(field))];
+ };
+ }
+ return super.update(uuid, payload);