Refactor, variable naming and myNoteList mapping

Signed-off-by: James Tsai <jamesscamel@gmail.com>
This commit is contained in:
James Tsai 2020-07-14 15:38:02 +08:00
parent dcf48e749e
commit a22cf73f60
1 changed files with 18 additions and 22 deletions

View File

@ -189,30 +189,26 @@ async function noteActions (req, res) {
} }
} }
async function getMyNoteList (userid, callback) { async function getMyNoteList(userId, callback) {
const myNotes = await Note.findAll({ const myNotes = await Note.findAll({
where: { where: {
ownerId: userid ownerId: userId
} }
}) })
if (!myNotes) { if (!myNotes) {
return callback(null, null) return callback(null, null)
} }
try { try {
const myNoteList = [] const myNoteList = myNotes.map(note => ({
for (let i = 0; i < myNotes.length; i++) {
const note = myNotes[i]
myNoteList[i] = {
id: Note.encodeNoteId(note.id), id: Note.encodeNoteId(note.id),
text: note.title, text: note.title,
tags: Note.parseNoteInfo(note.content).tags, tags: Note.parseNoteInfo(note.content).tags,
createdAt: note.createdAt, createdAt: note.createdAt,
lastchangeAt: note.lastchangeAt, lastchangeAt: note.lastchangeAt,
shortId: note.shortid shortId: note.shortid
} }))
}
if (config.debug) { if (config.debug) {
logger.info('Parse myNoteList success: ' + userid) logger.info('Parse myNoteList success: ' + userId)
} }
return callback(null, myNoteList) return callback(null, myNoteList)
} catch (err) { } catch (err) {