19482: Cypress tests WIP
[arvados-workbench2.git] / src / services / common-service / common-resource-service.ts
index 83af1e13acdc6af6b9a4133e17fbcd1741df3e1d..d9be8dae9f2a402268217cd8704c0e1d5f538a48 100644 (file)
@@ -3,10 +3,10 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { AxiosInstance } from "axios";
-import * as _ from "lodash";
-import { Resource } from "src/models/resource";
-import { ApiActions } from "~/services/api/api-actions";
-import { CommonService } from "~/services/common-service/common-service";
+import { snakeCase } from "lodash";
+import { Resource } from "models/resource";
+import { ApiActions } from "services/api/api-actions";
+import { CommonService } from "services/common-service/common-service";
 
 export enum CommonResourceServiceError {
     UNIQUE_NAME_VIOLATION = 'UniqueNameViolation',
@@ -26,31 +26,34 @@ export class CommonResourceService<T extends Resource> extends CommonService<T>
         ]));
     }
 
-    create(data?: Partial<T>) {
+    create(data?: Partial<T>, showErrors?: boolean) {
         let payload: any;
         if (data !== undefined) {
             this.readOnlyFields.forEach( field => delete data[field] );
             payload = {
-                [this.resourceType.slice(0, -1)]: CommonService.mapKeys(_.snakeCase)(data),
+                [this.resourceType.slice(0, -1)]: CommonService.mapKeys(snakeCase)(data),
             };
         }
-        return super.create(payload);
+        return super.create(payload, showErrors);
     }
 
-    update(uuid: string, data: Partial<T>) {
+    update(uuid: string, data: Partial<T>, showErrors?: boolean, 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),
+                [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);
+        return super.update(uuid, payload, showErrors);
     }
 }
 
 export const getCommonResourceServiceError = (errorResponse: any) => {
-    if ('errors' in errorResponse && 'errorToken' in errorResponse) {
+    if ('errors' in errorResponse) {
         const error = errorResponse.errors.join('');
         switch (true) {
             case /UniqueViolation/.test(error):