Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filename attribute on create object #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/__tests__/files-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
Expand Down Expand Up @@ -195,10 +195,10 @@ 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" } } });
expect(new12).toEqual({ a: { create: { fileId: "FILE-ID1" , filename:'filename'} } });

});

Expand Down Expand Up @@ -301,15 +301,15 @@ 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" }] } });
expect(new14).toEqual({ a: { create: [{ fileId: "FILE-ID1" , filename:'filename'}], 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" }] } });
expect(new15).toEqual({ a: { create: [{ fileId: "FILE-ID1" , filename:'filename'}], disconnect: [{ id: "FILE-ID2" }] } });

});
8 changes: 4 additions & 4 deletions src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.filename } };
};


Expand Down Expand Up @@ -64,7 +64,7 @@ export const normalize8baseDocumentsCreate = (
const documents: Record<string, any>[] = [];
for (const file of currentValues) {
_validateFile(file, "normalize8baseDocumentsCreate:file.fileId");
documents.push({ fileId: file.fileId });
documents.push({ fileId: file.fileId , filename: file.filename});
}

data[key] = { create: documents };
Expand Down Expand Up @@ -99,7 +99,7 @@ export const normalize8baseDocumentDeleteAndUpdate = (data: Record<string, any>,
_validateFile(newFile, "normalize8baseDocumentDeleteAndUpdate:newFile");

if (isNullOrUndefined(newFile.id)) {
data[key] = { create: { fileId: newFile.fileId } };
data[key] = { create: { fileId: newFile.fileId , filename: newFile.filename} };
return;
}

Expand Down Expand Up @@ -166,7 +166,7 @@ export const normalize8BaseDocumentsDeleteAndUpdate = (data: Record<string, any>
data[key] = {};
if (toBeCreated.length > 0)
data[key].create = toBeCreated.map(file => {
return { fileId: file.fileId };
return { fileId: file.fileId , filename: file.filename};
});
if (toBeDeleted.length > 0)
data[key].disconnect = toBeDeleted.map(file => {
Expand Down