Skip to content
Snippets Groups Projects
Commit e91a61cd authored by Alan Chamathil's avatar Alan Chamathil
Browse files

updated to async and await

parent dd9c359d
No related branches found
No related tags found
No related merge requests found
...@@ -14,65 +14,49 @@ const Notification = require('../schema/schema') ...@@ -14,65 +14,49 @@ const Notification = require('../schema/schema')
// get that repsond - delete the notifcations from the database // get that repsond - delete the notifcations from the database
router.get("/info/:id",(req,res) =>{ router.get("/info/:id", async (req,res) =>{
// grab the userid // grab the userid
// retrieve all the notifcations stored in the database // retrieve all the notifcations stored in the database
try{
Notification.find({userid:req.params.id}).then((notifiaction) => { const notifications = await Notification.find({userid:req.params.id});
if(!notifiaction){ res.status(200).send(notifications);
return res.status(404).send(); }catch(error){
} res.status(500).send(error);
res.send(notifiaction); }
}).catch((error) => {
res.status(500).send(error);
})
// send the notifications to the notification page // send the notifications to the notification page
});
})
router.delete("/delete/:id",(req,res) =>{ router.delete("/delete/:id", async (req,res) =>{
//64216d2a4341c23ccfa83506
// delete the notifications // delete the notifications
// grab the notification id // grab the notification id
// delete on the database // delete on the database
try{
Notification.findByIdAndDelete(req.params.id).then((notifiaction) => { const notifications = await Notification.findByIdAndDelete(req.params.id)
if(!notifiaction){ if(!notifications){
return res.status(404).send(); return res.status(404).send();
} }
res.send(notifiaction); res.send(notifications);
}).catch((error) => { }catch(error){
res.status(500).send(error); res.status(500).send(error);
}) }
}) });
router.post("/create", (req,res) => { router.post("/create", async (req,res) => {
//recieve the notifcation info from the user //recieve the notifcation info from the user
// const user_id = req.body['user_id'];
// const title = req.body['title'];
// const description = req.body['description'];
// const time = new Date();
// send the notifcation to the database (create/save/insert methods) // send the notifcation to the database (create/save/insert methods)
const notifications = new Notification(req.body);
const notification = new Notification(req.body); try{
notification.save().then((notifiaction)=>{ await notifications.save();
res.status(201).send(notifiaction) res.status(201).send(notifications);
}).catch((error)=>{ } catch (error){
res.status(400).send(error); res.status(400).send(error);
}) }
}); });
module.exports = router module.exports = router
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment