2
0
Эх сурвалжийг харах

success fetchNotificationStatus

Shun Miyazawa 4 жил өмнө
parent
commit
d7a24ca754

+ 14 - 1
packages/app/src/components/InAppNotification/InAppNotificationDropdown.tsx

@@ -4,6 +4,7 @@ import {
 } from 'reactstrap';
 import PropTypes from 'prop-types';
 import AppContainer from '~/client/services/AppContainer';
+import { toastError } from '~/client/util/apiNotification';
 import { withUnstatedContainers } from '../UnstatedUtils';
 import { InAppNotification as IInAppNotification } from '../../interfaces/in-app-notification';
 // import DropdownMenu from './InAppNotificationDropdown/DropdownMenu';
@@ -33,7 +34,7 @@ const InAppNotificationDropdown: FC = (props) => {
   useEffect(() => {
     initializeSocket(props);
     fetchNotificationList(props);
-    // fetchNotificationStatus();
+    fetchNotificationStatus(props);
   }, []);
 
   const initializeSocket = (props) => {
@@ -70,6 +71,18 @@ const InAppNotificationDropdown: FC = (props) => {
   //   }
   // }
 
+  const fetchNotificationStatus = async(props) => {
+    try {
+      const res = await props.appContainer.apiv3Get('in-app-notification/status');
+      const { count } = res.data;
+      console.log(count);
+      setCount(count);
+    }
+    catch (err) {
+      toastError(err);
+    }
+  };
+
   const updateNotificationStatus = () => {
     try {
       // await this.props.crowi.apiPost('/notification.read');

+ 5 - 3
packages/app/src/server/routes/apiv3/in-app-notification.ts

@@ -10,6 +10,8 @@ module.exports = (crowi) => {
   const loginRequiredStrictly = require('../../middlewares/login-required')(crowi);
   const csrf = require('../../middlewares/csrf')(crowi);
 
+  const { inAppNotificationService } = crowi;
+
   router.get('/list', accessTokenParser, loginRequiredStrictly, (req, res) => {
     const user = req.user;
 
@@ -57,14 +59,14 @@ module.exports = (crowi) => {
   });
 
   router.get('/status', accessTokenParser, loginRequiredStrictly, async(req, res) => {
-    const user = req.user;
-
+    const userId = req.user._id;
     try {
-      const count = await InAppNotification.getUnreadCountByUser(user._id);
+      const count = await inAppNotificationService.getUnreadCountByUser(userId);
       const result = { count };
       return res.apiv3(result);
     }
     catch (err) {
+      console.log(err);
       return res.apiv3Err(err);
     }
   });