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({
where: {
ownerId: userid
ownerId: userId
}
})
if (!myNotes) {
return callback(null, null)
}
try {
const myNoteList = []
for (let i = 0; i < myNotes.length; i++) {
const note = myNotes[i]
myNoteList[i] = {
const myNoteList = myNotes.map(note => ({
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)
logger.info('Parse myNoteList success: ' + userId)
}
return callback(null, myNoteList)
} catch (err) {