From 7d6584017eb4d1475dcaf276a9791aa385ea030b Mon Sep 17 00:00:00 2001 From: nael Date: Thu, 23 May 2024 23:12:18 +0200 Subject: [PATCH] :sparkles: New features in api --- .../Configuration/Catalog/CopySnippet.tsx | 34 +++++++++++-------- docs/recipes/embed-catalog.mdx | 2 +- .../api/src/@core/connections/@utils/index.ts | 30 ++++++++++++++-- .../services/freeagent/freeagent.service.ts | 9 ++++- .../services/freshbooks/freshbooks.service.ts | 9 ++++- .../services/moneybird/moneybird.service.ts | 15 ++++++-- .../services/pennylane/pennylane.service.ts | 15 ++++++-- .../services/quickbooks/quickbooks.service.ts | 9 ++++- .../accounting/services/sage/sage.service.ts | 9 ++++- .../wave_financial/wave_financial.service.ts | 9 ++++- .../crm/services/accelo/accelo.service.ts | 12 +++++-- .../crm/services/attio/attio.service.ts | 9 ++++- .../crm/services/capsule/capsule.service.ts | 9 ++++- .../crm/services/close/close.service.ts | 9 ++++- .../crm/services/copper/copper.service.ts | 9 ++++- .../crm/services/hubspot/hubspot.service.ts | 12 ++++--- .../crm/services/keap/keap.service.ts | 9 ++++- .../services/pipedrive/pipedrive.service.ts | 9 ++++- .../services/teamleader/teamleader.service.ts | 9 ++++- .../crm/services/teamwork/teamwork.service.ts | 12 +++++-- .../crm/services/zendesk/zendesk.service.ts | 9 ++++- .../crm/services/zoho/zoho.service.ts | 15 ++++++-- .../getresponse/getresponse.service.ts | 15 ++++++-- .../services/mailchimp/mailchimp.service.ts | 9 ++++- .../services/podium/podium.service.ts | 9 ++++- .../ticketing/services/aha/aha.service.ts | 12 +++++-- .../services/clickup/clickup.service.ts | 9 ++++- .../ticketing/services/front/front.service.ts | 9 ++++- .../services/github/github.service.ts | 9 ++++- .../services/gitlab/gitlab.service.ts | 9 ++++- .../services/gorgias/gorgias.service.ts | 9 ++++- .../ticketing/services/jira/jira.service.ts | 9 ++++- .../jira_service_mgmt/jira.service.ts | 9 ++++- .../services/linear/linear.service.ts | 9 ++++- .../services/zendesk/zendesk.service.ts | 9 ++++- 35 files changed, 326 insertions(+), 64 deletions(-) diff --git a/apps/client-ts/src/components/Configuration/Catalog/CopySnippet.tsx b/apps/client-ts/src/components/Configuration/Catalog/CopySnippet.tsx index 879cf906f..ca06379ba 100644 --- a/apps/client-ts/src/components/Configuration/Catalog/CopySnippet.tsx +++ b/apps/client-ts/src/components/Configuration/Catalog/CopySnippet.tsx @@ -25,11 +25,12 @@ export const CopySnippet = () => { const handleCopyLeft = () => { navigator.clipboard.writeText( - ` - projectId={'c9a1b1f8-466d-442d-a95e-11cdd00baf49'} - returnUrl={'https://acme.inc'} - linkedUserId={'b860d6c1-28f9-485c-86cd-fb09e60f10a2'} - ` + `` ); toast.success("Code snippet copied", { action: { @@ -45,13 +46,13 @@ export const CopySnippet = () => { const handleCopyRight = () => { navigator.clipboard.writeText( - ` - name={'hubspot'} - vertical={'crm'} - projectId={'c9a1b1f8-466d-442d-a95e-11cdd00baf49'} - returnUrl={'https://acme.inc'} - linkedUserId={'b860d6c1-28f9-485c-86cd-fb09e60f10a2'} - ` + `` ); toast.success("Code snippet copied", { action: { @@ -120,9 +121,12 @@ export const CopySnippet = () => { - {``} + {``} + + category{`=crm`} + projectId{`={'c9a1b1f8-466d-442d-a95e-11cdd00baf49'}`} @@ -134,7 +138,7 @@ export const CopySnippet = () => { - {``} + {``} @@ -181,7 +185,7 @@ export const CopySnippet = () => { name{`={'hubspot'}`} - vertical{`={'crm'}`} + category{`={'crm'}`} projectId{`={'c9a1b1f8-466d-442d-a95e-11cdd00baf49'}`} diff --git a/docs/recipes/embed-catalog.mdx b/docs/recipes/embed-catalog.mdx index ea4fd1dd4..7a5a16cd4 100644 --- a/docs/recipes/embed-catalog.mdx +++ b/docs/recipes/embed-catalog.mdx @@ -37,7 +37,7 @@ icon: "square-terminal" linkedUserId={"b860d6c1-28f9-485c-86cd-fb09e60f10a2"} # the linked id of the user if already created in Panora system or user's info in your system /> ) - } + } ``` #### Import the whole connector catalog diff --git a/packages/api/src/@core/connections/@utils/index.ts b/packages/api/src/@core/connections/@utils/index.ts index 08adb842e..f2c078cf7 100644 --- a/packages/api/src/@core/connections/@utils/index.ts +++ b/packages/api/src/@core/connections/@utils/index.ts @@ -1,5 +1,5 @@ import { PrismaClient } from '@prisma/client'; -import { WebhookService } from '@@core/webhook/webhook.service'; +import { v4 as uuidv4 } from 'uuid'; export type ConnectionMetadata = { linkedUserId: string; @@ -8,7 +8,6 @@ export type ConnectionMetadata = { export class ConnectionUtils { private readonly prisma: PrismaClient; - private readonly webhookService: WebhookService; constructor() { this.prisma = new PrismaClient(); @@ -35,4 +34,31 @@ export class ConnectionUtils { throw new Error(error); } } + + async getLinkedUserId( + projectId: string, + linkedUserId: string, + ): Promise { + const linked_user = await this.prisma.linked_users.findFirst({ + where: { + id_linked_user: linkedUserId, + }, + }); + let id_linked_user: string; + if (!linked_user) { + //create a linked-user out of remote_id + const res = await this.prisma.linked_users.create({ + data: { + id_linked_user: uuidv4(), + id_project: projectId, + linked_user_origin_id: linkedUserId, + alias: '', + }, + }); + id_linked_user = res.id_linked_user; + } else { + id_linked_user = linkedUserId; + } + return id_linked_user; + } } diff --git a/packages/api/src/@core/connections/accounting/services/freeagent/freeagent.service.ts b/packages/api/src/@core/connections/accounting/services/freeagent/freeagent.service.ts index 74e2db9d3..dd32819c0 100644 --- a/packages/api/src/@core/connections/accounting/services/freeagent/freeagent.service.ts +++ b/packages/api/src/@core/connections/accounting/services/freeagent/freeagent.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type FreeagentOAuthResponse = { access_token: string; @@ -29,6 +30,7 @@ export class FreeagentConnectionService implements IAccountingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -124,7 +126,12 @@ export class FreeagentConnectionService connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/accounting/services/freshbooks/freshbooks.service.ts b/packages/api/src/@core/connections/accounting/services/freshbooks/freshbooks.service.ts index c97427812..541aa7f14 100644 --- a/packages/api/src/@core/connections/accounting/services/freshbooks/freshbooks.service.ts +++ b/packages/api/src/@core/connections/accounting/services/freshbooks/freshbooks.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type FreshbooksOAuthResponse = { access_token: string; @@ -29,6 +30,7 @@ export class FreshbooksConnectionService implements IAccountingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -123,7 +125,12 @@ export class FreshbooksConnectionService connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/accounting/services/moneybird/moneybird.service.ts b/packages/api/src/@core/connections/accounting/services/moneybird/moneybird.service.ts index e95355793..5923400a9 100644 --- a/packages/api/src/@core/connections/accounting/services/moneybird/moneybird.service.ts +++ b/packages/api/src/@core/connections/accounting/services/moneybird/moneybird.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type MoneybirdOAuthResponse = { access_token: string; @@ -30,6 +31,7 @@ export class MoneybirdConnectionService implements IAccountingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -94,7 +96,8 @@ export class MoneybirdConnectionService data: { access_token: this.cryptoService.encrypt(data.access_token), refresh_token: this.cryptoService.encrypt(data.refresh_token), - account_url: CONNECTORS_METADATA['accounting']['moneybird'].urls.apiUrl, + account_url: + CONNECTORS_METADATA['accounting']['moneybird'].urls.apiUrl, expiration_timestamp: new Date( new Date().getTime() + Number(data.expires_in) * 1000, ), @@ -110,7 +113,8 @@ export class MoneybirdConnectionService provider_slug: 'moneybird', vertical: 'accounting', token_type: 'oauth', - account_url: CONNECTORS_METADATA['accounting']['moneybird'].urls.apiUrl, + account_url: + CONNECTORS_METADATA['accounting']['moneybird'].urls.apiUrl, access_token: this.cryptoService.encrypt(data.access_token), refresh_token: this.cryptoService.encrypt(data.refresh_token), expiration_timestamp: new Date( @@ -122,7 +126,12 @@ export class MoneybirdConnectionService connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/accounting/services/pennylane/pennylane.service.ts b/packages/api/src/@core/connections/accounting/services/pennylane/pennylane.service.ts index 8ca4ba266..0f9d8da77 100644 --- a/packages/api/src/@core/connections/accounting/services/pennylane/pennylane.service.ts +++ b/packages/api/src/@core/connections/accounting/services/pennylane/pennylane.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type PennylaneOAuthResponse = { access_token: string; @@ -28,6 +29,7 @@ export class PennylaneConnectionService implements IAccountingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -92,7 +94,8 @@ export class PennylaneConnectionService data: { access_token: this.cryptoService.encrypt(data.access_token), refresh_token: this.cryptoService.encrypt(data.refresh_token), - account_url: CONNECTORS_METADATA['accounting']['pennylane'].urls.apiUrl, + account_url: + CONNECTORS_METADATA['accounting']['pennylane'].urls.apiUrl, expiration_timestamp: new Date( new Date().getTime() + Number(data.expires_in) * 1000, ), @@ -108,7 +111,8 @@ export class PennylaneConnectionService provider_slug: 'pennylane', vertical: 'accounting', token_type: 'oauth', - account_url: CONNECTORS_METADATA['accounting']['pennylane'].urls.apiUrl, + account_url: + CONNECTORS_METADATA['accounting']['pennylane'].urls.apiUrl, access_token: this.cryptoService.encrypt(data.access_token), refresh_token: this.cryptoService.encrypt(data.refresh_token), expiration_timestamp: new Date( @@ -120,7 +124,12 @@ export class PennylaneConnectionService connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/accounting/services/quickbooks/quickbooks.service.ts b/packages/api/src/@core/connections/accounting/services/quickbooks/quickbooks.service.ts index 07c214cac..b36efddb4 100644 --- a/packages/api/src/@core/connections/accounting/services/quickbooks/quickbooks.service.ts +++ b/packages/api/src/@core/connections/accounting/services/quickbooks/quickbooks.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type QuickbooksOAuthResponse = { access_token: string; @@ -29,6 +30,7 @@ export class QuickbooksConnectionService implements IAccountingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -124,7 +126,12 @@ export class QuickbooksConnectionService connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/accounting/services/sage/sage.service.ts b/packages/api/src/@core/connections/accounting/services/sage/sage.service.ts index d2c6b1f3b..45d1a5318 100644 --- a/packages/api/src/@core/connections/accounting/services/sage/sage.service.ts +++ b/packages/api/src/@core/connections/accounting/services/sage/sage.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type SageOAuthResponse = { access_token: string; @@ -29,6 +30,7 @@ export type SageOAuthResponse = { @Injectable() export class SageConnectionService implements IAccountingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -121,7 +123,12 @@ export class SageConnectionService implements IAccountingConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/accounting/services/wave_financial/wave_financial.service.ts b/packages/api/src/@core/connections/accounting/services/wave_financial/wave_financial.service.ts index c3b83024d..29fac39fe 100644 --- a/packages/api/src/@core/connections/accounting/services/wave_financial/wave_financial.service.ts +++ b/packages/api/src/@core/connections/accounting/services/wave_financial/wave_financial.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type WaveFinancialOAuthResponse = { access_token: string; @@ -31,6 +32,7 @@ export class WaveFinancialConnectionService implements IAccountingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -129,7 +131,12 @@ export class WaveFinancialConnectionService connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/crm/services/accelo/accelo.service.ts b/packages/api/src/@core/connections/crm/services/accelo/accelo.service.ts index 679b1ef54..72a33ff81 100644 --- a/packages/api/src/@core/connections/crm/services/accelo/accelo.service.ts +++ b/packages/api/src/@core/connections/crm/services/accelo/accelo.service.ts @@ -19,6 +19,7 @@ import { } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; type AcceloOAuthResponse = { access_token: string; @@ -32,6 +33,7 @@ type AcceloOAuthResponse = { @Injectable() export class AcceloConnectionService implements ICrmConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -90,7 +92,8 @@ export class AcceloConnectionService implements ICrmConnectionService { const connection_token = uuidv4(); //get the right BASE URL API const BASE_API_URL = - CREDENTIALS.SUBDOMAIN + CONNECTORS_METADATA['crm']['accelo'].urls.apiUrl; + CREDENTIALS.SUBDOMAIN + + CONNECTORS_METADATA['crm']['accelo'].urls.apiUrl; if (isNotUnique) { // Update existing connection @@ -128,7 +131,12 @@ export class AcceloConnectionService implements ICrmConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/crm/services/attio/attio.service.ts b/packages/api/src/@core/connections/crm/services/attio/attio.service.ts index 25d2b0bf7..21a2bf720 100644 --- a/packages/api/src/@core/connections/crm/services/attio/attio.service.ts +++ b/packages/api/src/@core/connections/crm/services/attio/attio.service.ts @@ -19,6 +19,7 @@ import { } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export interface AttioOAuthResponse { access_token: string; @@ -28,6 +29,7 @@ export interface AttioOAuthResponse { @Injectable() export class AttioConnectionService implements ICrmConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -116,7 +118,12 @@ export class AttioConnectionService implements ICrmConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/crm/services/capsule/capsule.service.ts b/packages/api/src/@core/connections/crm/services/capsule/capsule.service.ts index e0b9425d5..383bea9b3 100644 --- a/packages/api/src/@core/connections/crm/services/capsule/capsule.service.ts +++ b/packages/api/src/@core/connections/crm/services/capsule/capsule.service.ts @@ -19,6 +19,7 @@ import { } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type CapsuleOAuthResponse = { access_token: string; @@ -32,6 +33,7 @@ export type CapsuleOAuthResponse = { @Injectable() export class CapsuleConnectionService implements ICrmConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -122,7 +124,12 @@ export class CapsuleConnectionService implements ICrmConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/crm/services/close/close.service.ts b/packages/api/src/@core/connections/crm/services/close/close.service.ts index e19143386..0461f0482 100644 --- a/packages/api/src/@core/connections/crm/services/close/close.service.ts +++ b/packages/api/src/@core/connections/crm/services/close/close.service.ts @@ -19,6 +19,7 @@ import { } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type CloseOAuthResponse = { access_token: string; @@ -33,6 +34,7 @@ export type CloseOAuthResponse = { @Injectable() export class CloseConnectionService implements ICrmConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -126,7 +128,12 @@ export class CloseConnectionService implements ICrmConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/crm/services/copper/copper.service.ts b/packages/api/src/@core/connections/crm/services/copper/copper.service.ts index a985f315a..d2253e051 100644 --- a/packages/api/src/@core/connections/crm/services/copper/copper.service.ts +++ b/packages/api/src/@core/connections/crm/services/copper/copper.service.ts @@ -19,6 +19,7 @@ import { } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type CopperOAuthResponse = { access_token: string; @@ -29,6 +30,7 @@ export type CopperOAuthResponse = { @Injectable() export class CopperConnectionService implements ICrmConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -112,7 +114,12 @@ export class CopperConnectionService implements ICrmConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/crm/services/hubspot/hubspot.service.ts b/packages/api/src/@core/connections/crm/services/hubspot/hubspot.service.ts index 458d8aae4..062c5e7e0 100644 --- a/packages/api/src/@core/connections/crm/services/hubspot/hubspot.service.ts +++ b/packages/api/src/@core/connections/crm/services/hubspot/hubspot.service.ts @@ -19,6 +19,7 @@ import { } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export interface HubspotOAuthResponse { refresh_token: string; @@ -29,6 +30,7 @@ export interface HubspotOAuthResponse { @Injectable() export class HubspotConnectionService implements ICrmConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -46,9 +48,6 @@ export class HubspotConnectionService implements ICrmConnectionService { async handleCallback(opts: CallbackParams) { try { const { linkedUserId, projectId, code } = opts; - /* this.logger.log( - 'linkeduserid is ' + linkedUserId + ' inside callback hubspot', - );*/ const isNotUnique = await this.prisma.connections.findFirst({ where: { id_linked_user: linkedUserId, @@ -123,7 +122,12 @@ export class HubspotConnectionService implements ICrmConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/crm/services/keap/keap.service.ts b/packages/api/src/@core/connections/crm/services/keap/keap.service.ts index 9fbcfc27c..663d9bee2 100644 --- a/packages/api/src/@core/connections/crm/services/keap/keap.service.ts +++ b/packages/api/src/@core/connections/crm/services/keap/keap.service.ts @@ -19,6 +19,7 @@ import { } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type KeapOAuthResponse = { access_token: string; @@ -29,6 +30,7 @@ export type KeapOAuthResponse = { @Injectable() export class KeapConnectionService implements ICrmConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -120,7 +122,12 @@ export class KeapConnectionService implements ICrmConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/crm/services/pipedrive/pipedrive.service.ts b/packages/api/src/@core/connections/crm/services/pipedrive/pipedrive.service.ts index 81d14c787..71e7c7901 100644 --- a/packages/api/src/@core/connections/crm/services/pipedrive/pipedrive.service.ts +++ b/packages/api/src/@core/connections/crm/services/pipedrive/pipedrive.service.ts @@ -19,6 +19,7 @@ import { } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export interface PipedriveOAuthResponse { access_token: string; @@ -31,6 +32,7 @@ export interface PipedriveOAuthResponse { @Injectable() export class PipedriveConnectionService implements ICrmConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -120,7 +122,12 @@ export class PipedriveConnectionService implements ICrmConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/crm/services/teamleader/teamleader.service.ts b/packages/api/src/@core/connections/crm/services/teamleader/teamleader.service.ts index d46bfe6e5..9e343e269 100644 --- a/packages/api/src/@core/connections/crm/services/teamleader/teamleader.service.ts +++ b/packages/api/src/@core/connections/crm/services/teamleader/teamleader.service.ts @@ -19,6 +19,7 @@ import { } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type TeamleaderOAuthResponse = { access_token: string; @@ -30,6 +31,7 @@ export type TeamleaderOAuthResponse = { @Injectable() export class TeamleaderConnectionService implements ICrmConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -122,7 +124,12 @@ export class TeamleaderConnectionService implements ICrmConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/crm/services/teamwork/teamwork.service.ts b/packages/api/src/@core/connections/crm/services/teamwork/teamwork.service.ts index 04e8f0b5f..1fe98720e 100644 --- a/packages/api/src/@core/connections/crm/services/teamwork/teamwork.service.ts +++ b/packages/api/src/@core/connections/crm/services/teamwork/teamwork.service.ts @@ -19,6 +19,7 @@ import { } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type TeamworkOAuthResponse = { access_token: string; @@ -27,6 +28,7 @@ export type TeamworkOAuthResponse = { @Injectable() export class TeamworkConnectionService implements ICrmConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -83,7 +85,8 @@ export class TeamworkConnectionService implements ICrmConnectionService { const connection_token = uuidv4(); //get the right BASE URL API const BASE_API_URL = - CREDENTIALS.SUBDOMAIN + CONNECTORS_METADATA['crm']['teamwork'].urls.apiUrl; + CREDENTIALS.SUBDOMAIN + + CONNECTORS_METADATA['crm']['teamwork'].urls.apiUrl; if (isNotUnique) { db_res = await this.prisma.connections.update({ @@ -112,7 +115,12 @@ export class TeamworkConnectionService implements ICrmConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/crm/services/zendesk/zendesk.service.ts b/packages/api/src/@core/connections/crm/services/zendesk/zendesk.service.ts index 351e81088..0d5f20d6c 100644 --- a/packages/api/src/@core/connections/crm/services/zendesk/zendesk.service.ts +++ b/packages/api/src/@core/connections/crm/services/zendesk/zendesk.service.ts @@ -19,6 +19,7 @@ import { } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export interface ZendeskSellOAuthResponse { access_token: string; @@ -31,6 +32,7 @@ export interface ZendeskSellOAuthResponse { @Injectable() export class ZendeskConnectionService implements ICrmConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -126,7 +128,12 @@ export class ZendeskConnectionService implements ICrmConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/crm/services/zoho/zoho.service.ts b/packages/api/src/@core/connections/crm/services/zoho/zoho.service.ts index 91f0da6c6..b578d5d53 100644 --- a/packages/api/src/@core/connections/crm/services/zoho/zoho.service.ts +++ b/packages/api/src/@core/connections/crm/services/zoho/zoho.service.ts @@ -19,6 +19,7 @@ import { } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; type ZohoUrlType = { [key: string]: { @@ -61,6 +62,7 @@ export interface ZohoOAuthResponse { @Injectable() export class ZohoConnectionService implements ICrmConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -134,7 +136,8 @@ export class ZohoConnectionService implements ICrmConnectionService { ), status: 'valid', created_at: new Date(), - account_url: apiDomain + CONNECTORS_METADATA['crm']['zoho'].urls.apiUrl, + account_url: + apiDomain + CONNECTORS_METADATA['crm']['zoho'].urls.apiUrl, }, }); } else { @@ -158,9 +161,15 @@ export class ZohoConnectionService implements ICrmConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, - account_url: apiDomain + CONNECTORS_METADATA['crm']['zoho'].urls.apiUrl, + account_url: + apiDomain + CONNECTORS_METADATA['crm']['zoho'].urls.apiUrl, }, }); } diff --git a/packages/api/src/@core/connections/marketingautomation/services/getresponse/getresponse.service.ts b/packages/api/src/@core/connections/marketingautomation/services/getresponse/getresponse.service.ts index 5dfd1fd24..33eb77b20 100644 --- a/packages/api/src/@core/connections/marketingautomation/services/getresponse/getresponse.service.ts +++ b/packages/api/src/@core/connections/marketingautomation/services/getresponse/getresponse.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type GetresponseOAuthResponse = { access_token: string; @@ -29,6 +30,7 @@ export class GetresponseConnectionService implements IMarketingAutomationConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -98,7 +100,8 @@ export class GetresponseConnectionService access_token: this.cryptoService.encrypt(data.access_token), refresh_token: this.cryptoService.encrypt(data.refresh_token), account_url: - CONNECTORS_METADATA['marketingautomation']['getresponse'].urls.apiUrl, + CONNECTORS_METADATA['marketingautomation']['getresponse'].urls + .apiUrl, expiration_timestamp: new Date( new Date().getTime() + Number(data.expires_in) * 1000, ), @@ -115,7 +118,8 @@ export class GetresponseConnectionService vertical: 'marketingautomation', token_type: 'oauth', account_url: - CONNECTORS_METADATA['marketingautomation']['getresponse'].urls.apiUrl, + CONNECTORS_METADATA['marketingautomation']['getresponse'].urls + .apiUrl, access_token: this.cryptoService.encrypt(data.access_token), refresh_token: this.cryptoService.encrypt(data.refresh_token), expiration_timestamp: new Date( @@ -127,7 +131,12 @@ export class GetresponseConnectionService connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/marketingautomation/services/mailchimp/mailchimp.service.ts b/packages/api/src/@core/connections/marketingautomation/services/mailchimp/mailchimp.service.ts index b250aa7c5..355cba371 100644 --- a/packages/api/src/@core/connections/marketingautomation/services/mailchimp/mailchimp.service.ts +++ b/packages/api/src/@core/connections/marketingautomation/services/mailchimp/mailchimp.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { AuthStrategy } from '@panora/shared'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type MailchimpOAuthResponse = { access_token: string; @@ -28,6 +29,7 @@ export class MailchimpConnectionService implements IMarketingAutomationConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -135,7 +137,12 @@ export class MailchimpConnectionService connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/marketingautomation/services/podium/podium.service.ts b/packages/api/src/@core/connections/marketingautomation/services/podium/podium.service.ts index 9e997d3be..607d0fa60 100644 --- a/packages/api/src/@core/connections/marketingautomation/services/podium/podium.service.ts +++ b/packages/api/src/@core/connections/marketingautomation/services/podium/podium.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type PodiumOAuthResponse = { access_token: string; @@ -26,6 +27,7 @@ export class PodiumConnectionService implements IMarketingAutomationConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -123,7 +125,12 @@ export class PodiumConnectionService connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/ticketing/services/aha/aha.service.ts b/packages/api/src/@core/connections/ticketing/services/aha/aha.service.ts index 43ee059f8..0b338e910 100644 --- a/packages/api/src/@core/connections/ticketing/services/aha/aha.service.ts +++ b/packages/api/src/@core/connections/ticketing/services/aha/aha.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type AhaOAuthResponse = { access_token: string; @@ -24,6 +25,7 @@ export type AhaOAuthResponse = { @Injectable() export class AhaConnectionService implements ITicketingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -82,7 +84,8 @@ export class AhaConnectionService implements ITicketingConnectionService { const connection_token = uuidv4(); //get the right BASE URL API const BASE_API_URL = - CREDENTIALS.SUBDOMAIN + CONNECTORS_METADATA['ticketing']['aha'].urls.apiUrl; + CREDENTIALS.SUBDOMAIN + + CONNECTORS_METADATA['ticketing']['aha'].urls.apiUrl; if (isNotUnique) { db_res = await this.prisma.connections.update({ @@ -112,7 +115,12 @@ export class AhaConnectionService implements ITicketingConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/ticketing/services/clickup/clickup.service.ts b/packages/api/src/@core/connections/ticketing/services/clickup/clickup.service.ts index 83248f2c0..d642d3b7a 100644 --- a/packages/api/src/@core/connections/ticketing/services/clickup/clickup.service.ts +++ b/packages/api/src/@core/connections/ticketing/services/clickup/clickup.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type ClickupOAuthResponse = { access_token: string; @@ -23,6 +24,7 @@ export type ClickupOAuthResponse = { @Injectable() export class ClickupConnectionService implements ITicketingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -107,7 +109,12 @@ export class ClickupConnectionService implements ITicketingConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/ticketing/services/front/front.service.ts b/packages/api/src/@core/connections/ticketing/services/front/front.service.ts index 9f0aed530..997c8c05f 100644 --- a/packages/api/src/@core/connections/ticketing/services/front/front.service.ts +++ b/packages/api/src/@core/connections/ticketing/services/front/front.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { AuthStrategy } from '@panora/shared'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type FrontOAuthResponse = { access_token: string; @@ -26,6 +27,7 @@ export type FrontOAuthResponse = { @Injectable() export class FrontConnectionService implements ITicketingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -117,7 +119,12 @@ export class FrontConnectionService implements ITicketingConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/ticketing/services/github/github.service.ts b/packages/api/src/@core/connections/ticketing/services/github/github.service.ts index 918392e77..53626a9ae 100644 --- a/packages/api/src/@core/connections/ticketing/services/github/github.service.ts +++ b/packages/api/src/@core/connections/ticketing/services/github/github.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type GithubOAuthResponse = { access_token: string; @@ -28,6 +29,7 @@ export type GithubOAuthResponse = { @Injectable() export class GithubConnectionService implements ITicketingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -118,7 +120,12 @@ export class GithubConnectionService implements ITicketingConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/ticketing/services/gitlab/gitlab.service.ts b/packages/api/src/@core/connections/ticketing/services/gitlab/gitlab.service.ts index 859f56605..2663f2031 100644 --- a/packages/api/src/@core/connections/ticketing/services/gitlab/gitlab.service.ts +++ b/packages/api/src/@core/connections/ticketing/services/gitlab/gitlab.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export interface GitlabOAuthResponse { access_token: string; @@ -27,6 +28,7 @@ export interface GitlabOAuthResponse { @Injectable() export class GitlabConnectionService implements ITicketingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -120,7 +122,12 @@ export class GitlabConnectionService implements ITicketingConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/ticketing/services/gorgias/gorgias.service.ts b/packages/api/src/@core/connections/ticketing/services/gorgias/gorgias.service.ts index 86ba75ed7..120ce873b 100644 --- a/packages/api/src/@core/connections/ticketing/services/gorgias/gorgias.service.ts +++ b/packages/api/src/@core/connections/ticketing/services/gorgias/gorgias.service.ts @@ -19,6 +19,7 @@ import { } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type GorgiasOAuthResponse = { access_token: string; @@ -32,6 +33,7 @@ export type GorgiasOAuthResponse = { @Injectable() export class GorgiasConnectionService implements ITicketingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -128,7 +130,12 @@ export class GorgiasConnectionService implements ITicketingConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/ticketing/services/jira/jira.service.ts b/packages/api/src/@core/connections/ticketing/services/jira/jira.service.ts index 458ef701d..8f966d934 100644 --- a/packages/api/src/@core/connections/ticketing/services/jira/jira.service.ts +++ b/packages/api/src/@core/connections/ticketing/services/jira/jira.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type JiraCloudIdInformation = { id: string; @@ -34,6 +35,7 @@ export type JiraOAuthResponse = { @Injectable() export class JiraConnectionService implements ITicketingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -146,7 +148,12 @@ export class JiraConnectionService implements ITicketingConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/ticketing/services/jira_service_mgmt/jira.service.ts b/packages/api/src/@core/connections/ticketing/services/jira_service_mgmt/jira.service.ts index 33820e25c..42b727091 100644 --- a/packages/api/src/@core/connections/ticketing/services/jira_service_mgmt/jira.service.ts +++ b/packages/api/src/@core/connections/ticketing/services/jira_service_mgmt/jira.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { AuthStrategy } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type JiraCloudIdInformation = { id: string; @@ -39,6 +40,7 @@ export class JiraServiceMgmtConnectionService implements ITicketingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -158,7 +160,12 @@ export class JiraServiceMgmtConnectionService connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/ticketing/services/linear/linear.service.ts b/packages/api/src/@core/connections/ticketing/services/linear/linear.service.ts index 2e4338e7c..f8985fe7f 100644 --- a/packages/api/src/@core/connections/ticketing/services/linear/linear.service.ts +++ b/packages/api/src/@core/connections/ticketing/services/linear/linear.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { AuthStrategy } from '@panora/shared'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export type LinearOAuthResponse = { access_token: string; @@ -26,6 +27,7 @@ export type LinearOAuthResponse = { @Injectable() export class LinearConnectionService implements ITicketingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -116,7 +118,12 @@ export class LinearConnectionService implements ITicketingConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, }); diff --git a/packages/api/src/@core/connections/ticketing/services/zendesk/zendesk.service.ts b/packages/api/src/@core/connections/ticketing/services/zendesk/zendesk.service.ts index df782d5a1..dc4deb376 100644 --- a/packages/api/src/@core/connections/ticketing/services/zendesk/zendesk.service.ts +++ b/packages/api/src/@core/connections/ticketing/services/zendesk/zendesk.service.ts @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service'; import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared'; import { OAuth2AuthData, providerToType } from '@panora/shared'; import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service'; +import { ConnectionUtils } from '@@core/connections/@utils'; export interface ZendeskOAuthResponse { access_token: string; @@ -24,6 +25,7 @@ export interface ZendeskOAuthResponse { @Injectable() export class ZendeskConnectionService implements ITicketingConnectionService { private readonly type: string; + private readonly connectionUtils = new ConnectionUtils(); constructor( private prisma: PrismaService, @@ -117,7 +119,12 @@ export class ZendeskConnectionService implements ITicketingConnectionService { connect: { id_project: projectId }, }, linked_users: { - connect: { id_linked_user: linkedUserId }, + connect: { + id_linked_user: await this.connectionUtils.getLinkedUserId( + projectId, + linkedUserId, + ), + }, }, }, });