Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
notification-service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Group 5
notification-service
Commits
e91a61cd
Commit
e91a61cd
authored
2 years ago
by
Alan Chamathil
Browse files
Options
Downloads
Patches
Plain Diff
updated to async and await
parent
dd9c359d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/routes/notification.js
+27
-43
27 additions, 43 deletions
src/routes/notification.js
with
27 additions
and
43 deletions
src/routes/notification.js
+
27
−
43
View file @
e91a61cd
...
...
@@ -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
(
!
notifi
a
ction
){
return
res
.
status
(
404
).
send
();
}
res
.
send
(
notifi
a
ction
);
}
).
catch
(
(
error
)
=>
{
try
{
const
notifications
=
await
Notification
.
findByIdAndDelete
(
req
.
params
.
id
)
if
(
!
notific
a
tion
s
){
return
res
.
status
(
404
).
send
();
}
res
.
send
(
notific
a
tion
s
);
}
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment