Added ability to append to documents. Added test cases for the same (#963)
* added ability to append to documents. Added test cases for the same * made changes required for lint test * updated snapshot for document.test.js to reflect new test cases added * append should not enforce newline character
This commit is contained in:
@@ -600,9 +600,19 @@ router.post('documents.create', auth(), async ctx => {
|
||||
});
|
||||
|
||||
router.post('documents.update', auth(), async ctx => {
|
||||
const { id, title, text, publish, autosave, done, lastRevision } = ctx.body;
|
||||
const {
|
||||
id,
|
||||
title,
|
||||
text,
|
||||
publish,
|
||||
autosave,
|
||||
done,
|
||||
lastRevision,
|
||||
append,
|
||||
} = ctx.body;
|
||||
ctx.assertPresent(id, 'id is required');
|
||||
ctx.assertPresent(title || text, 'title or text is required');
|
||||
if (append) ctx.assertPresent(text, 'Text is required while appending');
|
||||
|
||||
const user = ctx.state.user;
|
||||
const document = await Document.findById(id);
|
||||
@@ -615,7 +625,12 @@ router.post('documents.update', auth(), async ctx => {
|
||||
|
||||
// Update document
|
||||
if (title) document.title = title;
|
||||
if (text) document.text = text;
|
||||
//append to document
|
||||
if (append) {
|
||||
document.text += text;
|
||||
} else if (text) {
|
||||
document.text = text;
|
||||
}
|
||||
document.lastModifiedById = user.id;
|
||||
|
||||
if (publish) {
|
||||
|
||||
Reference in New Issue
Block a user