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

delete entities files now ignores file do not exist error #902

Merged
merged 2 commits into from
Mar 28, 2017
Merged
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
10 changes: 9 additions & 1 deletion app/api/entities/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,15 @@ export default {
return `./uploaded_documents/${doc.file.filename}`;
});
filesToDelete = filesToDelete.filter((doc, index) => filesToDelete.indexOf(doc) === index);
return deleteFiles(filesToDelete);
return deleteFiles(filesToDelete)
.catch((error) => {
const fileNotExist = -2;
if (error.errno === fileNotExist) {
return Promise.resolve();
}

return Promise.reject(error);
});
},

deleteMultiple(sharedIds) {
Expand Down
12 changes: 12 additions & 0 deletions app/api/entities/specs/entities.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,18 @@ describe('entities', () => {
fs.writeFileSync('./uploaded_documents/8202c463d6158af8065022d9b5014cc1.pdf');
});

describe('when the original file does not exist', () => {
it('should delete the entiti and not throw an error', (done) => {
entities.delete('shared1')
.then(() => entities.get({sharedId: 'shared1'}))
.then((response) => {
expect(response.length).toBe(0);
done();
})
.catch(catchErrors(done));
});
});

it('should delete the document in the database', (done) => {
entities.delete('shared')
.then(() => entities.get({sharedId: 'shared'}))
Expand Down
2 changes: 1 addition & 1 deletion app/api/entities/specs/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
_id: db.id(), sharedId: 'shared', type: 'entity', language: 'pt', title: 'Penguin almost done', creationDate: 1, published: true, metadata: {text: 'test'}
},
//select/multiselect/date sync
{_id: syncPropertiesEntityId, template: templateId, sharedId: 'shared1', type: 'entity', language: 'en', title: 'EN', published: true, metadata: {property1: 'text'}},
{_id: syncPropertiesEntityId, template: templateId, sharedId: 'shared1', type: 'entity', language: 'en', title: 'EN', published: true, metadata: {property1: 'text'}, file: {filename: 'nonexistent.pdf'}},
{_id: db.id(), template: templateId, sharedId: 'shared1', type: 'entity', language: 'es', title: 'ES', creationDate: 1, published: true, metadata: {property1: 'text'}},
{_id: db.id(), template: templateId, sharedId: 'shared1', type: 'entity', language: 'pt', title: 'PT', creationDate: 1, published: true, metadata: {property1: 'text'}},
//docs to change metadata property names
Expand Down
2 changes: 1 addition & 1 deletion app/api/utils/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function deleteFile(file) {
}

function deleteFiles(files) {
return Promise.all(files.map((file) => deleteFile(file)))
return Promise.all(files.map((file) => deleteFile(file)));
}

export {deleteFiles, deleteFile};