Fix renaming collection files
[arvados-workbench2.git] / src / services / collection-files-service / collection-files-service.ts
index 3b320eb6c9780f7bd407ee01ce9be2902d4d313f..dfeed0b7032de2fec5e7b654345113292b4ce39d 100644 (file)
@@ -6,6 +6,8 @@ import { CollectionService } from "../collection-service/collection-service";
 import { parseKeepManifestText, stringifyKeepManifest } from "./collection-manifest-parser";
 import { mapManifestToCollectionFilesTree } from "./collection-manifest-mapper";
 import { CollectionFile } from "../../models/collection-file";
+import { CommonResourceService } from "../../common/api/common-resource-service";
+import * as _ from "lodash";
 
 export class CollectionFilesService {
 
@@ -26,19 +28,21 @@ export class CollectionFilesService {
     async renameFile(collectionUuid: string, file: { name: string, path: string }, newName: string) {
         const collection = await this.collectionService.get(collectionUuid);
         const manifest = parseKeepManifestText(collection.manifestText);
-        const updatedManifest = manifest.map(stream =>
-            stream.name === file.path
+        const updatedManifest = manifest.map(
+            stream => stream.name === file.path
                 ? {
                     ...stream,
-                    files: stream.files.map(f =>
-                        f.name === file.name
+                    files: stream.files.map(
+                        f => f.name === file.name
                             ? { ...f, name: newName }
-                            : f)
+                            : f
+                    )
                 }
                 : stream
         );
         const manifestText = stringifyKeepManifest(updatedManifest);
-        return this.collectionService.update(collectionUuid, { ...collection, manifestText });
+        const data = { ...collection, manifestText };
+        return this.collectionService.update(collectionUuid, CommonResourceService.mapKeys(_.snakeCase)(data));
     }
 
     async deleteFile(collectionUuid: string, file: { name: string, path: string }) {
@@ -56,4 +60,10 @@ export class CollectionFilesService {
         return this.collectionService.update(collectionUuid, { manifestText });
     }
 
-}
\ No newline at end of file
+    renameTest() {
+        const u = this.renameFile('qr1hi-4zz18-n0sx074erl4p0ph', {
+            name: 'extracted2.txt.png',
+            path: ''
+        }, 'extracted-new.txt.png');
+    }
+}