From 758dc8f832d75b670b2490fd3f918bab110b07cd Mon Sep 17 00:00:00 2001 From: Harshith Mullapudi Date: Sun, 9 Jul 2023 14:01:48 -0700 Subject: [PATCH] Fix: send integration definitions in link get call --- .../entities/integrationDefinition.entity.ts | 40 +++++++++---------- .../src/modules/link/link.interface.ts | 9 +++++ engine-server/src/modules/link/link.module.ts | 4 +- .../src/modules/link/link.service.ts | 31 +++++++++++++- 4 files changed, 61 insertions(+), 23 deletions(-) diff --git a/engine-server/src/@@generated/integrationDefinition/entities/integrationDefinition.entity.ts b/engine-server/src/@@generated/integrationDefinition/entities/integrationDefinition.entity.ts index 4a8ac64f..f050698e 100644 --- a/engine-server/src/@@generated/integrationDefinition/entities/integrationDefinition.entity.ts +++ b/engine-server/src/@@generated/integrationDefinition/entities/integrationDefinition.entity.ts @@ -1,24 +1,22 @@ - -import {ReleaseStage,IntegrationType} from '@prisma/client' -import {Workspace} from '../../workspace/entities/workspace.entity' -import {IntegrationAccount} from '../../integrationAccount/entities/integrationAccount.entity' -import {IntegrationOAuthApp} from '../../integrationOAuthApp/entities/integrationOAuthApp.entity' - +import { ReleaseStage, IntegrationType } from '@prisma/client'; +import { Workspace } from '../../workspace/entities/workspace.entity'; +import { IntegrationAccount } from '../../integrationAccount/entities/integrationAccount.entity'; +import { IntegrationOAuthApp } from '../../integrationOAuthApp/entities/integrationOAuthApp.entity'; export class IntegrationDefinition { - integrationDefinitionId: string ; -name: string ; -key: string ; -icon: string | null; -version: string ; -releaseStage: ReleaseStage ; -sourceUrl: string ; -integrationType: IntegrationType ; -workspace?: Workspace | null; -workspaceId: string | null; -IntegrationAccount?: IntegrationAccount[] ; -IntegrationOAuthApp?: IntegrationOAuthApp[] ; -deleted: Date | null; -createdAt: Date ; -updatedAt: Date ; + integrationDefinitionId: string; + name: string; + key: string; + icon: string | null; + version: string; + releaseStage: ReleaseStage; + sourceUrl: string; + integrationType: IntegrationType; + workspace?: Workspace | null; + workspaceId: string | null; + IntegrationAccount?: IntegrationAccount[]; + IntegrationOAuthApp?: IntegrationOAuthApp[]; + deleted: Date | null; + createdAt: Date; + updatedAt: Date; } diff --git a/engine-server/src/modules/link/link.interface.ts b/engine-server/src/modules/link/link.interface.ts index c209be47..07f4f4f5 100644 --- a/engine-server/src/modules/link/link.interface.ts +++ b/engine-server/src/modules/link/link.interface.ts @@ -3,6 +3,7 @@ import { IntegrationType } from '@prisma/client'; import { IsArray, IsNumber, IsOptional, IsString } from 'class-validator'; +import { IntegrationDefinition } from '@@generated/integrationDefinition/entities'; import { Link } from '@@generated/link/entities'; export class CreateLinkBody { @@ -41,6 +42,14 @@ export class LinkIdRequest { linkId: string; } +export class IntegrationAccount { + integrationAccountId: string; + integrationDefinitionId: string; +} + export class LinkResponse extends Link { expired: boolean; + + integrationAccounts?: IntegrationAccount[]; + integrationDefinitions?: IntegrationDefinition[]; } diff --git a/engine-server/src/modules/link/link.module.ts b/engine-server/src/modules/link/link.module.ts index 2d81a66e..d7dee7d2 100644 --- a/engine-server/src/modules/link/link.module.ts +++ b/engine-server/src/modules/link/link.module.ts @@ -3,11 +3,13 @@ import { Module } from '@nestjs/common'; import { PrismaModule, PrismaService } from 'nestjs-prisma'; +import { IntegrationDefinitionModule } from 'modules/integration_definition/integration_definition.module'; + import { LinkController } from './link.controller'; import { LinkService } from './link.service'; @Module({ - imports: [PrismaModule], + imports: [PrismaModule, IntegrationDefinitionModule], controllers: [LinkController], providers: [LinkService, PrismaService], exports: [LinkService], diff --git a/engine-server/src/modules/link/link.service.ts b/engine-server/src/modules/link/link.service.ts index af63d114..9d5b570a 100644 --- a/engine-server/src/modules/link/link.service.ts +++ b/engine-server/src/modules/link/link.service.ts @@ -4,8 +4,11 @@ import { Injectable } from '@nestjs/common'; import { differenceInSeconds } from 'date-fns'; import { PrismaService } from 'nestjs-prisma'; +import { IntegrationDefinition } from '@@generated/integrationDefinition/entities'; import { Link } from '@@generated/link/entities'; +import { IntegrationDefinitionService } from 'modules/integration_definition/integration_definition.service'; + import { CreateLinkBody, GetLinkRequest, @@ -14,7 +17,10 @@ import { @Injectable() export class LinkService { - constructor(private prisma: PrismaService) {} + constructor( + private prisma: PrismaService, + private integrationDefinitionService: IntegrationDefinitionService, + ) {} async createLink(createLinkBody: CreateLinkBody): Promise { return await this.prisma.link.create({ @@ -37,6 +43,28 @@ export class LinkService { new Date(link.createdAt), ); + let integrationDefinitions: IntegrationDefinition[] = []; + + if (!link.integrationDefinitionId) { + integrationDefinitions = + await this.integrationDefinitionService.getIntegrationDefinitionsForWorkspace( + { + workspaceId: link.workspaceId, + category: link.category, + }, + ); + } else { + const integrationDefinition = + await this.integrationDefinitionService.getIntegrationDefinitionWithId( + { + integrationDefinitionId: link.integrationDefinitionId, + }, + link.workspaceId, + ); + + integrationDefinitions = [integrationDefinition]; + } + return { expired: differenceSeconds < link.expiresIn ? false : true, ...link, @@ -46,6 +74,7 @@ export class LinkService { integrationDefinitionId: integrationAccount.integrationDefinitionId, }), ), + integrationDefinitions, }; }