Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / services / common-service / trashable-resource-service.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { snakeCase } from "lodash";
6 import { AxiosInstance } from "axios";
7 import { TrashableResource } from "models/resource";
8 import { CommonResourceService } from "services/common-service/common-resource-service";
9 import { ApiActions } from "services/api/api-actions";
10
11 export class TrashableResourceService<T extends TrashableResource> extends CommonResourceService<T> {
12     constructor(serverApi: AxiosInstance, resourceType: string, actions: ApiActions, readOnlyFields: string[] = []) {
13         super(serverApi, resourceType, actions, readOnlyFields);
14     }
15
16     trash(uuid: string): Promise<T> {
17         return CommonResourceService.defaultResponse(this.serverApi.post(this.resourceType + `/${uuid}/trash`), this.actions);
18     }
19
20     untrash(uuid: string): Promise<T> {
21         const params = {
22             ensure_unique_name: true,
23         };
24         return CommonResourceService.defaultResponse(
25             this.serverApi.post(this.resourceType + `/${uuid}/untrash`, {
26                 params: CommonResourceService.mapKeys(snakeCase)(params),
27             }),
28             this.actions,
29             undefined,
30             false
31         );
32     }
33 }