kaori 4 лет назад
Родитель
Сommit
df2d319cfc

+ 2 - 1
packages/app/src/components/InAppNotification/InAppNotificationPage.tsx

@@ -21,7 +21,7 @@ const InAppNotificationPageBody: FC<Props> = (props) => {
   const limit = appContainer.config.pageLimitationXL;
   const [activePageOfAllNotificationCat, setActivePage] = useState(1);
   const offsetOfAllNotificationCat = (activePageOfAllNotificationCat - 1) * limit;
-  const { data: allNotificationData } = useSWRxInAppNotifications(limit, offsetOfAllNotificationCat);
+  const { data: allNotificationData, mutate } = useSWRxInAppNotifications(limit, offsetOfAllNotificationCat);
 
   const [activePageOfUnopenedNotificationCat, setActiveUnopenedNotificationPage] = useState(1);
   const offsetOfUnopenedNotificationCat = (activePageOfUnopenedNotificationCat - 1) * limit;
@@ -66,6 +66,7 @@ const InAppNotificationPageBody: FC<Props> = (props) => {
 
   const updateUnopendNotificationStatusesToOpened = async() => {
     await apiv3Put('/in-app-notification/all-statuses-open');
+    mutate();
   };
 
   // commonize notification lists by 81953

+ 2 - 4
packages/app/src/server/routes/apiv3/in-app-notification.ts

@@ -107,10 +107,8 @@ module.exports = (crowi) => {
     const user = req.user;
 
     try {
-      const notifications = await inAppNotificationService.updateAllNotificationsAsOpened(user);
-
-      const result = { notifications };
-      return res.apiv3(result);
+      await inAppNotificationService.updateAllNotificationsAsOpened(user);
+      return res.apiv3();
     }
     catch (err) {
       return res.apiv3Err(err);

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

@@ -1,6 +1,6 @@
 import { Types } from 'mongoose';
 import { subDays } from 'date-fns';
-import { InAppNotificationStatuses, PaginateResult } from '~/interfaces/in-app-notification';
+import { InAppNotificationStatuses, PaginateResult, IInAppNotification } from '~/interfaces/in-app-notification';
 import Crowi from '../crowi';
 import {
   InAppNotification,
@@ -12,6 +12,7 @@ import InAppNotificationSettings from '~/server/models/in-app-notification-setti
 import Subscription, { STATUS_SUBSCRIBE } from '~/server/models/subscription';
 
 import { IUser } from '~/interfaces/user';
+
 import { HasObjectId } from '~/interfaces/has-object-id';
 import loggerFactory from '~/utils/logger';
 import { RoomPrefix, getRoomNameWithId } from '../util/socket-io-helpers';
@@ -139,8 +140,10 @@ export default class InAppNotificationService {
   }
 
   updateAllNotificationsAsOpened = async function(user: IUser & HasObjectId): Promise<void> {
-    const unopenedNotificatins = await InAppNotification.find({ user: user._id, status: 'UNOPENED' });
-    console.log('notifiunopenedNotificatinscatins', unopenedNotificatins);
+    const filter = { user: user._id, status: STATUS_UNOPENED };
+    const options = { status: STATUS_OPENED };
+
+    await InAppNotification.updateMany(filter, options);
     return;
   }