Create GroupsService and implement contents method
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Mon, 2 Jul 2018 10:12:08 +0000 (12:12 +0200)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Mon, 2 Jul 2018 10:12:08 +0000 (12:12 +0200)
Feature #13702

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/services/groups-service/groups-service.ts [new file with mode: 0644]
src/services/services.ts

diff --git a/src/services/groups-service/groups-service.ts b/src/services/groups-service/groups-service.ts
new file mode 100644 (file)
index 0000000..9016714
--- /dev/null
@@ -0,0 +1,49 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as _ from "lodash";
+import CommonResourceService, { Resource, ListResults } from "../../common/api/common-resource-service";
+import FilterBuilder from "../../common/api/filter-builder";
+import OrderBuilder from "../../common/api/order-builder";
+import { AxiosInstance } from "axios";
+
+interface GroupResource extends Resource {
+    name: string;
+    groupClass: string;
+    description: string;
+    properties: string;
+    writeableBy: string[];
+    trashAt: string;
+    deleteAt: string;
+    isTrashed: boolean;
+}
+
+interface ContensArguments {
+    limit?: number;
+    offset?: number;
+    order?: OrderBuilder;
+    filters?: FilterBuilder;
+    recursive?: boolean;
+}
+
+export default class GroupsService extends CommonResourceService<GroupResource> {
+
+    constructor(serverApi: AxiosInstance) {
+        super(serverApi, "groups");
+    }
+
+    contents (uuid: string, args: ContensArguments = {}): Promise<ListResults<Resource>> {
+        const { filters, order, ...other } = args;
+        const params = {
+            ...other,
+            filters: filters ? filters.get() : undefined,
+            order: order ? order.get() : undefined
+        };
+        return this.serverApi
+            .get(this.resourceType + `/${uuid}/contents`, {
+                params: CommonResourceService.mapKeys(_.snakeCase)(params)
+            })
+            .then(CommonResourceService.mapResponseKeys);
+    }
+}
\ No newline at end of file
index 47a24b344aaa7d43c0f257d3c47aabd526995368..7ad2ff7d855dcbc45c64836c8a8b7d7fbfeb96be 100644 (file)
@@ -5,7 +5,10 @@
 import AuthService from "./auth-service/auth-service";
 import ProjectService from "./project-service/project-service";
 import CollectionService from "./collection-service/collection-service";
 import AuthService from "./auth-service/auth-service";
 import ProjectService from "./project-service/project-service";
 import CollectionService from "./collection-service/collection-service";
+import GroupsService from "./groups-service/groups-service";
+import { serverApi } from "../common/api/server-api";
 
 export const authService = new AuthService();
 export const projectService = new ProjectService();
 export const collectionService = new CollectionService();
 
 export const authService = new AuthService();
 export const projectService = new ProjectService();
 export const collectionService = new CollectionService();
+export const groupsService = new GroupsService(serverApi);