@@ -104,19 +104,17 @@ module.exports = (crowi) => {
});
router.put('/all-statuses-open', accessTokenParser, loginRequiredStrictly, csrf, async(req, res) => {
- // const user = req.user;
- // const id = req.body.id;
- console.log('api叩かれた');
-
- // try {
- // // findする
- // const notifications = await inAppNotificationService.markAllNotificationsAsOpened(user);
- // const result = { notifications };
- // return res.apiv3(result);
- // }
- // catch (err) {
- // return res.apiv3Err(err);
+ const user = req.user;
+
+ try {
+ const notifications = await inAppNotificationService.updateAllNotificationsAsOpened(user);
+ const result = { notifications };
+ return res.apiv3(result);
+ }
+ catch (err) {
+ return res.apiv3Err(err);
return router;
@@ -138,6 +138,12 @@ export default class InAppNotificationService {
return;
}
+ updateAllNotificationsAsOpened = async function(user: IUser & HasObjectId): Promise<void> {
+ const unopenedNotificatins = await InAppNotification.find({ user: user._id, status: 'UNOPENED' });
+ console.log('notifiunopenedNotificatinscatins', unopenedNotificatins);
+ return;
getUnreadCountByUser = async function(user: Types.ObjectId): Promise<number| undefined> {
const query = { user, status: STATUS_UNREAD };