itizawa пре 5 година
родитељ
комит
131b9a7022

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

@@ -72,11 +72,21 @@ export class SlackCtrl {
       throw new Error('installation is reqiured');
     }
 
-    console.log('body', body);
-    const teamId = body.team_id;
+    // Find the latest order by installationId
+    let order = await this.orderRepository.findOne({
+      installation: installation.id,
+    }, {
+      order: {
+        createdAt: 'DESC',
+      },
+    });
 
-    // TODO move to service
-    // console.log('order', order);
+    if (order == null || order.isExpired()) {
+      order = await this.orderRepository.save({ installation: installation.id });
+    }
+
+    console.log('body', body);
+    console.log('order', order);
 
     return 'This action will be handled by bolt service.';
   }

+ 1 - 1
packages/slackbot-proxy/src/entities/installation.ts

@@ -33,7 +33,7 @@ export class Installation {
   @Column({ nullable: true, unique: true })
   enterpriseId?: string;
 
-  @OneToMany(() => Order, order => order.installationId)
+  @OneToMany(() => Order, order => order.installation)
   orders?: Order[];
 
   setData(slackInstallation: SlackInstallation): void {

+ 4 - 3
packages/slackbot-proxy/src/entities/order.ts

@@ -16,7 +16,7 @@ export class Order {
   readonly updatedAt: Date;
 
   @ManyToOne(() => Installation, installation => installation.orders)
-  readonly installationId: number;
+  readonly installation: number;
 
   @Column({ nullable: true, default: false })
   isCompleted?: boolean;
@@ -30,8 +30,9 @@ export class Order {
   @Column({ nullable: true })
   proxyAccessToken?: string;
 
-  isExpired():Error {
-    throw new Error('TODO GW-5555 implement this');
+  isExpired():boolean {
+    // TODO GW-5555 implement this
+    return false;
   }
 
 }