zahmis 4 лет назад
Родитель
Сommit
c0dfc06f15

+ 17 - 16
packages/slackbot-proxy/src/controllers/slack.ts

@@ -182,21 +182,23 @@ export class SlackCtrl {
       }
     }));
 
-    let isCommandPermitted = false;
 
     if (relationsForSingleUse.length > 0) {
-      isCommandPermitted = true;
       body.growiUrisForSingleUse = relationsForSingleUse.map(v => v.growiUri);
       return this.selectGrowiService.process(growiCommand, authorizeResult, body);
     }
 
     const relationsForBroadcastUse:RelationMock[] = [];
     await Promise.all(relations.map(async(relation) => {
+
       const isSupported = await this.relationsService.isSupportedGrowiCommandForBroadcastUse(
         relation, growiCommand.growiCommandType, body.channel_name, baseDate,
       );
+      console.log(isSupported);
       if (isSupported) {
         relationsForBroadcastUse.push(relation);
+        console.log(relationsForBroadcastUse);
+
       }
     }));
 
@@ -204,25 +206,24 @@ export class SlackCtrl {
      * forward to GROWI server
      */
     if (relationsForBroadcastUse.length > 0) {
-      isCommandPermitted = true;
+      body.growiUrisForBroadcastUse = relationsForBroadcastUse.map(v => v.growiUri);
       return this.sendCommand(growiCommand, relationsForBroadcastUse, body);
     }
 
-    if (!isCommandPermitted) {
-      const botToken = relations[0].installation?.data.bot?.token;
+    const botToken = relations[0].installation?.data.bot?.token;
 
-      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      const client = generateWebClient(botToken!);
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    const client = generateWebClient(botToken!);
+
+    return client.chat.postEphemeral({
+      text: 'Error occured.',
+      channel: body.channel_id,
+      user: body.user_id,
+      blocks: [
+        markdownSectionBlock(`It is not allowed to run *'${growiCommand.growiCommandType}'* command to this GROWI.`),
+      ],
+    });
 
-      return client.chat.postEphemeral({
-        text: 'Error occured.',
-        channel: body.channel_id,
-        user: body.user_id,
-        blocks: [
-          markdownSectionBlock(`It is not allowed to run *'${growiCommand.growiCommandType}'* command to this GROWI.`),
-        ],
-      });
-    }
   }
 
 

+ 5 - 4
packages/slackbot-proxy/src/services/SelectGrowiService.ts

@@ -99,16 +99,17 @@ export class SelectGrowiService implements GrowiCommandProcessor {
     // ovverride trigger_id
     sendCommandBody.trigger_id = triggerId;
 
-    const relation = await this.relationMockRepository.createQueryBuilder('relation')
-      .where('relation.growiUri =:growiUri', { growiUri })
-      .andWhere('relation.installationId = :id', { id: installation?.id })
-      .leftJoinAndSelect('relation.installation', 'installation')
+    const relation = await this.relationMockRepository.createQueryBuilder('relation_mock')
+      .where('relation_mock.growiUri =:growiUri', { growiUri })
+      .andWhere('relation_mock.installationId = :id', { id: installation?.id })
+      .leftJoinAndSelect('relation_mock.installation', 'installation')
       .getOne();
 
     if (relation == null) {
       // TODO: postEphemeralErrors
       throw new Error('No relation found.');
     }
+    console.log(112, relation);
 
     return {
       relation,