Skip to content

Commit

Permalink
Fix: send integration definitions in link get call
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithmullapudi committed Jul 9, 2023
1 parent 0f959b0 commit 758dc8f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
9 changes: 9 additions & 0 deletions engine-server/src/modules/link/link.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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[];
}
4 changes: 3 additions & 1 deletion engine-server/src/modules/link/link.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
31 changes: 30 additions & 1 deletion engine-server/src/modules/link/link.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<Link> {
return await this.prisma.link.create({
Expand All @@ -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,
Expand All @@ -46,6 +74,7 @@ export class LinkService {
integrationDefinitionId: integrationAccount.integrationDefinitionId,
}),
),
integrationDefinitions,
};
}

Expand Down

0 comments on commit 758dc8f

Please sign in to comment.