X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/be8de5acc35c47d0b191223e5ece96fcf452ea5d..1d7fbccb64462c349ea223df3ac02817ba60bfe1:/src/services/common-service/common-service.ts diff --git a/src/services/common-service/common-service.ts b/src/services/common-service/common-service.ts index d8117821..48fcb06d 100644 --- a/src/services/common-service/common-service.ts +++ b/src/services/common-service/common-service.ts @@ -9,6 +9,7 @@ import { ApiActions } from "~/services/api/api-actions"; import * as QueryString from "query-string"; interface Errors { + status: number; errors: string[]; errorToken: string; } @@ -21,6 +22,7 @@ export interface ListArguments { select?: string[]; distinct?: boolean; count?: string; + includeOldVersions?: boolean; } export interface ListResults { @@ -36,11 +38,13 @@ export class CommonService { protected serverApi: AxiosInstance; protected resourceType: string; protected actions: ApiActions; + protected readOnlyFields: string[]; - constructor(serverApi: AxiosInstance, resourceType: string, actions: ApiActions) { + constructor(serverApi: AxiosInstance, resourceType: string, actions: ApiActions, readOnlyFields: string[] = []) { this.serverApi = serverApi; this.resourceType = '/' + resourceType; this.actions = actions; + this.readOnlyFields = readOnlyFields; } static mapResponseKeys = (response: { data: any }) => @@ -64,7 +68,7 @@ export class CommonService { } } - static defaultResponse(promise: AxiosPromise, actions: ApiActions, mapKeys = true): Promise { + static defaultResponse(promise: AxiosPromise, actions: ApiActions, mapKeys = true, showErrors = true): Promise { const reqId = uuid(); actions.progressFn(reqId, true); return promise @@ -78,16 +82,19 @@ export class CommonService { .catch(({ response }) => { actions.progressFn(reqId, false); const errors = CommonService.mapResponseKeys(response) as Errors; - actions.errorFn(reqId, errors); + errors.status = response.status; + actions.errorFn(reqId, errors, showErrors); throw errors; }); } - create(data?: Partial) { + create(data?: Partial, showErrors?: boolean) { return CommonService.defaultResponse( this.serverApi .post(this.resourceType, data && CommonService.mapKeys(_.snakeCase)(data)), - this.actions + this.actions, + true, // mapKeys + showErrors ); } @@ -99,18 +106,20 @@ export class CommonService { ); } - get(uuid: string) { + get(uuid: string, showErrors?: boolean) { return CommonService.defaultResponse( this.serverApi .get(this.resourceType + '/' + uuid), - this.actions + this.actions, + true, // mapKeys + showErrors ); } list(args: ListArguments = {}): Promise> { const { filters, order, ...other } = args; const params = { - ...other, + ...CommonService.mapKeys(_.snakeCase)(other), filters: filters ? `[${filters}]` : undefined, order: order ? order : undefined };