21691: Add types to replace files methods for differing parameter/result types
authorStephen Smith <stephen@curii.com>
Fri, 12 Apr 2024 00:29:04 +0000 (20:29 -0400)
committerStephen Smith <stephen@curii.com>
Fri, 12 Apr 2024 13:13:40 +0000 (09:13 -0400)
Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen@curii.com>

services/workbench2/src/services/collection-service/collection-service.ts

index e50e5ed35026403c6332865d6b897c32a01f5605..12d31d1678b7de140a2f5cb34c4849927e1a1f32 100644 (file)
@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { CollectionResource, defaultCollectionSelectedFields } from "models/collection";
-import { AxiosInstance } from "axios";
+import { AxiosInstance, AxiosResponse } from "axios";
 import { CollectionFile, CollectionDirectory } from "models/collection-file";
 import { WebDAV } from "common/webdav";
 import { AuthService } from "../auth-service/auth-service";
@@ -20,6 +20,11 @@ type CollectionPartialUpdateOrCreate =
     | (Partial<CollectionResource> & Pick<CollectionResource, "uuid">)
     | (Partial<CollectionResource> & Pick<CollectionResource, "ownerUuid">);
 
+type ReplaceFilesPayload = {
+    collection: Partial<CollectionResource>;
+    replace_files: {[key: string]: string};
+}
+
 export const emptyCollectionPdh = "d41d8cd98f00b204e9800998ecf8427e+0";
 export const SOURCE_DESTINATION_EQUAL_ERROR_MESSAGE = "Source and destination cannot be the same";
 
@@ -78,7 +83,7 @@ export class CollectionService extends TrashableResourceService<CollectionResour
     }
 
     private replaceFiles(data: CollectionPartialUpdateOrCreate, fileMap: {}, showErrors?: boolean) {
-        const payload = {
+        const payload: ReplaceFilesPayload = {
             collection: {
                 preserve_version: true,
                 ...CommonService.mapKeys(snakeCase)(data),
@@ -89,14 +94,14 @@ export class CollectionService extends TrashableResourceService<CollectionResour
         };
         if (data.uuid) {
             return CommonService.defaultResponse(
-                this.serverApi.put<CollectionResource>(`/${this.resourceType}/${data.uuid}`, payload),
+                this.serverApi.put<ReplaceFilesPayload, AxiosResponse<CollectionResource>>(`/${this.resourceType}/${data.uuid}`, payload),
                 this.actions,
                 true, // mapKeys
                 showErrors
             );
         } else {
             return CommonService.defaultResponse(
-                this.serverApi.post<CollectionResource>(`/${this.resourceType}`, payload),
+                this.serverApi.post<ReplaceFilesPayload, AxiosResponse<CollectionResource>>(`/${this.resourceType}`, payload),
                 this.actions,
                 true, // mapKeys
                 showErrors