Просмотр исходного кода

Merge pull request #1534 from weseek/reactify-admin/create-apiV3-delete-notification

Reactify admin/create api v3 delete notification
Yuki Takei 6 лет назад
Родитель
Сommit
47a863e9b6

+ 2 - 2
src/client/js/components/Admin/Notification/GlobalNotificationList.jsx

@@ -40,8 +40,8 @@ class GlobalNotificationList extends React.Component {
     const { t, adminNotificationContainer } = this.props;
 
     try {
-      await adminNotificationContainer.deleteGlobalNotificationPattern(this.state.notificatiionForConfiguration);
-      toastSuccess(t('notification_setting.delete_notification_pattern'));
+      const deletedNotificaton = await adminNotificationContainer.deleteGlobalNotificationPattern(this.state.notificatiionForConfiguration._id);
+      toastSuccess(t('notification_setting.delete_notification_pattern', { path: deletedNotificaton.triggerPath }));
     }
     catch (err) {
       toastError(err);

+ 4 - 1
src/client/js/services/AdminNotificationContainer.js

@@ -118,7 +118,10 @@ export default class AdminNotificationContainer extends Container {
    * Delete global notification pattern
    */
   async deleteGlobalNotificationPattern(notificatiionId) {
-    // TODO GW-780 create apiV3
+    const response = await this.appContainer.apiv3.delete(`/notification-setting/global-notification/${notificatiionId}`);
+    const deletedNotificaton = response.data;
+    await this.retrieveNotificationData();
+    return deletedNotificaton;
   }
 
 }

+ 41 - 0
src/server/routes/apiv3/notification-setting.js

@@ -190,5 +190,46 @@ module.exports = (crowi) => {
 
   });
 
+  /**
+  * @swagger
+  *
+  *    /_api/v3/notification-setting/global-notification/{id}:
+  *      delete:
+  *        tags: [NotificationSetting]
+  *        description: delete global notification pattern
+  *        parameters:
+  *          - name: id
+  *            in: path
+  *            required: true
+  *            description: id of global notification
+  *            schema:
+  *              type: string
+  *        responses:
+  *          200:
+  *            description: Succeeded to delete global notification pattern
+  *            content:
+  *              application/json:
+  *                schema:
+  *                  properties:
+  *                    deletedNotificaton:
+  *                      type: object
+  *                      description: deleted notification
+  */
+  router.delete('/global-notification/:id', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
+    const { id } = req.params;
+
+    try {
+      const deletedNotificaton = await GlobalNotificationSetting.findOneAndRemove({ _id: id });
+      return res.apiv3(deletedNotificaton);
+    }
+    catch (err) {
+      const msg = 'Error occurred in delete global notification';
+      logger.error('Error', err);
+      return res.apiv3Err(new ErrorV3(msg, 'delete-globalNotification-failed'));
+    }
+
+
+  });
+
   return router;
 };