Skip to content

Commit

Permalink
🎨 Func names updated
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Dec 20, 2023
1 parent 0cf3254 commit c3902ac
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 52 deletions.
40 changes: 20 additions & 20 deletions packages/api/src/crm/@types/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import {
mapToContact_Freshsales,
mapToUnifiedContact_Freshsales,
convertUnifiedContactToFreshsales,
convertFreshsalesContactToUnified,
} from '@contact/services/freshsales/mappers';
import {
mapToContact_Hubspot,
mapToUnifiedContact_Hubspot,
convertUnifiedContactToHubspot,
convertHubspotContactToUnified,
} from '@contact/services/hubspot/mappers';
import {
mapToContact_Pipedrive,
mapToUnifiedContact_Pipedrive,
convertUnifiedContactToPipedrive,
convertPipedriveContactToUnified,
} from '@contact/services/pipedrive/mappers';
import {
mapToContact_Zendesk,
mapToUnifiedContact_Zendesk,
convertUnifiedContactToZendesk,
convertZendeskContactToUnified,
} from '@contact/services/zendesk/mappers';
import {
mapToContact_Zoho,
mapToUnifiedContact_Zoho,
convertUnifiedContactToZoho,
convertZohoContactToUnified,
} from '@contact/services/zoho/mappers';
import {
UnifiedContactInput,
Expand All @@ -43,34 +43,34 @@ export type UnifiedCrm =
export const providerUnificationMapping = {
hubspot: {
[CrmObject.contact]: {
unify: mapToUnifiedContact_Hubspot,
desunify: mapToContact_Hubspot,
unify: convertHubspotContactToUnified,
desunify: convertUnifiedContactToHubspot,
},
//[CrmObject.deal]: ,
//[CrmObject.company]:,
},
pipedrive: {
[CrmObject.contact]: {
unify: mapToUnifiedContact_Pipedrive,
desunify: mapToContact_Pipedrive,
unify: convertPipedriveContactToUnified,
desunify: convertUnifiedContactToPipedrive,
},
},
zoho: {
[CrmObject.contact]: {
unify: mapToUnifiedContact_Zoho,
desunify: mapToContact_Zoho,
unify: convertZohoContactToUnified,
desunify: convertUnifiedContactToZoho,
},
},
zendesk: {
[CrmObject.contact]: {
unify: mapToUnifiedContact_Zendesk,
desunify: mapToContact_Zendesk,
unify: convertZendeskContactToUnified,
desunify: convertUnifiedContactToZendesk,
},
},
freshsales: {
[CrmObject.contact]: {
unify: mapToUnifiedContact_Freshsales,
desunify: mapToContact_Freshsales,
unify: convertFreshsalesContactToUnified,
desunify: convertUnifiedContactToFreshsales,
},
},
};
Expand Down
51 changes: 44 additions & 7 deletions packages/api/src/crm/contact/contact.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ export class ContactController {
})
@ApiQuery({ name: 'integrationId', required: true, type: String })
@ApiQuery({ name: 'linkedUserId', required: true, type: String })
@ApiQuery({ name: 'remote_data', required: false, type: Boolean, description: 'Set to true to include data from the original CRM software.' })
@ApiQuery({
name: 'remote_data',
required: false,
type: Boolean,
description: 'Set to true to include data from the original CRM software.',
})
@ApiCustomResponse(ContactResponse)
@Get()
getContacts(
Expand All @@ -54,8 +59,18 @@ export class ContactController {
summary: 'Retrieve a CRM Contact',
description: 'Retrieve a contact from any connected CRM',
})
@ApiParam({ name: 'id', required: true, type: String, description: "id of the `contact` you want to retrive." })
@ApiQuery({ name: 'remote_data', required: false, type: Boolean, description: 'Set to true to include data from the original CRM software.' })
@ApiParam({
name: 'id',
required: true,
type: String,
description: 'id of the `contact` you want to retrive.',
})
@ApiQuery({
name: 'remote_data',
required: false,
type: Boolean,
description: 'Set to true to include data from the original CRM software.',
})
@ApiCustomResponse(ContactResponse)
@Get(':id')
getContact(
Expand All @@ -70,9 +85,26 @@ export class ContactController {
summary: 'Create CRM Contact',
description: 'Create a contact in any supported CRM',
})
@ApiQuery({ name: 'integrationId', required: true, type: String, description: 'The integration ID', example: '6aa2acf3-c244-4f85-848b-13a57e7abf55' })
@ApiQuery({ name: 'linkedUserId', required: true, type: String, description: 'The linked user ID', example: 'b008e199-eda9-4629-bd41-a01b6195864a' })
@ApiQuery({ name: 'remote_data', required: false, type: Boolean, description: 'Set to true to include data from the original CRM software.' })
@ApiQuery({
name: 'integrationId',
required: true,
type: String,
description: 'The integration ID',
example: '6aa2acf3-c244-4f85-848b-13a57e7abf55',
})
@ApiQuery({
name: 'linkedUserId',
required: true,
type: String,
description: 'The linked user ID',
example: 'b008e199-eda9-4629-bd41-a01b6195864a',
})
@ApiQuery({
name: 'remote_data',
required: false,
type: Boolean,
description: 'Set to true to include data from the original CRM software.',
})
@ApiBody({ type: UnifiedContactInput })
@ApiCustomResponse(ContactResponse)
@Post()
Expand All @@ -96,7 +128,12 @@ export class ContactController {
})
@ApiQuery({ name: 'integrationId', required: true, type: String })
@ApiQuery({ name: 'linkedUserId', required: true, type: String })
@ApiQuery({ name: 'remote_data', required: false, type: Boolean, description: 'Set to true to include data from the original CRM software.' })
@ApiQuery({
name: 'remote_data',
required: false,
type: Boolean,
description: 'Set to true to include data from the original CRM software.',
})
@ApiBody({ type: UnifiedContactInput, isArray: true })
@ApiCustomResponse(ContactResponse)
@Post('batch')
Expand Down
10 changes: 5 additions & 5 deletions packages/api/src/crm/contact/services/freshsales/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
UnifiedContactOutput,
} from '@contact/types/model.unified';

