Przeglądaj źródła

find unopened notifications by userId

kaori 4 lat temu
rodzic
commit
777d0be44a

+ 11 - 13
packages/app/src/server/routes/apiv3/in-app-notification.ts

@@ -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;

+ 6 - 0
packages/app/src/server/service/in-app-notification.ts

@@ -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 };