Skip to content

Commit

Permalink
Merge pull request #902 from huridocs/873
Browse files Browse the repository at this point in the history
delete entities files now ignores file do not exist error
  • Loading branch information
konzz authored Mar 28, 2017
2 parents 37ae890 + 375ad89 commit 19d7444
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
10 changes: 9 additions & 1 deletion app/api/entities/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,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 @@ -415,6 +415,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 @@ -19,7 +19,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};

0 comments on commit 19d7444

Please sign in to comment.