server: notificationService: replace callbacks with promises

This commit is contained in:
Jesse Chan
2020-12-28 21:35:54 +08:00
parent d29873b62b
commit 4239ecf80e
4 changed files with 110 additions and 86 deletions
+33 -2
View File
@@ -70,12 +70,43 @@ router.get<unknown, unknown, unknown, {snapshot: HistorySnapshot}>('/history', (
);
});
/**
* GET /api/notifications
* @summary Gets notifications
* @tags Flood
* @security User
* @param {NotificationFetchOptions} queries - options
* @return {{Notification[][], NotificationCount}} 200 - success response - application/json
* @return {Error} 500 - failure response - application/json
*/
router.get<unknown, unknown, unknown, NotificationFetchOptions>('/notifications', (req, res) => {
req.services?.notificationService.getNotifications(req.query, getResponseFn(res));
req.services?.notificationService.getNotifications(req.query).then(
(notifications) => {
res.status(200).json(notifications);
},
(err: Error) => {
res.status(500).json({message: err.message});
},
);
});
/**
* DELETE /api/notifications
* @summary Clears notifications
* @tags Flood
* @security User
* @return 200 - success response
* @return {Error} 500 - failure response - application/json
*/
router.delete('/notifications', (req, res) => {
req.services?.notificationService.clearNotifications(getResponseFn(res));
req.services?.notificationService.clearNotifications().then(
() => {
res.status(200).send();
},
(err: Error) => {
res.status(500).json({message: err.message});
},
);
});
/**