refs #master Merge branch 'origin/master' into 14186-progress-indicator-store
[arvados-workbench2.git] / src / services / groups-service / groups-service.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as _ from "lodash";
6 import { CommonResourceService, ListResults, ListArguments } from '~/services/common-service/common-resource-service';
7 import { AxiosInstance } from "axios";
8 import { CollectionResource } from "~/models/collection";
9 import { ProjectResource } from "~/models/project";
10 import { ProcessResource } from "~/models/process";
11 import { TrashableResource } from "~/models/resource";
12 import { TrashableResourceService } from "~/services/common-service/trashable-resource-service";
13 import { ApiActions } from "~/services/api/api-actions";
14 import { GroupResource } from "~/models/group";
15
16 export interface ContentsArguments {
17     limit?: number;
18     offset?: number;
19     order?: string;
20     filters?: string;
21     recursive?: boolean;
22     includeTrash?: boolean;
23 }
24
25 export interface SharedArguments extends ListArguments {
26     include?: string;
27 }
28
29 export type GroupContentsResource =
30     CollectionResource |
31     ProjectResource |
32     ProcessResource;
33
34 export class GroupsService<T extends GroupResource = GroupResource> extends TrashableResourceService<T> {
35
36     constructor(serverApi: AxiosInstance, actions: ApiActions) {
37         super(serverApi, "groups", actions);
38     }
39
40     contents(uuid: string, args: ContentsArguments = {}): Promise<ListResults<GroupContentsResource>> {
41         const { filters, order, ...other } = args;
42         const params = {
43             ...other,
44             filters: filters ? `[${filters}]` : undefined,
45             order: order ? order : undefined
46         };
47         return CommonResourceService.defaultResponse(
48             this.serverApi
49                 .get(this.resourceType + `${uuid}/contents`, {
50                     params: CommonResourceService.mapKeys(_.snakeCase)(params)
51                 }),
52             this.actions
53         );
54     }
55
56     shared(params: SharedArguments = {}): Promise<ListResults<GroupContentsResource>> {
57         return CommonResourceService.defaultResponse(
58             this.serverApi
59                 .get(this.resourceType + 'shared', { params }),
60             this.actions
61         );
62     }
63 }
64
65 export enum GroupContentsResourcePrefix {
66     COLLECTION = "collections",
67     PROJECT = "groups",
68     PROCESS = "container_requests"
69 }