Document editing

This commit is contained in:
Jori Lallo
2016-05-25 21:26:06 -07:00
parent 814ed7b2da
commit 4c6964ad07
16 changed files with 261 additions and 52 deletions

View File

@@ -62,4 +62,34 @@ router.post('documents.create', auth(), async (ctx) => {
};
});
router.post('documents.update', auth(), async (ctx) => {
let {
id,
title,
text,
} = ctx.request.body;
ctx.assertPresent(id, 'id is required');
ctx.assertPresent(title, 'title is required');
ctx.assertPresent(text, 'text is required');
const user = ctx.state.user;
const team = await user.getTeam();
let document = await Document.findOne({
where: {
id: id,
teamId: team.id,
},
});
if (!document) throw httpErrors.BadRequest();
document.title = title;
document.text = text;
await document.save();
ctx.body = {
data: await presentDocument(document, true),
};
});
export default router;