zahmis 4 years ago
parent
commit
2982246517

+ 18 - 12
packages/slackbot-proxy/src/controllers/growi-to-slack.ts

@@ -15,7 +15,8 @@ import { WebclientRes, AddWebclientResponseToRes } from '~/middlewares/slack-to-
 
 import { GrowiReq } from '~/interfaces/growi-to-slack/growi-req';
 import { InstallationRepository } from '~/repositories/installation';
-import { RelationRepository } from '~/repositories/relation';
+// import { RelationRepository } from '~/repositories/relation';
+import { RelationMockRepository } from '~/repositories/relation-mock';
 import { OrderRepository } from '~/repositories/order';
 
 import { InstallerService } from '~/services/InstallerService';
@@ -36,8 +37,11 @@ export class GrowiToSlackCtrl {
   @Inject()
   installationRepository: InstallationRepository;
 
+  // @Inject()
+  // relationRepository: RelationRepository;
+
   @Inject()
-  relationRepository: RelationRepository;
+  relationMockRepository: RelationMockRepository;
 
   @Inject()
   orderRepository: OrderRepository;
@@ -71,9 +75,9 @@ export class GrowiToSlackCtrl {
     const { tokenGtoPs } = req;
 
     // retrieve Relation with Installation
-    const relations = await this.relationRepository.createQueryBuilder('relation')
-      .where('relation.tokenGtoP IN (:...tokens)', { tokens: tokenGtoPs })
-      .leftJoinAndSelect('relation.installation', 'installation')
+    const relations = await this.relationMockRepository.createQueryBuilder('relation_mock')
+      .where('relation_mock.tokenGtoP IN (:...tokens)', { tokens: tokenGtoPs })
+      .leftJoinAndSelect('relation_mock.installation', 'installation')
       .getMany();
 
     logger.debug(`${relations.length} relations found`, relations);
@@ -104,7 +108,7 @@ export class GrowiToSlackCtrl {
     }
 
     const tokenGtoP = tokenGtoPs[0];
-    const relation = await this.relationRepository.update({ tokenGtoP }, { supportedCommandsForBroadcastUse, supportedCommandsForSingleUse });
+    const relation = await this.relationMockRepository.update({ tokenGtoP }, { supportedCommandsForBroadcastUse, supportedCommandsForSingleUse });
 
     return res.send({ relation });
   }
@@ -121,9 +125,9 @@ export class GrowiToSlackCtrl {
     const tokenGtoP = tokenGtoPs[0];
 
     // retrieve relation with Installation
-    const relation = await this.relationRepository.createQueryBuilder('relation')
+    const relation = await this.relationMockRepository.createQueryBuilder('relation_mock')
       .where('tokenGtoP = :token', { token: tokenGtoP })
-      .leftJoinAndSelect('relation.installation', 'installation')
+      .leftJoinAndSelect('relation_mock.installation', 'installation')
       .getOne();
 
     // Returns the result of the test if it already exists
@@ -189,7 +193,7 @@ export class GrowiToSlackCtrl {
     const expiredAtCommands = addHours(new Date(), 48);
 
     // Transaction is not considered because it is used infrequently,
-    const response = await this.relationRepository.createQueryBuilder('relation')
+    const response = await this.relationMockRepository.createQueryBuilder('relation_mock')
       .insert()
       .values({
         installation: order.installation,
@@ -199,6 +203,8 @@ export class GrowiToSlackCtrl {
         supportedCommandsForBroadcastUse: req.body.supportedCommandsForBroadcastUse,
         supportedCommandsForSingleUse: req.body.supportedCommandsForSingleUse,
         expiredAtCommands,
+        // HARD CORDING
+        permittedChannelsForEachCommand: { create: ['srv'], search: ['srv', 'admin'] },
       })
       // https://github.com/typeorm/typeorm/issues/1090#issuecomment-634391487
       .orUpdate({
@@ -208,7 +214,7 @@ export class GrowiToSlackCtrl {
       .execute();
 
     // Find the generated relation
-    const generatedRelation = await this.relationRepository.findOne({ id: response.identifiers[0].id });
+    const generatedRelation = await this.relationMockRepository.findOne({ id: response.identifiers[0].id });
 
     return res.send({ relation: generatedRelation, slackBotToken: token });
   }
@@ -257,9 +263,9 @@ export class GrowiToSlackCtrl {
     const tokenGtoP = tokenGtoPs[0];
 
     // retrieve relation with Installation
-    const relation = await this.relationRepository.createQueryBuilder('relation')
+    const relation = await this.relationMockRepository.createQueryBuilder('relation_mock')
       .where('tokenGtoP = :token', { token: tokenGtoP })
-      .leftJoinAndSelect('relation.installation', 'installation')
+      .leftJoinAndSelect('relation_mock.installation', 'installation')
       .getOne();
 
     if (relation == null) {

+ 1 - 1
packages/slackbot-proxy/src/entities/relation-mock.ts

@@ -11,7 +11,7 @@ import { Installation } from './installation';
 //     search: ['admin'],
 //   }
 interface PermittedChannelsForEachCommand {
-  commandToChannelMap: { [command: string]: string[] };
+   [command: string]: string[] ;
 }
 
 @Entity()

+ 3 - 3
packages/slackbot-proxy/src/services/RelationsService.ts

@@ -4,7 +4,7 @@ import { addHours } from 'date-fns';
 
 // import { Relation } from '~/entities/relation';
 import { RelationMock } from '~/entities/relation-mock';
-import { RelationRepository } from '~/repositories/relation';
+// import { RelationRepository } from '~/repositories/relation';
 import { RelationMockRepository } from '~/repositories/relation-mock';
 
 import loggerFactory from '~/utils/logger';
@@ -15,7 +15,7 @@ const logger = loggerFactory('slackbot-proxy:services:RelationsService');
 export class RelationsService {
 
   @Inject()
-  relationRepository: RelationRepository;
+  // relationRepository: RelationRepository;
 
   relationMockRepository: RelationMockRepository;
 
@@ -36,7 +36,7 @@ export class RelationsService {
     relation.supportedCommandsForSingleUse = supportedCommandsForSingleUse;
     relation.expiredAtCommands = addHours(new Date(), 48);
 
-    return this.relationRepository.save(relation);
+    return this.relationMockRepository.save(relation);
   }
 
   async syncRelation(relation:RelationMock, baseDate:Date):Promise<RelationMock|null> {