1e5318530853fbbe4b947b45311261550a9f7235
[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, { Resource, ListResults } from "../../common/api/common-resource-service";
7 import FilterBuilder from "../../common/api/filter-builder";
8 import OrderBuilder from "../../common/api/order-builder";
9 import { AxiosInstance } from "axios";
10
11 interface GroupResource extends Resource {
12     name: string;
13     groupClass: string;
14     description: string;
15     properties: string;
16     writeableBy: string[];
17     trashAt: string;
18     deleteAt: string;
19     isTrashed: boolean;
20 }
21
22 interface ContensArguments {
23     limit?: number;
24     offset?: number;
25     order?: OrderBuilder;
26     filters?: FilterBuilder;
27     recursive?: boolean;
28 }
29
30 export default class GroupsService extends CommonResourceService<GroupResource> {
31
32     constructor(serverApi: AxiosInstance) {
33         super(serverApi, "groups");
34     }
35
36     contents (uuid: string, args: ContensArguments = {}): Promise<ListResults<Resource>> {
37         const { filters, order, ...other } = args;
38         const params = {
39             ...other,
40             filters: filters ? filters.get() : undefined,
41             order: order ? order.getOrder() : undefined
42         };
43         return this.serverApi
44             .get(this.resourceType + `${uuid}/contents/`, {
45                 params: CommonResourceService.mapKeys(_.snakeCase)(params)
46             })
47             .then(CommonResourceService.mapResponseKeys);
48     }
49 }