mirror of https://github.com/status-im/codimd.git
Refactor, use body parser, adjust update api content column
Signed-off-by: James Tsai <jamesscamel@gmail.com>
This commit is contained in:
parent
53526c154a
commit
04fe74d520
|
@ -8,7 +8,6 @@ const { newCheckViewPermission, errorForbidden, responseCodiMD, errorNotFound, e
|
||||||
const { updateHistory, historyDelete } = require('../history')
|
const { updateHistory, historyDelete } = require('../history')
|
||||||
const { actionPublish, actionSlide, actionInfo, actionDownload, actionPDF, actionGist, actionRevision, actionPandoc } = require('./noteActions')
|
const { actionPublish, actionSlide, actionInfo, actionDownload, actionPDF, actionGist, actionRevision, actionPandoc } = require('./noteActions')
|
||||||
const realtime = require('../realtime/realtime')
|
const realtime = require('../realtime/realtime')
|
||||||
const moment = require('moment')
|
|
||||||
|
|
||||||
async function getNoteById (noteId, { includeUser } = { includeUser: false }) {
|
async function getNoteById (noteId, { includeUser } = { includeUser: false }) {
|
||||||
const id = await Note.parseNoteIdAsync(noteId)
|
const id = await Note.parseNoteIdAsync(noteId)
|
||||||
|
@ -291,7 +290,7 @@ const updateNote = async (req, res) => {
|
||||||
const content = req.body.content
|
const content = req.body.content
|
||||||
const updated = await note.update({
|
const updated = await note.update({
|
||||||
content: content,
|
content: content,
|
||||||
lastchangeAt: moment(now).format('YYYY-MM-DD HH:mm:ss'),
|
lastchangeAt: now,
|
||||||
authorship: [
|
authorship: [
|
||||||
[
|
[
|
||||||
req.user.id,
|
req.user.id,
|
||||||
|
@ -309,14 +308,17 @@ const updateNote = async (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
Revision.saveNoteRevision(note, (err, revision) => {
|
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)
|
if (!revision) return errorNotFound(req, res)
|
||||||
})
|
res.send({
|
||||||
|
status: 'ok'
|
||||||
res.send({
|
})
|
||||||
status: 'ok'
|
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
logger.error(err)
|
||||||
logger.error('Update note failed: Internal Error.')
|
logger.error('Update note failed: Internal Error.')
|
||||||
return errorInternalError(req, res)
|
return errorInternalError(req, res)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ const historyController = require('./history')
|
||||||
const userController = require('./user')
|
const userController = require('./user')
|
||||||
const noteController = require('./note')
|
const noteController = require('./note')
|
||||||
const response = require('./response')
|
const response = require('./response')
|
||||||
|
const bodyParser = require('body-parser')
|
||||||
const appRouter = Router()
|
const appRouter = Router()
|
||||||
|
|
||||||
// register route
|
// register route
|
||||||
|
@ -75,7 +76,7 @@ appRouter.get('/api/notes/myNotes', noteController.listMyNotes)
|
||||||
// delete note by id
|
// delete note by id
|
||||||
appRouter.delete('/api/notes/:noteId', noteController.deleteNote)
|
appRouter.delete('/api/notes/:noteId', noteController.deleteNote)
|
||||||
// update note content by id
|
// 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
|
// get note by id
|
||||||
appRouter.get('/:noteId', wrap(noteController.showNote))
|
appRouter.get('/:noteId', wrap(noteController.showNote))
|
||||||
// note actions
|
// note actions
|
||||||
|
|
Loading…
Reference in New Issue