File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -259,8 +259,42 @@ const deleteNote = async (req, res) => {
259259 }
260260}
261261
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+
262295exports . showNote = showNote
263296exports . showPublishNote = showPublishNote
264297exports . noteActions = noteActions
265298exports . listMyNotes = listMyNotes
266299exports . 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)
7474appRouter . get ( '/api/notes/myNotes' , noteController . listMyNotes )
7575// delete note by id
7676appRouter . delete ( '/api/notes/:noteId' , noteController . deleteNote )
77+ // update note content by id
78+ appRouter . put ( '/api/notes/:noteId' , urlencodedParser , noteController . updateNote )
7779// get note by id
7880appRouter . get ( '/:noteId' , wrap ( noteController . showNote ) )
7981// note actions
You can’t perform that action at this time.
0 commit comments