Browse Source

can update put actio: supported commands

zahmis 4 years ago
parent
commit
f0b39bb852
1 changed files with 16 additions and 29 deletions
  1. 16 29
      packages/app/src/server/routes/apiv3/slack-integration-settings.js

+ 16 - 29
packages/app/src/server/routes/apiv3/slack-integration-settings.js

@@ -138,7 +138,7 @@ module.exports = (crowi) => {
       throw new Error('Proxy URL is not registered');
       throw new Error('Proxy URL is not registered');
     }
     }
 
 
-    console.log(method);
+
     try {
     try {
       const result = await axios[method](
       const result = await axios[method](
         urljoin(proxyUri, endpoint),
         urljoin(proxyUri, endpoint),
@@ -562,51 +562,38 @@ module.exports = (crowi) => {
     const { supportedCommandsForBroadcastUse, supportedCommandsForSingleUse } = req.body;
     const { supportedCommandsForBroadcastUse, supportedCommandsForSingleUse } = req.body;
     const { id } = req.params;
     const { id } = req.params;
 
 
-    // const slackAppIntegration = mongoose.model('SlackAppIntegration');
+    const updateSingle = new Map();
+    const updateBroad = new Map();
+    supportedCommandsForBroadcastUse.forEach((commandName) => {
+      updateBroad.set(commandName, true);
+    });
+    supportedCommandsForSingleUse.forEach((commandName) => {
+      updateSingle.set(commandName, true);
+    });
 
 
     try {
     try {
-      // NOT MOCK DATA BUT REFER THIS GW-7006
+
       const slackAppIntegration = await SlackAppIntegration.findByIdAndUpdate(
       const slackAppIntegration = await SlackAppIntegration.findByIdAndUpdate(
         id,
         id,
-        { supportedCommandsForBroadcastUse, supportedCommandsForSingleUse },
-        { new: true },
-      );
-
-      // MOCK DATA MODIFY THIS GW-6972 ---------------
-      /**
-       * this code represents the update operation using request from client (slackapp integration settings page)
-       * , then send request to proxy to update cache
-       * permittedChannelsForEachCommandFromClient represents the data sent from client
-       */
-      // MOCK DATA FROM CLIENT assume that these data were sent from client
-      const permissionsForBroadcastUseCommandsFromClient = {
-        search: false,
-      };
-      const permissionsForSingleUseCommandsFromClient = {
-        create: ['random'],
-      };
-      const SlackAppIntegration = await SlackAppIntegration.findOneAndUpdate(
-        // MOCK DATA USE id IN req.params LIKE ABOVE
-        { tokenPtoG: slackAppIntegration.tokenPtoG },
         {
         {
-          permissionsForBroadcastUseCommands: permissionsForBroadcastUseCommandsFromClient,
-          permissionsForSingleUseCommands: permissionsForSingleUseCommandsFromClient,
+          permissionsForBroadcastUseCommands: updateBroad,
+          permissionsForSingleUseCommands: updateSingle,
         },
         },
         { new: true },
         { new: true },
       );
       );
 
 
       await requestToProxyServer(
       await requestToProxyServer(
-        SlackAppIntegration.tokenGtoP,
+        slackAppIntegration.tokenGtoP,
         'put',
         'put',
         '/g2s/supported-commands',
         '/g2s/supported-commands',
         {
         {
-          permissionsForBroadcastUseCommands: SlackAppIntegration.permissionsForBroadcastUseCommands,
-          permissionsForSingleUseCommands: SlackAppIntegration.permissionsForSingleUseCommands,
+          permissionsForBroadcastUseCommands: slackAppIntegration.permissionsForBroadcastUseCommands,
+          permissionsForSingleUseCommands: slackAppIntegration.permissionsForSingleUseCommands,
         },
         },
       );
       );
       // MOCK DATA MODIFY THIS GW-6972 ---------------
       // MOCK DATA MODIFY THIS GW-6972 ---------------
 
 
-      return res.apiv3({ SlackAppIntegration });
+      return res.apiv3({ slackAppIntegration });
     }
     }
     catch (error) {
     catch (error) {
       const msg = `Error occured in updating settings. Cause: ${error.message}`;
       const msg = `Error occured in updating settings. Cause: ${error.message}`;