@@ -53,7 +53,7 @@ router.delete('/deletenote/:id', fetchuser, async (req, res) => {
5353 const theNote = await NoteSchema . findById ( req . params . id ) ;
5454
5555 if ( theNote . authorId === theUser . id ) {
56- await theNote . delete ( ) ;
56+ await theNote . update ( { isDeleted : true } ) ;
5757 return res . status ( 200 ) . json ( { success : "Successfully Deleted the Note" } ) ;
5858 }
5959 else {
@@ -73,7 +73,7 @@ router.delete('/deletenote/:id', fetchuser, async (req, res) => {
7373// Route 3: Getting all user specific notes: GET: http://localhost:8181/api/notes/getallnotes. Login Required
7474router . get ( '/getallnotes' , fetchuser , async ( req , res ) => {
7575 try {
76- const allNotes = await NoteSchema . find ( { authorId : req . user . id } ) . sort ( { createdAt : - 1 } ) ;
76+ const allNotes = await NoteSchema . find ( { authorId : req . user . id , isDeleted : false } ) . sort ( { createdAt : - 1 } ) ;
7777 res . status ( 200 ) . json ( allNotes ) ;
7878
7979 } catch ( error ) {
@@ -133,4 +133,50 @@ router.put('/updatenote/:id', fetchuser, [
133133} ) ;
134134
135135
136+
137+ // ROUTE 6: Getting all the deleted notes: GET : http://localhost:8181/api/notes/bin. Login Required!!
138+ router . get ( '/bin' , fetchuser , async ( req , res ) => {
139+ try {
140+ const allDeletedNotes = await NoteSchema . find ( { authorId : req . user . id , isDeleted : true } ) ;
141+ return res . status ( 200 ) . json ( allDeletedNotes ) ;
142+
143+ } catch ( error ) {
144+ console . error ( error ) ;
145+ return res . status ( 500 ) . send ( "Internal Server Error" ) ;
146+ }
147+ } ) ;
148+
149+
150+
151+
152+
153+
154+
155+
156+ // ROUTE 7: Unarchiving a Note: PUT : http://localhost:8181/api/notes/unarchive/:id. Login Required!!
157+ router . put ( '/unarchive/:id' , fetchuser , async ( req , res ) => {
158+ try {
159+
160+ const theNote = await NoteSchema . findById ( req . params . id ) ;
161+ if ( theNote . authorId === req . user . id ) {
162+ // This note belongs to this user...
163+ await theNote . update ( { isDeleted : false } ) ;
164+ res . status ( 200 ) . json ( { success : "Successfully Unarchived the Note!!" } )
165+ }
166+ else {
167+ // This note doesn't belongs to this user...
168+ return res . status ( 403 ) . json ( { error : "Unauthorized Access" } ) ;
169+ }
170+
171+ } catch ( error ) {
172+ console . error ( error ) ;
173+ return res . status ( 500 ) . send ( "Internal Server Error" ) ;
174+ }
175+
176+
177+
178+ } ) ;
179+
180+
181+
136182module . exports = router ;
0 commit comments