From a3b38b5af29ae112e30be7f1c11969ed4bd6b755 Mon Sep 17 00:00:00 2001 From: mit-27 Date: Thu, 28 Mar 2024 04:46:57 -0400 Subject: [PATCH 1/2] Added remote id extraction inside mapping and optimize sync services for all objects --- .../src/crm/company/services/attio/mappers.ts | 3 +++ .../crm/company/services/hubspot/mappers.ts | 2 ++ .../crm/company/services/pipedrive/mappers.ts | 1 + .../crm/company/services/zendesk/mappers.ts | 4 +++ .../src/crm/company/services/zoho/mappers.ts | 1 + .../api/src/crm/company/sync/sync.service.ts | 9 ++----- .../src/crm/contact/services/attio/mappers.ts | 3 +++ .../contact/services/freshsales/mappers.ts | 1 + .../crm/contact/services/hubspot/mappers.ts | 2 ++ .../crm/contact/services/pipedrive/mappers.ts | 1 + .../crm/contact/services/zendesk/mappers.ts | 1 + .../src/crm/contact/services/zoho/mappers.ts | 1 + .../api/src/crm/contact/sync/sync.service.ts | 25 +++++++++++-------- .../src/crm/deal/services/hubspot/mappers.ts | 1 + .../crm/deal/services/pipedrive/mappers.ts | 1 + .../src/crm/deal/services/zendesk/mappers.ts | 1 + .../api/src/crm/deal/services/zoho/mappers.ts | 2 ++ .../api/src/crm/deal/sync/sync.service.ts | 9 ++----- .../engagement/services/hubspot/mappers.ts | 17 +++++++------ .../engagement/services/pipedrive/mappers.ts | 1 + .../engagement/services/zendesk/mappers.ts | 1 + .../src/crm/engagement/sync/sync.service.ts | 9 ++----- .../src/crm/note/services/hubspot/mappers.ts | 1 + .../crm/note/services/pipedrive/mappers.ts | 1 + .../src/crm/note/services/zendesk/mappers.ts | 1 + .../api/src/crm/note/services/zoho/mappers.ts | 2 ++ .../api/src/crm/note/sync/sync.service.ts | 9 ++----- .../src/crm/stage/services/hubspot/mappers.ts | 1 + .../crm/stage/services/pipedrive/mappers.ts | 1 + .../src/crm/stage/services/zendesk/mappers.ts | 1 + .../api/src/crm/stage/sync/sync.service.ts | 9 ++----- .../src/crm/task/services/hubspot/mappers.ts | 5 ++-- .../crm/task/services/pipedrive/mappers.ts | 4 ++- .../src/crm/task/services/zendesk/mappers.ts | 1 + .../api/src/crm/task/sync/sync.service.ts | 9 ++----- .../src/crm/user/services/hubspot/mappers.ts | 1 + .../crm/user/services/pipedrive/mappers.ts | 1 + .../src/crm/user/services/zendesk/mappers.ts | 1 + .../api/src/crm/user/sync/sync.service.ts | 9 ++----- .../account/services/front/mappers.ts | 1 + .../account/services/zendesk/mappers.ts | 1 + .../ticketing/account/sync/sync.service.ts | 9 ++----- .../comment/services/front/mappers.ts | 1 + .../comment/services/zendesk/mappers.ts | 1 + .../ticketing/comment/sync/sync.service.ts | 16 +++++------- .../contact/services/front/mappers.ts | 1 + .../contact/services/zendesk/mappers.ts | 1 + .../ticketing/contact/sync/sync.service.ts | 9 ++----- .../ticketing/tag/services/zendesk/mappers.ts | 1 + .../src/ticketing/tag/sync/sync.service.ts | 9 ++----- .../ticketing/team/services/front/mappers.ts | 1 + .../team/services/zendesk/mappers.ts | 1 + .../src/ticketing/team/sync/sync.service.ts | 9 ++----- .../ticket/services/front/mappers.ts | 5 ++-- .../ticket/services/hubspot/mappers.ts | 1 + .../ticket/services/zendesk/mappers.ts | 1 + .../src/ticketing/ticket/sync/sync.service.ts | 9 ++----- .../ticketing/user/services/front/mappers.ts | 1 + .../user/services/zendesk/mappers.ts | 1 + .../src/ticketing/user/sync/sync.service.ts | 9 ++----- 60 files changed, 116 insertions(+), 125 deletions(-) diff --git a/packages/api/src/crm/company/services/attio/mappers.ts b/packages/api/src/crm/company/services/attio/mappers.ts index af858e958..1f527d314 100644 --- a/packages/api/src/crm/company/services/attio/mappers.ts +++ b/packages/api/src/crm/company/services/attio/mappers.ts @@ -126,6 +126,8 @@ export class AttioCompanyMapper implements ICompanyMapper { let opts: any = {}; + + //TODO - Logic needs to be reconsider if (company.values.team[0]?.target_record_id) { const owner_id = await this.utils.getUserUuidFromRemoteId( company.values.team[0].target_record_id, @@ -139,6 +141,7 @@ export class AttioCompanyMapper implements ICompanyMapper { } return { + remote_id: company.id?.record_id, name: company.values.name[0]?.value, industry: typeof company.values.categories[0]?.option === "string" ? company.values.categories[0]?.option : company.values.categories[0]?.option.title, number_of_employees: 0, // Placeholder, as there's no direct mapping provided diff --git a/packages/api/src/crm/company/services/hubspot/mappers.ts b/packages/api/src/crm/company/services/hubspot/mappers.ts index c420929cb..d0e333546 100644 --- a/packages/api/src/crm/company/services/hubspot/mappers.ts +++ b/packages/api/src/crm/company/services/hubspot/mappers.ts @@ -95,6 +95,7 @@ export class HubspotCompanyMapper implements ICompanyMapper { })) || []; let opts: any = {}; + //TODO - Logic needs to be reconsider if (company.properties.hubspot_owner_id) { const owner_id = await this.utils.getUserUuidFromRemoteId( company.properties.hubspot_owner_id, @@ -108,6 +109,7 @@ export class HubspotCompanyMapper implements ICompanyMapper { } return { + remote_id: company.id, name: company.properties.name, industry: company.properties.industry, number_of_employees: 0, // Placeholder, as there's no direct mapping provided diff --git a/packages/api/src/crm/company/services/pipedrive/mappers.ts b/packages/api/src/crm/company/services/pipedrive/mappers.ts index 6280ef259..7a85d5643 100644 --- a/packages/api/src/crm/company/services/pipedrive/mappers.ts +++ b/packages/api/src/crm/company/services/pipedrive/mappers.ts @@ -90,6 +90,7 @@ export class PipedriveCompanyMapper implements ICompanyMapper { })) || []; let res = { + remote_id: company.id, name: company.name, industry: '', // Pipedrive may not directly provide this, need custom mapping number_of_employees: 0, // Placeholder, as there's no direct mapping provided diff --git a/packages/api/src/crm/company/services/zendesk/mappers.ts b/packages/api/src/crm/company/services/zendesk/mappers.ts index 8c79cf148..02410707f 100644 --- a/packages/api/src/crm/company/services/zendesk/mappers.ts +++ b/packages/api/src/crm/company/services/zendesk/mappers.ts @@ -10,6 +10,9 @@ import { import { ICompanyMapper } from '@crm/company/types'; import { Utils } from '@crm/contact/utils'; + +//TODO - Zendesk does not have Company object + export class ZendeskCompanyMapper implements ICompanyMapper { private readonly utils: Utils; @@ -134,6 +137,7 @@ export class ZendeskCompanyMapper implements ICompanyMapper { } return { + remote_id: company.id, name: company.name, email_addresses, phone_numbers, diff --git a/packages/api/src/crm/company/services/zoho/mappers.ts b/packages/api/src/crm/company/services/zoho/mappers.ts index f1e8ffdaa..e507bcb1e 100644 --- a/packages/api/src/crm/company/services/zoho/mappers.ts +++ b/packages/api/src/crm/company/services/zoho/mappers.ts @@ -70,6 +70,7 @@ export class ZohoCompanyMapper implements ICompanyMapper { })) || []; return { + remote_id: company.id, name: company.Account_Name, phone_numbers: [ { diff --git a/packages/api/src/crm/company/sync/sync.service.ts b/packages/api/src/crm/company/sync/sync.service.ts index bf9fcadba..a759fdd49 100644 --- a/packages/api/src/crm/company/sync/sync.service.ts +++ b/packages/api/src/crm/company/sync/sync.service.ts @@ -138,16 +138,12 @@ export class SyncService implements OnModuleInit { customFieldMappings, })) as UnifiedCompanyOutput[]; - //TODO - const companyIds = sourceObject.map((company) => - 'id' in company ? String(company.id) : undefined, - ); + //insert the data in the DB with the fieldMappings (value table) const companies_data = await this.saveCompanysInDb( linkedUserId, unifiedObject, - companyIds, integrationId, sourceObject, ); @@ -178,7 +174,6 @@ export class SyncService implements OnModuleInit { async saveCompanysInDb( linkedUserId: string, companies: UnifiedCompanyOutput[], - originIds: string[], originSource: string, remote_data: Record[], ): Promise { @@ -186,7 +181,7 @@ export class SyncService implements OnModuleInit { let companies_results: CrmCompany[] = []; for (let i = 0; i < companies.length; i++) { const company = companies[i]; - const originId = originIds[i]; + const originId = company.remote_id[i]; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/crm/contact/services/attio/mappers.ts b/packages/api/src/crm/contact/services/attio/mappers.ts index 0fa7c84a1..69745629d 100644 --- a/packages/api/src/crm/contact/services/attio/mappers.ts +++ b/packages/api/src/crm/contact/services/attio/mappers.ts @@ -117,7 +117,10 @@ export class AttioContactMapper implements IContactMapper { }; const opts: any = {}; + console.log(JSON.stringify(contact.id)) + return { + remote_id: contact.id?.record_id, first_name: contact.values.name[0]?.first_name, last_name: contact.values.name[0]?.last_name, // user_id: contact.values.created_by[0]?.referenced_actor_id, diff --git a/packages/api/src/crm/contact/services/freshsales/mappers.ts b/packages/api/src/crm/contact/services/freshsales/mappers.ts index 3943fbcf6..0713a388b 100644 --- a/packages/api/src/crm/contact/services/freshsales/mappers.ts +++ b/packages/api/src/crm/contact/services/freshsales/mappers.ts @@ -66,6 +66,7 @@ export class FreshsalesContactMapper implements IContactMapper { }; return { + remote_id: contact.id + "", first_name: contact.first_name, last_name: contact.last_name, email_addresses, diff --git a/packages/api/src/crm/contact/services/hubspot/mappers.ts b/packages/api/src/crm/contact/services/hubspot/mappers.ts index df1e583e7..2e4b18106 100644 --- a/packages/api/src/crm/contact/services/hubspot/mappers.ts +++ b/packages/api/src/crm/contact/services/hubspot/mappers.ts @@ -92,6 +92,8 @@ export class HubspotContactMapper implements IContactMapper { };*/ return { + // Setting remote_id field + remote_id: contact.id, first_name: contact.properties.firstname, last_name: contact.properties.lastname, email_addresses: [ diff --git a/packages/api/src/crm/contact/services/pipedrive/mappers.ts b/packages/api/src/crm/contact/services/pipedrive/mappers.ts index 5e3f91dcd..3194be0b6 100644 --- a/packages/api/src/crm/contact/services/pipedrive/mappers.ts +++ b/packages/api/src/crm/contact/services/pipedrive/mappers.ts @@ -121,6 +121,7 @@ export class PipedriveContactMapper implements IContactMapper { } return { + remote_id: contact.id, first_name: contact.first_name, last_name: contact.last_name, email_addresses: contact.email.map((e) => ({ diff --git a/packages/api/src/crm/contact/services/zendesk/mappers.ts b/packages/api/src/crm/contact/services/zendesk/mappers.ts index eca9cf966..efc77ef97 100644 --- a/packages/api/src/crm/contact/services/zendesk/mappers.ts +++ b/packages/api/src/crm/contact/services/zendesk/mappers.ts @@ -132,6 +132,7 @@ export class ZendeskContactMapper implements IContactMapper { }; return { + remote_id: contact.id + "", first_name: contact.first_name, last_name: contact.last_name, email_addresses, diff --git a/packages/api/src/crm/contact/services/zoho/mappers.ts b/packages/api/src/crm/contact/services/zoho/mappers.ts index d97bb053f..87715a4f2 100644 --- a/packages/api/src/crm/contact/services/zoho/mappers.ts +++ b/packages/api/src/crm/contact/services/zoho/mappers.ts @@ -118,6 +118,7 @@ export class ZohoContactMapper implements IContactMapper { }; return { + remote_id: contact.id, first_name: contact.First_Name ? contact.First_Name : '', last_name: contact.Last_Name ? contact.Last_Name : '', email_addresses, diff --git a/packages/api/src/crm/contact/sync/sync.service.ts b/packages/api/src/crm/contact/sync/sync.service.ts index 8ecb5dfc3..b4971c288 100644 --- a/packages/api/src/crm/contact/sync/sync.service.ts +++ b/packages/api/src/crm/contact/sync/sync.service.ts @@ -138,20 +138,23 @@ export class SyncContactsService implements OnModuleInit { customFieldMappings, })) as UnifiedContactOutput[]; - //TODO - const contactIds = sourceObject.map((contact) => - 'id' in contact - ? String(contact.id) - : 'contact_id' in contact - ? String(contact.contact_id) - : undefined, - ); + + // Removing contactsIds + + // //TODO + // const contactIds = sourceObject.map((contact) => + // 'id' in contact + // ? String(contact.id) + // : 'contact_id' in contact + // ? String(contact.contact_id) + // : undefined, + // ); //insert the data in the DB with the fieldMappings (value table) const contacts_data = await this.saveContactsInDb( linkedUserId, unifiedObject, - contactIds, + // contactIds, integrationId, sourceObject, ); @@ -182,7 +185,7 @@ export class SyncContactsService implements OnModuleInit { async saveContactsInDb( linkedUserId: string, contacts: UnifiedContactOutput[], - originIds: string[], + // originIds: string[], originSource: string, remote_data: Record[], ): Promise { @@ -190,7 +193,7 @@ export class SyncContactsService implements OnModuleInit { let contacts_results: CrmContact[] = []; for (let i = 0; i < contacts.length; i++) { const contact = contacts[i]; - const originId = originIds[i]; + const originId = contact.remote_id; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/crm/deal/services/hubspot/mappers.ts b/packages/api/src/crm/deal/services/hubspot/mappers.ts index 33df083dd..e9accfeff 100644 --- a/packages/api/src/crm/deal/services/hubspot/mappers.ts +++ b/packages/api/src/crm/deal/services/hubspot/mappers.ts @@ -100,6 +100,7 @@ export class HubspotDealMapper implements IDealMapper { } return { + remote_id: deal.id, name: deal.properties.dealname, description: deal.properties.dealname, // Placeholder if there's no direct mapping amount: parseFloat(deal.properties.amount), diff --git a/packages/api/src/crm/deal/services/pipedrive/mappers.ts b/packages/api/src/crm/deal/services/pipedrive/mappers.ts index 1a91794f6..7b1b3ef40 100644 --- a/packages/api/src/crm/deal/services/pipedrive/mappers.ts +++ b/packages/api/src/crm/deal/services/pipedrive/mappers.ts @@ -109,6 +109,7 @@ export class PipedriveDealMapper implements IDealMapper { } return { + remote_id: deal.id, name: deal.title, amount: deal.value, description: '', diff --git a/packages/api/src/crm/deal/services/zendesk/mappers.ts b/packages/api/src/crm/deal/services/zendesk/mappers.ts index 5e98b3552..9ecc7671a 100644 --- a/packages/api/src/crm/deal/services/zendesk/mappers.ts +++ b/packages/api/src/crm/deal/services/zendesk/mappers.ts @@ -122,6 +122,7 @@ export class ZendeskDealMapper implements IDealMapper { } return { + remote_id: deal.id, name: deal.name, amount: typeof deal.value === 'string' ? parseFloat(deal.value) : deal.value, diff --git a/packages/api/src/crm/deal/services/zoho/mappers.ts b/packages/api/src/crm/deal/services/zoho/mappers.ts index 230cc09da..5a7a6a91c 100644 --- a/packages/api/src/crm/deal/services/zoho/mappers.ts +++ b/packages/api/src/crm/deal/services/zoho/mappers.ts @@ -61,6 +61,8 @@ export class ZohoDealMapper implements IDealMapper { })) || []; return { + //TODO - might be wrong deal.Owner + remote_id: deal.Owner, name: deal.Title, description: deal.Description, amount: 0, //todo; diff --git a/packages/api/src/crm/deal/sync/sync.service.ts b/packages/api/src/crm/deal/sync/sync.service.ts index 7b8a3ba72..8b760eec4 100644 --- a/packages/api/src/crm/deal/sync/sync.service.ts +++ b/packages/api/src/crm/deal/sync/sync.service.ts @@ -135,16 +135,12 @@ export class SyncService implements OnModuleInit { customFieldMappings, })) as UnifiedDealOutput[]; - //TODO - const dealIds = sourceObject.map((deal) => - 'id' in deal ? String(deal.id) : undefined, - ); + //insert the data in the DB with the fieldMappings (value table) const deals_data = await this.saveDealsInDb( linkedUserId, unifiedObject, - dealIds, integrationId, sourceObject, ); @@ -175,7 +171,6 @@ export class SyncService implements OnModuleInit { async saveDealsInDb( linkedUserId: string, deals: UnifiedDealOutput[], - originIds: string[], originSource: string, remote_data: Record[], ): Promise { @@ -183,7 +178,7 @@ export class SyncService implements OnModuleInit { let deals_results: CrmDeal[] = []; for (let i = 0; i < deals.length; i++) { const deal = deals[i]; - const originId = originIds[i]; + const originId = deal.remote_id; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/crm/engagement/services/hubspot/mappers.ts b/packages/api/src/crm/engagement/services/hubspot/mappers.ts index c3b2ef645..d1a048b1c 100644 --- a/packages/api/src/crm/engagement/services/hubspot/mappers.ts +++ b/packages/api/src/crm/engagement/services/hubspot/mappers.ts @@ -143,8 +143,8 @@ export class HubspotEngagementMapper implements IEngagementMapper { source.direction === 'INBOUND' ? 'INCOMING_EMAIL' : source.direction === 'OUTBOUND' - ? 'FORWARDED_EMAIL' - : '', + ? 'FORWARDED_EMAIL' + : '', hs_email_to_lastname: '', // Placeholder, needs appropriate mapping hs_email_sender_email: '', // Placeholder, needs appropriate mapping hs_email_to_firstname: '', // Placeholder, needs appropriate mapping @@ -191,15 +191,15 @@ export class HubspotEngagementMapper implements IEngagementMapper { case 'MEETING': return await this.unifyMeeting( source as - | HubspotEngagementMeetingOutput - | HubspotEngagementMeetingOutput[], + | HubspotEngagementMeetingOutput + | HubspotEngagementMeetingOutput[], customFieldMappings, ); case 'EMAIL': return await this.unifyEmail( source as - | HubspotEngagementEmailOutput - | HubspotEngagementEmailOutput[], + | HubspotEngagementEmailOutput + | HubspotEngagementEmailOutput[], customFieldMappings, ); default: @@ -296,6 +296,7 @@ export class HubspotEngagementMapper implements IEngagementMapper { } return { + remote_id: engagement.id, content: engagement.properties.hs_call_body, subject: engagement.properties.hs_call_title, start_at: new Date(engagement.properties.createdate), @@ -378,8 +379,8 @@ export class HubspotEngagementMapper implements IEngagementMapper { engagement.properties.hs_email_direction === 'INCOMING_EMAIL' ? 'INBOUND' : engagement.properties.hs_email_direction === 'FORWARDED_EMAIL' - ? 'OUTBOUND' - : '', + ? 'OUTBOUND' + : '', field_mappings, ...opts, }; diff --git a/packages/api/src/crm/engagement/services/pipedrive/mappers.ts b/packages/api/src/crm/engagement/services/pipedrive/mappers.ts index 98e01f579..321107377 100644 --- a/packages/api/src/crm/engagement/services/pipedrive/mappers.ts +++ b/packages/api/src/crm/engagement/services/pipedrive/mappers.ts @@ -174,6 +174,7 @@ export class PipedriveEngagementMapper implements IEngagementMapper { } return { + remote_id: engagement.id, content: engagement.note, subject: engagement.subject, start_at: new Date(engagement.due_date + ' ' + engagement.due_time), // Combine due_date and due_time diff --git a/packages/api/src/crm/engagement/services/zendesk/mappers.ts b/packages/api/src/crm/engagement/services/zendesk/mappers.ts index 7f58ae667..0ba534703 100644 --- a/packages/api/src/crm/engagement/services/zendesk/mappers.ts +++ b/packages/api/src/crm/engagement/services/zendesk/mappers.ts @@ -138,6 +138,7 @@ export class ZendeskEngagementMapper implements IEngagementMapper { const direction = engagement.incoming ? 'incoming' : 'outgoing'; return { + remote_id: engagement.id, content: engagement.summary, subject: '', start_at: new Date(engagement.made_at), diff --git a/packages/api/src/crm/engagement/sync/sync.service.ts b/packages/api/src/crm/engagement/sync/sync.service.ts index c389624e0..6e5efb2c7 100644 --- a/packages/api/src/crm/engagement/sync/sync.service.ts +++ b/packages/api/src/crm/engagement/sync/sync.service.ts @@ -143,16 +143,12 @@ export class SyncService implements OnModuleInit { customFieldMappings, })) as UnifiedEngagementOutput[]; - //TODO - const engagementIds = sourceObject.map((engagement) => - 'id' in engagement ? String(engagement.id) : undefined, - ); + //insert the data in the DB with the fieldMappings (value table) const engagements_data = await this.saveEngagementsInDb( linkedUserId, unifiedObject, - engagementIds, integrationId, sourceObject, ); @@ -183,7 +179,6 @@ export class SyncService implements OnModuleInit { async saveEngagementsInDb( linkedUserId: string, engagements: UnifiedEngagementOutput[], - originIds: string[], originSource: string, remote_data: Record[], ): Promise { @@ -191,7 +186,7 @@ export class SyncService implements OnModuleInit { let engagements_results: CrmEngagement[] = []; for (let i = 0; i < engagements.length; i++) { const engagement = engagements[i]; - const originId = originIds[i]; + const originId = engagement.remote_id[i]; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/crm/note/services/hubspot/mappers.ts b/packages/api/src/crm/note/services/hubspot/mappers.ts index eec061079..8d6bb551d 100644 --- a/packages/api/src/crm/note/services/hubspot/mappers.ts +++ b/packages/api/src/crm/note/services/hubspot/mappers.ts @@ -89,6 +89,7 @@ export class HubspotNoteMapper implements INoteMapper { } return { + remote_id: note.id, content: note.properties.hs_note_body, field_mappings, ...opts, diff --git a/packages/api/src/crm/note/services/pipedrive/mappers.ts b/packages/api/src/crm/note/services/pipedrive/mappers.ts index 3e406112e..7f9f82f35 100644 --- a/packages/api/src/crm/note/services/pipedrive/mappers.ts +++ b/packages/api/src/crm/note/services/pipedrive/mappers.ts @@ -130,6 +130,7 @@ export class PipedriveNoteMapper implements INoteMapper { } return { + remote_id: note.id, content: note.content, field_mappings, ...opts, diff --git a/packages/api/src/crm/note/services/zendesk/mappers.ts b/packages/api/src/crm/note/services/zendesk/mappers.ts index f8d92ede2..dda36763f 100644 --- a/packages/api/src/crm/note/services/zendesk/mappers.ts +++ b/packages/api/src/crm/note/services/zendesk/mappers.ts @@ -114,6 +114,7 @@ export class ZendeskNoteMapper implements INoteMapper { } return { + remote_id: note.id, content: note.content, field_mappings, ...opts, diff --git a/packages/api/src/crm/note/services/zoho/mappers.ts b/packages/api/src/crm/note/services/zoho/mappers.ts index 3e161e266..442aee62d 100644 --- a/packages/api/src/crm/note/services/zoho/mappers.ts +++ b/packages/api/src/crm/note/services/zoho/mappers.ts @@ -66,6 +66,8 @@ export class ZohoNoteMapper implements INoteMapper { })) || []; return { + //TODO + remote_id: note.Owner, content: note.Description, field_mappings, }; diff --git a/packages/api/src/crm/note/sync/sync.service.ts b/packages/api/src/crm/note/sync/sync.service.ts index f477cfcce..bd760cbd0 100644 --- a/packages/api/src/crm/note/sync/sync.service.ts +++ b/packages/api/src/crm/note/sync/sync.service.ts @@ -135,16 +135,12 @@ export class SyncService implements OnModuleInit { customFieldMappings, })) as UnifiedNoteOutput[]; - //TODO - const noteIds = sourceObject.map((note) => - 'id' in note ? String(note.id) : undefined, - ); + //insert the data in the DB with the fieldMappings (value table) const notes_data = await this.saveNotesInDb( linkedUserId, unifiedObject, - noteIds, integrationId, sourceObject, ); @@ -175,7 +171,6 @@ export class SyncService implements OnModuleInit { async saveNotesInDb( linkedUserId: string, notes: UnifiedNoteOutput[], - originIds: string[], originSource: string, remote_data: Record[], ): Promise { @@ -183,7 +178,7 @@ export class SyncService implements OnModuleInit { let notes_results: CrmNote[] = []; for (let i = 0; i < notes.length; i++) { const note = notes[i]; - const originId = originIds[i]; + const originId = note.remote_id[i]; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/crm/stage/services/hubspot/mappers.ts b/packages/api/src/crm/stage/services/hubspot/mappers.ts index 1d22bd5a0..212fad1c1 100644 --- a/packages/api/src/crm/stage/services/hubspot/mappers.ts +++ b/packages/api/src/crm/stage/services/hubspot/mappers.ts @@ -44,6 +44,7 @@ export class HubspotStageMapper implements IStageMapper { [mapping.slug]: stage[mapping.remote_id], })) || []; return { + remote_id: stage.id, stage_name: stage.properties.dealstage, field_mappings, }; diff --git a/packages/api/src/crm/stage/services/pipedrive/mappers.ts b/packages/api/src/crm/stage/services/pipedrive/mappers.ts index 24cbc3f2e..6683fa941 100644 --- a/packages/api/src/crm/stage/services/pipedrive/mappers.ts +++ b/packages/api/src/crm/stage/services/pipedrive/mappers.ts @@ -46,6 +46,7 @@ export class PipedriveStageMapper implements IStageMapper { })) || []; return { + remote_id: stage.id + "", stage_name: stage.name, field_mappings, }; diff --git a/packages/api/src/crm/stage/services/zendesk/mappers.ts b/packages/api/src/crm/stage/services/zendesk/mappers.ts index 4538b5ca2..892339943 100644 --- a/packages/api/src/crm/stage/services/zendesk/mappers.ts +++ b/packages/api/src/crm/stage/services/zendesk/mappers.ts @@ -46,6 +46,7 @@ export class ZendeskStageMapper implements IStageMapper { })) || []; return { + remote_id: stage.id + "", stage_name: stage.name, field_mappings, }; diff --git a/packages/api/src/crm/stage/sync/sync.service.ts b/packages/api/src/crm/stage/sync/sync.service.ts index dda10ec5b..d9a1b2831 100644 --- a/packages/api/src/crm/stage/sync/sync.service.ts +++ b/packages/api/src/crm/stage/sync/sync.service.ts @@ -151,16 +151,12 @@ export class SyncService implements OnModuleInit { customFieldMappings, })) as UnifiedStageOutput[]; - //TODO - const stageIds = sourceObject.map((stage) => - 'id' in stage ? String(stage.id) : undefined, - ); + //insert the data in the DB with the fieldMappings (value table) const stages_data = await this.saveStagesInDb( linkedUserId, unifiedObject, - stageIds, integrationId, deal_id, sourceObject, @@ -192,7 +188,6 @@ export class SyncService implements OnModuleInit { async saveStagesInDb( linkedUserId: string, stages: UnifiedStageOutput[], - originIds: string[], originSource: string, deal_id: string, remote_data: Record[], @@ -201,7 +196,7 @@ export class SyncService implements OnModuleInit { let stages_results: CrmStage[] = []; for (let i = 0; i < stages.length; i++) { const stage = stages[i]; - const originId = originIds[i]; + const originId = stage.remote_id[i]; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/crm/task/services/hubspot/mappers.ts b/packages/api/src/crm/task/services/hubspot/mappers.ts index cc4729f19..483876c2f 100644 --- a/packages/api/src/crm/task/services/hubspot/mappers.ts +++ b/packages/api/src/crm/task/services/hubspot/mappers.ts @@ -91,6 +91,7 @@ export class HubspotTaskMapper implements ITaskMapper { } } return { + remote_id: task.id, subject: task.properties.hs_task_subject, content: task.properties.hs_task_body, status: this.mapStatusReverse(task.properties.hs_task_status), @@ -113,8 +114,8 @@ export class HubspotTaskMapper implements ITaskMapper { return priority === 'High' ? 'HIGH' : priority === 'Medium' - ? 'MEDIUM' - : 'LOW'; + ? 'MEDIUM' + : 'LOW'; } private mapStatusReverse(status: string): string { diff --git a/packages/api/src/crm/task/services/pipedrive/mappers.ts b/packages/api/src/crm/task/services/pipedrive/mappers.ts index 1883cc8c0..ac053ebd4 100644 --- a/packages/api/src/crm/task/services/pipedrive/mappers.ts +++ b/packages/api/src/crm/task/services/pipedrive/mappers.ts @@ -133,10 +133,12 @@ export class PipedriveTaskMapper implements ITaskMapper { } return { + remote_id: task.id, subject: task.subject, content: task.public_description, status: task.done ? 'Completed' : 'Pending', - due_date: task.due_date ? new Date(task.due_date) : undefined, + due_date: task.due_date + ? new Date(task.due_date) : undefined, finished_date: task.marked_as_done_time ? new Date(task.marked_as_done_time) : undefined, diff --git a/packages/api/src/crm/task/services/zendesk/mappers.ts b/packages/api/src/crm/task/services/zendesk/mappers.ts index 6086537b1..220c77131 100644 --- a/packages/api/src/crm/task/services/zendesk/mappers.ts +++ b/packages/api/src/crm/task/services/zendesk/mappers.ts @@ -135,6 +135,7 @@ export class ZendeskTaskMapper implements ITaskMapper { } return { + remote_id: task.id, content: task.content, status: task.completed ? 'Completed' : 'Pending', finished_date: task.completed_at diff --git a/packages/api/src/crm/task/sync/sync.service.ts b/packages/api/src/crm/task/sync/sync.service.ts index b7a953ee1..f783b4313 100644 --- a/packages/api/src/crm/task/sync/sync.service.ts +++ b/packages/api/src/crm/task/sync/sync.service.ts @@ -135,16 +135,12 @@ export class SyncService implements OnModuleInit { customFieldMappings, })) as UnifiedTaskOutput[]; - //TODO - const taskIds = sourceObject.map((task) => - 'id' in task ? String(task.id) : undefined, - ); + //insert the data in the DB with the fieldMappings (value table) const tasks_data = await this.saveTasksInDb( linkedUserId, unifiedObject, - taskIds, integrationId, sourceObject, ); @@ -175,7 +171,6 @@ export class SyncService implements OnModuleInit { async saveTasksInDb( linkedUserId: string, tasks: UnifiedTaskOutput[], - originIds: string[], originSource: string, remote_data: Record[], ): Promise { @@ -183,7 +178,7 @@ export class SyncService implements OnModuleInit { let tasks_results: CrmTask[] = []; for (let i = 0; i < tasks.length; i++) { const task = tasks[i]; - const originId = originIds[i]; + const originId = task.remote_id[i]; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/crm/user/services/hubspot/mappers.ts b/packages/api/src/crm/user/services/hubspot/mappers.ts index 975ad80a8..165793faa 100644 --- a/packages/api/src/crm/user/services/hubspot/mappers.ts +++ b/packages/api/src/crm/user/services/hubspot/mappers.ts @@ -45,6 +45,7 @@ export class HubspotUserMapper implements IUserMapper { })) || []; return { + remote_id: user.id, name: `${user.firstName} ${user.lastName}`, email: user.email, field_mappings, diff --git a/packages/api/src/crm/user/services/pipedrive/mappers.ts b/packages/api/src/crm/user/services/pipedrive/mappers.ts index 55b892a96..0dee70c4e 100644 --- a/packages/api/src/crm/user/services/pipedrive/mappers.ts +++ b/packages/api/src/crm/user/services/pipedrive/mappers.ts @@ -60,6 +60,7 @@ export class PipedriveUserMapper implements IUserMapper { })) || []; return { + remote_id: user.id, name: user.name, email: user.email, field_mappings, diff --git a/packages/api/src/crm/user/services/zendesk/mappers.ts b/packages/api/src/crm/user/services/zendesk/mappers.ts index d2b625a55..8c9e38cc6 100644 --- a/packages/api/src/crm/user/services/zendesk/mappers.ts +++ b/packages/api/src/crm/user/services/zendesk/mappers.ts @@ -60,6 +60,7 @@ export class ZendeskUserMapper implements IUserMapper { })) || []; return { + remote_id: user.id + "", name: user.name, email: user.email, field_mappings, diff --git a/packages/api/src/crm/user/sync/sync.service.ts b/packages/api/src/crm/user/sync/sync.service.ts index d2ca17d6f..731209f03 100644 --- a/packages/api/src/crm/user/sync/sync.service.ts +++ b/packages/api/src/crm/user/sync/sync.service.ts @@ -134,16 +134,12 @@ export class SyncService implements OnModuleInit { customFieldMappings, })) as UnifiedUserOutput[]; - //TODO - const userIds = sourceObject.map((user) => - 'id' in user ? String(user.id) : undefined, - ); + //insert the data in the DB with the fieldMappings (value table) const users_data = await this.saveUsersInDb( linkedUserId, unifiedObject, - userIds, integrationId, sourceObject, ); @@ -174,7 +170,6 @@ export class SyncService implements OnModuleInit { async saveUsersInDb( linkedUserId: string, users: UnifiedUserOutput[], - originIds: string[], originSource: string, remote_data: Record[], ): Promise { @@ -182,7 +177,7 @@ export class SyncService implements OnModuleInit { let users_results: CrmUser[] = []; for (let i = 0; i < users.length; i++) { const user = users[i]; - const originId = originIds[i]; + const originId = user.id[i]; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/ticketing/account/services/front/mappers.ts b/packages/api/src/ticketing/account/services/front/mappers.ts index cf4089ec3..0a9cc0dee 100644 --- a/packages/api/src/ticketing/account/services/front/mappers.ts +++ b/packages/api/src/ticketing/account/services/front/mappers.ts @@ -43,6 +43,7 @@ export class FrontAccountMapper implements IAccountMapper { })); const unifiedAccount: UnifiedAccountOutput = { + remote_id: account.id, name: account.name, domains: account.domains.flat(), field_mappings: field_mappings, diff --git a/packages/api/src/ticketing/account/services/zendesk/mappers.ts b/packages/api/src/ticketing/account/services/zendesk/mappers.ts index c84c8e39c..6762224e9 100644 --- a/packages/api/src/ticketing/account/services/zendesk/mappers.ts +++ b/packages/api/src/ticketing/account/services/zendesk/mappers.ts @@ -39,6 +39,7 @@ export class ZendeskAccountMapper implements IAccountMapper { }[], ): UnifiedAccountOutput { const unifiedAccount: UnifiedAccountOutput = { + remote_id: account.id + "", name: account.name, domains: account.domain_names, }; diff --git a/packages/api/src/ticketing/account/sync/sync.service.ts b/packages/api/src/ticketing/account/sync/sync.service.ts index 1a958fe54..8b2fe9181 100644 --- a/packages/api/src/ticketing/account/sync/sync.service.ts +++ b/packages/api/src/ticketing/account/sync/sync.service.ts @@ -133,16 +133,12 @@ export class SyncService implements OnModuleInit { customFieldMappings, })) as UnifiedAccountOutput[]; - //TODO - const accountIds = sourceObject.map((account) => - 'id' in account ? String(account.id) : undefined, - ); + //insert the data in the DB with the fieldMappings (value table) const account_data = await this.saveAccountsInDb( linkedUserId, unifiedObject, - accountIds, integrationId, sourceObject, ); @@ -173,7 +169,6 @@ export class SyncService implements OnModuleInit { async saveAccountsInDb( linkedUserId: string, accounts: UnifiedAccountOutput[], - originIds: string[], originSource: string, remote_data: Record[], ): Promise { @@ -181,7 +176,7 @@ export class SyncService implements OnModuleInit { let accounts_results: TicketingAccount[] = []; for (let i = 0; i < accounts.length; i++) { const account = accounts[i]; - const originId = originIds[i]; + const originId = account.id[i]; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/ticketing/comment/services/front/mappers.ts b/packages/api/src/ticketing/comment/services/front/mappers.ts index c73cd0d58..ff15ec293 100644 --- a/packages/api/src/ticketing/comment/services/front/mappers.ts +++ b/packages/api/src/ticketing/comment/services/front/mappers.ts @@ -84,6 +84,7 @@ export class FrontCommentMapper implements ICommentMapper { } const res = { + remote_id: comment.id, body: comment.body, ...opts, }; diff --git a/packages/api/src/ticketing/comment/services/zendesk/mappers.ts b/packages/api/src/ticketing/comment/services/zendesk/mappers.ts index 7fa9c8730..9954e126a 100644 --- a/packages/api/src/ticketing/comment/services/zendesk/mappers.ts +++ b/packages/api/src/ticketing/comment/services/zendesk/mappers.ts @@ -95,6 +95,7 @@ export class ZendeskCommentMapper implements ICommentMapper { } const res = { + remote_id: comment.id, body: comment.body || '', html_body: comment.html_body || '', is_private: !comment.public, diff --git a/packages/api/src/ticketing/comment/sync/sync.service.ts b/packages/api/src/ticketing/comment/sync/sync.service.ts index 9037becdc..04053f5a3 100644 --- a/packages/api/src/ticketing/comment/sync/sync.service.ts +++ b/packages/api/src/ticketing/comment/sync/sync.service.ts @@ -142,15 +142,11 @@ export class SyncService implements OnModuleInit { customFieldMappings, })) as UnifiedCommentOutput[]; - //TODO - const commentsIds = sourceObject.map((comment) => - 'id' in comment ? String(comment.id) : undefined, - ); + //insert the data in the DB with the fieldMappings (value table) const comments_data = await this.saveCommentsInDb( linkedUserId, unifiedObject, - commentsIds, integrationId, id_ticket, sourceObject, @@ -192,7 +188,7 @@ export class SyncService implements OnModuleInit { let comments_results: TicketingComment[] = []; for (let i = 0; i < comments.length; i++) { const comment = comments[i]; - const originId = originIds[i]; + const originId = comment.remote_id[i]; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); @@ -210,13 +206,13 @@ export class SyncService implements OnModuleInit { const opts = comment.creator_type === 'contact' ? { - id_tcg_contact: comment.contact_id, - } + id_tcg_contact: comment.contact_id, + } : comment.creator_type === 'user' - ? { + ? { id_tcg_user: comment.user_id, } - : {}; //case where nothing is passed for creator or a not authorized value; + : {}; //case where nothing is passed for creator or a not authorized value; if (existingComment) { // Update the existing comment diff --git a/packages/api/src/ticketing/contact/services/front/mappers.ts b/packages/api/src/ticketing/contact/services/front/mappers.ts index b3f604ae6..e5bb3523f 100644 --- a/packages/api/src/ticketing/contact/services/front/mappers.ts +++ b/packages/api/src/ticketing/contact/services/front/mappers.ts @@ -49,6 +49,7 @@ export class FrontContactMapper implements IContactMapper { ); const unifiedContact: UnifiedContactOutput = { + remote_id: contact.id, name: contact.name, email_address: emailHandle.handle || '', phone_number: phoneHandle.handle || '', diff --git a/packages/api/src/ticketing/contact/services/zendesk/mappers.ts b/packages/api/src/ticketing/contact/services/zendesk/mappers.ts index 8d227b39d..39e019c38 100644 --- a/packages/api/src/ticketing/contact/services/zendesk/mappers.ts +++ b/packages/api/src/ticketing/contact/services/zendesk/mappers.ts @@ -43,6 +43,7 @@ export class ZendeskContactMapper implements IContactMapper { })); const unifiedContact: UnifiedContactOutput = { + remote_id: contact.id + "", name: contact.name, email_address: contact.email, phone_number: contact.phone, diff --git a/packages/api/src/ticketing/contact/sync/sync.service.ts b/packages/api/src/ticketing/contact/sync/sync.service.ts index 04e205bb1..cf2b1552e 100644 --- a/packages/api/src/ticketing/contact/sync/sync.service.ts +++ b/packages/api/src/ticketing/contact/sync/sync.service.ts @@ -147,16 +147,12 @@ export class SyncService implements OnModuleInit { customFieldMappings, })) as UnifiedContactOutput[]; - //TODO - const contactIds = sourceObject.map((contact) => - 'id' in contact ? String(contact.id) : undefined, - ); + //insert the data in the DB with the fieldMappings (value table) const contact_data = await this.saveContactsInDb( linkedUserId, unifiedObject, - contactIds, integrationId, sourceObject, remote_account_id, @@ -188,7 +184,6 @@ export class SyncService implements OnModuleInit { async saveContactsInDb( linkedUserId: string, contacts: UnifiedContactOutput[], - originIds: string[], originSource: string, remote_data: Record[], remote_account_id?: string, @@ -197,7 +192,7 @@ export class SyncService implements OnModuleInit { let contacts_results: TicketingContact[] = []; for (let i = 0; i < contacts.length; i++) { const contact = contacts[i]; - const originId = originIds[i]; + const originId = contact.remote_id[i]; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/ticketing/tag/services/zendesk/mappers.ts b/packages/api/src/ticketing/tag/services/zendesk/mappers.ts index ea636cc80..ec5541a6f 100644 --- a/packages/api/src/ticketing/tag/services/zendesk/mappers.ts +++ b/packages/api/src/ticketing/tag/services/zendesk/mappers.ts @@ -38,6 +38,7 @@ export class ZendeskTagMapper implements ITagMapper { }[], ): UnifiedTagOutput { const unifiedTag: UnifiedTagOutput = { + id: `zendesk_tag_uuid_${tag}`, // this is used so we can have a remote_id inside our Tag table //this id is a fake id put in place as Zendesk does not store any uuid for it,it must not be onsidered the same as the uuid from panora which is stored also in this id field diff --git a/packages/api/src/ticketing/tag/sync/sync.service.ts b/packages/api/src/ticketing/tag/sync/sync.service.ts index 74c79c285..2cc48063f 100644 --- a/packages/api/src/ticketing/tag/sync/sync.service.ts +++ b/packages/api/src/ticketing/tag/sync/sync.service.ts @@ -147,16 +147,12 @@ export class SyncService implements OnModuleInit { customFieldMappings, })) as UnifiedTagOutput[]; - //TODO: exceptionally we use the unifiedObject as we might need to get the fake remote ids from Zendesk store in id field - const tagIds = unifiedObject.map((tag) => - 'id' in tag ? String(tag.id) : undefined, - ); + //insert the data in the DB with the fieldMappings (value table) const tag_data = await this.saveTagsInDb( linkedUserId, unifiedObject, - tagIds, integrationId, id_ticket, sourceObject, @@ -188,7 +184,6 @@ export class SyncService implements OnModuleInit { async saveTagsInDb( linkedUserId: string, tags: UnifiedTagOutput[], - originIds: string[], originSource: string, id_ticket: string, remote_data: Record[], @@ -197,7 +192,7 @@ export class SyncService implements OnModuleInit { let tags_results: TicketingTag[] = []; for (let i = 0; i < tags.length; i++) { const tag = tags[i]; - const originId = originIds[i]; + const originId = tag.remote_id[i]; if (!originId || originId == '') { return; diff --git a/packages/api/src/ticketing/team/services/front/mappers.ts b/packages/api/src/ticketing/team/services/front/mappers.ts index e746bf085..0a6285ab1 100644 --- a/packages/api/src/ticketing/team/services/front/mappers.ts +++ b/packages/api/src/ticketing/team/services/front/mappers.ts @@ -39,6 +39,7 @@ export class FrontTeamMapper implements ITeamMapper { }[], ): UnifiedTeamOutput { const unifiedTeam: UnifiedTeamOutput = { + remote_id: team.id, name: team.name, }; diff --git a/packages/api/src/ticketing/team/services/zendesk/mappers.ts b/packages/api/src/ticketing/team/services/zendesk/mappers.ts index bf76e8280..0fe02d304 100644 --- a/packages/api/src/ticketing/team/services/zendesk/mappers.ts +++ b/packages/api/src/ticketing/team/services/zendesk/mappers.ts @@ -39,6 +39,7 @@ export class ZendeskTeamMapper implements ITeamMapper { }[], ): UnifiedTeamOutput { const unifiedTeam: UnifiedTeamOutput = { + remote_id: team.id + "", name: team.name, description: team.description, }; diff --git a/packages/api/src/ticketing/team/sync/sync.service.ts b/packages/api/src/ticketing/team/sync/sync.service.ts index 7540f62c2..650ac1a21 100644 --- a/packages/api/src/ticketing/team/sync/sync.service.ts +++ b/packages/api/src/ticketing/team/sync/sync.service.ts @@ -133,16 +133,12 @@ export class SyncService implements OnModuleInit { customFieldMappings, })) as UnifiedTeamOutput[]; - //TODO - const teamIds = sourceObject.map((team) => - 'id' in team ? String(team.id) : undefined, - ); + //insert the data in the DB with the fieldMappings (value table) const team_data = await this.saveTeamsInDb( linkedUserId, unifiedObject, - teamIds, integrationId, sourceObject, ); @@ -175,7 +171,6 @@ export class SyncService implements OnModuleInit { async saveTeamsInDb( linkedUserId: string, teams: UnifiedTeamOutput[], - originIds: string[], originSource: string, remote_data: Record[], ): Promise { @@ -183,7 +178,7 @@ export class SyncService implements OnModuleInit { let teams_results: TicketingTeam[] = []; for (let i = 0; i < teams.length; i++) { const team = teams[i]; - const originId = originIds[i]; + const originId = team.id[i]; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/ticketing/ticket/services/front/mappers.ts b/packages/api/src/ticketing/ticket/services/front/mappers.ts index 50094c721..25106823f 100644 --- a/packages/api/src/ticketing/ticket/services/front/mappers.ts +++ b/packages/api/src/ticketing/ticket/services/front/mappers.ts @@ -29,8 +29,8 @@ export class FrontTicketMapper implements ITicketMapper { author_id: source.comment.creator_type === 'user' ? await this.utils.getAsigneeRemoteIdFromUserUuid( - source.comment.user_id, - ) + source.comment.user_id, + ) : undefined, attachments: source.comment.attachments, }, @@ -115,6 +115,7 @@ export class FrontTicketMapper implements ITicketMapper { } const unifiedTicket: UnifiedTicketOutput = { + remote_id: ticket.id, name: ticket.subject, status: ticket.status, description: ticket.subject, // todo: ? diff --git a/packages/api/src/ticketing/ticket/services/hubspot/mappers.ts b/packages/api/src/ticketing/ticket/services/hubspot/mappers.ts index 6fb5e3ea9..da2d7b5e1 100644 --- a/packages/api/src/ticketing/ticket/services/hubspot/mappers.ts +++ b/packages/api/src/ticketing/ticket/services/hubspot/mappers.ts @@ -64,6 +64,7 @@ export class HubspotTicketMapper implements ITicketMapper { })); return { + remote_id: ticket.id, name: ticket.properties.name, //TODO status: ticket.properties.hs_pipeline_stage, description: ticket.properties.description, //TODO diff --git a/packages/api/src/ticketing/ticket/services/zendesk/mappers.ts b/packages/api/src/ticketing/ticket/services/zendesk/mappers.ts index 2d8cf3746..ec35bc170 100644 --- a/packages/api/src/ticketing/ticket/services/zendesk/mappers.ts +++ b/packages/api/src/ticketing/ticket/services/zendesk/mappers.ts @@ -143,6 +143,7 @@ export class ZendeskTicketMapper implements ITicketMapper { } const unifiedTicket: UnifiedTicketOutput = { + remote_id: ticket.id, name: ticket.subject, status: ticket.status, description: ticket.description, diff --git a/packages/api/src/ticketing/ticket/sync/sync.service.ts b/packages/api/src/ticketing/ticket/sync/sync.service.ts index 4dbc35ee8..1b3240c26 100644 --- a/packages/api/src/ticketing/ticket/sync/sync.service.ts +++ b/packages/api/src/ticketing/ticket/sync/sync.service.ts @@ -131,16 +131,12 @@ export class SyncService implements OnModuleInit { customFieldMappings, })) as UnifiedTicketOutput[]; - //remote Ids in provider's tools - const ticketIds = sourceObject.map((ticket) => - 'id' in ticket ? String(ticket.id) : undefined, - ); + //insert the data in the DB with the fieldMappings (value table) const tickets_data = await this.saveTicketsInDb( linkedUserId, unifiedObject, - ticketIds, integrationId, sourceObject, ); @@ -173,7 +169,6 @@ export class SyncService implements OnModuleInit { async saveTicketsInDb( linkedUserId: string, tickets: UnifiedTicketOutput[], - originIds: string[], originSource: string, remote_data: Record[], ): Promise { @@ -181,7 +176,7 @@ export class SyncService implements OnModuleInit { let tickets_results: TicketingTicket[] = []; for (let i = 0; i < tickets.length; i++) { const ticket = tickets[i]; - const originId = originIds[i]; + const originId = ticket.remote_id[i]; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/ticketing/user/services/front/mappers.ts b/packages/api/src/ticketing/user/services/front/mappers.ts index cfb94b288..738e45ddd 100644 --- a/packages/api/src/ticketing/user/services/front/mappers.ts +++ b/packages/api/src/ticketing/user/services/front/mappers.ts @@ -43,6 +43,7 @@ export class FrontUserMapper implements IUserMapper { })); const unifiedUser: UnifiedUserOutput = { + remote_id: user.id, name: `${user.last_name} ${user.last_name}`, email_address: user.email, field_mappings: field_mappings, diff --git a/packages/api/src/ticketing/user/services/zendesk/mappers.ts b/packages/api/src/ticketing/user/services/zendesk/mappers.ts index 6c58979c3..adf5e0e34 100644 --- a/packages/api/src/ticketing/user/services/zendesk/mappers.ts +++ b/packages/api/src/ticketing/user/services/zendesk/mappers.ts @@ -43,6 +43,7 @@ export class ZendeskUserMapper implements IUserMapper { })); const unifiedUser: UnifiedUserOutput = { + remote_id: user.id + "", name: user.name, email_address: user.email, field_mappings: field_mappings, diff --git a/packages/api/src/ticketing/user/sync/sync.service.ts b/packages/api/src/ticketing/user/sync/sync.service.ts index b312d519d..0e81ef1ef 100644 --- a/packages/api/src/ticketing/user/sync/sync.service.ts +++ b/packages/api/src/ticketing/user/sync/sync.service.ts @@ -133,16 +133,12 @@ export class SyncService implements OnModuleInit { customFieldMappings, })) as UnifiedUserOutput[]; - //TODO - const userIds = sourceObject.map((user) => - 'id' in user ? String(user.id) : undefined, - ); + //insert the data in the DB with the fieldMappings (value table) const user_data = await this.saveUsersInDb( linkedUserId, unifiedObject, - userIds, integrationId, sourceObject, ); @@ -173,7 +169,6 @@ export class SyncService implements OnModuleInit { async saveUsersInDb( linkedUserId: string, users: UnifiedUserOutput[], - originIds: string[], originSource: string, remote_data: Record[], ): Promise { @@ -181,7 +176,7 @@ export class SyncService implements OnModuleInit { let users_results: TicketingUser[] = []; for (let i = 0; i < users.length; i++) { const user = users[i]; - const originId = originIds[i]; + const originId = user.remote_id[i]; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); From 8686a3c45d59f06d2e35f680837e25656a2f555b Mon Sep 17 00:00:00 2001 From: mit-27 Date: Thu, 28 Mar 2024 23:54:49 -0400 Subject: [PATCH 2/2] Fix typo --- packages/api/src/crm/company/sync/sync.service.ts | 2 +- packages/api/src/crm/engagement/sync/sync.service.ts | 2 +- packages/api/src/crm/note/sync/sync.service.ts | 2 +- packages/api/src/crm/stage/sync/sync.service.ts | 2 +- packages/api/src/crm/task/sync/sync.service.ts | 2 +- packages/api/src/crm/user/sync/sync.service.ts | 2 +- packages/api/src/ticketing/account/sync/sync.service.ts | 2 +- packages/api/src/ticketing/comment/sync/sync.service.ts | 2 +- packages/api/src/ticketing/contact/sync/sync.service.ts | 2 +- packages/api/src/ticketing/tag/sync/sync.service.ts | 2 +- packages/api/src/ticketing/team/sync/sync.service.ts | 2 +- packages/api/src/ticketing/ticket/sync/sync.service.ts | 2 +- packages/api/src/ticketing/user/sync/sync.service.ts | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/api/src/crm/company/sync/sync.service.ts b/packages/api/src/crm/company/sync/sync.service.ts index a759fdd49..9a188b8a9 100644 --- a/packages/api/src/crm/company/sync/sync.service.ts +++ b/packages/api/src/crm/company/sync/sync.service.ts @@ -181,7 +181,7 @@ export class SyncService implements OnModuleInit { let companies_results: CrmCompany[] = []; for (let i = 0; i < companies.length; i++) { const company = companies[i]; - const originId = company.remote_id[i]; + const originId = company.remote_id; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/crm/engagement/sync/sync.service.ts b/packages/api/src/crm/engagement/sync/sync.service.ts index 6e5efb2c7..48616e1a5 100644 --- a/packages/api/src/crm/engagement/sync/sync.service.ts +++ b/packages/api/src/crm/engagement/sync/sync.service.ts @@ -186,7 +186,7 @@ export class SyncService implements OnModuleInit { let engagements_results: CrmEngagement[] = []; for (let i = 0; i < engagements.length; i++) { const engagement = engagements[i]; - const originId = engagement.remote_id[i]; + const originId = engagement.remote_id; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/crm/note/sync/sync.service.ts b/packages/api/src/crm/note/sync/sync.service.ts index bd760cbd0..29e200120 100644 --- a/packages/api/src/crm/note/sync/sync.service.ts +++ b/packages/api/src/crm/note/sync/sync.service.ts @@ -178,7 +178,7 @@ export class SyncService implements OnModuleInit { let notes_results: CrmNote[] = []; for (let i = 0; i < notes.length; i++) { const note = notes[i]; - const originId = note.remote_id[i]; + const originId = note.remote_id; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/crm/stage/sync/sync.service.ts b/packages/api/src/crm/stage/sync/sync.service.ts index d9a1b2831..55742b4c1 100644 --- a/packages/api/src/crm/stage/sync/sync.service.ts +++ b/packages/api/src/crm/stage/sync/sync.service.ts @@ -196,7 +196,7 @@ export class SyncService implements OnModuleInit { let stages_results: CrmStage[] = []; for (let i = 0; i < stages.length; i++) { const stage = stages[i]; - const originId = stage.remote_id[i]; + const originId = stage.remote_id; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/crm/task/sync/sync.service.ts b/packages/api/src/crm/task/sync/sync.service.ts index f783b4313..237a952e7 100644 --- a/packages/api/src/crm/task/sync/sync.service.ts +++ b/packages/api/src/crm/task/sync/sync.service.ts @@ -178,7 +178,7 @@ export class SyncService implements OnModuleInit { let tasks_results: CrmTask[] = []; for (let i = 0; i < tasks.length; i++) { const task = tasks[i]; - const originId = task.remote_id[i]; + const originId = task.remote_id; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/crm/user/sync/sync.service.ts b/packages/api/src/crm/user/sync/sync.service.ts index 731209f03..a27cc2741 100644 --- a/packages/api/src/crm/user/sync/sync.service.ts +++ b/packages/api/src/crm/user/sync/sync.service.ts @@ -177,7 +177,7 @@ export class SyncService implements OnModuleInit { let users_results: CrmUser[] = []; for (let i = 0; i < users.length; i++) { const user = users[i]; - const originId = user.id[i]; + const originId = user.id; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/ticketing/account/sync/sync.service.ts b/packages/api/src/ticketing/account/sync/sync.service.ts index 8b2fe9181..173d21b4c 100644 --- a/packages/api/src/ticketing/account/sync/sync.service.ts +++ b/packages/api/src/ticketing/account/sync/sync.service.ts @@ -176,7 +176,7 @@ export class SyncService implements OnModuleInit { let accounts_results: TicketingAccount[] = []; for (let i = 0; i < accounts.length; i++) { const account = accounts[i]; - const originId = account.id[i]; + const originId = account.id; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/ticketing/comment/sync/sync.service.ts b/packages/api/src/ticketing/comment/sync/sync.service.ts index 04053f5a3..696f28f8f 100644 --- a/packages/api/src/ticketing/comment/sync/sync.service.ts +++ b/packages/api/src/ticketing/comment/sync/sync.service.ts @@ -188,7 +188,7 @@ export class SyncService implements OnModuleInit { let comments_results: TicketingComment[] = []; for (let i = 0; i < comments.length; i++) { const comment = comments[i]; - const originId = comment.remote_id[i]; + const originId = comment.remote_id; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/ticketing/contact/sync/sync.service.ts b/packages/api/src/ticketing/contact/sync/sync.service.ts index cf2b1552e..46b3492b3 100644 --- a/packages/api/src/ticketing/contact/sync/sync.service.ts +++ b/packages/api/src/ticketing/contact/sync/sync.service.ts @@ -192,7 +192,7 @@ export class SyncService implements OnModuleInit { let contacts_results: TicketingContact[] = []; for (let i = 0; i < contacts.length; i++) { const contact = contacts[i]; - const originId = contact.remote_id[i]; + const originId = contact.remote_id; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/ticketing/tag/sync/sync.service.ts b/packages/api/src/ticketing/tag/sync/sync.service.ts index 2cc48063f..853d2692d 100644 --- a/packages/api/src/ticketing/tag/sync/sync.service.ts +++ b/packages/api/src/ticketing/tag/sync/sync.service.ts @@ -192,7 +192,7 @@ export class SyncService implements OnModuleInit { let tags_results: TicketingTag[] = []; for (let i = 0; i < tags.length; i++) { const tag = tags[i]; - const originId = tag.remote_id[i]; + const originId = tag.remote_id; if (!originId || originId == '') { return; diff --git a/packages/api/src/ticketing/team/sync/sync.service.ts b/packages/api/src/ticketing/team/sync/sync.service.ts index 650ac1a21..8631dc869 100644 --- a/packages/api/src/ticketing/team/sync/sync.service.ts +++ b/packages/api/src/ticketing/team/sync/sync.service.ts @@ -178,7 +178,7 @@ export class SyncService implements OnModuleInit { let teams_results: TicketingTeam[] = []; for (let i = 0; i < teams.length; i++) { const team = teams[i]; - const originId = team.id[i]; + const originId = team.id; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/ticketing/ticket/sync/sync.service.ts b/packages/api/src/ticketing/ticket/sync/sync.service.ts index 1b3240c26..acc3fb9e7 100644 --- a/packages/api/src/ticketing/ticket/sync/sync.service.ts +++ b/packages/api/src/ticketing/ticket/sync/sync.service.ts @@ -176,7 +176,7 @@ export class SyncService implements OnModuleInit { let tickets_results: TicketingTicket[] = []; for (let i = 0; i < tickets.length; i++) { const ticket = tickets[i]; - const originId = ticket.remote_id[i]; + const originId = ticket.remote_id; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`); diff --git a/packages/api/src/ticketing/user/sync/sync.service.ts b/packages/api/src/ticketing/user/sync/sync.service.ts index 0e81ef1ef..a9a305ada 100644 --- a/packages/api/src/ticketing/user/sync/sync.service.ts +++ b/packages/api/src/ticketing/user/sync/sync.service.ts @@ -176,7 +176,7 @@ export class SyncService implements OnModuleInit { let users_results: TicketingUser[] = []; for (let i = 0; i < users.length; i++) { const user = users[i]; - const originId = user.remote_id[i]; + const originId = user.remote_id; if (!originId || originId == '') { throw new NotFoundError(`Origin id not there, found ${originId}`);