itizawa 4 лет назад
Родитель
Сommit
e2cbaf3567
1 измененных файлов с 13 добавлено и 10 удалено
  1. 13 10
      packages/slackbot-proxy/src/controllers/growi-to-slack.ts

+ 13 - 10
packages/slackbot-proxy/src/controllers/growi-to-slack.ts

@@ -169,16 +169,19 @@ export class GrowiToSlackCtrl {
 
 
     logger.debug('relation test is success', order);
     logger.debug('relation test is success', order);
 
 
-    // Transaction is not considered because it is used infrequently,
-    const createdRelation = await this.relationRepository.save({
-      installation: order.installation,
-      tokenGtoP: order.tokenGtoP,
-      tokenPtoG: order.tokenPtoG,
-      growiUri: order.growiUrl,
-      siglePostCommands: temporarySinglePostCommands,
-    });
-
-    return res.send({ relation: createdRelation, slackBotToken: token });
+    await this.relationRepository.createQueryBuilder('relation')
+      .insert()
+      .values({
+        installation: order.installation,
+        tokenGtoP: order.tokenGtoP,
+        tokenPtoG: order.tokenPtoG,
+        growiUri: order.growiUrl,
+        siglePostCommands: temporarySinglePostCommands,
+      })
+      .orUpdate({ conflict_target: ['installation', 'growiUri'], overwrite: ['tokenGtoP', 'tokenPtoG', 'siglePostCommands'] })
+      .execute();
+
+    return res.send({ slackBotToken: token });
   }
   }
 
 
   injectGrowiUri(req: GrowiReq, growiUri: string): void {
   injectGrowiUri(req: GrowiReq, growiUri: string): void {