Просмотр исходного кода

Merge pull request #4013 from weseek/feat/6737-6747-update-relation-after-test

feat/6737-6747-update-relation-after-test
itizawa 4 лет назад
Родитель
Сommit
aca889cc8c
1 измененных файлов с 17 добавлено и 9 удалено
  1. 17 9
      packages/slackbot-proxy/src/controllers/growi-to-slack.ts

+ 17 - 9
packages/slackbot-proxy/src/controllers/growi-to-slack.ts

@@ -170,15 +170,23 @@ 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,
     // 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 });
+    const response = await this.relationRepository.createQueryBuilder('relation')
+      .insert()
+      .values({
+        installation: order.installation,
+        tokenGtoP: order.tokenGtoP,
+        tokenPtoG: order.tokenPtoG,
+        growiUri: order.growiUrl,
+        siglePostCommands: temporarySinglePostCommands,
+      })
+      // https://github.com/typeorm/typeorm/issues/1090#issuecomment-634391487
+      .orUpdate({ conflict_target: ['installation', 'growiUri'], overwrite: ['tokenGtoP', 'tokenPtoG', 'siglePostCommands'] })
+      .execute();
+
+    // Find the generated relation
+    const generatedRelation = await this.relationRepository.findOne({ id: response.identifiers[0].id });
+
+    return res.send({ relation: generatedRelation, slackBotToken: token });
   }
   }
 
 
   injectGrowiUri(req: GrowiReq, growiUri: string): void {
   injectGrowiUri(req: GrowiReq, growiUri: string): void {