diff --git a/server/api/documents.js b/server/api/documents.js index d5985be9b..efc0ef0a6 100644 --- a/server/api/documents.js +++ b/server/api/documents.js @@ -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; \ No newline at end of file +export default router; diff --git a/server/models/Atlas.js b/server/models/Atlas.js index f6f778d22..7fc61cf0b 100644 --- a/server/models/Atlas.js +++ b/server/models/Atlas.js @@ -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);