X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/71b9264c1720e619f8cfcb297a7848ece420c61c..9ea56060efd17410075fc213f347867e51955224:/src/services/common-service/common-resource-service.ts diff --git a/src/services/common-service/common-resource-service.ts b/src/services/common-service/common-resource-service.ts index 17c287d2..bc24f227 100644 --- a/src/services/common-service/common-resource-service.ts +++ b/src/services/common-service/common-resource-service.ts @@ -8,7 +8,7 @@ import { ApiActions } from "~/services/api/api-actions"; import { CommonService } from "~/services/common-service/common-service"; export enum CommonResourceServiceError { - UNIQUE_VIOLATION = 'UniqueViolation', + UNIQUE_NAME_VIOLATION = 'UniqueNameViolation', OWNERSHIP_CYCLE = 'OwnershipCycle', MODIFYING_CONTAINER_REQUEST_FINAL_STATE = 'ModifyingContainerRequestFinalState', NAME_HAS_ALREADY_BEEN_TAKEN = 'NameHasAlreadyBeenTaken', @@ -17,8 +17,26 @@ export enum CommonResourceServiceError { } export class CommonResourceService extends CommonService { - 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) { + if (data !== undefined) { + this.readOnlyFields.forEach( field => delete data[field] ); + } + return super.create(data); + } + + update(uuid: string, data: Partial) { + if (data !== undefined) { + this.readOnlyFields.forEach( field => delete data[field] ); + } + return super.update(uuid, data); } } @@ -27,7 +45,7 @@ export const getCommonResourceServiceError = (errorResponse: any) => { const error = errorResponse.errors.join(''); switch (true) { case /UniqueViolation/.test(error): - return CommonResourceServiceError.UNIQUE_VIOLATION; + return CommonResourceServiceError.UNIQUE_NAME_VIOLATION; case /ownership cycle/.test(error): return CommonResourceServiceError.OWNERSHIP_CYCLE; case /Mounts cannot be modified in state 'Final'/.test(error):