1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as _ from "lodash";
6 import { CommonResourceService } from '~/services/common-service/common-resource-service';
7 import { ListResults, ListArguments } from '~/services/common-service/common-service';
8 import { AxiosInstance } from "axios";
9 import { CollectionResource } from "~/models/collection";
10 import { ProjectResource } from "~/models/project";
11 import { ProcessResource } from "~/models/process";
12 import { ResourceKind } from '~/models/resource';
13 import { TrashableResourceService } from "~/services/common-service/trashable-resource-service";
14 import { ApiActions } from "~/services/api/api-actions";
15 import { GroupResource } from "~/models/group";
17 export interface ContentsArguments {
23 includeTrash?: boolean;
24 excludeHomeProject?: boolean;
27 export interface SharedArguments extends ListArguments {
31 export type GroupContentsResource =
36 export class GroupsService<T extends GroupResource = GroupResource> extends TrashableResourceService<T> {
38 constructor(serverApi: AxiosInstance, actions: ApiActions) {
39 super(serverApi, "groups", actions);
42 async contents(uuid: string, args: ContentsArguments = {}): Promise<ListResults<GroupContentsResource>> {
43 const { filters, order, ...other } = args;
46 filters: filters ? `[${filters}]` : undefined,
47 order: order ? order : undefined
50 const pathUrl = uuid ? `${uuid}/contents` : 'contents';
51 const response = await CommonResourceService.defaultResponse(
53 .get(this.resourceType + pathUrl, {
54 params: CommonResourceService.mapKeys(_.snakeCase)(params)
60 const { items, ...res } = response;
61 const mappedItems = items.map((item: GroupContentsResource) => {
62 const mappedItem = TrashableResourceService.mapKeys(_.camelCase)(item);
63 if (item.kind === ResourceKind.COLLECTION || item.kind === ResourceKind.PROJECT) {
64 const { properties } = item;
65 return { ...mappedItem, properties };
70 const mappedResponse = { ...TrashableResourceService.mapKeys(_.camelCase)(res) };
71 return { ...mappedResponse, items: mappedItems };
74 shared(params: SharedArguments = {}): Promise<ListResults<GroupContentsResource>> {
75 return CommonResourceService.defaultResponse(
77 .get(this.resourceType + 'shared', { params }),
83 export enum GroupContentsResourcePrefix {
84 COLLECTION = "collections",
86 PROCESS = "container_requests"