mirror of https://github.com/status-im/codimd.git
Add list-my-note API
Signed-off-by: James Tsai <jamesscamel@gmail.com>
This commit is contained in:
parent
7b148457a7
commit
2973bfbceb
|
@ -2,10 +2,9 @@
|
||||||
|
|
||||||
const config = require('../config')
|
const config = require('../config')
|
||||||
const logger = require('../logger')
|
const logger = require('../logger')
|
||||||
|
|
||||||
const { Note, User } = require('../models')
|
const { Note, User } = require('../models')
|
||||||
|
|
||||||
const { newCheckViewPermission, errorForbidden, responseCodiMD, errorNotFound } = require('../response')
|
const { newCheckViewPermission, errorForbidden, responseCodiMD, errorNotFound, errorInternalError } = require('../response')
|
||||||
const { updateHistory } = require('../history')
|
const { updateHistory } = require('../history')
|
||||||
const { actionPublish, actionSlide, actionInfo, actionDownload, actionPDF, actionGist, actionRevision, actionPandoc } = require('./noteActions')
|
const { actionPublish, actionSlide, actionInfo, actionDownload, actionPDF, actionGist, actionRevision, actionPandoc } = require('./noteActions')
|
||||||
|
|
||||||
|
@ -190,6 +189,55 @@ async function noteActions (req, res) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getMyNoteList(userid, callback) {
|
||||||
|
const myNotes = await Note.findAll({
|
||||||
|
where: {
|
||||||
|
ownerId: userid
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (!myNotes) {
|
||||||
|
return callback(null, null)
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
let myNoteList = []
|
||||||
|
for (let i = 0; i < myNotes.length; i++) {
|
||||||
|
const note = myNotes[i]
|
||||||
|
myNoteList[i] = {
|
||||||
|
id: Note.encodeNoteId(note.id),
|
||||||
|
text: note.title,
|
||||||
|
tags: Note.parseNoteInfo(note.content).tags,
|
||||||
|
createdAt: note.createdAt,
|
||||||
|
lastchangeAt: note.lastchangeAt,
|
||||||
|
shortId: note.shortid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (config.debug) {
|
||||||
|
logger.info('Parse myNoteList success: ' + userid)
|
||||||
|
}
|
||||||
|
return callback(null, myNoteList)
|
||||||
|
} catch (err){
|
||||||
|
logger.error('Parse myNoteList failed')
|
||||||
|
return callback(err, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function listMyNotes(req, res) {
|
||||||
|
if (req.isAuthenticated()) {
|
||||||
|
getMyNoteList(req.user.id, (err, myNoteList) => {
|
||||||
|
if (err) return errorInternalError(req, res)
|
||||||
|
if (!myNoteList) return errorNotFound(req, res)
|
||||||
|
res.send({
|
||||||
|
myNotes: myNoteList
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return errorForbidden(req, res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exports.showNote = showNote
|
exports.showNote = showNote
|
||||||
exports.showPublishNote = showPublishNote
|
exports.showPublishNote = showPublishNote
|
||||||
exports.noteActions = noteActions
|
exports.noteActions = noteActions
|
||||||
|
exports.listMyNotes = listMyNotes
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,8 @@ appRouter.get('/s/:shortid/:action', response.publishNoteActions)
|
||||||
appRouter.get('/p/:shortid', response.showPublishSlide)
|
appRouter.get('/p/:shortid', response.showPublishSlide)
|
||||||
// publish slide actions
|
// publish slide actions
|
||||||
appRouter.get('/p/:shortid/:action', response.publishSlideActions)
|
appRouter.get('/p/:shortid/:action', response.publishSlideActions)
|
||||||
|
// gey my note list
|
||||||
|
appRouter.get('/myNotes', noteController.listMyNotes)
|
||||||
// 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