From 2459df0972ed15bc18d7407166991f437854ca5b Mon Sep 17 00:00:00 2001 From: Luis Eulacio Date: Fri, 15 May 2020 11:45:54 -0400 Subject: [PATCH 1/4] Add filename attribute on create object --- package-lock.json | 2 +- src/files.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index afed485..dfebcea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@cobuildlab/8base-utils", - "version": "0.0.5", + "version": "0.2.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/files.ts b/src/files.ts index ee9a5f2..8dd70ee 100644 --- a/src/files.ts +++ b/src/files.ts @@ -30,7 +30,7 @@ export const normalize8baseDocumentCreate = ( } _validateFile(currentValue, "normalize8baseDocumentCreate:currentValue"); - data[key] = { create: { fileId: currentValue.fileId } }; + data[key] = { create: { fileId: currentValue.fileId , filename: currentValue.name } }; }; @@ -64,7 +64,7 @@ export const normalize8baseDocumentsCreate = ( const documents: Record[] = []; for (const file of currentValues) { _validateFile(file, "normalize8baseDocumentsCreate:file.fileId"); - documents.push({ fileId: file.fileId }); + documents.push({ fileId: file.fileId , filename: file.name}); } data[key] = { create: documents }; @@ -99,7 +99,7 @@ export const normalize8baseDocumentDeleteAndUpdate = (data: Record, _validateFile(newFile, "normalize8baseDocumentDeleteAndUpdate:newFile"); if (isNullOrUndefined(newFile.id)) { - data[key] = { create: { fileId: newFile.fileId } }; + data[key] = { create: { fileId: newFile.fileId , filename: newFile.name} }; return; } @@ -166,7 +166,7 @@ export const normalize8BaseDocumentsDeleteAndUpdate = (data: Record data[key] = {}; if (toBeCreated.length > 0) data[key].create = toBeCreated.map(file => { - return { fileId: file.fileId }; + return { fileId: file.fileId , filename: file.name}; }); if (toBeDeleted.length > 0) data[key].disconnect = toBeDeleted.map(file => { From 8294a6f38fa28253d6b0be38df12387a1463d858 Mon Sep 17 00:00:00 2001 From: Luis Eulacio Date: Fri, 15 May 2020 11:59:25 -0400 Subject: [PATCH 2/4] fix --- src/files.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/files.ts b/src/files.ts index 8dd70ee..3f1526c 100644 --- a/src/files.ts +++ b/src/files.ts @@ -30,7 +30,7 @@ export const normalize8baseDocumentCreate = ( } _validateFile(currentValue, "normalize8baseDocumentCreate:currentValue"); - data[key] = { create: { fileId: currentValue.fileId , filename: currentValue.name } }; + data[key] = { create: { fileId: currentValue.fileId , filename: currentValue.filename } }; }; @@ -64,7 +64,7 @@ export const normalize8baseDocumentsCreate = ( const documents: Record[] = []; for (const file of currentValues) { _validateFile(file, "normalize8baseDocumentsCreate:file.fileId"); - documents.push({ fileId: file.fileId , filename: file.name}); + documents.push({ fileId: file.fileId , filename: file.filename}); } data[key] = { create: documents }; @@ -99,7 +99,7 @@ export const normalize8baseDocumentDeleteAndUpdate = (data: Record, _validateFile(newFile, "normalize8baseDocumentDeleteAndUpdate:newFile"); if (isNullOrUndefined(newFile.id)) { - data[key] = { create: { fileId: newFile.fileId , filename: newFile.name} }; + data[key] = { create: { fileId: newFile.fileId , filename: newFile.filename} }; return; } @@ -166,7 +166,7 @@ export const normalize8BaseDocumentsDeleteAndUpdate = (data: Record data[key] = {}; if (toBeCreated.length > 0) data[key].create = toBeCreated.map(file => { - return { fileId: file.fileId , filename: file.name}; + return { fileId: file.fileId , filename: file.filename}; }); if (toBeDeleted.length > 0) data[key].disconnect = toBeDeleted.map(file => { From bcc4a7dd59c3cd037ba7264f81ccc9040944400d Mon Sep 17 00:00:00 2001 From: Luis Eulacio Date: Fri, 15 May 2020 12:15:50 -0400 Subject: [PATCH 3/4] update tests --- src/__tests__/files-test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/__tests__/files-test.ts b/src/__tests__/files-test.ts index fa5a35b..02862e9 100644 --- a/src/__tests__/files-test.ts +++ b/src/__tests__/files-test.ts @@ -111,7 +111,7 @@ test("normalize8baseDocumentDeleteAndUpdate:", () => { new ValidationError(`normalize8baseDocumentDeleteAndUpdate:key: value: can't be blank, null or undefined.`) ); - const newO0 = { a: { id: "ID", fileId: "fileID" } }; + const newO0 = { a: { id: "ID", fileId: "fileID" , filename: "filename" } }; const oldO0 = { a: null }; normalize8baseDocumentDeleteAndUpdate(newO0, "a", oldO0); expect(newO0).toEqual({}); @@ -195,7 +195,7 @@ test("normalize8baseDocumentDeleteAndUpdate:", () => { ) ); - const new12 = { a: { fileId: "FILE-ID1" } }; + const new12 = { a: { fileId: "FILE-ID1" , filename:'filename'} }; const old12 = {}; normalize8baseDocumentDeleteAndUpdate(new12, "a", old12); expect(new12).toEqual({ a: { create: { fileId: "FILE-ID1" } } }); @@ -301,13 +301,13 @@ test("normalize8BaseDocumentsDeleteAndUpdate:", () => { normalize8BaseDocumentsDeleteAndUpdate(new13, "a", old13); expect(new13).toEqual({ a: { disconnect: [{ id: "ID" }] } }); - const new14 = { a: [{ fileId: "FILE-ID1" }] }; + const new14 = { a: [{ fileId: "FILE-ID1" , filename:'filename' }] }; const old14 = { a: [{ id: "FILE-ID2" }] }; normalize8BaseDocumentsDeleteAndUpdate(new14, "a", old14); expect(new14).toEqual({ a: { create: [{ fileId: "FILE-ID1" }], disconnect: [{ id: "FILE-ID2" }] } }); - const new15 = { a: [{ fileId: "FILE-ID1" }, { id: "ID2", fileId: "FILE-ID2" }] }; + const new15 = { a: [{ fileId: "FILE-ID1" , filename:'filename' }, { id: "ID2", fileId: "FILE-ID2" , filename:'filename' }] }; const old15 = { a: [{ id: "FILE-ID2" }, { id: "ID2" }] }; normalize8BaseDocumentsDeleteAndUpdate(new15, "a", old15); expect(new15).toEqual({ a: { create: [{ fileId: "FILE-ID1" }], disconnect: [{ id: "FILE-ID2" }] } }); From 000518d269abbab69e1b463c4b5f6e21d1b21a34 Mon Sep 17 00:00:00 2001 From: Luis Eulacio Date: Fri, 15 May 2020 12:39:38 -0400 Subject: [PATCH 4/4] Add new attribute on results --- src/__tests__/files-test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/__tests__/files-test.ts b/src/__tests__/files-test.ts index 02862e9..83c69ef 100644 --- a/src/__tests__/files-test.ts +++ b/src/__tests__/files-test.ts @@ -198,7 +198,7 @@ test("normalize8baseDocumentDeleteAndUpdate:", () => { const new12 = { a: { fileId: "FILE-ID1" , filename:'filename'} }; const old12 = {}; normalize8baseDocumentDeleteAndUpdate(new12, "a", old12); - expect(new12).toEqual({ a: { create: { fileId: "FILE-ID1" } } }); + expect(new12).toEqual({ a: { create: { fileId: "FILE-ID1" , filename:'filename'} } }); }); @@ -304,12 +304,12 @@ test("normalize8BaseDocumentsDeleteAndUpdate:", () => { const new14 = { a: [{ fileId: "FILE-ID1" , filename:'filename' }] }; const old14 = { a: [{ id: "FILE-ID2" }] }; normalize8BaseDocumentsDeleteAndUpdate(new14, "a", old14); - expect(new14).toEqual({ a: { create: [{ fileId: "FILE-ID1" }], disconnect: [{ id: "FILE-ID2" }] } }); + expect(new14).toEqual({ a: { create: [{ fileId: "FILE-ID1" , filename:'filename'}], disconnect: [{ id: "FILE-ID2" }] } }); const new15 = { a: [{ fileId: "FILE-ID1" , filename:'filename' }, { id: "ID2", fileId: "FILE-ID2" , filename:'filename' }] }; const old15 = { a: [{ id: "FILE-ID2" }, { id: "ID2" }] }; normalize8BaseDocumentsDeleteAndUpdate(new15, "a", old15); - expect(new15).toEqual({ a: { create: [{ fileId: "FILE-ID1" }], disconnect: [{ id: "FILE-ID2" }] } }); + expect(new15).toEqual({ a: { create: [{ fileId: "FILE-ID1" , filename:'filename'}], disconnect: [{ id: "FILE-ID2" }] } }); });