Addressed user feedback

This commit is contained in:
Jori Lallo
2017-09-24 13:51:33 -07:00
parent 3648c11a41
commit a5a1e286d4
5 changed files with 89 additions and 42 deletions

View File

@@ -133,16 +133,23 @@ Collection.prototype.addDocumentToStructure = async function(document, index) {
// Sequelize doesn't seem to set the value with splice on JSONB field
this.documentStructure = this.documentStructure;
} else {
this.documentStructure = this.documentStructure.map(childDocument => {
if (document.parentDocumentId === childDocument.id) {
childDocument.children.splice(
index || childDocument.children.length,
0,
document.toJSON()
);
}
return childDocument;
});
// Recursively place document
const placeDocument = documentList => {
return documentList.map(childDocument => {
if (document.parentDocumentId === childDocument.id) {
childDocument.children.splice(
index || childDocument.children.length,
0,
document.toJSON()
);
} else {
childDocument.children = placeDocument(childDocument.children);
}
return childDocument;
});
};
this.documentStructure = placeDocument(this.documentStructure);
}
await this.save();