From e7b72df51f61df0f83a8867d3b8c0bf3a3363cb8 Mon Sep 17 00:00:00 2001
From: Alan Chamathil <77508072+AlanChamathil@users.noreply.github.com>
Date: Mon, 27 Mar 2023 14:09:02 +0100
Subject: [PATCH] Added delete all notification

---
 src/index.js               | 10 +++++-----
 src/routes/notification.js | 19 ++++++++++++++++++-
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/index.js b/src/index.js
index 0562aec..0d18b90 100644
--- a/src/index.js
+++ b/src/index.js
@@ -8,16 +8,16 @@ const app = express();
 app.use(express.json());
 
 app.get("/",(req,res) =>{
-  console.log("testing")
-  res.send("Hello")
+  console.log("testing");
+  res.send("Hello");
   
 })
 
-const notificationRouter = require("./routes/notification")
-app.use("/notification",notificationRouter)
+const notificationRouter = require("./routes/notification");
+app.use("/notification",notificationRouter);
 
   app.listen(3001, function(){
-    console.log("Notifcation Microservice is running ...")
+    console.log("Notifcation Microservice is running ...");
   })
 
 
diff --git a/src/routes/notification.js b/src/routes/notification.js
index a1b1388..fbe6c86 100644
--- a/src/routes/notification.js
+++ b/src/routes/notification.js
@@ -30,7 +30,7 @@ router.get("/info/:id", async (req,res) =>{
   
   
   router.delete("/delete/:id", async (req,res) =>{
-    // delete the notifications
+    // delete a notification
     // grab the notification id
     // delete on the database
     try{
@@ -44,6 +44,23 @@ router.get("/info/:id", async (req,res) =>{
     }
 
   });
+
+  router.delete("/delete/all/:id", async (req,res) =>{
+    // delete all the notifications
+    // grab the user id
+    // delete on the database
+    try{
+      const notifications = await Notification.deleteMany({userid:req.params.id})
+      if(!notifications){
+            return res.status(404).send();
+       }
+      res.send(notifications);
+    }catch(error){
+      res.status(500).send(error);
+    }
+
+  });
+
   
   
   router.post("/create", async (req,res) => {
-- 
GitLab