Shun Miyazawa 4 лет назад
Родитель
Сommit
89cb7f807d
1 измененных файлов с 21 добавлено и 0 удалено
  1. 21 0
      packages/app/src/server/routes/apiv3/personal-setting.js

+ 21 - 0
packages/app/src/server/routes/apiv3/personal-setting.js

@@ -4,6 +4,8 @@ import loggerFactory from '~/utils/logger';
 
 import { listLocaleIds } from '~/utils/locale-utils';
 
+import InAppNotificationSettngs from '../../models/in-app-notification-settings';
+
 const logger = loggerFactory('growi:routes:apiv3:personal-setting');
 
 const express = require('express');
@@ -459,5 +461,24 @@ module.exports = (crowi) => {
 
   });
 
+  router.put('/in-app-notification-settngs', async(req, res) => {
+    const query = { userId: req.user.id };
+    const defaultSubscribeRules = req.body.defaultSubscribeRules;
+
+    if (defaultSubscribeRules == null) {
+      return res.apiv3Err('no-rules-found');
+    }
+
+    try {
+      const options = { upsert: true, new: true, runValidators: true };
+      const response = await InAppNotificationSettngs.findOneAndUpdate(query, { defaultSubscribeRules }, options);
+      return res.apiv3({ response });
+    }
+    catch (err) {
+      logger.error(err);
+      return res.apiv3Err('updating-in-app-notification-settings-failed');
+    }
+  });
+
   return router;
 };