Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix access token refresh functionality #427

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 61 additions & 9 deletions packages/api/src/@core/tasks/tasks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}

}
}
}
Expand Down
Loading