15407: Restricts mapKeys' recursion to only "items" keys, to support listing.
[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 * as _ from "lodash";
6 import { AxiosInstance } from "axios";
7 import { TrashableResource } from "src/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
13     constructor(serverApi: AxiosInstance, resourceType: string, actions: ApiActions) {
14         super(serverApi, resourceType, actions);
15     }
16
17     trash(uuid: string): Promise<T> {
18         return CommonResourceService.defaultResponse(
19             this.serverApi
20                 .post(this.resourceType + `${uuid}/trash`),
21             this.actions
22         );
23     }
24
25     untrash(uuid: string): Promise<T> {
26         const params = {
27             ensure_unique_name: true
28         };
29         return CommonResourceService.defaultResponse(
30             this.serverApi
31                 .post(this.resourceType + `${uuid}/untrash`, {
32                     params: CommonResourceService.mapKeys(_.snakeCase)(params)
33                 }),
34             this.actions
35         );
36     }
37 }