Update nav tree after document update

This commit is contained in:
Jori Lallo
2016-06-30 23:47:49 -07:00
parent 34e59876bd
commit b5012c43a9
2 changed files with 9 additions and 2 deletions

View File

@@ -114,12 +114,19 @@ router.post('documents.update', auth(), async (ctx) => {
if (!document) throw httpErrors.BadRequest();
// Update document
document.title = title;
document.text = text;
document.lastModifiedById = user.id;
await document.save();
await document.createRevision();
// Update
const atlas = await Atlas.findById(document.atlasId);
if (atlas.type === 'atlas') {
await atlas.updateNavigationTree();
}
ctx.body = {
data: await presentDocument(document, true),
};
@@ -155,4 +162,4 @@ router.post('documents.delete', auth(), async (ctx) => {
};
});
export default router;
export default router;

View File

@@ -68,7 +68,7 @@ const Atlas = sequelize.define('atlas', {
return; // TODO should create a root doc
}
},
async updateNavigationTree(tree) {
async updateNavigationTree(tree = this.navigationTree) {
let nodeIds = [];
nodeIds.push(tree.id);