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')
// 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
// retrieve all the notifcations stored in the database
Notification.find({userid:req.params.id}).then((notifiaction) => {
if(!notifiaction){
return res.status(404).send();
}
res.send(notifiaction);
}).catch((error) => {
res.status(500).send(error);
})
try{
const notifications = await Notification.find({userid:req.params.id});
res.status(200).send(notifications);
}catch(error){
res.status(500).send(error);
}
// send the notifications to the notification page
})
});
router.delete("/delete/:id",(req,res) =>{
//64216d2a4341c23ccfa83506
router.delete("/delete/:id", async (req,res) =>{
// delete the notifications
// grab the notification id
// delete on the database
Notification.findByIdAndDelete(req.params.id).then((notifiaction) => {
if(!notifiaction){
return res.status(404).send();
}
res.send(notifiaction);
}).catch((error) => {
try{
const notifications = await Notification.findByIdAndDelete(req.params.id)
if(!notifications){
return res.status(404).send();
}
res.send(notifications);
}catch(error){
res.status(500).send(error);
})
}
})
});
router.post("/create", (req,res) => {
router.post("/create", async (req,res) => {
//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)
const notification = new Notification(req.body);
notification.save().then((notifiaction)=>{
res.status(201).send(notifiaction)
}).catch((error)=>{
res.status(400).send(error);
})
const notifications = new Notification(req.body);
try{
await notifications.save();
res.status(201).send(notifications);
} catch (error){
res.status(400).send(error);
}
});
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