Refactor to apply global navigation actions
[arvados-workbench2.git] / src / common / api / common-resource-service.ts
index da5bc33cf7c08f33af05e7e5c938c6b9e0663bc4..fe7494b4460faf57ee2b5e47f2691c208961ce76 100644 (file)
@@ -31,6 +31,7 @@ export interface Errors {
 
 export enum CommonResourceServiceError {
     UNIQUE_VIOLATION = 'UniqueViolation',
+    OWNERSHIP_CYCLE = 'OwnershipCycle',
     UNKNOWN = 'Unknown',
     NONE = 'None'
 }
@@ -104,12 +105,13 @@ export class CommonResourceService<T extends Resource> {
                 }));
     }
 
-    update(uuid: string, data: any) {
+    update(uuid: string, data: Partial<T>) {
         return CommonResourceService.defaultResponse(
             this.serverApi
-                .put<T>(this.resourceType + uuid, data));
+                .put<T>(this.resourceType + uuid, data && CommonResourceService.mapKeys(_.snakeCase)(data)));
 
     }
+
 }
 
 export const getCommonResourceServiceError = (errorResponse: any) => {
@@ -118,6 +120,8 @@ export const getCommonResourceServiceError = (errorResponse: any) => {
         switch (true) {
             case /UniqueViolation/.test(error):
                 return CommonResourceServiceError.UNIQUE_VIOLATION;
+            case /ownership cycle/.test(error):
+                return CommonResourceServiceError.OWNERSHIP_CYCLE;
             default:
                 return CommonResourceServiceError.UNKNOWN;
         }