Procházet zdrojové kódy

WIP: use repository

Yuki Takei před 5 roky
rodič
revize
d065c1f102

+ 4 - 1
packages/slackbot-proxy/src/Server.ts

@@ -13,6 +13,9 @@ import { ConnectionOptions } from 'typeorm';
 export const rootDir = __dirname;
 export const rootDir = __dirname;
 
 
 const connectionOptions: ConnectionOptions = {
 const connectionOptions: ConnectionOptions = {
+  // The 'name' property must be set. Otherwise, the 'name' will be '0' and won't work well. -- 2021.04.05 Yuki Takei
+  // see: https://github.com/TypedProject/tsed/blob/7630cda20a1f6fa3a692ecc3e6cd51d37bc3c45f/packages/typeorm/src/utils/createConnection.ts#L10
+  name: 'default',
   type: process.env.TYPEORM_CONNECTION,
   type: process.env.TYPEORM_CONNECTION,
   host: process.env.TYPEORM_HOST,
   host: process.env.TYPEORM_HOST,
   database: process.env.TYPEORM_DATABASE,
   database: process.env.TYPEORM_DATABASE,
@@ -87,7 +90,7 @@ export class Server {
     const typeormService = this.injector.get<TypeORMService>(TypeORMService);
     const typeormService = this.injector.get<TypeORMService>(TypeORMService);
     console.log(typeormService);
     console.log(typeormService);
 
 
-    const connection = typeormService?.connectionManager.get('0');
+    const connection = typeormService?.connectionManager.get('default');
     console.log(connection);
     console.log(connection);
   }
   }
 
 

+ 8 - 4
packages/slackbot-proxy/src/controllers/slack.ts

@@ -1,6 +1,8 @@
 import {
 import {
-  BodyParams, Controller, Get, Inject, Post, Req, Res,
+  BodyParams, Controller, Get, Post, Req, Res,
 } from '@tsed/common';
 } from '@tsed/common';
+import { getRepository } from 'typeorm';
+
 import { Installation } from '~/entities/installation';
 import { Installation } from '~/entities/installation';
 import { InstallationRepository } from '~/repositories/installation';
 import { InstallationRepository } from '~/repositories/installation';
 
 
@@ -9,8 +11,8 @@ import { InstallerService } from '~/services/InstallerService';
 @Controller('/slack')
 @Controller('/slack')
 export class SlackCtrl {
 export class SlackCtrl {
 
 
-  @Inject()
-  installationRepository: InstallationRepository;
+  // @Inject()
+  // installationRepository: InstallationRepository;
 
 
   // eslint-disable-next-line no-useless-constructor
   // eslint-disable-next-line no-useless-constructor
   constructor(private readonly installerService: InstallerService) {
   constructor(private readonly installerService: InstallerService) {
@@ -29,7 +31,9 @@ export class SlackCtrl {
       },
       },
     };
     };
 
 
-    this.installationRepository.save(installation);
+    const installationRepository = getRepository(Installation);
+
+    installationRepository.save(installation);
   }
   }