Skip to content

Commit 6715a4d

Browse files
Add Recycle Bin Functionality (#35) (#55)
2 parents 9a9b889 + a469a5b commit 6715a4d

File tree

9 files changed

+974
-515
lines changed

9 files changed

+974
-515
lines changed

backend/package-lock.json

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/routes/auth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ router.post('/forgotpassword', [
323323

324324
transporter.sendMail(options, (err, info) => {
325325
if (err) {
326+
console.log(err);
326327
return res.status(400).json({ error: "Internal Server Error!" });
327-
console.log(error);
328328
}
329329
console.log(info.response);
330330

backend/routes/notes.js

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
7474
router.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+
136182
module.exports = router;

0 commit comments

Comments
 (0)