-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from panoratech/feat/fix-apis
Feat/fix apis
- Loading branch information
Showing
16 changed files
with
259 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 49 additions & 14 deletions
63
packages/api/src/@core/utils/unification/crm/freshsales/mappers/contact.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,63 @@ | ||
import { FreshsalesContactInput, HubspotContactInput } from 'src/crm/@types'; | ||
import { | ||
FreshsalesContactInput, | ||
FreshsalesContactOutput, | ||
} from 'src/crm/@types'; | ||
import { | ||
UnifiedContactInput, | ||
UnifiedContactOutput, | ||
} from 'src/crm/contact/dto/create-contact.dto'; | ||
import { Unified, UnifySourceType } from '../../../../types'; | ||
|
||
export function mapToFreshsalesContact<T extends Unified>( | ||
source: T, | ||
export function mapToFreshsalesContact( | ||
source: UnifiedContactInput, | ||
): FreshsalesContactInput { | ||
const source_ = source as UnifiedContactInput; | ||
// Assuming 'email_addresses' array contains at least one email and 'phone_numbers' array contains at least one phone number | ||
const primaryEmail = source_.email_addresses?.[0]?.email_address; | ||
const primaryPhone = source_.phone_numbers?.[0]?.phone_number; | ||
const primaryEmail = source.email_addresses?.[0]?.email_address; | ||
const primaryPhone = source.phone_numbers?.[0]?.phone_number; | ||
|
||
return { | ||
first_name: source_.first_name, | ||
last_name: source_.last_name, | ||
first_name: source.first_name, | ||
last_name: source.last_name, | ||
mobile_number: primaryPhone, | ||
}; | ||
} | ||
|
||
//TODO | ||
export function mapToUnifiedContact< | ||
T extends UnifySourceType | UnifySourceType[], | ||
>(source: T): UnifiedContactOutput | UnifiedContactOutput[] { | ||
return; | ||
export function mapToUnifiedContact( | ||
source: FreshsalesContactOutput | FreshsalesContactOutput[], | ||
): UnifiedContactOutput | UnifiedContactOutput[] { | ||
// Handling single FreshsalesContactOutput | ||
if (!Array.isArray(source)) { | ||
return _mapSingleFreshsalesContact(source); | ||
} | ||
|
||
// Handling array of FreshsalesContactOutput | ||
return source.map(_mapSingleFreshsalesContact); | ||
} | ||
|
||
function _mapSingleFreshsalesContact( | ||
contact: FreshsalesContactOutput, | ||
): UnifiedContactOutput { | ||
// Map email and phone details | ||
const email_addresses = contact.email | ||
? [{ email_address: contact.email, email_address_type: 'primary' }] | ||
: []; | ||
const phone_numbers = []; | ||
if (contact.work_number) { | ||
phone_numbers.push({ | ||
phone_number: contact.work_number, | ||
phone_type: 'work', | ||
}); | ||
} | ||
if (contact.mobile_number) { | ||
phone_numbers.push({ | ||
phone_number: contact.mobile_number, | ||
phone_type: 'mobile', | ||
}); | ||
} | ||
|
||
return { | ||
first_name: contact.first_name, | ||
last_name: contact.last_name, | ||
email_addresses, | ||
phone_numbers, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 29 additions & 14 deletions
43
packages/api/src/@core/utils/unification/crm/hubspot/mappers/contact.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,46 @@ | ||
import { HubspotContactInput } from 'src/crm/@types'; | ||
import { HubspotContactInput, HubspotContactOutput } from 'src/crm/@types'; | ||
import { | ||
UnifiedContactInput, | ||
UnifiedContactOutput, | ||
} from 'src/crm/contact/dto/create-contact.dto'; | ||
import { Unified, UnifySourceType } from '../../../../types'; | ||
|
||
export function mapToHubspotContact<T extends Unified>( | ||
source: T, | ||
export function mapToHubspotContact( | ||
source: UnifiedContactInput, | ||
): HubspotContactInput { | ||
const source_ = source as UnifiedContactInput; | ||
// Assuming 'email_addresses' array contains at least one email and 'phone_numbers' array contains at least one phone number | ||
const primaryEmail = source_.email_addresses?.[0]?.email_address; | ||
const primaryPhone = source_.phone_numbers?.[0]?.phone_number; | ||
const primaryEmail = source.email_addresses?.[0]?.email_address; | ||
const primaryPhone = source.phone_numbers?.[0]?.phone_number; | ||
|
||
return { | ||
firstname: source_.first_name, | ||
lastname: source_.last_name, | ||
firstname: source.first_name, | ||
lastname: source.last_name, | ||
email: primaryEmail, | ||
phone: primaryPhone, | ||
// Map other fields as needed | ||
// If there are fields such as city, country, etc., in your UnifiedContactInput, map them here | ||
}; | ||
} | ||
|
||
//TODO | ||
export function mapToUnifiedContact< | ||
T extends UnifySourceType | UnifySourceType[], | ||
>(source: T): UnifiedContactOutput | UnifiedContactOutput[] { | ||
return; | ||
export function mapToUnifiedContact( | ||
source: HubspotContactOutput | HubspotContactOutput[], | ||
): UnifiedContactOutput | UnifiedContactOutput[] { | ||
if (!Array.isArray(source)) { | ||
return _mapSingleContact(source); | ||
} | ||
|
||
// Handling array of HubspotContactOutput | ||
return source.map(_mapSingleContact); | ||
} | ||
|
||
function _mapSingleContact( | ||
contact: HubspotContactOutput, | ||
): UnifiedContactOutput { | ||
return { | ||
first_name: contact.firstname, | ||
last_name: contact.lastname, | ||
email_addresses: [ | ||
{ email_address: contact.email, email_address_type: 'primary' }, | ||
], | ||
phone_numbers: [{ phone_number: contact.phone, phone_type: 'primary' }], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.