From 33a52d27b997fafd2c6258cd3b3a337309618f8a Mon Sep 17 00:00:00 2001 From: nael Date: Thu, 6 Jun 2024 13:21:40 +0200 Subject: [PATCH] :bug: Fix project connectors inside code --- .../connections-strategies.service.ts | 13 ++++----- .../src/@core/projects/projects.service.ts | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/packages/api/src/@core/connections-strategies/connections-strategies.service.ts b/packages/api/src/@core/connections-strategies/connections-strategies.service.ts index c31ab961b..a31451f1d 100644 --- a/packages/api/src/@core/connections-strategies/connections-strategies.service.ts +++ b/packages/api/src/@core/connections-strategies/connections-strategies.service.ts @@ -30,7 +30,7 @@ export class ConnectionsStrategiesService { private prisma: PrismaService, private crypto: EncryptionService, private configService: ConfigService, - ) { } + ) {} async isCustomCredentials(projectId: string, type: string) { const res = await this.prisma.connection_strategies.findFirst({ @@ -230,8 +230,9 @@ export class ConnectionsStrategiesService { data = { ...data, SCOPE: - CONNECTORS_METADATA[vertical.toLowerCase()][provider.toLowerCase()] - .scopes, + CONNECTORS_METADATA[vertical.toLowerCase()][ + provider.toLowerCase() + ].scopes, }; } /*const isSubdomain = needsSubdomain( @@ -337,7 +338,7 @@ export class ConnectionsStrategiesService { values: string[], ) { try { - console.log("In updateAPI xzx") + console.log('In updateAPI xzx'); const cs = await this.prisma.connection_strategies.findFirst({ where: { id_connection_strategy: id_cs, @@ -382,8 +383,8 @@ export class ConnectionsStrategiesService { } return cs; } catch (error) { - console.log("Error xzx") - console.log(error) + console.log('Error xzx'); + console.log(error); throw new Error('Update Failed'); } } diff --git a/packages/api/src/@core/projects/projects.service.ts b/packages/api/src/@core/projects/projects.service.ts index 86900fe23..a8ec87667 100644 --- a/packages/api/src/@core/projects/projects.service.ts +++ b/packages/api/src/@core/projects/projects.service.ts @@ -4,6 +4,12 @@ import { LoggerService } from '../logger/logger.service'; import { CreateProjectDto } from './dto/create-project.dto'; import { v4 as uuidv4 } from 'uuid'; import { handleServiceError } from '@@core/utils/errors'; +import { + ConnectorCategory, + CONNECTORS_METADATA, + providersArray, + slugFromCategory, +} from '@panora/shared'; @Injectable() export class ProjectsService { @@ -43,6 +49,27 @@ export class ProjectsService { //id_organization: id_organization, }, }); + + const ACTIVE_CONNECTORS = providersArray(); + // update project-connectors table for the project + const updateData: any = { + id_project_connector: uuidv4(), + id_project: res.id_project, + }; + + ACTIVE_CONNECTORS.forEach((connector) => { + if (connector.vertical) { + // Construct the property name using the vertical name + const propertyName = `${slugFromCategory( + connector.vertical as ConnectorCategory, + )}_`; + // Add the property to updateData with a value of true + updateData[propertyName + connector.name] = true; + } + }); + await this.prisma.project_connectors.create({ + data: updateData, + }); return res; } catch (error) { handleServiceError(error, this.logger);