export function mapToContact_Freshsales(
export function convertUnifiedContactToFreshsales(
source: UnifiedContactInput,
): FreshsalesContactInput {
// Assuming 'email_addresses' array contains at least one email and 'phone_numbers' array contains at least one phone number
Expand All @@ -21,19 +21,19 @@ export function mapToContact_Freshsales(
};
}

export function mapToUnifiedContact_Freshsales(
export function convertFreshsalesContactToUnified(
source: FreshsalesContactOutput | FreshsalesContactOutput[],
): UnifiedContactOutput | UnifiedContactOutput[] {
// Handling single FreshsalesContactOutput
if (!Array.isArray(source)) {
return _mapSingleFreshsalesContact(source);
return mapSingleFreshsalesContactToUnified(source);
}

// Handling array of FreshsalesContactOutput
return source.map(_mapSingleFreshsalesContact);
return source.map(mapSingleFreshsalesContactToUnified);
}

function _mapSingleFreshsalesContact(
function mapSingleFreshsalesContactToUnified(
contact: FreshsalesContactOutput,
): UnifiedContactOutput {
// Map email and phone details
Expand Down
10 changes: 5 additions & 5 deletions packages/api/src/crm/contact/services/hubspot/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@contact/types/model.unified';
import { UnifySourceType } from '@@core/utils/types';

export function mapToContact_Hubspot(
export function convertUnifiedContactToHubspot(
source: UnifiedContactInput,
customFieldMappings?: {
slug: string;
Expand Down Expand Up @@ -38,7 +38,7 @@ export function mapToContact_Hubspot(
return result;
}

export function mapToUnifiedContact_Hubspot<
export function convertHubspotContactToUnified<
T extends UnifySourceType | UnifySourceType[],
>(
source: T,
Expand All @@ -50,15 +50,15 @@ export function mapToUnifiedContact_Hubspot<
const source_ = source as HubspotContactOutput | HubspotContactOutput[];

if (!Array.isArray(source_)) {
return _mapSingleContact(source_, customFieldMappings);
return mapSingleHubspotContactToUnified(source_, customFieldMappings);
}
// Handling array of HubspotContactOutput
return source_.map((contact) =>
_mapSingleContact(contact, customFieldMappings),
mapSingleHubspotContactToUnified(contact, customFieldMappings),
);
}

function _mapSingleContact(
function mapSingleHubspotContactToUnified(
contact: HubspotContactOutput,
customFieldMappings?: {
slug: string;
Expand Down
10 changes: 5 additions & 5 deletions packages/api/src/crm/contact/services/pipedrive/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
UnifiedContactOutput,
} from '@contact/types/model.unified';

export function mapToContact_Pipedrive(
export function convertUnifiedContactToPipedrive(
source: UnifiedContactInput,
customFieldMappings?: {
slug: string;
Expand Down Expand Up @@ -42,24 +42,24 @@ export function mapToContact_Pipedrive(
return result;
}

export function mapToUnifiedContact_Pipedrive(
export function convertPipedriveContactToUnified(
source: PipedriveContactOutput | PipedriveContactOutput[],
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): UnifiedContactOutput | UnifiedContactOutput[] {
if (!Array.isArray(source)) {
return _mapSinglePipedriveContact(source, customFieldMappings);
return mapSinglePipedriveContactToUnified(source, customFieldMappings);
}

// Handling array of HubspotContactOutput
return source.map((contact) =>
_mapSinglePipedriveContact(contact, customFieldMappings),
mapSinglePipedriveContactToUnified(contact, customFieldMappings),
);
}

function _mapSinglePipedriveContact(
function mapSinglePipedriveContactToUnified(
contact: PipedriveContactOutput,
customFieldMappings?: {
slug: string;
Expand Down
10 changes: 5 additions & 5 deletions packages/api/src/crm/contact/services/zendesk/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
UnifiedContactOutput,
} from '@contact/types/model.unified';

export function mapToContact_Zendesk(
export function convertUnifiedContactToZendesk(
source: UnifiedContactInput,
customFieldMappings?: {
slug: string;
Expand Down Expand Up @@ -39,24 +39,24 @@ export function mapToContact_Zendesk(
return result;
}

export function mapToUnifiedContact_Zendesk(
export function convertZendeskContactToUnified(
source: ZendeskContactOutput | ZendeskContactOutput[],
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): UnifiedContactOutput | UnifiedContactOutput[] {
if (!Array.isArray(source)) {
return _mapSingleZendeskContact(source, customFieldMappings);
return mapSingleZendeskContactToUnified(source, customFieldMappings);
}

// Handling array of HubspotContactOutput
return source.map((contact) =>
_mapSingleZendeskContact(contact, customFieldMappings),
mapSingleZendeskContactToUnified(contact, customFieldMappings),
);
}

function _mapSingleZendeskContact(
function mapSingleZendeskContactToUnified(
contact: ZendeskContactOutput,
customFieldMappings?: {
slug: string;
Expand Down
10 changes: 5 additions & 5 deletions packages/api/src/crm/contact/services/zoho/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
UnifiedContactOutput,
} from '@contact/types/model.unified';

export function mapToContact_Zoho(
export function convertUnifiedContactToZoho(
source: UnifiedContactInput,
customFieldMappings?: {
slug: string;
Expand Down Expand Up @@ -38,24 +38,24 @@ export function mapToContact_Zoho(
return result;
}

export function mapToUnifiedContact_Zoho(
export function convertZohoContactToUnified(
source: ZohoContactOutput | ZohoContactOutput[],
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): UnifiedContactOutput | UnifiedContactOutput[] {
if (!Array.isArray(source)) {
return _mapSingleZohoContact(source, customFieldMappings);
return mapSingleZohoContactToUnified(source, customFieldMappings);
}

// Handling array of HubspotContactOutput
return source.map((contact) =>
_mapSingleZohoContact(contact, customFieldMappings),
mapSingleZohoContactToUnified(contact, customFieldMappings),
);
}

function _mapSingleZohoContact(
function mapSingleZohoContactToUnified(
contact: ZohoContactOutput,
customFieldMappings?: {
slug: string;
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/contact/sync/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class SyncContactsService implements OnModuleInit {
},
});
linkedUsers.map(async (linkedUser) => {
//TODO: loop through all providers
try {
await this.syncContactsForLinkedUser(
'hubspot',
Expand Down

0 comments on commit c3902ac

Please sign in to comment.