Procházet zdrojové kódy

delete Promise.all

zahmis před 4 roky
rodič
revize
8cf3d1aa9b

+ 23 - 21
packages/slackbot-proxy/src/middlewares/slack-to-growi/checkCommandPermission.ts

@@ -70,7 +70,7 @@ export class checkCommandPermissionMiddleware implements IMiddleware {
       else {
       else {
         console.log(56, payload.view.callback_id);
         console.log(56, payload.view.callback_id);
 
 
-        command = payload.view.callback_id!.split(':')[0];
+        command = payload.view.callback_id.split(':')[0];
       }
       }
       console.log(37, command);
       console.log(37, command);
     }
     }
@@ -106,22 +106,25 @@ export class checkCommandPermissionMiddleware implements IMiddleware {
 
 
     const baseDate = new Date();
     const baseDate = new Date();
     // const relationsForSingleUse:RelationMock[] = [];
     // const relationsForSingleUse:RelationMock[] = [];
-    await Promise.all(relations.map(async(relation) => {
-      const isSupported = await this.relationsService.isSupportedGrowiCommandForSingleUse(relation, command, baseDate);
-      if (isSupported) {
-        console.log(75);
-        return next();
-      }
-    }));
+    // await Promise.all(relations.map(async(relation) => {
+    //   const isSupported = await this.relationsService.isSupportedGrowiCommandForSingleUse(relation, command, baseDate);
+    //   if (isSupported) {
+    //     console.log(75);
+    //     return next();
+    //   }
+    // }));
+    const isSupportedSingle = await relations.map(async(relation) => {
+      await this.relationsService.isSupportedGrowiCommandForSingleUse(relation, command, baseDate);
+      return;
+    });
+    if (isSupportedSingle) return next();
 
 
-    // const relationsForBroadcastUse:RelationMock[] = [];
-    // check cache
-    await Promise.all(relations.map(async(relation) => {
-      const isSupported = await this.relationsService.isSupportedGrowiCommandForBroadcastUse(relation, command, baseDate);
-      if (isSupported) {
-        return next();
-      }
-    }));
+
+    const isSupportedBroadCast = await relations.map(async(relation) => {
+      await this.relationsService.isSupportedGrowiCommandForBroadcastUse(relation, command, baseDate);
+      return;
+    });
+    if (isSupportedBroadCast) return next();
 
 
     // check permission at channel level
     // check permission at channel level
     const relationMock = await this.relationMockRepository.findOne({ where: { installation } });
     const relationMock = await this.relationMockRepository.findOne({ where: { installation } });
@@ -156,6 +159,7 @@ export class checkCommandPermissionMiddleware implements IMiddleware {
       fromChannel = privateMeta.channelName;
       fromChannel = privateMeta.channelName;
 
 
     }
     }
+
     const isPermittedChannel = permittedChannels.includes(fromChannel);
     const isPermittedChannel = permittedChannels.includes(fromChannel);
     console.log(151, isPermittedChannel);
     console.log(151, isPermittedChannel);
     if (isPermittedChannel) {
     if (isPermittedChannel) {
@@ -163,10 +167,6 @@ export class checkCommandPermissionMiddleware implements IMiddleware {
     }
     }
 
 
 
 
-    console.log(payload);
-    console.log(req);
-
-
     if (payload != null) {
     if (payload != null) {
       const isPermittedChannel = permittedChannels.includes(fromChannel);
       const isPermittedChannel = permittedChannels.includes(fromChannel);
       if (isPermittedChannel) {
       if (isPermittedChannel) {
@@ -177,7 +177,8 @@ export class checkCommandPermissionMiddleware implements IMiddleware {
     // send postEphemral message for not permitted
     // send postEphemral message for not permitted
     const botToken = relations[0].installation?.data.bot?.token;
     const botToken = relations[0].installation?.data.bot?.token;
 
 
-    console.log(111);
+
+    console.log(179);
 
 
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     const client = generateWebClient(botToken!);
     const client = generateWebClient(botToken!);
@@ -190,6 +191,7 @@ export class checkCommandPermissionMiddleware implements IMiddleware {
       ],
       ],
     });
     });
     return;
     return;
+
   }
   }
 
 
 }
 }