itizawa 5 лет назад
Родитель
Сommit
a651ebc5d1

+ 10 - 1
packages/slackbot-proxy/src/controllers/slack.ts

@@ -3,7 +3,10 @@ import {
 } from '@tsed/common';
 
 import { Installation } from '~/entities/installation';
+import { Order } from '~/entities/order';
+
 import { InstallationRepository } from '~/repositories/installation';
+import { OrderRepository } from '~/repositories/order';
 import { InstallerService } from '~/services/InstallerService';
 
 
@@ -16,6 +19,9 @@ export class SlackCtrl {
   @Inject()
   installationRepository: InstallationRepository;
 
+  @Inject()
+  orderRepository: OrderRepository;
+
   @Get('/testsave')
   testsave(): void {
     const installation = new Installation();
@@ -56,13 +62,16 @@ export class SlackCtrl {
   }
 
   @Post('/events')
-  handleEvent(@BodyParams() body: any, @Res() res: Res): string {
+  async handleEvent(@BodyParams() body: any, @Res() res: Res): Promise<string> {
     // Send response immediately to avoid opelation_timeout error
     // See https://api.slack.com/apis/connections/events-api#the-events-api__responding-to-events
     res.send();
 
     console.log('body', body);
 
+    const order = new Order(body.team_id);
+    await this.orderRepository.save(order);
+
     return 'This action will be handled by bolt service.';
   }
 

+ 5 - 1
packages/slackbot-proxy/src/entities/order.ts

@@ -14,7 +14,7 @@ export class Order {
   @UpdateDateColumn()
   readonly updatedAt: Date;
 
-  @Column()
+  @Column({ unique: true })
   teamId: string;
 
   @Column({ nullable: true, default: false })
@@ -29,4 +29,8 @@ export class Order {
   @Column({ nullable: true })
   proxyAccessToken?: string;
 
+  constructor(teamId:string) {
+    this.teamId = teamId;
+  }
+
 }