Fixed Collection#updateDocument

This commit is contained in:
Jori Lallo
2017-06-04 22:12:36 -07:00
parent c229369efd
commit a4dca58ae7
4 changed files with 85 additions and 57 deletions

View File

@@ -157,18 +157,16 @@ router.post('documents.create', auth(), async ctx => {
router.post('documents.update', auth(), async ctx => {
const { id, title, text } = ctx.body;
ctx.assertPresent(id, 'id is required');
ctx.assertPresent(title, 'title is required');
ctx.assertPresent(text, 'text is required');
ctx.assertPresent(title || text, 'title or text is required');
const user = ctx.state.user;
const document = await getDocumentForId(id);
if (!document || document.teamId !== user.teamId)
throw httpErrors.BadRequest();
if (!document || document.teamId !== user.teamId) throw httpErrors.NotFound();
// Update document
document.title = title;
document.text = text;
if (title) document.title = title;
if (text) document.text = text;
document.lastModifiedById = user.id;
await document.save();
@@ -181,6 +179,7 @@ router.post('documents.update', auth(), async ctx => {
data: await presentDocument(ctx, document, {
includeCollection: true,
includeCollaborators: true,
collection: collection,
}),
};
});