Skip to content

Commit

Permalink
Add Recycle Bin Functionality (#35) (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
devarshishimpi authored Oct 1, 2022
2 parents 9a9b889 + a469a5b commit 6715a4d
Show file tree
Hide file tree
Showing 9 changed files with 974 additions and 515 deletions.
60 changes: 30 additions & 30 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ router.post('/forgotpassword', [

transporter.sendMail(options, (err, info) => {
if (err) {
console.log(err);
return res.status(400).json({ error: "Internal Server Error!" });
console.log(error);
}
console.log(info.response);

Expand Down
50 changes: 48 additions & 2 deletions backend/routes/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ router.delete('/deletenote/:id', fetchuser, async (req, res) => {
const theNote = await NoteSchema.findById(req.params.id);

if (theNote.authorId === theUser.id) {
await theNote.delete();
await theNote.update({ isDeleted: true });
return res.status(200).json({ success: "Successfully Deleted the Note" });
}
else {
Expand All @@ -73,7 +73,7 @@ router.delete('/deletenote/:id', fetchuser, async (req, res) => {
// Route 3: Getting all user specific notes: GET: http://localhost:8181/api/notes/getallnotes. Login Required
router.get('/getallnotes', fetchuser, async (req, res) => {
try {
const allNotes = await NoteSchema.find({ authorId: req.user.id }).sort({ createdAt: -1 });
const allNotes = await NoteSchema.find({ authorId: req.user.id, isDeleted: false }).sort({ createdAt: -1 });
res.status(200).json(allNotes);

} catch (error) {
Expand Down Expand Up @@ -133,4 +133,50 @@ router.put('/updatenote/:id', fetchuser, [
});



// ROUTE 6: Getting all the deleted notes: GET : http://localhost:8181/api/notes/bin. Login Required!!
router.get('/bin', fetchuser, async (req, res) => {
try {
const allDeletedNotes = await NoteSchema.find({ authorId: req.user.id, isDeleted: true });
return res.status(200).json(allDeletedNotes);

} catch (error) {
console.error(error);
return res.status(500).send("Internal Server Error");
}
});








// ROUTE 7: Unarchiving a Note: PUT : http://localhost:8181/api/notes/unarchive/:id. Login Required!!
router.put('/unarchive/:id', fetchuser, async (req, res) => {
try {

const theNote = await NoteSchema.findById(req.params.id);
if (theNote.authorId === req.user.id) {
// This note belongs to this user...
await theNote.update({ isDeleted: false });
res.status(200).json({ success: "Successfully Unarchived the Note!!" })
}
else {
// This note doesn't belongs to this user...
return res.status(403).json({ error: "Unauthorized Access" });
}

} catch (error) {
console.error(error);
return res.status(500).send("Internal Server Error");
}



});



module.exports = router;
Loading

0 comments on commit 6715a4d

Please sign in to comment.