diff --git a/lib/note/index.js b/lib/note/index.js index 9ae7a160..de401883 100644 --- a/lib/note/index.js +++ b/lib/note/index.js @@ -8,7 +8,6 @@ const { newCheckViewPermission, errorForbidden, responseCodiMD, errorNotFound, e const { updateHistory, historyDelete } = require('../history') const { actionPublish, actionSlide, actionInfo, actionDownload, actionPDF, actionGist, actionRevision, actionPandoc } = require('./noteActions') const realtime = require('../realtime/realtime') -const moment = require('moment') async function getNoteById (noteId, { includeUser } = { includeUser: false }) { const id = await Note.parseNoteIdAsync(noteId) @@ -291,7 +290,7 @@ const updateNote = async (req, res) => { const content = req.body.content const updated = await note.update({ content: content, - lastchangeAt: moment(now).format('YYYY-MM-DD HH:mm:ss'), + lastchangeAt: now, authorship: [ [ req.user.id, @@ -309,14 +308,17 @@ const updateNote = async (req, res) => { } Revision.saveNoteRevision(note, (err, revision) => { - if (err) return errorInternalError(req, res) + if (err) { + logger.error(err) + return errorInternalError(req, res) + } if (!revision) return errorNotFound(req, res) - }) - - res.send({ - status: 'ok' + res.send({ + status: 'ok' + }) }) } catch (err) { + logger.error(err) logger.error('Update note failed: Internal Error.') return errorInternalError(req, res) } diff --git a/lib/routes.js b/lib/routes.js index 744339e5..9d15c349 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -12,6 +12,7 @@ const historyController = require('./history') const userController = require('./user') const noteController = require('./note') const response = require('./response') +const bodyParser = require('body-parser') const appRouter = Router() // register route @@ -75,7 +76,7 @@ appRouter.get('/api/notes/myNotes', noteController.listMyNotes) // delete note by id appRouter.delete('/api/notes/:noteId', noteController.deleteNote) // update note content by id -appRouter.put('/api/notes/:noteId', urlencodedParser, noteController.updateNote) +appRouter.put('/api/notes/:noteId', bodyParser.json(), noteController.updateNote) // get note by id appRouter.get('/:noteId', wrap(noteController.showNote)) // note actions