Added API to update document tree

This commit is contained in:
Jori Lallo
2016-06-25 22:27:44 -07:00
parent 7ea6eb5d28
commit a0649e6fd3
11 changed files with 182 additions and 30 deletions

View File

@ -46,6 +46,7 @@ router.post('documents.create', auth(), async (ctx) => {
atlas,
title,
text,
parentDocument,
} = ctx.request.body;
ctx.assertPresent(atlas, 'atlas is required');
ctx.assertPresent(title, 'title is required');
@ -61,7 +62,18 @@ router.post('documents.create', auth(), async (ctx) => {
if (!ownerAtlas) throw httpErrors.BadRequest();
let parentDocumentObj;
if (parentDocument && ownerAtlas.type === 'atlas') {
parentDocumentObj = await Document.findOne({
where: {
id: parentDocument,
atlasId: ownerAtlas.id,
},
});
}
const document = await Document.create({
parentDocumentId: parentDocumentObj.id,
atlasId: ownerAtlas.id,
teamId: user.teamId,
userId: user.id,
@ -69,6 +81,10 @@ router.post('documents.create', auth(), async (ctx) => {
text: text,
});
// TODO: Move to afterSave hook if possible with imports
ownerAtlas.addNodeToNavigationTree(document);
await ownerAtlas.save();
ctx.body = {
data: await presentDocument(document, true),
};