diff --git a/packages/api/src/@core/connections/@utils/index.ts b/packages/api/src/@core/connections/@utils/index.ts index 770d19ab4..7e3034532 100644 --- a/packages/api/src/@core/connections/@utils/index.ts +++ b/packages/api/src/@core/connections/@utils/index.ts @@ -1,11 +1,11 @@ import { PrismaService } from '@@core/prisma/prisma.service'; -import { ConnectionsError, throwTypedError } from '@@core/utils/errors'; import { Injectable } from '@nestjs/common'; import { v4 as uuidv4 } from 'uuid'; export type ConnectionMetadata = { linkedUserId: string; remoteSource: string; + connectionId: string; }; @Injectable() @@ -26,6 +26,7 @@ export class ConnectionUtils { return { linkedUserId: res.id_linked_user, remoteSource: res.provider_slug, + connectionId: res.id_connection, }; } catch (error) { throw error; diff --git a/packages/api/src/@core/sync/sync.service.ts b/packages/api/src/@core/sync/sync.service.ts index 183ef0666..b7bb60207 100644 --- a/packages/api/src/@core/sync/sync.service.ts +++ b/packages/api/src/@core/sync/sync.service.ts @@ -131,13 +131,19 @@ export class CoreSyncService { ), ); + const connection = await this.prisma.connections.findFirst({ + where: { + id_linked_user: linkedUserId, + provider_slug: provider.toLowerCase(), + }, + }); + // Execute all tasks and handle results const results = await Promise.allSettled(tasks.map((task) => task())); const deals = await this.prisma.crm_deals.findMany({ where: { - remote_platform: provider, - id_linked_user: linkedUserId, + id_connection: connection.id_connection, }, }); @@ -205,12 +211,18 @@ export class CoreSyncService { ), ]; + const connection = await this.prisma.connections.findFirst({ + where: { + id_linked_user: linkedUserId, + provider_slug: provider.toLowerCase(), + }, + }); + const results = await Promise.allSettled(tasks.map((task) => task())); const accounts = await this.prisma.tcg_accounts.findMany({ where: { - remote_platform: provider, - id_linked_user: linkedUserId, + id_connection: connection.id_connection, }, }); let contactTasks = []; @@ -233,12 +245,12 @@ export class CoreSyncService { ), ]; } + const contactTasksResults = await Promise.allSettled(contactTasks); const tickets = await this.prisma.tcg_tickets.findMany({ where: { - remote_platform: provider, - id_linked_user: linkedUserId, + id_connection: connection.id_connection, }, }); diff --git a/packages/api/src/accounting/account/account.controller.ts b/packages/api/src/accounting/account/account.controller.ts index 80c804206..75c5511c8 100644 --- a/packages/api/src/accounting/account/account.controller.ts +++ b/packages/api/src/accounting/account/account.controller.ts @@ -57,12 +57,13 @@ export class AccountController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.accountService.getAccounts( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/accounting/account/services/account.service.ts b/packages/api/src/accounting/account/services/account.service.ts index 1307eec9f..ba2373ac8 100644 --- a/packages/api/src/accounting/account/services/account.service.ts +++ b/packages/api/src/accounting/account/services/account.service.ts @@ -44,6 +44,7 @@ export class AccountService { } async getAccounts( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/address/address.controller.ts b/packages/api/src/accounting/address/address.controller.ts index 24c4b5c1f..093c64ec3 100644 --- a/packages/api/src/accounting/address/address.controller.ts +++ b/packages/api/src/accounting/address/address.controller.ts @@ -57,12 +57,13 @@ export class AddressController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.addressService.getAddresss( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/accounting/address/services/address.service.ts b/packages/api/src/accounting/address/services/address.service.ts index 53ddf153b..3addfbeec 100644 --- a/packages/api/src/accounting/address/services/address.service.ts +++ b/packages/api/src/accounting/address/services/address.service.ts @@ -35,6 +35,7 @@ export class AddressService { } async getAddresss( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/attachment/attachment.controller.ts b/packages/api/src/accounting/attachment/attachment.controller.ts index 48248e16d..7a7e8b36c 100644 --- a/packages/api/src/accounting/attachment/attachment.controller.ts +++ b/packages/api/src/accounting/attachment/attachment.controller.ts @@ -57,12 +57,13 @@ export class AttachmentController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.attachmentService.getAttachments( + connectionId, remoteSource, linkedUserId, limit, @@ -130,12 +131,13 @@ export class AttachmentController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.attachmentService.addAttachment( unifiedAttachmentData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/accounting/attachment/services/attachment.service.ts b/packages/api/src/accounting/attachment/services/attachment.service.ts index a782354e6..e46eb8dec 100644 --- a/packages/api/src/accounting/attachment/services/attachment.service.ts +++ b/packages/api/src/accounting/attachment/services/attachment.service.ts @@ -29,6 +29,7 @@ export class AttachmentService { async addAttachment( unifiedAttachmentData: UnifiedAttachmentInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -44,6 +45,7 @@ export class AttachmentService { } async getAttachments( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/balancesheet/balancesheet.controller.ts b/packages/api/src/accounting/balancesheet/balancesheet.controller.ts index 24d93ff45..2aaa53d99 100644 --- a/packages/api/src/accounting/balancesheet/balancesheet.controller.ts +++ b/packages/api/src/accounting/balancesheet/balancesheet.controller.ts @@ -57,12 +57,13 @@ export class BalanceSheetController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.balancesheetService.getBalanceSheets( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/accounting/balancesheet/services/balancesheet.service.ts b/packages/api/src/accounting/balancesheet/services/balancesheet.service.ts index d7b6bd9e0..06fc0f75f 100644 --- a/packages/api/src/accounting/balancesheet/services/balancesheet.service.ts +++ b/packages/api/src/accounting/balancesheet/services/balancesheet.service.ts @@ -36,6 +36,7 @@ export class BalanceSheetService { } async getBalanceSheets( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/cashflowstatement/cashflowstatement.controller.ts b/packages/api/src/accounting/cashflowstatement/cashflowstatement.controller.ts index ce70bf203..6e28c3b1e 100644 --- a/packages/api/src/accounting/cashflowstatement/cashflowstatement.controller.ts +++ b/packages/api/src/accounting/cashflowstatement/cashflowstatement.controller.ts @@ -57,12 +57,13 @@ export class CashflowStatementController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.cashflowstatementService.getCashflowStatements( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/accounting/cashflowstatement/services/cashflowstatement.service.ts b/packages/api/src/accounting/cashflowstatement/services/cashflowstatement.service.ts index 7a8fb9a3b..7a252dd18 100644 --- a/packages/api/src/accounting/cashflowstatement/services/cashflowstatement.service.ts +++ b/packages/api/src/accounting/cashflowstatement/services/cashflowstatement.service.ts @@ -36,6 +36,7 @@ export class CashflowStatementService { } async getCashflowStatements( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/companyinfo/companyinfo.controller.ts b/packages/api/src/accounting/companyinfo/companyinfo.controller.ts index 47b4726e2..31327108e 100644 --- a/packages/api/src/accounting/companyinfo/companyinfo.controller.ts +++ b/packages/api/src/accounting/companyinfo/companyinfo.controller.ts @@ -57,12 +57,13 @@ export class CompanyInfoController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.companyinfoService.getCompanyInfos( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/accounting/companyinfo/services/companyinfo.service.ts b/packages/api/src/accounting/companyinfo/services/companyinfo.service.ts index 7b1c54c54..ec890cbc3 100644 --- a/packages/api/src/accounting/companyinfo/services/companyinfo.service.ts +++ b/packages/api/src/accounting/companyinfo/services/companyinfo.service.ts @@ -36,6 +36,7 @@ export class CompanyInfoService { } async getCompanyInfos( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/contact/contact.controller.ts b/packages/api/src/accounting/contact/contact.controller.ts index 85b0f1cc2..d364d2a82 100644 --- a/packages/api/src/accounting/contact/contact.controller.ts +++ b/packages/api/src/accounting/contact/contact.controller.ts @@ -57,12 +57,13 @@ export class ContactController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.contactService.getContacts( + connectionId, remoteSource, linkedUserId, limit, @@ -130,12 +131,13 @@ export class ContactController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.contactService.addContact( unifiedContactData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/accounting/contact/services/contact.service.ts b/packages/api/src/accounting/contact/services/contact.service.ts index 731b5a6ec..cff93aebf 100644 --- a/packages/api/src/accounting/contact/services/contact.service.ts +++ b/packages/api/src/accounting/contact/services/contact.service.ts @@ -30,6 +30,7 @@ export class ContactService { async addContact( unifiedContactData: UnifiedContactInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -45,6 +46,7 @@ export class ContactService { } async getContacts( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/creditnote/creditnote.controller.ts b/packages/api/src/accounting/creditnote/creditnote.controller.ts index c8c6b084c..599f2def2 100644 --- a/packages/api/src/accounting/creditnote/creditnote.controller.ts +++ b/packages/api/src/accounting/creditnote/creditnote.controller.ts @@ -57,12 +57,13 @@ export class CreditNoteController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.creditnoteService.getCreditNotes( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/accounting/creditnote/services/creditnote.service.ts b/packages/api/src/accounting/creditnote/services/creditnote.service.ts index 6957fcb63..0244a21ef 100644 --- a/packages/api/src/accounting/creditnote/services/creditnote.service.ts +++ b/packages/api/src/accounting/creditnote/services/creditnote.service.ts @@ -36,6 +36,7 @@ export class CreditNoteService { } async getCreditNotes( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/expense/expense.controller.ts b/packages/api/src/accounting/expense/expense.controller.ts index 6dbaebbc1..fa8513401 100644 --- a/packages/api/src/accounting/expense/expense.controller.ts +++ b/packages/api/src/accounting/expense/expense.controller.ts @@ -57,12 +57,13 @@ export class ExpenseController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.expenseService.getExpenses( + connectionId, remoteSource, linkedUserId, limit, @@ -130,12 +131,13 @@ export class ExpenseController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.expenseService.addExpense( unifiedExpenseData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/accounting/expense/services/expense.service.ts b/packages/api/src/accounting/expense/services/expense.service.ts index 5a8443b36..9260134a3 100644 --- a/packages/api/src/accounting/expense/services/expense.service.ts +++ b/packages/api/src/accounting/expense/services/expense.service.ts @@ -30,6 +30,7 @@ export class ExpenseService { async addExpense( unifiedExpenseData: UnifiedExpenseInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -45,6 +46,7 @@ export class ExpenseService { } async getExpenses( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/incomestatement/incomestatement.controller.ts b/packages/api/src/accounting/incomestatement/incomestatement.controller.ts index 7493d99b5..b371c5f27 100644 --- a/packages/api/src/accounting/incomestatement/incomestatement.controller.ts +++ b/packages/api/src/accounting/incomestatement/incomestatement.controller.ts @@ -57,12 +57,13 @@ export class IncomeStatementController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.incomestatementService.getIncomeStatements( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/accounting/incomestatement/services/incomestatement.service.ts b/packages/api/src/accounting/incomestatement/services/incomestatement.service.ts index f659a79e6..8de861bb8 100644 --- a/packages/api/src/accounting/incomestatement/services/incomestatement.service.ts +++ b/packages/api/src/accounting/incomestatement/services/incomestatement.service.ts @@ -36,6 +36,7 @@ export class IncomeStatementService { } async getIncomeStatements( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/invoice/invoice.controller.ts b/packages/api/src/accounting/invoice/invoice.controller.ts index 5b174f3dd..af6ad9bb0 100644 --- a/packages/api/src/accounting/invoice/invoice.controller.ts +++ b/packages/api/src/accounting/invoice/invoice.controller.ts @@ -57,12 +57,13 @@ export class InvoiceController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.invoiceService.getInvoices( + connectionId, remoteSource, linkedUserId, limit, @@ -130,12 +131,13 @@ export class InvoiceController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.invoiceService.addInvoice( unifiedInvoiceData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/accounting/invoice/services/invoice.service.ts b/packages/api/src/accounting/invoice/services/invoice.service.ts index 49ec48539..51a990d5d 100644 --- a/packages/api/src/accounting/invoice/services/invoice.service.ts +++ b/packages/api/src/accounting/invoice/services/invoice.service.ts @@ -30,6 +30,7 @@ export class InvoiceService { async addInvoice( unifiedInvoiceData: UnifiedInvoiceInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -45,6 +46,7 @@ export class InvoiceService { } async getInvoices( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/item/item.controller.ts b/packages/api/src/accounting/item/item.controller.ts index 4622120c8..f25c9c174 100644 --- a/packages/api/src/accounting/item/item.controller.ts +++ b/packages/api/src/accounting/item/item.controller.ts @@ -54,12 +54,13 @@ export class ItemController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.itemService.getItems( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/accounting/item/services/item.service.ts b/packages/api/src/accounting/item/services/item.service.ts index cf92b9fde..bd91b61e5 100644 --- a/packages/api/src/accounting/item/services/item.service.ts +++ b/packages/api/src/accounting/item/services/item.service.ts @@ -33,6 +33,7 @@ export class ItemService { } async getItems( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/journalentry/journalentry.controller.ts b/packages/api/src/accounting/journalentry/journalentry.controller.ts index 9230b6dcb..f615694af 100644 --- a/packages/api/src/accounting/journalentry/journalentry.controller.ts +++ b/packages/api/src/accounting/journalentry/journalentry.controller.ts @@ -57,12 +57,13 @@ export class JournalEntryController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.journalentryService.getJournalEntrys( + connectionId, remoteSource, linkedUserId, limit, @@ -131,12 +132,13 @@ export class JournalEntryController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.journalentryService.addJournalEntry( unifiedJournalEntryData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/accounting/journalentry/services/journalentry.service.ts b/packages/api/src/accounting/journalentry/services/journalentry.service.ts index 93c8c5ee9..8ba567a88 100644 --- a/packages/api/src/accounting/journalentry/services/journalentry.service.ts +++ b/packages/api/src/accounting/journalentry/services/journalentry.service.ts @@ -30,6 +30,7 @@ export class JournalEntryService { async addJournalEntry( unifiedJournalEntryData: UnifiedJournalEntryInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -45,6 +46,7 @@ export class JournalEntryService { } async getJournalEntrys( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/payment/payment.controller.ts b/packages/api/src/accounting/payment/payment.controller.ts index a34ee2c80..f8cde65dd 100644 --- a/packages/api/src/accounting/payment/payment.controller.ts +++ b/packages/api/src/accounting/payment/payment.controller.ts @@ -57,12 +57,13 @@ export class PaymentController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.paymentService.getPayments( + connectionId, remoteSource, linkedUserId, limit, @@ -130,12 +131,13 @@ export class PaymentController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.paymentService.addPayment( unifiedPaymentData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/accounting/payment/services/payment.service.ts b/packages/api/src/accounting/payment/services/payment.service.ts index 2d9d163b5..4749fd7ec 100644 --- a/packages/api/src/accounting/payment/services/payment.service.ts +++ b/packages/api/src/accounting/payment/services/payment.service.ts @@ -30,6 +30,7 @@ export class PaymentService { async addPayment( unifiedPaymentData: UnifiedPaymentInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -45,6 +46,7 @@ export class PaymentService { } async getPayments( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/phonenumber/phonenumber.controller.ts b/packages/api/src/accounting/phonenumber/phonenumber.controller.ts index 217d2ec0a..b39e5b7b6 100644 --- a/packages/api/src/accounting/phonenumber/phonenumber.controller.ts +++ b/packages/api/src/accounting/phonenumber/phonenumber.controller.ts @@ -57,12 +57,13 @@ export class PhoneNumberController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.phonenumberService.getPhoneNumbers( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/accounting/phonenumber/services/phonenumber.service.ts b/packages/api/src/accounting/phonenumber/services/phonenumber.service.ts index 17d306919..d8b66405c 100644 --- a/packages/api/src/accounting/phonenumber/services/phonenumber.service.ts +++ b/packages/api/src/accounting/phonenumber/services/phonenumber.service.ts @@ -36,6 +36,7 @@ export class PhoneNumberService { } async getPhoneNumbers( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/purchaseorder/purchaseorder.controller.ts b/packages/api/src/accounting/purchaseorder/purchaseorder.controller.ts index 5b16b4cf7..1a3acb58f 100644 --- a/packages/api/src/accounting/purchaseorder/purchaseorder.controller.ts +++ b/packages/api/src/accounting/purchaseorder/purchaseorder.controller.ts @@ -57,12 +57,13 @@ export class PurchaseOrderController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.purchaseorderService.getPurchaseOrders( + connectionId, remoteSource, linkedUserId, limit, @@ -131,12 +132,13 @@ export class PurchaseOrderController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.purchaseorderService.addPurchaseOrder( unifiedPurchaseOrderData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/accounting/purchaseorder/services/purchaseorder.service.ts b/packages/api/src/accounting/purchaseorder/services/purchaseorder.service.ts index 3226422f3..820674e66 100644 --- a/packages/api/src/accounting/purchaseorder/services/purchaseorder.service.ts +++ b/packages/api/src/accounting/purchaseorder/services/purchaseorder.service.ts @@ -30,6 +30,7 @@ export class PurchaseOrderService { async addPurchaseOrder( unifiedPurchaseOrderData: UnifiedPurchaseOrderInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -45,6 +46,7 @@ export class PurchaseOrderService { } async getPurchaseOrders( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/taxrate/services/taxrate.service.ts b/packages/api/src/accounting/taxrate/services/taxrate.service.ts index d6f915bca..eb815a689 100644 --- a/packages/api/src/accounting/taxrate/services/taxrate.service.ts +++ b/packages/api/src/accounting/taxrate/services/taxrate.service.ts @@ -36,6 +36,7 @@ export class TaxRateService { } async getTaxRates( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/taxrate/taxrate.controller.ts b/packages/api/src/accounting/taxrate/taxrate.controller.ts index 23211afff..4d867a538 100644 --- a/packages/api/src/accounting/taxrate/taxrate.controller.ts +++ b/packages/api/src/accounting/taxrate/taxrate.controller.ts @@ -57,12 +57,13 @@ export class TaxRateController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.taxrateService.getTaxRates( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/accounting/trackingcategory/services/trackingcategory.service.ts b/packages/api/src/accounting/trackingcategory/services/trackingcategory.service.ts index a16409d95..ded8cc19f 100644 --- a/packages/api/src/accounting/trackingcategory/services/trackingcategory.service.ts +++ b/packages/api/src/accounting/trackingcategory/services/trackingcategory.service.ts @@ -36,6 +36,7 @@ export class TrackingCategoryService { } async getTrackingCategorys( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/trackingcategory/trackingcategory.controller.ts b/packages/api/src/accounting/trackingcategory/trackingcategory.controller.ts index b647b531d..3af130077 100644 --- a/packages/api/src/accounting/trackingcategory/trackingcategory.controller.ts +++ b/packages/api/src/accounting/trackingcategory/trackingcategory.controller.ts @@ -57,12 +57,13 @@ export class TrackingCategoryController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.trackingcategoryService.getTrackingCategorys( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/accounting/transaction/services/transaction.service.ts b/packages/api/src/accounting/transaction/services/transaction.service.ts index 6cc90a48e..95852b8a6 100644 --- a/packages/api/src/accounting/transaction/services/transaction.service.ts +++ b/packages/api/src/accounting/transaction/services/transaction.service.ts @@ -36,6 +36,7 @@ export class TransactionService { } async getTransactions( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/transaction/transaction.controller.ts b/packages/api/src/accounting/transaction/transaction.controller.ts index c5177d510..2ee846bf9 100644 --- a/packages/api/src/accounting/transaction/transaction.controller.ts +++ b/packages/api/src/accounting/transaction/transaction.controller.ts @@ -57,12 +57,13 @@ export class TransactionController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.transactionService.getTransactions( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/accounting/vendorcredit/services/vendorcredit.service.ts b/packages/api/src/accounting/vendorcredit/services/vendorcredit.service.ts index bf9db445d..479abfedc 100644 --- a/packages/api/src/accounting/vendorcredit/services/vendorcredit.service.ts +++ b/packages/api/src/accounting/vendorcredit/services/vendorcredit.service.ts @@ -36,6 +36,7 @@ export class VendorCreditService { } async getVendorCredits( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/accounting/vendorcredit/vendorcredit.controller.ts b/packages/api/src/accounting/vendorcredit/vendorcredit.controller.ts index 2d009f127..4e487b4d9 100644 --- a/packages/api/src/accounting/vendorcredit/vendorcredit.controller.ts +++ b/packages/api/src/accounting/vendorcredit/vendorcredit.controller.ts @@ -57,12 +57,13 @@ export class VendorCreditController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.vendorcreditService.getVendorCredits( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/ats/activity/activity.controller.ts b/packages/api/src/ats/activity/activity.controller.ts index fd86f4e63..032cc01a8 100644 --- a/packages/api/src/ats/activity/activity.controller.ts +++ b/packages/api/src/ats/activity/activity.controller.ts @@ -57,12 +57,13 @@ export class ActivityController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.activityService.getActivities( + connectionId, remoteSource, linkedUserId, limit, @@ -128,12 +129,13 @@ export class ActivityController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.activityService.addActivity( unifiedActivityData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/ats/activity/services/activity.service.ts b/packages/api/src/ats/activity/services/activity.service.ts index 4d5c25fd6..f871017c0 100644 --- a/packages/api/src/ats/activity/services/activity.service.ts +++ b/packages/api/src/ats/activity/services/activity.service.ts @@ -30,6 +30,7 @@ export class ActivityService { async addActivity( unifiedActivityData: UnifiedActivityInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -79,8 +80,7 @@ export class ActivityService { const existingActivity = await this.prisma.ats_activities.findFirst({ where: { remote_id: target_activity.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -112,9 +112,8 @@ export class ActivityService { remote_created_at: target_activity.remote_created_at, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_activity.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; const newActivity = await this.prisma.ats_activities.create({ @@ -275,6 +274,7 @@ export class ActivityService { } async getActivities( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -292,8 +292,7 @@ export class ActivityService { if (cursor) { const isCursorPresent = await this.prisma.ats_activities.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_ats_activity: cursor, }, }); @@ -307,8 +306,7 @@ export class ActivityService { cursor: cursor ? { id_ats_activity: cursor } : undefined, orderBy: { created_at: 'asc' }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ats/activity/sync/sync.service.ts b/packages/api/src/ats/activity/sync/sync.service.ts index 7cb7b88b8..6b8063385 100644 --- a/packages/api/src/ats/activity/sync/sync.service.ts +++ b/packages/api/src/ats/activity/sync/sync.service.ts @@ -217,8 +217,7 @@ export class SyncService implements OnModuleInit { const existingActivity = await this.prisma.ats_activities.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -263,9 +262,8 @@ export class SyncService implements OnModuleInit { id_ats_activity: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (activity.activity_type) { diff --git a/packages/api/src/ats/application/application.controller.ts b/packages/api/src/ats/application/application.controller.ts index 6e0b31cec..848b811de 100644 --- a/packages/api/src/ats/application/application.controller.ts +++ b/packages/api/src/ats/application/application.controller.ts @@ -57,12 +57,13 @@ export class ApplicationController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.applicationService.getApplications( + connectionId, remoteSource, linkedUserId, limit, @@ -128,12 +129,13 @@ export class ApplicationController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.applicationService.addApplication( unifiedApplicationData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/ats/application/services/application.service.ts b/packages/api/src/ats/application/services/application.service.ts index f8823b73e..70619273f 100644 --- a/packages/api/src/ats/application/services/application.service.ts +++ b/packages/api/src/ats/application/services/application.service.ts @@ -30,6 +30,7 @@ export class ApplicationService { async addApplication( unifiedApplicationData: UnifiedApplicationInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -79,8 +80,7 @@ export class ApplicationService { const existingApplication = await this.prisma.ats_applications.findFirst({ where: { remote_id: target_application.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -116,9 +116,8 @@ export class ApplicationService { reject_reason: target_application.reject_reason, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_application.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; const newApplication = await this.prisma.ats_applications.create({ @@ -293,6 +292,7 @@ export class ApplicationService { } async getApplications( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -310,8 +310,7 @@ export class ApplicationService { if (cursor) { const isCursorPresent = await this.prisma.ats_applications.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_ats_application: cursor, }, }); @@ -325,8 +324,7 @@ export class ApplicationService { cursor: cursor ? { id_ats_application: cursor } : undefined, orderBy: { created_at: 'asc' }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ats/application/sync/sync.service.ts b/packages/api/src/ats/application/sync/sync.service.ts index 7b2944101..89c28b6a4 100644 --- a/packages/api/src/ats/application/sync/sync.service.ts +++ b/packages/api/src/ats/application/sync/sync.service.ts @@ -215,8 +215,7 @@ export class SyncService implements OnModuleInit { await this.prisma.ats_applications.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -270,9 +269,8 @@ export class SyncService implements OnModuleInit { id_ats_application: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (application.applied_at) { diff --git a/packages/api/src/ats/attachment/attachment.controller.ts b/packages/api/src/ats/attachment/attachment.controller.ts index 526e2539e..6cef56561 100644 --- a/packages/api/src/ats/attachment/attachment.controller.ts +++ b/packages/api/src/ats/attachment/attachment.controller.ts @@ -57,12 +57,13 @@ export class AttachmentController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.attachmentService.getAttachments( + connectionId, remoteSource, linkedUserId, limit, @@ -128,12 +129,13 @@ export class AttachmentController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.attachmentService.addAttachment( unifiedAttachmentData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/ats/attachment/services/attachment.service.ts b/packages/api/src/ats/attachment/services/attachment.service.ts index 48244fa9d..5d7abbc5e 100644 --- a/packages/api/src/ats/attachment/services/attachment.service.ts +++ b/packages/api/src/ats/attachment/services/attachment.service.ts @@ -30,6 +30,7 @@ export class AttachmentService { async addAttachment( unifiedAttachmentData: UnifiedAttachmentInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -82,8 +83,7 @@ export class AttachmentService { await this.prisma.ats_candidate_attachments.findFirst({ where: { remote_id: target_attachment.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -118,9 +118,8 @@ export class AttachmentService { remote_modified_at: target_attachment.remote_modified_at, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_attachment.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; const newAttachment = @@ -288,6 +287,7 @@ export class AttachmentService { } async getAttachments( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -306,8 +306,7 @@ export class AttachmentService { const isCursorPresent = await this.prisma.ats_candidate_attachments.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_ats_candidate_attachment: cursor, }, }); @@ -321,8 +320,7 @@ export class AttachmentService { cursor: cursor ? { id_ats_candidate_attachment: cursor } : undefined, orderBy: { created_at: 'asc' }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ats/attachment/sync/sync.service.ts b/packages/api/src/ats/attachment/sync/sync.service.ts index a61777845..4ef1714ef 100644 --- a/packages/api/src/ats/attachment/sync/sync.service.ts +++ b/packages/api/src/ats/attachment/sync/sync.service.ts @@ -214,8 +214,7 @@ export class SyncService implements OnModuleInit { const existingAttachment = await this.prisma.ats_attachments.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -263,9 +262,8 @@ export class SyncService implements OnModuleInit { id_ats_attachment: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (attachment.file_url) { diff --git a/packages/api/src/ats/candidate/candidate.controller.ts b/packages/api/src/ats/candidate/candidate.controller.ts index df8788035..da91b9420 100644 --- a/packages/api/src/ats/candidate/candidate.controller.ts +++ b/packages/api/src/ats/candidate/candidate.controller.ts @@ -57,12 +57,13 @@ export class CandidateController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.candidateService.getCandidates( + connectionId, remoteSource, linkedUserId, limit, @@ -128,12 +129,13 @@ export class CandidateController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.candidateService.addCandidate( unifiedCandidateData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/ats/candidate/services/candidate.service.ts b/packages/api/src/ats/candidate/services/candidate.service.ts index 9f85d8c43..dcc58fb95 100644 --- a/packages/api/src/ats/candidate/services/candidate.service.ts +++ b/packages/api/src/ats/candidate/services/candidate.service.ts @@ -30,6 +30,7 @@ export class CandidateService { async addCandidate( unifiedCandidateData: UnifiedCandidateInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -79,8 +80,7 @@ export class CandidateService { const existingCandidate = await this.prisma.ats_candidates.findFirst({ where: { remote_id: target_candidate.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -122,9 +122,8 @@ export class CandidateService { locations: target_candidate.locations, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_candidate.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; const newCandidate = await this.prisma.ats_candidates.create({ @@ -345,6 +344,7 @@ export class CandidateService { } async getCandidates( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -362,8 +362,7 @@ export class CandidateService { if (cursor) { const isCursorPresent = await this.prisma.ats_candidates.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_ats_candidate: cursor, }, }); @@ -377,8 +376,7 @@ export class CandidateService { cursor: cursor ? { id_ats_candidate: cursor } : undefined, orderBy: { created_at: 'asc' }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ats/candidate/sync/sync.service.ts b/packages/api/src/ats/candidate/sync/sync.service.ts index 1824261d9..2a55ea0e4 100644 --- a/packages/api/src/ats/candidate/sync/sync.service.ts +++ b/packages/api/src/ats/candidate/sync/sync.service.ts @@ -214,8 +214,7 @@ export class SyncService implements OnModuleInit { const existingCandidate = await this.prisma.ats_candidates.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -278,9 +277,8 @@ export class SyncService implements OnModuleInit { id_ats_candidate: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (candidate.first_name) { diff --git a/packages/api/src/ats/department/department.controller.ts b/packages/api/src/ats/department/department.controller.ts index 386ef56b9..07e1d8b3e 100644 --- a/packages/api/src/ats/department/department.controller.ts +++ b/packages/api/src/ats/department/department.controller.ts @@ -57,12 +57,13 @@ export class DepartmentController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.departmentService.getDepartments( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/ats/department/services/department.service.ts b/packages/api/src/ats/department/services/department.service.ts index f756d1de3..078b21a61 100644 --- a/packages/api/src/ats/department/services/department.service.ts +++ b/packages/api/src/ats/department/services/department.service.ts @@ -81,6 +81,7 @@ export class DepartmentService { } async getDepartments( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -90,8 +91,7 @@ export class DepartmentService { try { const departments = await this.prisma.ats_departments.findMany({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ats/department/sync/sync.service.ts b/packages/api/src/ats/department/sync/sync.service.ts index 0873d7fec..4a49d2916 100644 --- a/packages/api/src/ats/department/sync/sync.service.ts +++ b/packages/api/src/ats/department/sync/sync.service.ts @@ -214,8 +214,7 @@ export class SyncService implements OnModuleInit { const existingDepartment = await this.prisma.ats_departments.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -245,9 +244,8 @@ export class SyncService implements OnModuleInit { id_ats_department: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (department.name) { diff --git a/packages/api/src/ats/eeocs/eeocs.controller.ts b/packages/api/src/ats/eeocs/eeocs.controller.ts index 9a7ba85da..f4cdde886 100644 --- a/packages/api/src/ats/eeocs/eeocs.controller.ts +++ b/packages/api/src/ats/eeocs/eeocs.controller.ts @@ -54,12 +54,13 @@ export class EeocsController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.eeocsService.getEeocss( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/ats/eeocs/services/eeocs.service.ts b/packages/api/src/ats/eeocs/services/eeocs.service.ts index c0c6cfc56..3a79652f5 100644 --- a/packages/api/src/ats/eeocs/services/eeocs.service.ts +++ b/packages/api/src/ats/eeocs/services/eeocs.service.ts @@ -86,6 +86,7 @@ export class EeocsService { } async getEeocss( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -95,8 +96,7 @@ export class EeocsService { try { const eeocss = await this.prisma.ats_eeocs.findMany({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ats/eeocs/sync/sync.service.ts b/packages/api/src/ats/eeocs/sync/sync.service.ts index 7dda21f0c..a05055e78 100644 --- a/packages/api/src/ats/eeocs/sync/sync.service.ts +++ b/packages/api/src/ats/eeocs/sync/sync.service.ts @@ -216,8 +216,7 @@ export class SyncService implements OnModuleInit { const existingEeoc = await this.prisma.ats_eeocs.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -262,9 +261,8 @@ export class SyncService implements OnModuleInit { id_ats_eeoc: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (eeoc.candidate_id) { diff --git a/packages/api/src/ats/interview/interview.controller.ts b/packages/api/src/ats/interview/interview.controller.ts index 630bc3e3d..e59cc3bb6 100644 --- a/packages/api/src/ats/interview/interview.controller.ts +++ b/packages/api/src/ats/interview/interview.controller.ts @@ -57,12 +57,13 @@ export class InterviewController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.interviewService.getInterviews( + connectionId, remoteSource, linkedUserId, limit, @@ -122,12 +123,13 @@ export class InterviewController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.interviewService.addInterview( unifiedInterviewData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/ats/interview/services/interview.service.ts b/packages/api/src/ats/interview/services/interview.service.ts index a2ec6da94..7f83f04c9 100644 --- a/packages/api/src/ats/interview/services/interview.service.ts +++ b/packages/api/src/ats/interview/services/interview.service.ts @@ -29,6 +29,7 @@ export class InterviewService { async addInterview( unifiedInterviewData: UnifiedInterviewInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -82,8 +83,7 @@ export class InterviewService { const existingInterview = await this.prisma.ats_interviews.findFirst({ where: { remote_id: target_interview.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -127,9 +127,8 @@ export class InterviewService { remote_updated_at: target_interview.remote_updated_at, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_interview.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; const newInterview = await this.prisma.ats_interviews.create({ @@ -306,6 +305,7 @@ export class InterviewService { } async getInterviews( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -323,8 +323,7 @@ export class InterviewService { if (cursor) { const isCursorPresent = await this.prisma.ats_interviews.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_ats_interview: cursor, }, }); @@ -344,8 +343,7 @@ export class InterviewService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ats/interview/sync/sync.service.ts b/packages/api/src/ats/interview/sync/sync.service.ts index 82cab2921..5ce0a1ed1 100644 --- a/packages/api/src/ats/interview/sync/sync.service.ts +++ b/packages/api/src/ats/interview/sync/sync.service.ts @@ -214,8 +214,7 @@ export class SyncService implements OnModuleInit { const existingInterview = await this.prisma.ats_interviews.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -275,9 +274,8 @@ export class SyncService implements OnModuleInit { id_ats_interview: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (interview.status) { diff --git a/packages/api/src/ats/job/job.controller.ts b/packages/api/src/ats/job/job.controller.ts index 553211ade..78248f07c 100644 --- a/packages/api/src/ats/job/job.controller.ts +++ b/packages/api/src/ats/job/job.controller.ts @@ -54,12 +54,19 @@ export class JobController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; - return this.jobService.getJobs(remoteSource, linkedUserId, remote_data); + return this.jobService.getJobs( + connectionId, + remoteSource, + linkedUserId, + limit, + remote_data, + cursor, + ); } catch (error) { throw new Error(error); } diff --git a/packages/api/src/ats/job/services/job.service.ts b/packages/api/src/ats/job/services/job.service.ts index 6b367b527..0ba8e3180 100644 --- a/packages/api/src/ats/job/services/job.service.ts +++ b/packages/api/src/ats/job/services/job.service.ts @@ -92,6 +92,7 @@ export class JobService { } async getJobs( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -101,8 +102,7 @@ export class JobService { try { const jobs = await this.prisma.ats_jobs.findMany({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ats/job/sync/sync.service.ts b/packages/api/src/ats/job/sync/sync.service.ts index 0db97bcb8..b2c2246e1 100644 --- a/packages/api/src/ats/job/sync/sync.service.ts +++ b/packages/api/src/ats/job/sync/sync.service.ts @@ -216,8 +216,7 @@ export class SyncService implements OnModuleInit { const existingJob = await this.prisma.ats_jobs.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -280,9 +279,8 @@ export class SyncService implements OnModuleInit { id_ats_job: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (job.name) { diff --git a/packages/api/src/ats/jobinterviewstage/jobinterviewstage.controller.ts b/packages/api/src/ats/jobinterviewstage/jobinterviewstage.controller.ts index ae4805fc8..bff81ef95 100644 --- a/packages/api/src/ats/jobinterviewstage/jobinterviewstage.controller.ts +++ b/packages/api/src/ats/jobinterviewstage/jobinterviewstage.controller.ts @@ -57,12 +57,13 @@ export class JobInterviewStageController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.jobinterviewstageService.getJobInterviewStages( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/ats/jobinterviewstage/services/jobinterviewstage.service.ts b/packages/api/src/ats/jobinterviewstage/services/jobinterviewstage.service.ts index af7347d66..29727f232 100644 --- a/packages/api/src/ats/jobinterviewstage/services/jobinterviewstage.service.ts +++ b/packages/api/src/ats/jobinterviewstage/services/jobinterviewstage.service.ts @@ -85,6 +85,7 @@ export class JobInterviewStageService { } async getJobInterviewStages( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -94,8 +95,7 @@ export class JobInterviewStageService { try { const stages = await this.prisma.ats_job_interview_stages.findMany({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ats/jobinterviewstage/sync/sync.service.ts b/packages/api/src/ats/jobinterviewstage/sync/sync.service.ts index fecda080c..67878c534 100644 --- a/packages/api/src/ats/jobinterviewstage/sync/sync.service.ts +++ b/packages/api/src/ats/jobinterviewstage/sync/sync.service.ts @@ -215,8 +215,7 @@ export class SyncService implements OnModuleInit { await this.prisma.ats_job_interview_stages.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -255,9 +254,8 @@ export class SyncService implements OnModuleInit { id_ats_job_interview_stage: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (jobInterviewStage.name) { diff --git a/packages/api/src/ats/offer/offer.controller.ts b/packages/api/src/ats/offer/offer.controller.ts index 74926db07..f5d4fe5fc 100644 --- a/packages/api/src/ats/offer/offer.controller.ts +++ b/packages/api/src/ats/offer/offer.controller.ts @@ -54,12 +54,13 @@ export class OfferController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.offerService.getOffers( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/ats/offer/services/offer.service.ts b/packages/api/src/ats/offer/services/offer.service.ts index 4b18de7e2..141e203b7 100644 --- a/packages/api/src/ats/offer/services/offer.service.ts +++ b/packages/api/src/ats/offer/services/offer.service.ts @@ -87,6 +87,7 @@ export class OfferService { } async getOffers( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -96,8 +97,7 @@ export class OfferService { try { const offers = await this.prisma.ats_offers.findMany({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ats/offer/sync/sync.service.ts b/packages/api/src/ats/offer/sync/sync.service.ts index 7189b36e0..e6fd6f103 100644 --- a/packages/api/src/ats/offer/sync/sync.service.ts +++ b/packages/api/src/ats/offer/sync/sync.service.ts @@ -216,8 +216,7 @@ export class SyncService implements OnModuleInit { const existingOffer = await this.prisma.ats_offers.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -267,7 +266,7 @@ export class SyncService implements OnModuleInit { modified_at: new Date(), id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (offer.created_by) { diff --git a/packages/api/src/ats/office/office.controller.ts b/packages/api/src/ats/office/office.controller.ts index 320d796b2..531db60e9 100644 --- a/packages/api/src/ats/office/office.controller.ts +++ b/packages/api/src/ats/office/office.controller.ts @@ -54,12 +54,13 @@ export class OfficeController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.officeService.getOffices( + connectionId, remoteSource, linkedUserId, limit, @@ -97,46 +98,4 @@ export class OfficeController { ) { return this.officeService.getOffice(id, remote_data); } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a Office', - description: 'Create a office in any supported Ats software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: 'Set to true to include data from the original Ats software.', - }) - @ApiBody({ type: UnifiedOfficeInput }) - @ApiCustomResponse(UnifiedOfficeOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedOfficeData: UnifiedOfficeInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.officeService.addOffice( - unifiedOfficeData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/ats/office/services/office.service.ts b/packages/api/src/ats/office/services/office.service.ts index 93074c684..225ca63b6 100644 --- a/packages/api/src/ats/office/services/office.service.ts +++ b/packages/api/src/ats/office/services/office.service.ts @@ -82,6 +82,7 @@ export class OfficeService { } async getOffices( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -91,8 +92,7 @@ export class OfficeService { try { const offices = await this.prisma.ats_offices.findMany({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ats/office/sync/sync.service.ts b/packages/api/src/ats/office/sync/sync.service.ts index 37ae12cd2..f0e3d5193 100644 --- a/packages/api/src/ats/office/sync/sync.service.ts +++ b/packages/api/src/ats/office/sync/sync.service.ts @@ -214,8 +214,7 @@ export class SyncService implements OnModuleInit { const existingOffice = await this.prisma.ats_offices.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -248,9 +247,8 @@ export class SyncService implements OnModuleInit { id_ats_office: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (office.name) { diff --git a/packages/api/src/ats/rejectreason/rejectreason.controller.ts b/packages/api/src/ats/rejectreason/rejectreason.controller.ts index 3b0559f9d..1aa3c4dfa 100644 --- a/packages/api/src/ats/rejectreason/rejectreason.controller.ts +++ b/packages/api/src/ats/rejectreason/rejectreason.controller.ts @@ -57,12 +57,13 @@ export class RejectReasonController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.rejectreasonService.getRejectReasons( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/ats/rejectreason/services/rejectreason.service.ts b/packages/api/src/ats/rejectreason/services/rejectreason.service.ts index 978d98a14..ab26f775f 100644 --- a/packages/api/src/ats/rejectreason/services/rejectreason.service.ts +++ b/packages/api/src/ats/rejectreason/services/rejectreason.service.ts @@ -83,6 +83,7 @@ export class RejectReasonService { } async getRejectReasons( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -92,8 +93,7 @@ export class RejectReasonService { try { const rejectReasons = await this.prisma.ats_reject_reasons.findMany({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ats/rejectreason/sync/sync.service.ts b/packages/api/src/ats/rejectreason/sync/sync.service.ts index 2212725f8..5a66a5d08 100644 --- a/packages/api/src/ats/rejectreason/sync/sync.service.ts +++ b/packages/api/src/ats/rejectreason/sync/sync.service.ts @@ -215,8 +215,7 @@ export class SyncService implements OnModuleInit { await this.prisma.ats_reject_reasons.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -246,9 +245,8 @@ export class SyncService implements OnModuleInit { id_ats_reject_reason: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (rejectReason.name) { diff --git a/packages/api/src/ats/scorecard/scorecard.controller.ts b/packages/api/src/ats/scorecard/scorecard.controller.ts index 4156225d2..dcbc67e37 100644 --- a/packages/api/src/ats/scorecard/scorecard.controller.ts +++ b/packages/api/src/ats/scorecard/scorecard.controller.ts @@ -57,12 +57,13 @@ export class ScoreCardController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.scorecardService.getScoreCards( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/ats/scorecard/services/scorecard.service.ts b/packages/api/src/ats/scorecard/services/scorecard.service.ts index 7f5bdb5ea..a91205f7b 100644 --- a/packages/api/src/ats/scorecard/services/scorecard.service.ts +++ b/packages/api/src/ats/scorecard/services/scorecard.service.ts @@ -85,6 +85,7 @@ export class ScoreCardService { } async getScoreCards( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -94,8 +95,7 @@ export class ScoreCardService { try { const scorecards = await this.prisma.ats_scorecards.findMany({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ats/scorecard/sync/sync.service.ts b/packages/api/src/ats/scorecard/sync/sync.service.ts index 3ae3ee05c..8f9a3d5c7 100644 --- a/packages/api/src/ats/scorecard/sync/sync.service.ts +++ b/packages/api/src/ats/scorecard/sync/sync.service.ts @@ -214,8 +214,7 @@ export class SyncService implements OnModuleInit { const existingScoreCard = await this.prisma.ats_scorecards.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -260,9 +259,8 @@ export class SyncService implements OnModuleInit { id_ats_score_card: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (scoreCard.overall_recommendation) { diff --git a/packages/api/src/ats/screeningquestion/screeningquestion.controller.ts b/packages/api/src/ats/screeningquestion/screeningquestion.controller.ts index 71a4ad693..4aabade73 100644 --- a/packages/api/src/ats/screeningquestion/screeningquestion.controller.ts +++ b/packages/api/src/ats/screeningquestion/screeningquestion.controller.ts @@ -57,12 +57,13 @@ export class ScreeningQuestionController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.screeningquestionService.getScreeningQuestions( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/ats/screeningquestion/services/screeningquestion.service.ts b/packages/api/src/ats/screeningquestion/services/screeningquestion.service.ts index dfc138f68..8903dcb0c 100644 --- a/packages/api/src/ats/screeningquestion/services/screeningquestion.service.ts +++ b/packages/api/src/ats/screeningquestion/services/screeningquestion.service.ts @@ -45,6 +45,7 @@ export class ScreeningQuestionService { } async getScreeningQuestions( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/ats/tag/services/tag.service.ts b/packages/api/src/ats/tag/services/tag.service.ts index e84e03409..38a9e3207 100644 --- a/packages/api/src/ats/tag/services/tag.service.ts +++ b/packages/api/src/ats/tag/services/tag.service.ts @@ -81,6 +81,7 @@ export class TagService { } async getTags( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -90,8 +91,7 @@ export class TagService { try { const tags = await this.prisma.ats_tags.findMany({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ats/tag/sync/sync.service.ts b/packages/api/src/ats/tag/sync/sync.service.ts index a5d3956be..05564110c 100644 --- a/packages/api/src/ats/tag/sync/sync.service.ts +++ b/packages/api/src/ats/tag/sync/sync.service.ts @@ -216,8 +216,7 @@ export class SyncService implements OnModuleInit { const existingTag = await this.prisma.ats_candidate_tags.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -250,9 +249,8 @@ export class SyncService implements OnModuleInit { id_ats_tag: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (tag.name) { diff --git a/packages/api/src/ats/tag/tag.controller.ts b/packages/api/src/ats/tag/tag.controller.ts index 588809500..5a46066cf 100644 --- a/packages/api/src/ats/tag/tag.controller.ts +++ b/packages/api/src/ats/tag/tag.controller.ts @@ -54,12 +54,13 @@ export class TagController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.tagService.getTags( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/ats/user/services/user.service.ts b/packages/api/src/ats/user/services/user.service.ts index 4b925c9ae..6b86becad 100644 --- a/packages/api/src/ats/user/services/user.service.ts +++ b/packages/api/src/ats/user/services/user.service.ts @@ -87,6 +87,7 @@ export class UserService { } async getUsers( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -96,8 +97,7 @@ export class UserService { try { const users = await this.prisma.ats_users.findMany({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ats/user/sync/sync.service.ts b/packages/api/src/ats/user/sync/sync.service.ts index 844c4527e..d82c7226d 100644 --- a/packages/api/src/ats/user/sync/sync.service.ts +++ b/packages/api/src/ats/user/sync/sync.service.ts @@ -216,8 +216,7 @@ export class SyncService implements OnModuleInit { const existingUser = await this.prisma.ats_users.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -265,9 +264,8 @@ export class SyncService implements OnModuleInit { id_ats_user: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (user.first_name) { diff --git a/packages/api/src/ats/user/user.controller.ts b/packages/api/src/ats/user/user.controller.ts index 9583c033e..dafcc42d2 100644 --- a/packages/api/src/ats/user/user.controller.ts +++ b/packages/api/src/ats/user/user.controller.ts @@ -54,12 +54,13 @@ export class UserController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.userService.getUsers( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/crm/@lib/@utils/index.ts b/packages/api/src/crm/@lib/@utils/index.ts index 1051d211d..7bd550cb6 100644 --- a/packages/api/src/crm/@lib/@utils/index.ts +++ b/packages/api/src/crm/@lib/@utils/index.ts @@ -104,12 +104,12 @@ export class Utils { } } - async getUserUuidFromRemoteId(remote_id: string, remote_platform: string) { + async getUserUuidFromRemoteId(remote_id: string, connection_id: string) { try { const res = await this.prisma.crm_users.findFirst({ where: { remote_id: remote_id, - remote_platform: remote_platform, + id_connection: connection_id, }, }); if (!res) { @@ -121,12 +121,12 @@ export class Utils { } } - async getCompanyNameFromUuid(id: string, remote_platform: string) { + async getCompanyNameFromUuid(id: string, connection_id: string) { try { const res = await this.prisma.crm_companies.findFirst({ where: { id_crm_company: id, - remote_platform: remote_platform, + id_connection: connection_id, }, }); @@ -139,12 +139,12 @@ export class Utils { } } - async getStageNameFromStageUuid(id: string, remote_platform: string) { + async getStageNameFromStageUuid(id: string, connection_id: string) { try { const res = await this.prisma.crm_deals_stages.findFirst({ where: { id_crm_deals_stage: id, - remote_platform: remote_platform, + id_connection: connection_id, }, }); if (!res) return undefined; @@ -171,12 +171,12 @@ export class Utils { } } - async getCompanyUuidFromRemoteId(remote_id: string, remote_platform: string) { + async getCompanyUuidFromRemoteId(remote_id: string, connection_id: string) { try { const res = await this.prisma.crm_companies.findFirst({ where: { remote_id: remote_id, - remote_platform: remote_platform, + id_connection: connection_id, }, }); if (!res) { @@ -202,12 +202,12 @@ export class Utils { } } - async getStageUuidFromRemoteId(remote_id: string, remote_platform: string) { + async getStageUuidFromRemoteId(remote_id: string, connection_id: string) { try { const res = await this.prisma.crm_deals_stages.findFirst({ where: { remote_id: remote_id, - remote_platform: remote_platform, + id_connection: connection_id, }, }); if (!res) { @@ -233,12 +233,12 @@ export class Utils { } } - async getContactUuidFromRemoteId(remote_id: string, remote_platform: string) { + async getContactUuidFromRemoteId(remote_id: string, connection_id: string) { try { const res = await this.prisma.crm_contacts.findFirst({ where: { remote_id: remote_id, - remote_platform: remote_platform, + id_connection: connection_id, }, }); if (!res) return undefined; @@ -262,12 +262,12 @@ export class Utils { } } - async getDealUuidFromRemoteId(remote_id: string, remote_platform: string) { + async getDealUuidFromRemoteId(remote_id: string, connection_id: string) { try { const res = await this.prisma.crm_deals.findFirst({ where: { remote_id: remote_id, - remote_platform: remote_platform, + id_connection: connection_id, }, }); if (!res) return undefined; diff --git a/packages/api/src/crm/company/company.controller.ts b/packages/api/src/crm/company/company.controller.ts index c64d7bc89..d157f9cf2 100644 --- a/packages/api/src/crm/company/company.controller.ts +++ b/packages/api/src/crm/company/company.controller.ts @@ -61,12 +61,13 @@ export class CompanyController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.companyService.getCompanies( + connectionId, remoteSource, linkedUserId, limit, @@ -132,12 +133,13 @@ export class CompanyController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.companyService.addCompany( unifiedCompanyData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/crm/company/services/company.service.ts b/packages/api/src/crm/company/services/company.service.ts index c3b42c306..c27d18f95 100644 --- a/packages/api/src/crm/company/services/company.service.ts +++ b/packages/api/src/crm/company/services/company.service.ts @@ -32,6 +32,7 @@ export class CompanyService { async addCompany( unifiedCompanyData: UnifiedCompanyInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -96,8 +97,7 @@ export class CompanyService { const existingCompany = await this.prisma.crm_companies.findFirst({ where: { remote_id: target_company.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, include: { crm_email_addresses: true, @@ -229,9 +229,8 @@ export class CompanyService { id_crm_company: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_company.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; if (target_company.name) { @@ -434,6 +433,7 @@ export class CompanyService { } async getCompanies( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -451,8 +451,7 @@ export class CompanyService { if (cursor) { const isCursorPresent = await this.prisma.crm_companies.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_crm_company: cursor, }, }); @@ -472,8 +471,7 @@ export class CompanyService { modified_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, include: { crm_email_addresses: true, diff --git a/packages/api/src/crm/company/sync/sync.service.ts b/packages/api/src/crm/company/sync/sync.service.ts index d804d95f4..7bb21c073 100644 --- a/packages/api/src/crm/company/sync/sync.service.ts +++ b/packages/api/src/crm/company/sync/sync.service.ts @@ -173,6 +173,7 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const companies_data = await this.saveCompanysInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -203,6 +204,7 @@ export class SyncService implements OnModuleInit { } async saveCompanysInDb( + connection_id: string, linkedUserId: string, companies: UnifiedCompanyOutput[], originSource: string, @@ -221,8 +223,7 @@ export class SyncService implements OnModuleInit { const existingCompany = await this.prisma.crm_companies.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, include: { crm_email_addresses: true, @@ -354,9 +355,8 @@ export class SyncService implements OnModuleInit { id_crm_company: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (company.name) { diff --git a/packages/api/src/crm/contact/contact.controller.ts b/packages/api/src/crm/contact/contact.controller.ts index 67406439a..7a5600cc0 100644 --- a/packages/api/src/crm/contact/contact.controller.ts +++ b/packages/api/src/crm/contact/contact.controller.ts @@ -62,12 +62,13 @@ export class ContactController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return await this.contactService.getContacts( + connectionId, remoteSource, linkedUserId, limit, @@ -134,12 +135,13 @@ export class ContactController { ) { try { // this.logger.log('x-connection-token is ' + connection_token); - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.contactService.addContact( unfiedContactData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/crm/contact/services/contact.service.ts b/packages/api/src/crm/contact/services/contact.service.ts index 80b333dce..d15cb41fb 100644 --- a/packages/api/src/crm/contact/services/contact.service.ts +++ b/packages/api/src/crm/contact/services/contact.service.ts @@ -32,6 +32,7 @@ export class ContactService { async addContact( unifiedContactData: UnifiedContactInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -92,8 +93,7 @@ export class ContactService { const existingContact = await this.prisma.crm_contacts.findFirst({ where: { remote_id: target_contact.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, include: { crm_email_addresses: true, @@ -222,9 +222,8 @@ export class ContactService { last_name: '', created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_contact.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; if (target_contact.first_name) { @@ -463,6 +462,7 @@ export class ContactService { } async getContacts( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -482,8 +482,7 @@ export class ContactService { if (cursor) { const isCursorPresent = await this.prisma.crm_contacts.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_crm_contact: cursor, }, }); @@ -503,8 +502,7 @@ export class ContactService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, include: { crm_email_addresses: true, diff --git a/packages/api/src/crm/contact/sync/sync.service.ts b/packages/api/src/crm/contact/sync/sync.service.ts index 40c071a74..c680ebbe0 100644 --- a/packages/api/src/crm/contact/sync/sync.service.ts +++ b/packages/api/src/crm/contact/sync/sync.service.ts @@ -188,6 +188,7 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const contacts_data = await this.saveContactsInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -218,6 +219,7 @@ export class SyncService implements OnModuleInit { } async saveContactsInDb( + connection_id: string, linkedUserId: string, contacts: UnifiedContactOutput[], originSource: string, @@ -236,8 +238,7 @@ export class SyncService implements OnModuleInit { const existingContact = await this.prisma.crm_contacts.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, include: { crm_email_addresses: true, @@ -372,9 +373,8 @@ export class SyncService implements OnModuleInit { last_name: '', created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (contact.first_name) { diff --git a/packages/api/src/crm/deal/deal.controller.ts b/packages/api/src/crm/deal/deal.controller.ts index 973457ded..30185adef 100644 --- a/packages/api/src/crm/deal/deal.controller.ts +++ b/packages/api/src/crm/deal/deal.controller.ts @@ -59,12 +59,13 @@ export class DealController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return await this.dealService.getDeals( + connectionId, remoteSource, linkedUserId, limit, @@ -130,12 +131,13 @@ export class DealController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return await this.dealService.addDeal( unifiedDealData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/crm/deal/services/deal.service.ts b/packages/api/src/crm/deal/services/deal.service.ts index 9924e8fdd..3576e99ae 100644 --- a/packages/api/src/crm/deal/services/deal.service.ts +++ b/packages/api/src/crm/deal/services/deal.service.ts @@ -28,6 +28,7 @@ export class DealService { async addDeal( unifiedDealData: UnifiedDealInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -105,8 +106,7 @@ export class DealService { const existingDeal = await this.prisma.crm_deals.findFirst({ where: { remote_id: target_deal.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -152,9 +152,8 @@ export class DealService { amount: target_deal.amount, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_deal.remote_id, - remote_platform: integrationId, + id_connection: connection_id, description: '', }; @@ -302,6 +301,7 @@ export class DealService { } async getDeals( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -319,8 +319,7 @@ export class DealService { if (cursor) { const isCursorPresent = await this.prisma.crm_deals.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_crm_deal: cursor, }, }); @@ -340,8 +339,7 @@ export class DealService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/crm/deal/sync/sync.service.ts b/packages/api/src/crm/deal/sync/sync.service.ts index 4bac24603..d4246bf75 100644 --- a/packages/api/src/crm/deal/sync/sync.service.ts +++ b/packages/api/src/crm/deal/sync/sync.service.ts @@ -181,6 +181,7 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const deals_data = await this.saveDealsInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -211,6 +212,7 @@ export class SyncService implements OnModuleInit { } async saveDealsInDb( + connection_id: string, linkedUserId: string, deals: UnifiedDealOutput[], originSource: string, @@ -229,8 +231,7 @@ export class SyncService implements OnModuleInit { const existingDeal = await this.prisma.crm_deals.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -277,10 +278,9 @@ export class SyncService implements OnModuleInit { id_crm_deal: uuidv4(), created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, description: '', remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; this.logger.log('deal name is ' + deal.name); diff --git a/packages/api/src/crm/engagement/engagement.controller.ts b/packages/api/src/crm/engagement/engagement.controller.ts index cfe93cfb7..71f5450e7 100644 --- a/packages/api/src/crm/engagement/engagement.controller.ts +++ b/packages/api/src/crm/engagement/engagement.controller.ts @@ -62,13 +62,14 @@ export class EngagementController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.engagementService.getEngagements( + connectionId, remoteSource, linkedUserId, limit, @@ -134,12 +135,13 @@ export class EngagementController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.engagementService.addEngagement( unifiedEngagementData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/crm/engagement/services/engagement.service.ts b/packages/api/src/crm/engagement/services/engagement.service.ts index f4a9725df..eebd007b7 100644 --- a/packages/api/src/crm/engagement/services/engagement.service.ts +++ b/packages/api/src/crm/engagement/services/engagement.service.ts @@ -31,6 +31,7 @@ export class EngagementService { async addEngagement( unifiedEngagementData: UnifiedEngagementInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -124,8 +125,7 @@ export class EngagementService { const existingEngagement = await this.prisma.crm_engagements.findFirst({ where: { remote_id: target_engagement.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -180,9 +180,8 @@ export class EngagementService { id_crm_engagement: uuidv4(), created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_engagement.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; if (target_engagement.content) { @@ -352,6 +351,7 @@ export class EngagementService { } async getEngagements( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -369,8 +369,7 @@ export class EngagementService { if (cursor) { const isCursorPresent = await this.prisma.crm_engagements.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_crm_engagement: cursor, }, }); @@ -390,8 +389,7 @@ export class EngagementService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/crm/engagement/sync/sync.service.ts b/packages/api/src/crm/engagement/sync/sync.service.ts index e3beb44d9..deb0eca58 100644 --- a/packages/api/src/crm/engagement/sync/sync.service.ts +++ b/packages/api/src/crm/engagement/sync/sync.service.ts @@ -182,6 +182,7 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const engagements_data = await this.saveEngagementsInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -212,6 +213,7 @@ export class SyncService implements OnModuleInit { } async saveEngagementsInDb( + connection_id: string, linkedUserId: string, engagements: UnifiedEngagementOutput[], originSource: string, @@ -230,8 +232,7 @@ export class SyncService implements OnModuleInit { const existingEngagement = await this.prisma.crm_engagements.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -287,9 +288,8 @@ export class SyncService implements OnModuleInit { id_crm_engagement: uuidv4(), created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (engagement.content) { diff --git a/packages/api/src/crm/note/note.controller.ts b/packages/api/src/crm/note/note.controller.ts index 66e0b7d43..68423bfcf 100644 --- a/packages/api/src/crm/note/note.controller.ts +++ b/packages/api/src/crm/note/note.controller.ts @@ -58,12 +58,13 @@ export class NoteController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.noteService.getNotes( + connectionId, remoteSource, linkedUserId, limit, @@ -129,12 +130,13 @@ export class NoteController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.noteService.addNote( unifiedNoteData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/crm/note/services/note.service.ts b/packages/api/src/crm/note/services/note.service.ts index bc8a7e77e..f4edb6670 100644 --- a/packages/api/src/crm/note/services/note.service.ts +++ b/packages/api/src/crm/note/services/note.service.ts @@ -28,6 +28,7 @@ export class NoteService { async addNote( unifiedNoteData: UnifiedNoteInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -132,8 +133,7 @@ export class NoteService { const existingNote = await this.prisma.crm_notes.findFirst({ where: { remote_id: target_note.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -174,9 +174,8 @@ export class NoteService { id_crm_note: uuidv4(), created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_note.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; if (target_note.content) { data = { ...data, content: target_note.content }; @@ -321,6 +320,7 @@ export class NoteService { } async getNotes( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -338,8 +338,7 @@ export class NoteService { if (cursor) { const isCursorPresent = await this.prisma.crm_notes.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_crm_note: cursor, }, }); @@ -359,8 +358,7 @@ export class NoteService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/crm/note/sync/sync.service.ts b/packages/api/src/crm/note/sync/sync.service.ts index 3fad4175c..dd9f421b2 100644 --- a/packages/api/src/crm/note/sync/sync.service.ts +++ b/packages/api/src/crm/note/sync/sync.service.ts @@ -173,6 +173,7 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const notes_data = await this.saveNotesInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -203,6 +204,7 @@ export class SyncService implements OnModuleInit { } async saveNotesInDb( + connection_id: string, linkedUserId: string, notes: UnifiedNoteOutput[], originSource: string, @@ -221,8 +223,7 @@ export class SyncService implements OnModuleInit { const existingNote = await this.prisma.crm_notes.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -264,9 +265,8 @@ export class SyncService implements OnModuleInit { id_crm_note: uuidv4(), created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (note.content) { data = { ...data, content: note.content }; diff --git a/packages/api/src/crm/stage/services/stage.service.ts b/packages/api/src/crm/stage/services/stage.service.ts index f1b3a079c..c1a247f2f 100644 --- a/packages/api/src/crm/stage/services/stage.service.ts +++ b/packages/api/src/crm/stage/services/stage.service.ts @@ -80,6 +80,7 @@ export class StageService { } async getStages( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -97,8 +98,7 @@ export class StageService { if (cursor) { const isCursorPresent = await this.prisma.crm_deals_stages.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_crm_deals_stage: cursor, }, }); @@ -118,8 +118,7 @@ export class StageService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/crm/stage/stage.controller.ts b/packages/api/src/crm/stage/stage.controller.ts index 6415ec611..eaab588f0 100644 --- a/packages/api/src/crm/stage/stage.controller.ts +++ b/packages/api/src/crm/stage/stage.controller.ts @@ -55,12 +55,13 @@ export class StageController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.stageService.getStages( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/crm/stage/sync/sync.service.ts b/packages/api/src/crm/stage/sync/sync.service.ts index d9ce6caa7..a27284ec7 100644 --- a/packages/api/src/crm/stage/sync/sync.service.ts +++ b/packages/api/src/crm/stage/sync/sync.service.ts @@ -98,11 +98,17 @@ export class SyncService implements OnModuleInit { for (const provider of providers) { try { try { + const connection = + await this.prisma.connections.findFirst({ + where: { + id_linked_user: linkedUser.id_linked_user, + provider_slug: provider.toLowerCase(), + }, + }); //call the sync comments for every ticket of the linkedUser (a comment is tied to a ticket) const deals = await this.prisma.crm_deals.findMany({ where: { - remote_platform: provider, - id_linked_user: linkedUser.id_linked_user, + id_connection: connection.id_connection, }, }); for (const deal of deals) { @@ -190,6 +196,7 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const stages_data = await this.saveStagesInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -221,6 +228,7 @@ export class SyncService implements OnModuleInit { } async saveStagesInDb( + connection_id: string, linkedUserId: string, stages: UnifiedStageOutput[], originSource: string, @@ -273,7 +281,7 @@ export class SyncService implements OnModuleInit { const isExistingStage = await this.prisma.crm_deals_stages.findFirst({ where: { remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }, }); if (isExistingStage) { @@ -295,9 +303,8 @@ export class SyncService implements OnModuleInit { id_crm_deals_stage: uuidv4(), created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId || '', - remote_platform: originSource, + id_connection: connection_id, }; if (stage.stage_name) { diff --git a/packages/api/src/crm/task/services/task.service.ts b/packages/api/src/crm/task/services/task.service.ts index 45c62d893..9aa10373e 100644 --- a/packages/api/src/crm/task/services/task.service.ts +++ b/packages/api/src/crm/task/services/task.service.ts @@ -28,6 +28,7 @@ export class TaskService { async addTask( unifiedTaskData: UnifiedTaskInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -119,8 +120,7 @@ export class TaskService { const existingTask = await this.prisma.crm_tasks.findFirst({ where: { remote_id: target_task.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -170,9 +170,8 @@ export class TaskService { id_crm_task: uuidv4(), created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_task.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; if (target_task.subject) { @@ -327,6 +326,7 @@ export class TaskService { } async getTasks( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -344,8 +344,7 @@ export class TaskService { if (cursor) { const isCursorPresent = await this.prisma.crm_tasks.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_crm_task: cursor, }, }); @@ -365,8 +364,7 @@ export class TaskService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/crm/task/sync/sync.service.ts b/packages/api/src/crm/task/sync/sync.service.ts index a667d7eb6..98f491bc3 100644 --- a/packages/api/src/crm/task/sync/sync.service.ts +++ b/packages/api/src/crm/task/sync/sync.service.ts @@ -173,6 +173,7 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const tasks_data = await this.saveTasksInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -203,6 +204,7 @@ export class SyncService implements OnModuleInit { } async saveTasksInDb( + connection_id: string, linkedUserId: string, tasks: UnifiedTaskOutput[], originSource: string, @@ -221,8 +223,7 @@ export class SyncService implements OnModuleInit { const existingTask = await this.prisma.crm_tasks.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -273,9 +274,8 @@ export class SyncService implements OnModuleInit { id_crm_task: uuidv4(), created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (task.subject) { diff --git a/packages/api/src/crm/task/task.controller.ts b/packages/api/src/crm/task/task.controller.ts index 13b449fdf..8abf3b533 100644 --- a/packages/api/src/crm/task/task.controller.ts +++ b/packages/api/src/crm/task/task.controller.ts @@ -59,13 +59,14 @@ export class TaskController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.taskService.getTasks( + connectionId, remoteSource, linkedUserId, limit, @@ -131,12 +132,13 @@ export class TaskController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.taskService.addTask( unifiedTaskData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/crm/user/services/user.service.ts b/packages/api/src/crm/user/services/user.service.ts index 215bb9c70..620abb45f 100644 --- a/packages/api/src/crm/user/services/user.service.ts +++ b/packages/api/src/crm/user/services/user.service.ts @@ -90,6 +90,7 @@ export class UserService { } async getUsers( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -107,8 +108,7 @@ export class UserService { if (cursor) { const isCursorPresent = await this.prisma.crm_users.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_crm_user: cursor, }, }); @@ -128,8 +128,7 @@ export class UserService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/crm/user/sync/sync.service.ts b/packages/api/src/crm/user/sync/sync.service.ts index 2aa02defe..ea2d8a601 100644 --- a/packages/api/src/crm/user/sync/sync.service.ts +++ b/packages/api/src/crm/user/sync/sync.service.ts @@ -174,6 +174,7 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const users_data = await this.saveUsersInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -204,6 +205,7 @@ export class SyncService implements OnModuleInit { } async saveUsersInDb( + connection_id: string, linkedUserId: string, users: UnifiedUserOutput[], originSource: string, @@ -222,8 +224,7 @@ export class SyncService implements OnModuleInit { const existingUser = await this.prisma.crm_users.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -257,9 +258,8 @@ export class SyncService implements OnModuleInit { id_crm_user: uuidv4(), created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (user.email) { diff --git a/packages/api/src/crm/user/user.controller.ts b/packages/api/src/crm/user/user.controller.ts index 14d86e42c..ab187737d 100644 --- a/packages/api/src/crm/user/user.controller.ts +++ b/packages/api/src/crm/user/user.controller.ts @@ -55,12 +55,13 @@ export class UserController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.userService.getUsers( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/filestorage/drive/drive.controller.ts b/packages/api/src/filestorage/drive/drive.controller.ts index b09da1921..b819c8a47 100644 --- a/packages/api/src/filestorage/drive/drive.controller.ts +++ b/packages/api/src/filestorage/drive/drive.controller.ts @@ -50,13 +50,14 @@ export class DriveController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.driveService.getDrives( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/filestorage/drive/services/drive.service.ts b/packages/api/src/filestorage/drive/services/drive.service.ts index 166a95662..f20aa1739 100644 --- a/packages/api/src/filestorage/drive/services/drive.service.ts +++ b/packages/api/src/filestorage/drive/services/drive.service.ts @@ -79,6 +79,7 @@ export class DriveService { } async getDrives( + connection_id: string, integrationId: string, linkedUserId: string, pageSize: number, @@ -96,8 +97,7 @@ export class DriveService { if (cursor) { const isCursorPresent = await this.prisma.fs_drives.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_fs_drive: cursor, }, }); @@ -117,8 +117,7 @@ export class DriveService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/filestorage/drive/sync/sync.service.ts b/packages/api/src/filestorage/drive/sync/sync.service.ts index eeabd9c2f..26072f57f 100644 --- a/packages/api/src/filestorage/drive/sync/sync.service.ts +++ b/packages/api/src/filestorage/drive/sync/sync.service.ts @@ -168,6 +168,7 @@ export class SyncService implements OnModuleInit { // insert the data in the DB with the fieldMappings (value table) const drives_data = await this.saveDrivesInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -198,6 +199,7 @@ export class SyncService implements OnModuleInit { } async saveDrivesInDb( + connection_id: string, linkedUserId: string, drives: UnifiedDriveOutput[], originSource: string, @@ -216,8 +218,7 @@ export class SyncService implements OnModuleInit { const existingDrive = await this.prisma.fs_drives.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -253,9 +254,8 @@ export class SyncService implements OnModuleInit { id_fs_drive: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (drive.name) { diff --git a/packages/api/src/filestorage/file/file.controller.ts b/packages/api/src/filestorage/file/file.controller.ts index 3fd4f3e08..8b7db08f0 100644 --- a/packages/api/src/filestorage/file/file.controller.ts +++ b/packages/api/src/filestorage/file/file.controller.ts @@ -53,13 +53,14 @@ export class FileController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.fileService.getFiles( + connectionId, remoteSource, linkedUserId, limit, @@ -113,12 +114,13 @@ export class FileController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.fileService.addFile( unifiedFileData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/filestorage/file/services/file.service.ts b/packages/api/src/filestorage/file/services/file.service.ts index 75321c201..01d5b119c 100644 --- a/packages/api/src/filestorage/file/services/file.service.ts +++ b/packages/api/src/filestorage/file/services/file.service.ts @@ -26,6 +26,7 @@ export class FileService { async addFile( unifiedFileData: UnifiedFileInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -81,8 +82,7 @@ export class FileService { const existingFile = await this.prisma.fs_files.findFirst({ where: { remote_id: target_file.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -120,9 +120,8 @@ export class FileService { permission_id: target_file.permission_id, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_file.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; const newFile = await this.prisma.fs_files.create({ @@ -290,6 +289,7 @@ export class FileService { } async getFiles( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -307,8 +307,7 @@ export class FileService { if (cursor) { const isCursorPresent = await this.prisma.fs_files.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_fs_file: cursor, }, }); @@ -328,8 +327,7 @@ export class FileService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/filestorage/file/sync/sync.service.ts b/packages/api/src/filestorage/file/sync/sync.service.ts index 4d0a75448..578d0c8b7 100644 --- a/packages/api/src/filestorage/file/sync/sync.service.ts +++ b/packages/api/src/filestorage/file/sync/sync.service.ts @@ -168,6 +168,7 @@ export class SyncService implements OnModuleInit { // insert the data in the DB with the fieldMappings (value table) const files_data = await this.saveFilesInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -198,6 +199,7 @@ export class SyncService implements OnModuleInit { } async saveFilesInDb( + connection_id: string, linkedUserId: string, files: UnifiedFileOutput[], originSource: string, @@ -216,8 +218,7 @@ export class SyncService implements OnModuleInit { const existingFile = await this.prisma.fs_files.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -265,9 +266,8 @@ export class SyncService implements OnModuleInit { id_fs_file: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (file.name) { diff --git a/packages/api/src/filestorage/folder/folder.controller.ts b/packages/api/src/filestorage/folder/folder.controller.ts index cbb237e5c..35b42deb7 100644 --- a/packages/api/src/filestorage/folder/folder.controller.ts +++ b/packages/api/src/filestorage/folder/folder.controller.ts @@ -54,12 +54,13 @@ export class FolderController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.folderService.getFolders( + connectionId, remoteSource, linkedUserId, limit, @@ -113,12 +114,13 @@ export class FolderController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.folderService.addFolder( unifiedFolderData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/filestorage/folder/services/folder.service.ts b/packages/api/src/filestorage/folder/services/folder.service.ts index 90cfe458c..4b542fa3e 100644 --- a/packages/api/src/filestorage/folder/services/folder.service.ts +++ b/packages/api/src/filestorage/folder/services/folder.service.ts @@ -29,6 +29,7 @@ export class FolderService { async addFolder( unifiedFolderData: UnifiedFolderInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -84,8 +85,7 @@ export class FolderService { const existingFolder = await this.prisma.fs_folders.findFirst({ where: { remote_id: target_folder.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -123,9 +123,8 @@ export class FolderService { id_fs_permission: target_folder.permission_id, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_folder.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; const newFolder = await this.prisma.fs_folders.create({ @@ -299,6 +298,7 @@ export class FolderService { } async getFolders( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -316,8 +316,7 @@ export class FolderService { if (cursor) { const isCursorPresent = await this.prisma.fs_folders.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_fs_folder: cursor, }, }); @@ -337,8 +336,7 @@ export class FolderService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/filestorage/folder/sync/sync.service.ts b/packages/api/src/filestorage/folder/sync/sync.service.ts index 6057861e0..998de82ef 100644 --- a/packages/api/src/filestorage/folder/sync/sync.service.ts +++ b/packages/api/src/filestorage/folder/sync/sync.service.ts @@ -166,6 +166,7 @@ export class SyncService implements OnModuleInit { // insert the data in the DB with the fieldMappings (value table) const folders_data = await this.saveFoldersInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -196,6 +197,7 @@ export class SyncService implements OnModuleInit { } async saveFoldersInDb( + connection_id: string, linkedUserId: string, folders: UnifiedFolderOutput[], originSource: string, @@ -214,8 +216,7 @@ export class SyncService implements OnModuleInit { const existingFolder = await this.prisma.fs_folders.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -263,9 +264,8 @@ export class SyncService implements OnModuleInit { id_fs_folder: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (folder.name) { diff --git a/packages/api/src/filestorage/group/group.controller.ts b/packages/api/src/filestorage/group/group.controller.ts index 8815892d6..7724b1951 100644 --- a/packages/api/src/filestorage/group/group.controller.ts +++ b/packages/api/src/filestorage/group/group.controller.ts @@ -54,12 +54,13 @@ export class GroupController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { connectionId, linkedUserId, remoteSource } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.permissionService.getGroups( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/filestorage/group/services/group.service.ts b/packages/api/src/filestorage/group/services/group.service.ts index 4e8ce3d31..048b2a865 100644 --- a/packages/api/src/filestorage/group/services/group.service.ts +++ b/packages/api/src/filestorage/group/services/group.service.ts @@ -83,7 +83,8 @@ export class GroupService { } async getGroups( - integrationId: string, + connection_id: string, + remoteSource: string, linkedUserId: string, limit: number, remote_data?: any, @@ -92,8 +93,7 @@ export class GroupService { try { const groups = await this.prisma.fs_groups.findMany({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/filestorage/group/sync/sync.service.ts b/packages/api/src/filestorage/group/sync/sync.service.ts index 356d6ddf6..a7d85c7e4 100644 --- a/packages/api/src/filestorage/group/sync/sync.service.ts +++ b/packages/api/src/filestorage/group/sync/sync.service.ts @@ -168,6 +168,7 @@ export class SyncService implements OnModuleInit { // insert the data in the DB with the fieldMappings (value table) const groups_data = await this.saveGroupsInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -198,6 +199,7 @@ export class SyncService implements OnModuleInit { } async saveGroupsInDb( + connection_id: string, linkedUserId: string, groups: UnifiedGroupOutput[], originSource: string, @@ -216,8 +218,7 @@ export class SyncService implements OnModuleInit { const existingGroup = await this.prisma.fs_groups.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -253,9 +254,8 @@ export class SyncService implements OnModuleInit { id_fs_group: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (group.name) { diff --git a/packages/api/src/filestorage/permission/permission.controller.ts b/packages/api/src/filestorage/permission/permission.controller.ts index 9303c9e55..067122f80 100644 --- a/packages/api/src/filestorage/permission/permission.controller.ts +++ b/packages/api/src/filestorage/permission/permission.controller.ts @@ -57,12 +57,13 @@ export class PermissionController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.permissionService.getPermissions( + connectionId, remoteSource, linkedUserId, limit, @@ -117,12 +118,13 @@ export class PermissionController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.permissionService.addPermission( unifiedPermissionData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/filestorage/permission/services/permission.service.ts b/packages/api/src/filestorage/permission/services/permission.service.ts index 66a6d55c0..7742e8792 100644 --- a/packages/api/src/filestorage/permission/services/permission.service.ts +++ b/packages/api/src/filestorage/permission/services/permission.service.ts @@ -29,6 +29,7 @@ export class PermissionService { async addPermission( unifiedPermissionData: UnifiedPermissionInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -82,8 +83,7 @@ export class PermissionService { const existingPermission = await this.prisma.fs_permissions.findFirst({ where: { remote_id: target_permission.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -115,9 +115,8 @@ export class PermissionService { roles: target_permission.roles, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_permission.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; const newPermission = await this.prisma.fs_permissions.create({ @@ -288,6 +287,7 @@ export class PermissionService { } async getPermissions( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, @@ -305,8 +305,7 @@ export class PermissionService { if (cursor) { const isCursorPresent = await this.prisma.fs_permissions.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connectionId, id_fs_permission: cursor, }, }); @@ -326,8 +325,7 @@ export class PermissionService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connectionId, }, }); diff --git a/packages/api/src/filestorage/permission/sync/sync.service.ts b/packages/api/src/filestorage/permission/sync/sync.service.ts index 524a83734..b73e7fa80 100644 --- a/packages/api/src/filestorage/permission/sync/sync.service.ts +++ b/packages/api/src/filestorage/permission/sync/sync.service.ts @@ -166,6 +166,7 @@ export class SyncService implements OnModuleInit { // insert the data in the DB with the fieldMappings (value table) const permissions_data = await this.savePermissionsInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -196,6 +197,7 @@ export class SyncService implements OnModuleInit { } async savePermissionsInDb( + connection_id: string, linkedUserId: string, permissions: UnifiedPermissionOutput[], originSource: string, @@ -214,8 +216,7 @@ export class SyncService implements OnModuleInit { const existingPermission = await this.prisma.fs_permissions.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -254,9 +255,8 @@ export class SyncService implements OnModuleInit { id_fs_permission: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (permission.roles) { diff --git a/packages/api/src/filestorage/sharedlink/services/sharedlink.service.ts b/packages/api/src/filestorage/sharedlink/services/sharedlink.service.ts index bb8b9f48b..da479f486 100644 --- a/packages/api/src/filestorage/sharedlink/services/sharedlink.service.ts +++ b/packages/api/src/filestorage/sharedlink/services/sharedlink.service.ts @@ -29,6 +29,7 @@ export class SharedLinkService { async addSharedlink( unifiedSharedlinkData: UnifiedSharedLinkInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -82,8 +83,7 @@ export class SharedLinkService { const existingSharedLink = await this.prisma.fs_shared_links.findFirst({ where: { remote_id: target_sharedlink.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -121,9 +121,8 @@ export class SharedLinkService { password: target_sharedlink.password, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_sharedlink.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; const newSharedLink = await this.prisma.fs_shared_links.create({ @@ -297,6 +296,7 @@ export class SharedLinkService { } async getSharedlinks( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -314,8 +314,7 @@ export class SharedLinkService { if (cursor) { const isCursorPresent = await this.prisma.fs_shared_links.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_fs_shared_link: cursor, }, }); @@ -335,8 +334,7 @@ export class SharedLinkService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/filestorage/sharedlink/sharedlink.controller.ts b/packages/api/src/filestorage/sharedlink/sharedlink.controller.ts index ea671ef7d..210492c38 100644 --- a/packages/api/src/filestorage/sharedlink/sharedlink.controller.ts +++ b/packages/api/src/filestorage/sharedlink/sharedlink.controller.ts @@ -55,12 +55,13 @@ export class SharedlinkController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.sharedlinkService.getSharedlinks( + connectionId, remoteSource, linkedUserId, limit, @@ -115,12 +116,13 @@ export class SharedlinkController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.sharedlinkService.addSharedlink( unifiedSharedlinkData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/filestorage/sharedlink/sync/sync.service.ts b/packages/api/src/filestorage/sharedlink/sync/sync.service.ts index 40a9b74ab..f233471bb 100644 --- a/packages/api/src/filestorage/sharedlink/sync/sync.service.ts +++ b/packages/api/src/filestorage/sharedlink/sync/sync.service.ts @@ -166,6 +166,7 @@ export class SyncService implements OnModuleInit { // insert the data in the DB with the fieldMappings (value table) const shared_links_data = await this.saveSharedLinksInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -196,6 +197,7 @@ export class SyncService implements OnModuleInit { } async saveSharedLinksInDb( + connection_id: string, linkedUserId: string, sharedLinks: UnifiedSharedLinkOutput[], originSource: string, @@ -214,8 +216,7 @@ export class SyncService implements OnModuleInit { const existingSharedLink = await this.prisma.fs_shared_links.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -266,9 +267,8 @@ export class SyncService implements OnModuleInit { id_fs_shared_link: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (sharedLink.url) { diff --git a/packages/api/src/filestorage/user/services/user.service.ts b/packages/api/src/filestorage/user/services/user.service.ts index cda9d495c..6110e53d4 100644 --- a/packages/api/src/filestorage/user/services/user.service.ts +++ b/packages/api/src/filestorage/user/services/user.service.ts @@ -83,6 +83,7 @@ export class UserService { } async getUsers( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -92,8 +93,7 @@ export class UserService { try { const users = await this.prisma.fs_users.findMany({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/filestorage/user/sync/sync.service.ts b/packages/api/src/filestorage/user/sync/sync.service.ts index fdad2327e..02038e261 100644 --- a/packages/api/src/filestorage/user/sync/sync.service.ts +++ b/packages/api/src/filestorage/user/sync/sync.service.ts @@ -168,6 +168,7 @@ export class SyncService implements OnModuleInit { // insert the data in the DB with the fieldMappings (value table) const users_data = await this.saveUsersInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -198,6 +199,7 @@ export class SyncService implements OnModuleInit { } async saveUsersInDb( + connection_id: string, linkedUserId: string, users: UnifiedUserOutput[], originSource: string, @@ -216,8 +218,7 @@ export class SyncService implements OnModuleInit { const existingUser = await this.prisma.fs_users.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -253,9 +254,8 @@ export class SyncService implements OnModuleInit { id_fs_user: uuid, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (user.name) { diff --git a/packages/api/src/filestorage/user/user.controller.ts b/packages/api/src/filestorage/user/user.controller.ts index 7ca6a15c9..4875e9e53 100644 --- a/packages/api/src/filestorage/user/user.controller.ts +++ b/packages/api/src/filestorage/user/user.controller.ts @@ -44,12 +44,13 @@ export class UserController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return await this.permissionService.getUsers( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/hris/bankinfo/bankinfo.controller.ts b/packages/api/src/hris/bankinfo/bankinfo.controller.ts index e4b2ce7de..970f12a41 100644 --- a/packages/api/src/hris/bankinfo/bankinfo.controller.ts +++ b/packages/api/src/hris/bankinfo/bankinfo.controller.ts @@ -56,12 +56,13 @@ export class BankinfoController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.bankinfoService.getBankinfos( + connectionId, remoteSource, linkedUserId, limit, @@ -99,46 +100,4 @@ export class BankinfoController { ) { return this.bankinfoService.getBankinfo(id, remote_data); } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a Bankinfo', - description: 'Create a bankinfo in any supported Hris software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: 'Set to true to include data from the original Hris software.', - }) - @ApiBody({ type: UnifiedBankInfoInput }) - @ApiCustomResponse(UnifiedBankInfoOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedBankinfoData: UnifiedBankInfoInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.bankinfoService.addBankinfo( - unifiedBankinfoData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/hris/bankinfo/services/bankinfo.service.ts b/packages/api/src/hris/bankinfo/services/bankinfo.service.ts index 38c45813e..f4924f71b 100644 --- a/packages/api/src/hris/bankinfo/services/bankinfo.service.ts +++ b/packages/api/src/hris/bankinfo/services/bankinfo.service.ts @@ -25,15 +25,6 @@ export class BankInfoService { this.logger.setContext(BankInfoService.name); } - async addBankinfo( - unifiedBankinfoData: UnifiedBankInfoInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getBankinfo( id_bankinfoing_bankinfo: string, remote_data?: boolean, @@ -42,6 +33,7 @@ export class BankInfoService { } async getBankinfos( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/hris/benefit/benefit.controller.ts b/packages/api/src/hris/benefit/benefit.controller.ts index a4c96859c..b194a4388 100644 --- a/packages/api/src/hris/benefit/benefit.controller.ts +++ b/packages/api/src/hris/benefit/benefit.controller.ts @@ -57,12 +57,13 @@ export class BenefitController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.benefitService.getBenefits( + connectionId, remoteSource, linkedUserId, limit, @@ -100,46 +101,4 @@ export class BenefitController { ) { return this.benefitService.getBenefit(id, remote_data); } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a Benefit', - description: 'Create a benefit in any supported Hris software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: 'Set to true to include data from the original Hris software.', - }) - @ApiBody({ type: UnifiedBenefitInput }) - @ApiCustomResponse(UnifiedBenefitOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedBenefitData: UnifiedBenefitInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.benefitService.addBenefit( - unifiedBenefitData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/hris/benefit/services/benefit.service.ts b/packages/api/src/hris/benefit/services/benefit.service.ts index 576dd9692..f6cd907e1 100644 --- a/packages/api/src/hris/benefit/services/benefit.service.ts +++ b/packages/api/src/hris/benefit/services/benefit.service.ts @@ -28,15 +28,6 @@ export class BenefitService { this.logger.setContext(BenefitService.name); } - async addBenefit( - unifiedBenefitData: UnifiedBenefitInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getBenefit( id_benefiting_benefit: string, remote_data?: boolean, @@ -45,6 +36,7 @@ export class BenefitService { } async getBenefits( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/hris/company/company.controller.ts b/packages/api/src/hris/company/company.controller.ts index 9626c33c3..cbb82a5b4 100644 --- a/packages/api/src/hris/company/company.controller.ts +++ b/packages/api/src/hris/company/company.controller.ts @@ -57,12 +57,13 @@ export class CompanyController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.companyService.getCompanys( + connectionId, remoteSource, linkedUserId, limit, @@ -73,73 +74,4 @@ export class CompanyController { throw new Error(error); } } - - @ApiOperation({ - operationId: 'retrieve', - summary: 'Retrieve a Company', - description: 'Retrieve a company from any connected Hris software', - }) - @ApiParam({ - name: 'id', - required: true, - type: String, - description: 'id of the company you want to retrieve.', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: 'Set to true to include data from the original Hris software.', - }) - @ApiCustomResponse(UnifiedCompanyOutput) - @UseGuards(ApiKeyAuthGuard) - @Get(':id') - retrieve( - @Param('id') id: string, - @Query('remote_data') remote_data?: boolean, - ) { - return this.companyService.getCompany(id, remote_data); - } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a Company', - description: 'Create a company in any supported Hris software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: 'Set to true to include data from the original Hris software.', - }) - @ApiBody({ type: UnifiedCompanyInput }) - @ApiCustomResponse(UnifiedCompanyOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedCompanyData: UnifiedCompanyInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.companyService.addCompany( - unifiedCompanyData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/hris/company/services/company.service.ts b/packages/api/src/hris/company/services/company.service.ts index 73eee5f7e..d2a84808f 100644 --- a/packages/api/src/hris/company/services/company.service.ts +++ b/packages/api/src/hris/company/services/company.service.ts @@ -28,15 +28,6 @@ export class CompanyService { this.logger.setContext(CompanyService.name); } - async addCompany( - unifiedCompanyData: UnifiedCompanyInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getCompany( id_companying_company: string, remote_data?: boolean, @@ -45,6 +36,7 @@ export class CompanyService { } async getCompanys( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/hris/dependent/dependent.controller.ts b/packages/api/src/hris/dependent/dependent.controller.ts index 54767af5b..08b487aa5 100644 --- a/packages/api/src/hris/dependent/dependent.controller.ts +++ b/packages/api/src/hris/dependent/dependent.controller.ts @@ -57,12 +57,13 @@ export class DependentController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.dependentService.getDependents( + connectionId, remoteSource, linkedUserId, limit, @@ -100,46 +101,4 @@ export class DependentController { ) { return this.dependentService.getDependent(id, remote_data); } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a Dependent', - description: 'Create a dependent in any supported Hris software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: 'Set to true to include data from the original Hris software.', - }) - @ApiBody({ type: UnifiedDependentInput }) - @ApiCustomResponse(UnifiedDependentOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedDependentData: UnifiedDependentInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.dependentService.addDependent( - unifiedDependentData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/hris/dependent/services/dependent.service.ts b/packages/api/src/hris/dependent/services/dependent.service.ts index ecc5c87ca..b42c276ab 100644 --- a/packages/api/src/hris/dependent/services/dependent.service.ts +++ b/packages/api/src/hris/dependent/services/dependent.service.ts @@ -28,15 +28,6 @@ export class DependentService { this.logger.setContext(DependentService.name); } - async addDependent( - unifiedDependentData: UnifiedDependentInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getDependent( id_dependenting_dependent: string, remote_data?: boolean, @@ -45,6 +36,7 @@ export class DependentService { } async getDependents( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/hris/employee/employee.controller.ts b/packages/api/src/hris/employee/employee.controller.ts index 52e7ab560..f1c629e97 100644 --- a/packages/api/src/hris/employee/employee.controller.ts +++ b/packages/api/src/hris/employee/employee.controller.ts @@ -57,12 +57,13 @@ export class EmployeeController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.employeeService.getEmployees( + connectionId, remoteSource, linkedUserId, limit, @@ -128,12 +129,13 @@ export class EmployeeController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.employeeService.addEmployee( unifiedEmployeeData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/hris/employee/services/employee.service.ts b/packages/api/src/hris/employee/services/employee.service.ts index 07a9ceb2c..5375e0335 100644 --- a/packages/api/src/hris/employee/services/employee.service.ts +++ b/packages/api/src/hris/employee/services/employee.service.ts @@ -30,6 +30,7 @@ export class EmployeeService { async addEmployee( unifiedEmployeeData: UnifiedEmployeeInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -45,6 +46,7 @@ export class EmployeeService { } async getEmployees( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/hris/employeepayrollrun/employeepayrollrun.controller.ts b/packages/api/src/hris/employeepayrollrun/employeepayrollrun.controller.ts index 8515ce84b..3e5b29ccb 100644 --- a/packages/api/src/hris/employeepayrollrun/employeepayrollrun.controller.ts +++ b/packages/api/src/hris/employeepayrollrun/employeepayrollrun.controller.ts @@ -57,12 +57,13 @@ export class EmployeePayrollRunController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.employeepayrollrunService.getEmployeePayrollRuns( + connectionId, remoteSource, linkedUserId, limit, @@ -104,46 +105,4 @@ export class EmployeePayrollRunController { remote_data, ); } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a EmployeePayrollRun', - description: 'Create a employeepayrollrun in any supported Hris software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: 'Set to true to include data from the original Hris software.', - }) - @ApiBody({ type: UnifiedEmployeePayrollRunInput }) - @ApiCustomResponse(UnifiedEmployeePayrollRunOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedEmployeePayrollRunData: UnifiedEmployeePayrollRunInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.employeepayrollrunService.addEmployeePayrollRun( - unifiedEmployeePayrollRunData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/hris/employeepayrollrun/services/employeepayrollrun.service.ts b/packages/api/src/hris/employeepayrollrun/services/employeepayrollrun.service.ts index 72ec0ddb9..c42b5d1e0 100644 --- a/packages/api/src/hris/employeepayrollrun/services/employeepayrollrun.service.ts +++ b/packages/api/src/hris/employeepayrollrun/services/employeepayrollrun.service.ts @@ -27,16 +27,6 @@ export class EmployeePayrollRunService { ) { this.logger.setContext(EmployeePayrollRunService.name); } - - async addEmployeePayrollRun( - unifiedEmployeePayrollRunData: UnifiedEmployeePayrollRunInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getEmployeePayrollRun( id_employeepayrollruning_employeepayrollrun: string, remote_data?: boolean, @@ -45,6 +35,7 @@ export class EmployeePayrollRunService { } async getEmployeePayrollRuns( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/hris/employerbenefit/employerbenefit.controller.ts b/packages/api/src/hris/employerbenefit/employerbenefit.controller.ts index 919f93fad..62f4244ab 100644 --- a/packages/api/src/hris/employerbenefit/employerbenefit.controller.ts +++ b/packages/api/src/hris/employerbenefit/employerbenefit.controller.ts @@ -57,12 +57,13 @@ export class EmployerBenefitController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.employerbenefitService.getEmployerBenefits( + connectionId, remoteSource, linkedUserId, limit, @@ -100,46 +101,4 @@ export class EmployerBenefitController { ) { return this.employerbenefitService.getEmployerBenefit(id, remote_data); } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a EmployerBenefit', - description: 'Create a employerbenefit in any supported Hris software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: 'Set to true to include data from the original Hris software.', - }) - @ApiBody({ type: UnifiedEmployerBenefitInput }) - @ApiCustomResponse(UnifiedEmployerBenefitOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedEmployerBenefitData: UnifiedEmployerBenefitInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.employerbenefitService.addEmployerBenefit( - unifiedEmployerBenefitData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/hris/employerbenefit/services/employerbenefit.service.ts b/packages/api/src/hris/employerbenefit/services/employerbenefit.service.ts index cb141fffc..58bddd678 100644 --- a/packages/api/src/hris/employerbenefit/services/employerbenefit.service.ts +++ b/packages/api/src/hris/employerbenefit/services/employerbenefit.service.ts @@ -28,15 +28,6 @@ export class EmployerBenefitService { this.logger.setContext(EmployerBenefitService.name); } - async addEmployerBenefit( - unifiedEmployerBenefitData: UnifiedEmployerBenefitInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getEmployerBenefit( id_employerbenefiting_employerbenefit: string, remote_data?: boolean, @@ -45,6 +36,7 @@ export class EmployerBenefitService { } async getEmployerBenefits( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/hris/employment/employment.controller.ts b/packages/api/src/hris/employment/employment.controller.ts index b564dbdf8..021ed2b75 100644 --- a/packages/api/src/hris/employment/employment.controller.ts +++ b/packages/api/src/hris/employment/employment.controller.ts @@ -57,12 +57,13 @@ export class EmploymentController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.employmentService.getEmployments( + connectionId, remoteSource, linkedUserId, limit, @@ -100,46 +101,4 @@ export class EmploymentController { ) { return this.employmentService.getEmployment(id, remote_data); } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a Employment', - description: 'Create a employment in any supported Hris software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: 'Set to true to include data from the original Hris software.', - }) - @ApiBody({ type: UnifiedEmploymentInput }) - @ApiCustomResponse(UnifiedEmploymentOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedEmploymentData: UnifiedEmploymentInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.employmentService.addEmployment( - unifiedEmploymentData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/hris/employment/services/employment.service.ts b/packages/api/src/hris/employment/services/employment.service.ts index 3b78746d5..e59470d29 100644 --- a/packages/api/src/hris/employment/services/employment.service.ts +++ b/packages/api/src/hris/employment/services/employment.service.ts @@ -28,15 +28,6 @@ export class EmploymentService { this.logger.setContext(EmploymentService.name); } - async addEmployment( - unifiedEmploymentData: UnifiedEmploymentInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getEmployment( id_employmenting_employment: string, remote_data?: boolean, @@ -45,6 +36,7 @@ export class EmploymentService { } async getEmployments( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/hris/group/group.controller.ts b/packages/api/src/hris/group/group.controller.ts index c234de3c6..967671188 100644 --- a/packages/api/src/hris/group/group.controller.ts +++ b/packages/api/src/hris/group/group.controller.ts @@ -54,12 +54,13 @@ export class GroupController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.groupService.getGroups( + connectionId, remoteSource, linkedUserId, limit, @@ -97,46 +98,4 @@ export class GroupController { ) { return this.groupService.getGroup(id, remote_data); } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a Group', - description: 'Create a group in any supported Hris software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: 'Set to true to include data from the original Hris software.', - }) - @ApiBody({ type: UnifiedGroupInput }) - @ApiCustomResponse(UnifiedGroupOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedGroupData: UnifiedGroupInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.groupService.addGroup( - unifiedGroupData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/hris/group/services/group.service.ts b/packages/api/src/hris/group/services/group.service.ts index a903cac76..f3bbd3a1f 100644 --- a/packages/api/src/hris/group/services/group.service.ts +++ b/packages/api/src/hris/group/services/group.service.ts @@ -25,15 +25,6 @@ export class GroupService { this.logger.setContext(GroupService.name); } - async addGroup( - unifiedGroupData: UnifiedGroupInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getGroup( id_grouping_group: string, remote_data?: boolean, @@ -42,6 +33,7 @@ export class GroupService { } async getGroups( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/hris/location/location.controller.ts b/packages/api/src/hris/location/location.controller.ts index d59822f4c..32f6340c8 100644 --- a/packages/api/src/hris/location/location.controller.ts +++ b/packages/api/src/hris/location/location.controller.ts @@ -57,12 +57,13 @@ export class LocationController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.locationService.getLocations( + connectionId, remoteSource, linkedUserId, limit, @@ -100,46 +101,4 @@ export class LocationController { ) { return this.locationService.getLocation(id, remote_data); } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a Location', - description: 'Create a location in any supported Hris software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: 'Set to true to include data from the original Hris software.', - }) - @ApiBody({ type: UnifiedLocationInput }) - @ApiCustomResponse(UnifiedLocationOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedLocationData: UnifiedLocationInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.locationService.addLocation( - unifiedLocationData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/hris/location/services/location.service.ts b/packages/api/src/hris/location/services/location.service.ts index c74ae62cd..a68555c8e 100644 --- a/packages/api/src/hris/location/services/location.service.ts +++ b/packages/api/src/hris/location/services/location.service.ts @@ -28,15 +28,6 @@ export class LocationService { this.logger.setContext(LocationService.name); } - async addLocation( - unifiedLocationData: UnifiedLocationInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getLocation( id_locationing_location: string, remote_data?: boolean, @@ -45,6 +36,7 @@ export class LocationService { } async getLocations( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/hris/paygroup/paygroup.controller.ts b/packages/api/src/hris/paygroup/paygroup.controller.ts index 07363b546..7f507e53a 100644 --- a/packages/api/src/hris/paygroup/paygroup.controller.ts +++ b/packages/api/src/hris/paygroup/paygroup.controller.ts @@ -57,12 +57,13 @@ export class PayGroupController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.paygroupService.getPayGroups( + connectionId, remoteSource, linkedUserId, limit, @@ -100,46 +101,4 @@ export class PayGroupController { ) { return this.paygroupService.getPayGroup(id, remote_data); } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a PayGroup', - description: 'Create a paygroup in any supported Hris software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: 'Set to true to include data from the original Hris software.', - }) - @ApiBody({ type: UnifiedPayGroupInput }) - @ApiCustomResponse(UnifiedPayGroupOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedPayGroupData: UnifiedPayGroupInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.paygroupService.addPayGroup( - unifiedPayGroupData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/hris/paygroup/services/paygroup.service.ts b/packages/api/src/hris/paygroup/services/paygroup.service.ts index fd6bb100f..40d643665 100644 --- a/packages/api/src/hris/paygroup/services/paygroup.service.ts +++ b/packages/api/src/hris/paygroup/services/paygroup.service.ts @@ -28,15 +28,6 @@ export class PayGroupService { this.logger.setContext(PayGroupService.name); } - async addPayGroup( - unifiedPayGroupData: UnifiedPayGroupInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getPayGroup( id_paygrouping_paygroup: string, remote_data?: boolean, @@ -45,6 +36,7 @@ export class PayGroupService { } async getPayGroups( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/hris/payrollrun/payrollrun.controller.ts b/packages/api/src/hris/payrollrun/payrollrun.controller.ts index c0b05dae6..18f089664 100644 --- a/packages/api/src/hris/payrollrun/payrollrun.controller.ts +++ b/packages/api/src/hris/payrollrun/payrollrun.controller.ts @@ -57,12 +57,13 @@ export class PayrollRunController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.payrollrunService.getPayrollRuns( + connectionId, remoteSource, linkedUserId, limit, @@ -73,73 +74,4 @@ export class PayrollRunController { throw new Error(error); } } - - @ApiOperation({ - operationId: 'retrieve', - summary: 'Retrieve a PayrollRun', - description: 'Retrieve a payrollrun from any connected Hris software', - }) - @ApiParam({ - name: 'id', - required: true, - type: String, - description: 'id of the payrollrun you want to retrieve.', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: 'Set to true to include data from the original Hris software.', - }) - @ApiCustomResponse(UnifiedPayrollRunOutput) - @UseGuards(ApiKeyAuthGuard) - @Get(':id') - retrieve( - @Param('id') id: string, - @Query('remote_data') remote_data?: boolean, - ) { - return this.payrollrunService.getPayrollRun(id, remote_data); - } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a PayrollRun', - description: 'Create a payrollrun in any supported Hris software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: 'Set to true to include data from the original Hris software.', - }) - @ApiBody({ type: UnifiedPayrollRunInput }) - @ApiCustomResponse(UnifiedPayrollRunOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedPayrollRunData: UnifiedPayrollRunInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.payrollrunService.addPayrollRun( - unifiedPayrollRunData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/hris/payrollrun/services/payrollrun.service.ts b/packages/api/src/hris/payrollrun/services/payrollrun.service.ts index 98a3bbd43..587e46ee3 100644 --- a/packages/api/src/hris/payrollrun/services/payrollrun.service.ts +++ b/packages/api/src/hris/payrollrun/services/payrollrun.service.ts @@ -28,15 +28,6 @@ export class PayrollRunService { this.logger.setContext(PayrollRunService.name); } - async addPayrollRun( - unifiedPayrollRunData: UnifiedPayrollRunInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getPayrollRun( id_payrollruning_payrollrun: string, remote_data?: boolean, @@ -45,6 +36,7 @@ export class PayrollRunService { } async getPayrollRuns( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/hris/timeoff/services/timeoff.service.ts b/packages/api/src/hris/timeoff/services/timeoff.service.ts index 7221811b7..379a2fade 100644 --- a/packages/api/src/hris/timeoff/services/timeoff.service.ts +++ b/packages/api/src/hris/timeoff/services/timeoff.service.ts @@ -30,6 +30,7 @@ export class TimeoffService { async addTimeoff( unifiedTimeoffData: UnifiedTimeoffInput, + connectionId: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -45,6 +46,7 @@ export class TimeoffService { } async getTimeoffs( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/hris/timeoff/timeoff.controller.ts b/packages/api/src/hris/timeoff/timeoff.controller.ts index a3616e22b..020b3002c 100644 --- a/packages/api/src/hris/timeoff/timeoff.controller.ts +++ b/packages/api/src/hris/timeoff/timeoff.controller.ts @@ -57,12 +57,13 @@ export class TimeoffController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.timeoffService.getTimeoffs( + connectionId, remoteSource, linkedUserId, limit, @@ -128,12 +129,13 @@ export class TimeoffController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.timeoffService.addTimeoff( unifiedTimeoffData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/hris/timeoffbalance/services/timeoffbalance.service.ts b/packages/api/src/hris/timeoffbalance/services/timeoffbalance.service.ts index 895c441ec..77119895b 100644 --- a/packages/api/src/hris/timeoffbalance/services/timeoffbalance.service.ts +++ b/packages/api/src/hris/timeoffbalance/services/timeoffbalance.service.ts @@ -28,15 +28,6 @@ export class TimeoffBalanceService { this.logger.setContext(TimeoffBalanceService.name); } - async addTimeoffBalance( - unifiedTimeoffBalanceData: UnifiedTimeoffBalanceInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getTimeoffBalance( id_timeoffbalanceing_timeoffbalance: string, remote_data?: boolean, @@ -45,6 +36,7 @@ export class TimeoffBalanceService { } async getTimeoffBalances( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/hris/timeoffbalance/timeoffbalance.controller.ts b/packages/api/src/hris/timeoffbalance/timeoffbalance.controller.ts index 1d5309818..c221134d3 100644 --- a/packages/api/src/hris/timeoffbalance/timeoffbalance.controller.ts +++ b/packages/api/src/hris/timeoffbalance/timeoffbalance.controller.ts @@ -57,12 +57,13 @@ export class TimeoffBalanceController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.timeoffbalanceService.getTimeoffBalances( + connectionId, remoteSource, linkedUserId, limit, @@ -100,46 +101,4 @@ export class TimeoffBalanceController { ) { return this.timeoffbalanceService.getTimeoffBalance(id, remote_data); } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a TimeoffBalance', - description: 'Create a timeoffbalance in any supported Hris software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: 'Set to true to include data from the original Hris software.', - }) - @ApiBody({ type: UnifiedTimeoffBalanceInput }) - @ApiCustomResponse(UnifiedTimeoffBalanceOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedTimeoffBalanceData: UnifiedTimeoffBalanceInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.timeoffbalanceService.addTimeoffBalance( - unifiedTimeoffBalanceData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/marketingautomation/action/action.controller.ts b/packages/api/src/marketingautomation/action/action.controller.ts index 78b34376e..bd13eab60 100644 --- a/packages/api/src/marketingautomation/action/action.controller.ts +++ b/packages/api/src/marketingautomation/action/action.controller.ts @@ -54,12 +54,13 @@ export class ActionController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.actionService.getActions( + connectionId, remoteSource, linkedUserId, limit, @@ -129,12 +130,13 @@ export class ActionController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.actionService.addAction( unifiedActionData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/marketingautomation/action/services/action.service.ts b/packages/api/src/marketingautomation/action/services/action.service.ts index eb1eb2872..a0b5d761a 100644 --- a/packages/api/src/marketingautomation/action/services/action.service.ts +++ b/packages/api/src/marketingautomation/action/services/action.service.ts @@ -29,6 +29,7 @@ export class ActionService { async addAction( unifiedActionData: UnifiedActionInput, + connectionId: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -44,6 +45,7 @@ export class ActionService { } async getActions( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/marketingautomation/automation/automation.controller.ts b/packages/api/src/marketingautomation/automation/automation.controller.ts index 3afc19f3b..472dab050 100644 --- a/packages/api/src/marketingautomation/automation/automation.controller.ts +++ b/packages/api/src/marketingautomation/automation/automation.controller.ts @@ -57,12 +57,13 @@ export class AutomationController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.automationService.getAutomations( + connectionId, remoteSource, linkedUserId, limit, @@ -132,12 +133,13 @@ export class AutomationController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.automationService.addAutomation( unifiedAutomationData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/marketingautomation/automation/services/automation.service.ts b/packages/api/src/marketingautomation/automation/services/automation.service.ts index 790d352ec..d85242081 100644 --- a/packages/api/src/marketingautomation/automation/services/automation.service.ts +++ b/packages/api/src/marketingautomation/automation/services/automation.service.ts @@ -29,6 +29,7 @@ export class AutomationService { async addAutomation( unifiedAutomationData: UnifiedAutomationInput, + connectionId: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -44,6 +45,7 @@ export class AutomationService { } async getAutomations( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/marketingautomation/campaign/campaign.controller.ts b/packages/api/src/marketingautomation/campaign/campaign.controller.ts index b374234ad..e9574a121 100644 --- a/packages/api/src/marketingautomation/campaign/campaign.controller.ts +++ b/packages/api/src/marketingautomation/campaign/campaign.controller.ts @@ -57,12 +57,13 @@ export class CampaignController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.campaignService.getCampaigns( + connectionId, remoteSource, linkedUserId, limit, @@ -132,12 +133,13 @@ export class CampaignController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.campaignService.addCampaign( unifiedCampaignData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/marketingautomation/campaign/services/campaign.service.ts b/packages/api/src/marketingautomation/campaign/services/campaign.service.ts index 64d47295f..40f937111 100644 --- a/packages/api/src/marketingautomation/campaign/services/campaign.service.ts +++ b/packages/api/src/marketingautomation/campaign/services/campaign.service.ts @@ -29,6 +29,7 @@ export class CampaignService { async addCampaign( unifiedCampaignData: UnifiedCampaignInput, + connectionId: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -44,6 +45,7 @@ export class CampaignService { } async getCampaigns( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/marketingautomation/contact/contact.controller.ts b/packages/api/src/marketingautomation/contact/contact.controller.ts index 360d09a02..cbe782482 100644 --- a/packages/api/src/marketingautomation/contact/contact.controller.ts +++ b/packages/api/src/marketingautomation/contact/contact.controller.ts @@ -57,12 +57,13 @@ export class ContactController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.contactService.getContacts( + connectionId, remoteSource, linkedUserId, limit, @@ -132,12 +133,13 @@ export class ContactController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.contactService.addContact( unifiedContactData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/marketingautomation/contact/services/contact.service.ts b/packages/api/src/marketingautomation/contact/services/contact.service.ts index 1d755967f..9a96e15c1 100644 --- a/packages/api/src/marketingautomation/contact/services/contact.service.ts +++ b/packages/api/src/marketingautomation/contact/services/contact.service.ts @@ -29,6 +29,7 @@ export class ContactService { async addContact( unifiedContactData: UnifiedContactInput, + connectionId: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -44,6 +45,7 @@ export class ContactService { } async getContacts( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/marketingautomation/email/email.controller.ts b/packages/api/src/marketingautomation/email/email.controller.ts index 1b75a77fe..4e688337a 100644 --- a/packages/api/src/marketingautomation/email/email.controller.ts +++ b/packages/api/src/marketingautomation/email/email.controller.ts @@ -54,12 +54,13 @@ export class EmailController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.emailService.getEmails( + connectionId, remoteSource, linkedUserId, limit, @@ -99,47 +100,4 @@ export class EmailController { ) { return this.emailService.getEmail(id, remote_data); } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a Email', - description: 'Create a email in any supported Marketingautomation software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: - 'Set to true to include data from the original Marketingautomation software.', - }) - @ApiBody({ type: UnifiedEmailInput }) - @ApiCustomResponse(UnifiedEmailOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedEmailData: UnifiedEmailInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.emailService.addEmail( - unifiedEmailData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/marketingautomation/email/services/email.service.ts b/packages/api/src/marketingautomation/email/services/email.service.ts index f304ffc59..8e8bc3d34 100644 --- a/packages/api/src/marketingautomation/email/services/email.service.ts +++ b/packages/api/src/marketingautomation/email/services/email.service.ts @@ -24,15 +24,6 @@ export class EmailService { this.logger.setContext(EmailService.name); } - async addEmail( - unifiedEmailData: UnifiedEmailInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getEmail( id_emailing_email: string, remote_data?: boolean, @@ -41,6 +32,7 @@ export class EmailService { } async getEmails( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/marketingautomation/event/event.controller.ts b/packages/api/src/marketingautomation/event/event.controller.ts index f1a54d37e..0be7e8d91 100644 --- a/packages/api/src/marketingautomation/event/event.controller.ts +++ b/packages/api/src/marketingautomation/event/event.controller.ts @@ -54,12 +54,13 @@ export class EventController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.eventService.getEvents( + connectionId, remoteSource, linkedUserId, limit, @@ -99,47 +100,4 @@ export class EventController { ) { return this.eventService.getEvent(id, remote_data); } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a Event', - description: 'Create a event in any supported Marketingautomation software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: - 'Set to true to include data from the original Marketingautomation software.', - }) - @ApiBody({ type: UnifiedEventInput }) - @ApiCustomResponse(UnifiedEventOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedEventData: UnifiedEventInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.eventService.addEvent( - unifiedEventData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/marketingautomation/event/services/event.service.ts b/packages/api/src/marketingautomation/event/services/event.service.ts index 4138290bf..c5be347cc 100644 --- a/packages/api/src/marketingautomation/event/services/event.service.ts +++ b/packages/api/src/marketingautomation/event/services/event.service.ts @@ -24,15 +24,6 @@ export class EventService { this.logger.setContext(EventService.name); } - async addEvent( - unifiedEventData: UnifiedEventInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getEvent( id_eventing_event: string, remote_data?: boolean, @@ -41,6 +32,7 @@ export class EventService { } async getEvents( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/marketingautomation/list/list.controller.ts b/packages/api/src/marketingautomation/list/list.controller.ts index 0e9e4d749..197b2f2d9 100644 --- a/packages/api/src/marketingautomation/list/list.controller.ts +++ b/packages/api/src/marketingautomation/list/list.controller.ts @@ -54,12 +54,13 @@ export class ListController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.listService.getLists( + connectionId, remoteSource, linkedUserId, limit, @@ -128,12 +129,13 @@ export class ListController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.listService.addList( unifiedListData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/marketingautomation/list/services/list.service.ts b/packages/api/src/marketingautomation/list/services/list.service.ts index bc5808b4d..93f60b5b7 100644 --- a/packages/api/src/marketingautomation/list/services/list.service.ts +++ b/packages/api/src/marketingautomation/list/services/list.service.ts @@ -26,6 +26,7 @@ export class ListService { async addList( unifiedListData: UnifiedListInput, + connectionId: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -41,6 +42,7 @@ export class ListService { } async getLists( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/marketingautomation/message/message.controller.ts b/packages/api/src/marketingautomation/message/message.controller.ts index 636f025ad..472914c87 100644 --- a/packages/api/src/marketingautomation/message/message.controller.ts +++ b/packages/api/src/marketingautomation/message/message.controller.ts @@ -57,12 +57,13 @@ export class MessageController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.messageService.getMessages( + connectionId, remoteSource, linkedUserId, limit, @@ -102,48 +103,4 @@ export class MessageController { ) { return this.messageService.getMessage(id, remote_data); } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a Message', - description: - 'Create a message in any supported Marketingautomation software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: - 'Set to true to include data from the original Marketingautomation software.', - }) - @ApiBody({ type: UnifiedMessageInput }) - @ApiCustomResponse(UnifiedMessageOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedMessageData: UnifiedMessageInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.messageService.addMessage( - unifiedMessageData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/marketingautomation/message/services/message.service.ts b/packages/api/src/marketingautomation/message/services/message.service.ts index 5870e6732..483d31821 100644 --- a/packages/api/src/marketingautomation/message/services/message.service.ts +++ b/packages/api/src/marketingautomation/message/services/message.service.ts @@ -27,15 +27,6 @@ export class MessageService { this.logger.setContext(MessageService.name); } - async addMessage( - unifiedMessageData: UnifiedMessageInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getMessage( id_messageing_message: string, remote_data?: boolean, @@ -44,6 +35,7 @@ export class MessageService { } async getMessages( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/marketingautomation/template/services/template.service.ts b/packages/api/src/marketingautomation/template/services/template.service.ts index 1ef208033..5d7a62ac1 100644 --- a/packages/api/src/marketingautomation/template/services/template.service.ts +++ b/packages/api/src/marketingautomation/template/services/template.service.ts @@ -29,6 +29,7 @@ export class TemplateService { async addTemplate( unifiedTemplateData: UnifiedTemplateInput, + connectionId: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -44,6 +45,7 @@ export class TemplateService { } async getTemplates( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/marketingautomation/template/template.controller.ts b/packages/api/src/marketingautomation/template/template.controller.ts index a3144c4b4..8a0442dfe 100644 --- a/packages/api/src/marketingautomation/template/template.controller.ts +++ b/packages/api/src/marketingautomation/template/template.controller.ts @@ -57,12 +57,13 @@ export class TemplateController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.templateService.getTemplates( + connectionId, remoteSource, linkedUserId, limit, @@ -132,12 +133,13 @@ export class TemplateController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.templateService.addTemplate( unifiedTemplateData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/marketingautomation/user/services/user.service.ts b/packages/api/src/marketingautomation/user/services/user.service.ts index f71919935..9dcba919d 100644 --- a/packages/api/src/marketingautomation/user/services/user.service.ts +++ b/packages/api/src/marketingautomation/user/services/user.service.ts @@ -24,15 +24,6 @@ export class UserService { this.logger.setContext(UserService.name); } - async addUser( - unifiedUserData: UnifiedUserInput, - integrationId: string, - linkedUserId: string, - remote_data?: boolean, - ): Promise { - return; - } - async getUser( id_usering_user: string, remote_data?: boolean, @@ -41,6 +32,7 @@ export class UserService { } async getUsers( + connectionId: string, integrationId: string, linkedUserId: string, limit: number, diff --git a/packages/api/src/marketingautomation/user/user.controller.ts b/packages/api/src/marketingautomation/user/user.controller.ts index 0f8a4f77e..791cbb8d1 100644 --- a/packages/api/src/marketingautomation/user/user.controller.ts +++ b/packages/api/src/marketingautomation/user/user.controller.ts @@ -54,12 +54,13 @@ export class UserController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.userService.getUsers( + connectionId, remoteSource, linkedUserId, limit, @@ -99,47 +100,4 @@ export class UserController { ) { return this.userService.getUser(id, remote_data); } - - @ApiOperation({ - operationId: 'create', - summary: 'Create a User', - description: 'Create a user in any supported Marketingautomation software', - }) - @ApiHeader({ - name: 'x-connection-token', - required: true, - description: 'The connection token', - example: 'b008e199-eda9-4629-bd41-a01b6195864a', - }) - @ApiQuery({ - name: 'remote_data', - required: false, - type: Boolean, - description: - 'Set to true to include data from the original Marketingautomation software.', - }) - @ApiBody({ type: UnifiedUserInput }) - @ApiCustomResponse(UnifiedUserOutput) - @UseGuards(ApiKeyAuthGuard) - @Post() - async create( - @Body() unifiedUserData: UnifiedUserInput, - @Headers('x-connection-token') connection_token: string, - @Query('remote_data') remote_data?: boolean, - ) { - try { - const { linkedUserId, remoteSource } = - await this.connectionUtils.getConnectionMetadataFromConnectionToken( - connection_token, - ); - return this.userService.addUser( - unifiedUserData, - remoteSource, - linkedUserId, - remote_data, - ); - } catch (error) { - throw new Error(error); - } - } } diff --git a/packages/api/src/ticketing/@lib/@utils/index.ts b/packages/api/src/ticketing/@lib/@utils/index.ts index 7a074a285..ac56e09ff 100644 --- a/packages/api/src/ticketing/@lib/@utils/index.ts +++ b/packages/api/src/ticketing/@lib/@utils/index.ts @@ -10,12 +10,12 @@ export class Utils { return fs.createReadStream(file_url); } - async getUserUuidFromRemoteId(remote_id: string, remote_platform: string) { + async getUserUuidFromRemoteId(remote_id: string, connection_id: string) { try { const res = await this.prisma.tcg_users.findFirst({ where: { remote_id: remote_id, - remote_platform: remote_platform, + id_connection: connection_id, }, }); if (!res) return undefined; @@ -40,12 +40,12 @@ export class Utils { } } - async getContactUuidFromRemoteId(remote_id: string, remote_platform: string) { + async getContactUuidFromRemoteId(remote_id: string, connection_id: string) { try { const res = await this.prisma.tcg_contacts.findFirst({ where: { remote_id: remote_id, - remote_platform: remote_platform, + id_connection: connection_id, }, }); if (!res) return undefined; @@ -101,13 +101,13 @@ export class Utils { async getCollectionUuidFromRemoteId( remote_id: string, - remote_platform: string, + connection_id: string, ) { try { const res = await this.prisma.tcg_collections.findFirst({ where: { remote_id: remote_id, - remote_platform: remote_platform, + id_connection: connection_id, }, }); if (!res) return undefined; @@ -133,12 +133,12 @@ export class Utils { } } - async getTicketUuidFromRemoteId(remote_id: string, remote_platform: string) { + async getTicketUuidFromRemoteId(remote_id: string, connection_id: string) { try { const res = await this.prisma.tcg_tickets.findFirst({ where: { remote_id: remote_id, - remote_platform: remote_platform, + id_connection: connection_id, }, }); if (!res) return undefined; diff --git a/packages/api/src/ticketing/account/account.controller.ts b/packages/api/src/ticketing/account/account.controller.ts index 9e402a792..5da4e58c1 100644 --- a/packages/api/src/ticketing/account/account.controller.ts +++ b/packages/api/src/ticketing/account/account.controller.ts @@ -55,12 +55,13 @@ export class AccountController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.accountService.getAccounts( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/ticketing/account/services/account.service.ts b/packages/api/src/ticketing/account/services/account.service.ts index f595c03f8..1a6047f74 100644 --- a/packages/api/src/ticketing/account/services/account.service.ts +++ b/packages/api/src/ticketing/account/services/account.service.ts @@ -80,6 +80,7 @@ export class AccountService { } async getAccounts( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -99,8 +100,7 @@ export class AccountService { if (cursor) { const isCursorPresent = await this.prisma.tcg_accounts.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_tcg_account: cursor, }, }); @@ -120,8 +120,7 @@ export class AccountService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ticketing/account/sync/sync.service.ts b/packages/api/src/ticketing/account/sync/sync.service.ts index 749aa3e63..50b35bfa8 100644 --- a/packages/api/src/ticketing/account/sync/sync.service.ts +++ b/packages/api/src/ticketing/account/sync/sync.service.ts @@ -165,8 +165,7 @@ export class SyncService implements OnModuleInit { switch (wh_real_time_trigger.action) { case 'DELETE': return await this.removeAccountInDb( - linkedUserId, - integrationId, + connection.id_connection, wh_real_time_trigger.data.remote_id, ); default: @@ -201,6 +200,7 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const account_data = await this.saveAccountsInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -231,6 +231,7 @@ export class SyncService implements OnModuleInit { } async saveAccountsInDb( + connection_id: string, linkedUserId: string, accounts: UnifiedAccountOutput[], originSource: string, @@ -249,8 +250,7 @@ export class SyncService implements OnModuleInit { const existingAccount = await this.prisma.tcg_accounts.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -279,9 +279,8 @@ export class SyncService implements OnModuleInit { domains: account.domains, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; const res = await this.prisma.tcg_accounts.create({ data: data, @@ -353,16 +352,11 @@ export class SyncService implements OnModuleInit { } } - async removeAccountInDb( - linkedUserId: string, - originSource: string, - remote_id: string, - ) { + async removeAccountInDb(connection_id: string, remote_id: string) { const existingAccount = await this.prisma.tcg_accounts.findFirst({ where: { remote_id: remote_id, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); await this.prisma.tcg_accounts.delete({ diff --git a/packages/api/src/ticketing/attachment/attachment.controller.ts b/packages/api/src/ticketing/attachment/attachment.controller.ts index 1335eee5a..0e84aa56e 100644 --- a/packages/api/src/ticketing/attachment/attachment.controller.ts +++ b/packages/api/src/ticketing/attachment/attachment.controller.ts @@ -61,13 +61,14 @@ export class AttachmentController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.attachmentService.getAttachments( + connectionId, remoteSource, linkedUserId, limit, @@ -163,12 +164,13 @@ export class AttachmentController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.attachmentService.addAttachment( unfiedAttachmentData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/ticketing/attachment/services/attachment.service.ts b/packages/api/src/ticketing/attachment/services/attachment.service.ts index 0383849fb..dbe8a681d 100644 --- a/packages/api/src/ticketing/attachment/services/attachment.service.ts +++ b/packages/api/src/ticketing/attachment/services/attachment.service.ts @@ -20,6 +20,7 @@ export class AttachmentService { async addAttachment( unifiedAttachmentData: UnifiedAttachmentInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -40,8 +41,7 @@ export class AttachmentService { const existingAttachment = await this.prisma.tcg_attachments.findFirst({ where: { file_name: unifiedAttachmentData.file_name, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -69,8 +69,7 @@ export class AttachmentService { uploader: linkedUserId, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, - remote_platform: integrationId, + id_connection: connection_id, }; const res = await this.prisma.tcg_attachments.create({ @@ -180,6 +179,7 @@ export class AttachmentService { } async getAttachments( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -198,8 +198,7 @@ export class AttachmentService { if (cursor) { const isCursorPresent = await this.prisma.tcg_attachments.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_tcg_attachment: cursor, }, }); @@ -218,8 +217,7 @@ export class AttachmentService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ticketing/collection/collection.controller.ts b/packages/api/src/ticketing/collection/collection.controller.ts index bd8bcdbe7..b7c26f559 100644 --- a/packages/api/src/ticketing/collection/collection.controller.ts +++ b/packages/api/src/ticketing/collection/collection.controller.ts @@ -62,12 +62,13 @@ export class CollectionController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.collectionService.getCollections( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/ticketing/collection/services/collection.service.ts b/packages/api/src/ticketing/collection/services/collection.service.ts index 8cae671f6..b697bf7ca 100644 --- a/packages/api/src/ticketing/collection/services/collection.service.ts +++ b/packages/api/src/ticketing/collection/services/collection.service.ts @@ -66,6 +66,7 @@ export class CollectionService { } async getCollections( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -83,8 +84,7 @@ export class CollectionService { if (cursor) { const isCursorPresent = await this.prisma.tcg_collections.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_tcg_collection: cursor, }, }); @@ -104,8 +104,7 @@ export class CollectionService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ticketing/collection/sync/sync.service.ts b/packages/api/src/ticketing/collection/sync/sync.service.ts index 6a5f0e81e..cdde2a6e8 100644 --- a/packages/api/src/ticketing/collection/sync/sync.service.ts +++ b/packages/api/src/ticketing/collection/sync/sync.service.ts @@ -159,6 +159,7 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const collection_data = await this.saveCollectionsInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -191,6 +192,7 @@ export class SyncService implements OnModuleInit { } async saveCollectionsInDb( + connection_id: string, linkedUserId: string, collections: UnifiedCollectionOutput[], originSource: string, @@ -210,8 +212,7 @@ export class SyncService implements OnModuleInit { const existingTeam = await this.prisma.tcg_collections.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -242,9 +243,8 @@ export class SyncService implements OnModuleInit { collection_type: collection.collection_type, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; const res = await this.prisma.tcg_collections.create({ data: data, diff --git a/packages/api/src/ticketing/comment/comment.controller.ts b/packages/api/src/ticketing/comment/comment.controller.ts index 43551a42b..d21b51ea0 100644 --- a/packages/api/src/ticketing/comment/comment.controller.ts +++ b/packages/api/src/ticketing/comment/comment.controller.ts @@ -61,12 +61,13 @@ export class CommentController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.commentService.getComments( + connectionId, remoteSource, linkedUserId, limit, @@ -134,12 +135,13 @@ export class CommentController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.commentService.addComment( unfiedCommentData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/ticketing/comment/services/comment.service.ts b/packages/api/src/ticketing/comment/services/comment.service.ts index d0a81cddc..348e913a5 100644 --- a/packages/api/src/ticketing/comment/services/comment.service.ts +++ b/packages/api/src/ticketing/comment/services/comment.service.ts @@ -28,6 +28,7 @@ export class CommentService { async addComment( unifiedCommentData: UnifiedCommentInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -147,8 +148,7 @@ export class CommentService { const existingComment = await this.prisma.tcg_comments.findFirst({ where: { remote_id: target_comment.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -199,9 +199,8 @@ export class CommentService { created_at: new Date(), modified_at: new Date(), id_tcg_ticket: unifiedCommentData.ticket_id, - id_linked_user: linkedUserId, remote_id: target_comment.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; if (target_comment.body) { @@ -354,6 +353,7 @@ export class CommentService { //TODO: return attachments if specified in param async getComments( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -371,8 +371,7 @@ export class CommentService { if (cursor) { const isCursorPresent = await this.prisma.tcg_comments.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_tcg_comment: cursor, }, }); @@ -392,8 +391,7 @@ export class CommentService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ticketing/comment/services/gitlab/index.ts b/packages/api/src/ticketing/comment/services/gitlab/index.ts index 5327c25ca..ac00f2420 100644 --- a/packages/api/src/ticketing/comment/services/gitlab/index.ts +++ b/packages/api/src/ticketing/comment/services/gitlab/index.ts @@ -78,7 +78,7 @@ export class GitlabService implements ICommentService { const ticket = await this.prisma.tcg_tickets.findFirst({ where: { remote_id: remoteIdTicket, - remote_platform: 'gitlab', + id_connection: connection.id_connection, }, select: { collections: true, diff --git a/packages/api/src/ticketing/comment/sync/sync.service.ts b/packages/api/src/ticketing/comment/sync/sync.service.ts index 0c863a9a8..2d1e0708b 100644 --- a/packages/api/src/ticketing/comment/sync/sync.service.ts +++ b/packages/api/src/ticketing/comment/sync/sync.service.ts @@ -93,11 +93,16 @@ export class SyncService implements OnModuleInit { const providers = TICKETING_PROVIDERS; for (const provider of providers) { try { + const connection = await this.prisma.connections.findFirst({ + where: { + id_linked_user: linkedUser.id_linked_user, + provider_slug: provider.toLowerCase(), + }, + }); //call the sync comments for every ticket of the linkedUser (a comment is tied to a ticket) const tickets = await this.prisma.tcg_tickets.findMany({ where: { - remote_platform: provider, - id_linked_user: linkedUser.id_linked_user, + id_connection: connection.id_connection, }, }); for (const ticket of tickets) { @@ -179,9 +184,9 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const comments_data = await this.saveCommentsInDb( + connection.id_connection, linkedUserId, unifiedObject, - integrationId, id_ticket, sourceObject, ); @@ -211,9 +216,9 @@ export class SyncService implements OnModuleInit { } async saveCommentsInDb( + connection_id: string, linkedUserId: string, comments: UnifiedCommentOutput[], - originSource: string, id_ticket: string, remote_data: Record[], ): Promise { @@ -230,8 +235,7 @@ export class SyncService implements OnModuleInit { const existingComment = await this.prisma.tcg_comments.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -283,9 +287,8 @@ export class SyncService implements OnModuleInit { created_at: new Date(), modified_at: new Date(), id_tcg_ticket: comment.ticket_id, - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (comment.body) { @@ -317,12 +320,10 @@ export class SyncService implements OnModuleInit { if (comment.attachments && comment.attachments.length > 0) { for (const attchmt of comment.attachments) { let unique_ticketing_attachmt_id: string; - const existingAttachmt = await this.prisma.tcg_attachments.findFirst({ where: { - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, remote_id: attchmt.id, }, }); @@ -354,8 +355,7 @@ export class SyncService implements OnModuleInit { modified_at: new Date(), uploader: linkedUserId, //TODO id_tcg_ticket: id_ticket, - id_linked_user: linkedUserId, - remote_platform: originSource, + id_connection: connection_id, }; const res = await this.prisma.tcg_attachments.create({ data: data, diff --git a/packages/api/src/ticketing/contact/contact.controller.ts b/packages/api/src/ticketing/contact/contact.controller.ts index 11f9d83e5..e140509ce 100644 --- a/packages/api/src/ticketing/contact/contact.controller.ts +++ b/packages/api/src/ticketing/contact/contact.controller.ts @@ -55,12 +55,13 @@ export class ContactController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.contactService.getContacts( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/ticketing/contact/services/contact.service.ts b/packages/api/src/ticketing/contact/services/contact.service.ts index e8e1cc079..9e1174ed3 100644 --- a/packages/api/src/ticketing/contact/services/contact.service.ts +++ b/packages/api/src/ticketing/contact/services/contact.service.ts @@ -82,6 +82,7 @@ export class ContactService { } async getContacts( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -100,8 +101,7 @@ export class ContactService { if (cursor) { const isCursorPresent = await this.prisma.tcg_contacts.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_tcg_contact: cursor, }, }); @@ -121,8 +121,7 @@ export class ContactService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ticketing/contact/sync/sync.service.ts b/packages/api/src/ticketing/contact/sync/sync.service.ts index ccbbd2600..22b9a9f1d 100644 --- a/packages/api/src/ticketing/contact/sync/sync.service.ts +++ b/packages/api/src/ticketing/contact/sync/sync.service.ts @@ -210,6 +210,7 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const contact_data = await this.saveContactsInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -241,6 +242,7 @@ export class SyncService implements OnModuleInit { } async saveContactsInDb( + connection_id: string, linkedUserId: string, contacts: UnifiedContactOutput[], originSource: string, @@ -260,8 +262,7 @@ export class SyncService implements OnModuleInit { const existingContact = await this.prisma.tcg_contacts.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -281,7 +282,7 @@ export class SyncService implements OnModuleInit { const res = await this.prisma.tcg_accounts.findFirst({ where: { remote_id: remote_account_id, - remote_platform: originSource, + id_connection: connection_id, }, }); data.id_tcg_account = res.id_tcg_account; @@ -307,15 +308,14 @@ export class SyncService implements OnModuleInit { details: contact.details, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (remote_account_id) { const res = await this.prisma.tcg_accounts.findFirst({ where: { remote_id: remote_account_id, - remote_platform: originSource, + id_connection: connection_id, }, }); data.id_tcg_account = res.id_tcg_account; @@ -397,8 +397,7 @@ export class SyncService implements OnModuleInit { const existingContact = await this.prisma.tcg_contacts.findFirst({ where: { remote_id: remote_id, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); await this.prisma.tcg_contacts.delete({ diff --git a/packages/api/src/ticketing/tag/services/tag.service.ts b/packages/api/src/ticketing/tag/services/tag.service.ts index 8e039fb15..52352c550 100644 --- a/packages/api/src/ticketing/tag/services/tag.service.ts +++ b/packages/api/src/ticketing/tag/services/tag.service.ts @@ -79,6 +79,7 @@ export class TagService { } async getTags( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -98,8 +99,7 @@ export class TagService { if (cursor) { const isCursorPresent = await this.prisma.tcg_tags.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_tcg_tag: cursor, }, }); @@ -119,8 +119,7 @@ export class TagService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ticketing/tag/sync/sync.service.ts b/packages/api/src/ticketing/tag/sync/sync.service.ts index bd89ecd9b..7562a406a 100644 --- a/packages/api/src/ticketing/tag/sync/sync.service.ts +++ b/packages/api/src/ticketing/tag/sync/sync.service.ts @@ -95,11 +95,16 @@ export class SyncService implements OnModuleInit { const providers = TICKETING_PROVIDERS; for (const provider of providers) { try { + const connection = await this.prisma.connections.findFirst({ + where: { + id_linked_user: linkedUser.id_linked_user, + provider_slug: provider.toLowerCase(), + }, + }); //call the sync comments for every ticket of the linkedUser (a comment is tied to a ticket) const tickets = await this.prisma.tcg_tickets.findMany({ where: { - remote_platform: provider, - id_linked_user: linkedUser.id_linked_user, + id_connection: connection.id_connection, }, }); for (const ticket of tickets) { @@ -188,6 +193,7 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const tag_data = await this.saveTagsInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -219,6 +225,7 @@ export class SyncService implements OnModuleInit { } async saveTagsInDb( + connection_id: string, linkedUserId: string, tags: UnifiedTagOutput[], originSource: string, @@ -238,8 +245,7 @@ export class SyncService implements OnModuleInit { const existingTag = await this.prisma.tcg_tags.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -268,9 +274,8 @@ export class SyncService implements OnModuleInit { created_at: new Date(), modified_at: new Date(), id_tcg_ticket: id_ticket, - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; const res = await this.prisma.tcg_tags.create({ data: data, diff --git a/packages/api/src/ticketing/tag/tag.controller.ts b/packages/api/src/ticketing/tag/tag.controller.ts index fdedb927c..79d126e3a 100644 --- a/packages/api/src/ticketing/tag/tag.controller.ts +++ b/packages/api/src/ticketing/tag/tag.controller.ts @@ -55,12 +55,13 @@ export class TagController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.tagService.getTags( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/ticketing/team/services/team.service.ts b/packages/api/src/ticketing/team/services/team.service.ts index 11d05c406..e53538006 100644 --- a/packages/api/src/ticketing/team/services/team.service.ts +++ b/packages/api/src/ticketing/team/services/team.service.ts @@ -80,6 +80,7 @@ export class TeamService { } async getTeams( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -99,8 +100,7 @@ export class TeamService { if (cursor) { const isCursorPresent = await this.prisma.tcg_teams.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_tcg_team: cursor, }, }); @@ -120,8 +120,7 @@ export class TeamService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ticketing/team/sync/sync.service.ts b/packages/api/src/ticketing/team/sync/sync.service.ts index 239aa389d..d8319e9a6 100644 --- a/packages/api/src/ticketing/team/sync/sync.service.ts +++ b/packages/api/src/ticketing/team/sync/sync.service.ts @@ -172,6 +172,7 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const team_data = await this.saveTeamsInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -204,6 +205,7 @@ export class SyncService implements OnModuleInit { } async saveTeamsInDb( + connection_id: string, linkedUserId: string, teams: UnifiedTeamOutput[], originSource: string, @@ -222,8 +224,7 @@ export class SyncService implements OnModuleInit { const existingTeam = await this.prisma.tcg_teams.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -252,9 +253,8 @@ export class SyncService implements OnModuleInit { description: team.description, created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; const res = await this.prisma.tcg_teams.create({ data: data, diff --git a/packages/api/src/ticketing/team/team.controller.ts b/packages/api/src/ticketing/team/team.controller.ts index 58d140f62..2ae2b3d54 100644 --- a/packages/api/src/ticketing/team/team.controller.ts +++ b/packages/api/src/ticketing/team/team.controller.ts @@ -55,12 +55,13 @@ export class TeamController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.teamService.getTeams( + connectionId, remoteSource, linkedUserId, limit, diff --git a/packages/api/src/ticketing/ticket/services/ticket.service.ts b/packages/api/src/ticketing/ticket/services/ticket.service.ts index b8f11aaa6..8e79ab165 100644 --- a/packages/api/src/ticketing/ticket/services/ticket.service.ts +++ b/packages/api/src/ticketing/ticket/services/ticket.service.ts @@ -30,6 +30,7 @@ export class TicketService { async addTicket( unifiedTicketData: UnifiedTicketInput, + connection_id: string, integrationId: string, linkedUserId: string, remote_data?: boolean, @@ -133,8 +134,7 @@ export class TicketService { const existingTicket = await this.prisma.tcg_tickets.findFirst({ where: { remote_id: target_ticket.remote_id, - remote_platform: integrationId, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -188,9 +188,8 @@ export class TicketService { id_tcg_ticket: uuidv4(), created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: target_ticket.remote_id, - remote_platform: integrationId, + id_connection: connection_id, }; if (target_ticket.name) { data = { ...data, name: target_ticket.name }; @@ -398,6 +397,7 @@ export class TicketService { } async getTickets( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -417,8 +417,7 @@ export class TicketService { if (cursor) { const isCursorPresent = await this.prisma.tcg_tickets.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_tcg_ticket: cursor, }, }); @@ -438,8 +437,7 @@ export class TicketService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, /* TODO: only if params include: { diff --git a/packages/api/src/ticketing/ticket/sync/sync.service.ts b/packages/api/src/ticketing/ticket/sync/sync.service.ts index b4b3c4ce1..a4c09981b 100644 --- a/packages/api/src/ticketing/ticket/sync/sync.service.ts +++ b/packages/api/src/ticketing/ticket/sync/sync.service.ts @@ -198,6 +198,7 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const tickets_data = await this.saveTicketsInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -230,6 +231,7 @@ export class SyncService implements OnModuleInit { } async saveTicketsInDb( + connection_id: string, linkedUserId: string, tickets: UnifiedTicketOutput[], originSource: string, @@ -248,8 +250,7 @@ export class SyncService implements OnModuleInit { const existingTicket = await this.prisma.tcg_tickets.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -303,9 +304,8 @@ export class SyncService implements OnModuleInit { id_tcg_ticket: uuidv4(), created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; if (ticket.name) { data = { ...data, name: ticket.name }; @@ -415,8 +415,7 @@ export class SyncService implements OnModuleInit { const existingTicket = await this.prisma.tcg_tickets.findFirst({ where: { remote_id: remote_id, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); await this.prisma.tcg_tickets.delete({ diff --git a/packages/api/src/ticketing/ticket/ticket.controller.ts b/packages/api/src/ticketing/ticket/ticket.controller.ts index b8a56bb3c..869c275a5 100644 --- a/packages/api/src/ticketing/ticket/ticket.controller.ts +++ b/packages/api/src/ticketing/ticket/ticket.controller.ts @@ -59,12 +59,13 @@ export class TicketController { @Query() query: FetchObjectsQueryDto, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.ticketService.getTickets( + connectionId, remoteSource, linkedUserId, limit, @@ -132,12 +133,13 @@ export class TicketController { @Query('remote_data') remote_data?: boolean, ) { try { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); return this.ticketService.addTicket( unfiedTicketData, + connectionId, remoteSource, linkedUserId, remote_data, diff --git a/packages/api/src/ticketing/user/services/user.service.ts b/packages/api/src/ticketing/user/services/user.service.ts index 16ebb34d9..edf2d04d2 100644 --- a/packages/api/src/ticketing/user/services/user.service.ts +++ b/packages/api/src/ticketing/user/services/user.service.ts @@ -83,6 +83,7 @@ export class UserService { } async getUsers( + connection_id: string, integrationId: string, linkedUserId: string, limit: number, @@ -101,8 +102,7 @@ export class UserService { if (cursor) { const isCursorPresent = await this.prisma.tcg_users.findFirst({ where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, id_tcg_user: cursor, }, }); @@ -122,8 +122,7 @@ export class UserService { created_at: 'asc', }, where: { - remote_platform: integrationId.toLowerCase(), - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); diff --git a/packages/api/src/ticketing/user/sync/sync.service.ts b/packages/api/src/ticketing/user/sync/sync.service.ts index b7e70939a..53ad0d449 100644 --- a/packages/api/src/ticketing/user/sync/sync.service.ts +++ b/packages/api/src/ticketing/user/sync/sync.service.ts @@ -169,8 +169,7 @@ export class SyncService implements OnModuleInit { switch (wh_real_time_trigger.action) { case 'DELETE': return await this.removeUserInDb( - linkedUserId, - integrationId, + connection.id_connection, wh_real_time_trigger.data.remote_id, ); default: @@ -205,6 +204,7 @@ export class SyncService implements OnModuleInit { //insert the data in the DB with the fieldMappings (value table) const user_data = await this.saveUsersInDb( + connection.id_connection, linkedUserId, unifiedObject, integrationId, @@ -235,6 +235,7 @@ export class SyncService implements OnModuleInit { } async saveUsersInDb( + connection_id: string, linkedUserId: string, users: UnifiedUserOutput[], originSource: string, @@ -253,8 +254,7 @@ export class SyncService implements OnModuleInit { const existingUser = await this.prisma.tcg_users.findFirst({ where: { remote_id: originId, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); @@ -286,10 +286,9 @@ export class SyncService implements OnModuleInit { teams: user.teams || [], created_at: new Date(), modified_at: new Date(), - id_linked_user: linkedUserId, // id_tcg_account: user.account_id || '', remote_id: originId, - remote_platform: originSource, + id_connection: connection_id, }; // console.log("Tcg user Data: ", data) @@ -363,16 +362,11 @@ export class SyncService implements OnModuleInit { } } - async removeUserInDb( - linkedUserId: string, - originSource: string, - remote_id: string, - ) { + async removeUserInDb(connection_id: string, remote_id: string) { const existingUser = await this.prisma.tcg_users.findFirst({ where: { remote_id: remote_id, - remote_platform: originSource, - id_linked_user: linkedUserId, + id_connection: connection_id, }, }); await this.prisma.tcg_users.delete({ diff --git a/packages/api/src/ticketing/user/user.controller.ts b/packages/api/src/ticketing/user/user.controller.ts index ee20cfa31..f1218f402 100644 --- a/packages/api/src/ticketing/user/user.controller.ts +++ b/packages/api/src/ticketing/user/user.controller.ts @@ -54,13 +54,14 @@ export class UserController { @Headers('x-connection-token') connection_token: string, @Query() query: FetchObjectsQueryDto, ) { - const { linkedUserId, remoteSource } = + const { linkedUserId, remoteSource, connectionId } = await this.connectionUtils.getConnectionMetadataFromConnectionToken( connection_token, ); const { remote_data, limit, cursor } = query; return this.userService.getUsers( + connectionId, remoteSource, linkedUserId, limit,