File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -259,8 +259,42 @@ const deleteNote = async (req, res) => {
259
259
}
260
260
}
261
261
262
+ const updateNote = async ( req , res ) => {
263
+ if ( req . isAuthenticated ( ) ) {
264
+ const noteId = await Note . parseNoteIdAsync ( req . params . noteId )
265
+ try {
266
+ const note = await Note . findOne ( {
267
+ where : {
268
+ id : noteId ,
269
+ }
270
+ } )
271
+ if ( ! note ) {
272
+ logger . error ( 'Update note failed: Can\'t find the note.' )
273
+ return errorNotFound ( req , res )
274
+ }
275
+
276
+ const updated = await note . update ( {
277
+ content : req . body . content ,
278
+ } )
279
+ if ( ! updated ) {
280
+ logger . error ( 'Update note failed: Write data error.' )
281
+ return errorInternalError ( req , res )
282
+ }
283
+ res . send ( {
284
+ status : 'ok'
285
+ } )
286
+ } catch ( err ) {
287
+ logger . error ( 'Update note failed: Internal Error.' )
288
+ return errorInternalError ( req , res )
289
+ }
290
+ } else {
291
+ return errorForbidden ( req , res )
292
+ }
293
+ }
294
+
262
295
exports . showNote = showNote
263
296
exports . showPublishNote = showPublishNote
264
297
exports . noteActions = noteActions
265
298
exports . listMyNotes = listMyNotes
266
299
exports . deleteNote = deleteNote
300
+ exports . updateNote = updateNote
Original file line number Diff line number Diff line change @@ -74,6 +74,8 @@ appRouter.get('/p/:shortid/:action', response.publishSlideActions)
74
74
appRouter . get ( '/api/notes/myNotes' , noteController . listMyNotes )
75
75
// delete note by id
76
76
appRouter . delete ( '/api/notes/:noteId' , noteController . deleteNote )
77
+ // update note content by id
78
+ appRouter . put ( '/api/notes/:noteId' , urlencodedParser , noteController . updateNote )
77
79
// get note by id
78
80
appRouter . get ( '/:noteId' , wrap ( noteController . showNote ) )
79
81
// note actions
You can’t perform that action at this time.
0 commit comments