@@ -8,7 +8,7 @@ const { newCheckViewPermission, errorForbidden, responseCodiMD, errorNotFound, e
8
8
const { updateHistory } = require ( '../history' )
9
9
const { actionPublish, actionSlide, actionInfo, actionDownload, actionPDF, actionGist, actionRevision, actionPandoc } = require ( './noteActions' )
10
10
11
- async function getNoteById ( noteId , { includeUser } = { includeUser : false } ) {
11
+ async function getNoteById ( noteId , { includeUser } = { includeUser : false } ) {
12
12
const id = await Note . parseNoteIdAsync ( noteId )
13
13
14
14
const includes = [ ]
@@ -32,7 +32,7 @@ async function getNoteById (noteId, { includeUser } = { includeUser: false }) {
32
32
return note
33
33
}
34
34
35
- async function createNote ( userId , noteAlias ) {
35
+ async function createNote ( userId , noteAlias ) {
36
36
if ( ! config . allowAnonymous && ! userId ) {
37
37
throw new Error ( 'can not create note' )
38
38
}
@@ -50,7 +50,7 @@ async function createNote (userId, noteAlias) {
50
50
}
51
51
52
52
// controller
53
- async function showNote ( req , res ) {
53
+ async function showNote ( req , res ) {
54
54
const noteId = req . params . noteId
55
55
const userId = req . user ? req . user . id : null
56
56
@@ -78,7 +78,7 @@ async function showNote (req, res) {
78
78
return responseCodiMD ( res , note )
79
79
}
80
80
81
- function canViewNote ( note , isLogin , userId ) {
81
+ function canViewNote ( note , isLogin , userId ) {
82
82
if ( note . permission === 'private' ) {
83
83
return note . ownerId === userId
84
84
}
@@ -88,7 +88,7 @@ function canViewNote (note, isLogin, userId) {
88
88
return true
89
89
}
90
90
91
- async function showPublishNote ( req , res ) {
91
+ async function showPublishNote ( req , res ) {
92
92
const shortid = req . params . shortid
93
93
94
94
const note = await getNoteById ( shortid , {
@@ -141,7 +141,7 @@ async function showPublishNote (req, res) {
141
141
res . render ( 'pretty.ejs' , data )
142
142
}
143
143
144
- async function noteActions ( req , res ) {
144
+ async function noteActions ( req , res ) {
145
145
const noteId = req . params . noteId
146
146
147
147
const note = await getNoteById ( noteId )
@@ -189,30 +189,26 @@ async function noteActions (req, res) {
189
189
}
190
190
}
191
191
192
- async function getMyNoteList ( userid , callback ) {
192
+ async function getMyNoteList ( userId , callback ) {
193
193
const myNotes = await Note . findAll ( {
194
194
where : {
195
- ownerId : userid
195
+ ownerId : userId
196
196
}
197
197
} )
198
198
if ( ! myNotes ) {
199
199
return callback ( null , null )
200
200
}
201
201
try {
202
- const myNoteList = [ ]
203
- for ( let i = 0 ; i < myNotes . length ; i ++ ) {
204
- const note = myNotes [ i ]
205
- myNoteList [ i ] = {
206
- id : Note . encodeNoteId ( note . id ) ,
207
- text : note . title ,
208
- tags : Note . parseNoteInfo ( note . content ) . tags ,
209
- createdAt : note . createdAt ,
210
- lastchangeAt : note . lastchangeAt ,
211
- shortId : note . shortid
212
- }
213
- }
202
+ const myNoteList = myNotes . map ( note => ( {
203
+ id : Note . encodeNoteId ( note . id ) ,
204
+ text : note . title ,
205
+ tags : Note . parseNoteInfo ( note . content ) . tags ,
206
+ createdAt : note . createdAt ,
207
+ lastchangeAt : note . lastchangeAt ,
208
+ shortId : note . shortid
209
+ } ) )
214
210
if ( config . debug ) {
215
- logger . info ( 'Parse myNoteList success: ' + userid )
211
+ logger . info ( 'Parse myNoteList success: ' + userId )
216
212
}
217
213
return callback ( null , myNoteList )
218
214
} catch ( err ) {
@@ -221,7 +217,7 @@ async function getMyNoteList (userid, callback) {
221
217
}
222
218
}
223
219
224
- function listMyNotes ( req , res ) {
220
+ function listMyNotes ( req , res ) {
225
221
if ( req . isAuthenticated ( ) ) {
226
222
getMyNoteList ( req . user . id , ( err , myNoteList ) => {
227
223
if ( err ) return errorInternalError ( req , res )
0 commit comments