Parcourir la source

save pathpattern

itizawa il y a 6 ans
Parent
commit
c5f0c05a49
2 fichiers modifiés avec 14 ajouts et 23 suppressions
  1. 0 22
      src/server/routes/admin.js
  2. 14 1
      src/server/routes/apiv3/notification-setting.js

+ 0 - 22
src/server/routes/admin.js

@@ -852,28 +852,6 @@ module.exports = function(crowi, app) {
     return res.json({ status: true });
     return res.json({ status: true });
   };
   };
 
 
-
-  // app.post('/_api/admin/notifications.add'    , admin.api.notificationAdd);
-  actions.api.notificationAdd = function(req, res) {
-    const UpdatePost = crowi.model('UpdatePost');
-    const pathPattern = req.body.pathPattern;
-    const channel = req.body.channel;
-
-    debug('notification.add', pathPattern, channel);
-    UpdatePost.create(pathPattern, channel, req.user)
-      .then((doc) => {
-        debug('Successfully save updatePost', doc);
-
-        // fixme: うーん
-        doc.creator = doc.creator._id.toString();
-        return res.json(ApiResponse.success({ updatePost: doc }));
-      })
-      .catch((err) => {
-        debug('Failed to save updatePost', err);
-        return res.json(ApiResponse.error());
-      });
-  };
-
   // app.post('/_api/admin/notifications.remove' , admin.api.notificationRemove);
   // app.post('/_api/admin/notifications.remove' , admin.api.notificationRemove);
   actions.api.notificationRemove = function(req, res) {
   actions.api.notificationRemove = function(req, res) {
     const UpdatePost = crowi.model('UpdatePost');
     const UpdatePost = crowi.model('UpdatePost');

+ 14 - 1
src/server/routes/apiv3/notification-setting.js

@@ -103,7 +103,20 @@ module.exports = (crowi) => {
 
 
   // TODO swagger
   // TODO swagger
   router.post('/user-notification', loginRequiredStrictly, adminRequired, csrf, validator.userNotification, ApiV3FormValidator, async(req, res) => {
   router.post('/user-notification', loginRequiredStrictly, adminRequired, csrf, validator.userNotification, ApiV3FormValidator, async(req, res) => {
-    return res.apiv3({ });
+    const { pathPattern, channel } = req.body;
+    const UpdatePost = crowi.model('UpdatePost');
+
+    try {
+      logger.info('notification.add', pathPattern, channel);
+      const params = await UpdatePost.create(pathPattern, channel, req.user);
+      return res.apiv3({ params });
+    }
+    catch (err) {
+      const msg = 'Error occurred in updating user notification';
+      logger.error('Error', err);
+      return res.apiv3Err(new ErrorV3(msg, 'update-userNotification-failed'));
+    }
+
   });
   });