From d30ad3ed2211f1f4c21e4e7cbe7619b6a6803316 Mon Sep 17 00:00:00 2001 From: mit-27 Date: Sun, 12 May 2024 20:39:47 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20handleTokenRefresh=20tasks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/api/src/@core/tasks/tasks.service.ts | 70 ++++++++++++++++--- 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/packages/api/src/@core/tasks/tasks.service.ts b/packages/api/src/@core/tasks/tasks.service.ts index aa3a4ff0b..dbbbba2bf 100644 --- a/packages/api/src/@core/tasks/tasks.service.ts +++ b/packages/api/src/@core/tasks/tasks.service.ts @@ -4,14 +4,21 @@ import { Cron, CronExpression } from '@nestjs/schedule'; import { PrismaService } from '../prisma/prisma.service'; import { CrmConnectionsService } from '../connections/crm/services/crm.connection.service'; import { LoggerService } from '@@core/logger/logger.service'; +import { ProviderVertical } from '@panora/shared'; +import { AccountingConnectionsService } from '@@core/connections/accounting/services/accounting.connection.service'; +import { MarketingAutomationConnectionsService } from '@@core/connections/marketingautomation/services/marketingautomation.connection.service'; +import { TicketingConnectionsService } from '@@core/connections/ticketing/services/ticketing.connection.service'; @Injectable() export class TasksService implements OnModuleInit { constructor( private prisma: PrismaService, - private crmConnectionsService: CrmConnectionsService, + private readonly crmConnectionsService: CrmConnectionsService, + private readonly ticketingConnectionsService: TicketingConnectionsService, + private readonly accountingConnectionsService: AccountingConnectionsService, + private readonly marketingAutomationConnectionsService: MarketingAutomationConnectionsService, private logger: LoggerService, - ) {} + ) { } onModuleInit() { this.handleCron(); @@ -34,13 +41,58 @@ export class TasksService implements OnModuleInit { if (connection.refresh_token) { const account_url = connection.provider_slug == 'zoho' ? connection.account_url : ''; - await this.crmConnectionsService.handleCRMTokensRefresh( - connection.id_connection, - connection.provider_slug, - connection.refresh_token, - connection.id_project, - account_url, - ); + + switch (connection.vertical) { + case ProviderVertical.CRM: + await this.crmConnectionsService.handleCRMTokensRefresh( + connection.id_connection, + connection.provider_slug, + connection.refresh_token, + connection.id_project, + account_url, + ); + break; + + case ProviderVertical.ATS: + break; + + case ProviderVertical.Accounting: + this.accountingConnectionsService.handleAccountingTokensRefresh( + connection.id_connection, + connection.provider_slug, + connection.refresh_token, + connection.id_project, + account_url, + ); + break; + + case ProviderVertical.FileStorage: + break; + + case ProviderVertical.HRIS: + break; + + case ProviderVertical.MarketingAutomation: + this.marketingAutomationConnectionsService.handleMarketingAutomationTokensRefresh( + connection.id_connection, + connection.provider_slug, + connection.refresh_token, + connection.id_project, + account_url, + ); + break; + + case ProviderVertical.Ticketing: + this.ticketingConnectionsService.handleTicketingTokensRefresh( + connection.id_connection, + connection.provider_slug, + connection.refresh_token, + connection.id_project, + account_url, + ); + break; + } + } } }