Skip to content

Commit

Permalink
🐛 Fix write unified for contact
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Jul 15, 2024
1 parent 89fb8d9 commit 80376ef
Show file tree
Hide file tree
Showing 17 changed files with 555 additions and 148 deletions.
213 changes: 213 additions & 0 deletions packages/api/src/@core/utils/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,216 @@ export const MIME_TYPES: { [key: string]: string } = {
'.3g2': 'video/3gpp2',
'.7z': 'application/x-7z-compressed',
};

export const COUNTRY_CODES: { [key: string]: string } = {
Afghanistan: 'AF',
Albania: 'AL',
Algeria: 'DZ',
Andorra: 'AD',
Angola: 'AO',
Antigua_and_Barbuda: 'AG',
Argentina: 'AR',
Armenia: 'AM',
Australia: 'AU',
Austria: 'AT',
Azerbaijan: 'AZ',
Bahamas: 'BS',
Bahrain: 'BH',
Bangladesh: 'BD',
Barbados: 'BB',
Belarus: 'BY',
Belgium: 'BE',
Belize: 'BZ',
Benin: 'BJ',
Bhutan: 'BT',
Bolivia: 'BO',
Bosnia_and_Herzegovina: 'BA',
Botswana: 'BW',
Brazil: 'BR',
Brunei: 'BN',
Bulgaria: 'BG',
Burkina_Faso: 'BF',
Burundi: 'BI',
Cambodia: 'KH',
Cameroon: 'CM',
Canada: 'CA',
Cape_Verde: 'CV',
Central_African_Republic: 'CF',
Chad: 'TD',
Chile: 'CL',
China: 'CN',
Colombia: 'CO',
Comoros: 'KM',
Congo: 'CG',
Costa_Rica: 'CR',
Croatia: 'HR',
Cuba: 'CU',
Cyprus: 'CY',
Czech_Republic: 'CZ',
Denmark: 'DK',
Djibouti: 'DJ',
Dominica: 'DM',
Dominican_Republic: 'DO',
East_Timor: 'TL',
Ecuador: 'EC',
Egypt: 'EG',
El_Salvador: 'SV',
Equatorial_Guinea: 'GQ',
Eritrea: 'ER',
Estonia: 'EE',
Eswatini: 'SZ',
Ethiopia: 'ET',
Fiji: 'FJ',
Finland: 'FI',
France: 'FR',
Gabon: 'GA',
Gambia: 'GM',
Georgia: 'GE',
Germany: 'DE',
Ghana: 'GH',
Greece: 'GR',
Grenada: 'GD',
Guatemala: 'GT',
Guinea: 'GN',
Guinea_Bissau: 'GW',
Guyana: 'GY',
Haiti: 'HT',
Honduras: 'HN',
Hungary: 'HU',
Iceland: 'IS',
India: 'IN',
Indonesia: 'ID',
Iran: 'IR',
Iraq: 'IQ',
Ireland: 'IE',
Israel: 'IL',
Italy: 'IT',
Ivory_Coast: 'CI',
Jamaica: 'JM',
Japan: 'JP',
Jordan: 'JO',
Kazakhstan: 'KZ',
Kenya: 'KE',
Kiribati: 'KI',
North_Korea: 'KP',
South_Korea: 'KR',
Kosovo: 'XK',
Kuwait: 'KW',
Kyrgyzstan: 'KG',
Laos: 'LA',
Latvia: 'LV',
Lebanon: 'LB',
Lesotho: 'LS',
Liberia: 'LR',
Libya: 'LY',
Liechtenstein: 'LI',
Lithuania: 'LT',
Luxembourg: 'LU',
Madagascar: 'MG',
Malawi: 'MW',
Malaysia: 'MY',
Maldives: 'MV',
Mali: 'ML',
Malta: 'MT',
Marshall_Islands: 'MH',
Mauritania: 'MR',
Mauritius: 'MU',
Mexico: 'MX',
Micronesia: 'FM',
Moldova: 'MD',
Monaco: 'MC',
Mongolia: 'MN',
Montenegro: 'ME',
Morocco: 'MA',
Mozambique: 'MZ',
Myanmar: 'MM',
Namibia: 'NA',
Nauru: 'NR',
Nepal: 'NP',
Netherlands: 'NL',
New_Zealand: 'NZ',
Nicaragua: 'NI',
Niger: 'NE',
Nigeria: 'NG',
North_Macedonia: 'MK',
Norway: 'NO',
Oman: 'OM',
Pakistan: 'PK',
Palau: 'PW',
Panama: 'PA',
Papua_New_Guinea: 'PG',
Paraguay: 'PY',
Peru: 'PE',
Philippines: 'PH',
Poland: 'PL',
Portugal: 'PT',
Qatar: 'QA',
Romania: 'RO',
Russia: 'RU',
Rwanda: 'RW',
Saint_Kitts_and_Nevis: 'KN',
Saint_Lucia: 'LC',
Saint_Vincent_and_the_Grenadines: 'VC',
Samoa: 'WS',
San_Marino: 'SM',
Sao_Tome_and_Principe: 'ST',
Saudi_Arabia: 'SA',
Senegal: 'SN',
Serbia: 'RS',
Seychelles: 'SC',
Sierra_Leone: 'SL',
Singapore: 'SG',
Slovakia: 'SK',
Slovenia: 'SI',
Solomon_Islands: 'SB',
Somalia: 'SO',
South_Africa: 'ZA',
Spain: 'ES',
Sri_Lanka: 'LK',
Sudan: 'SD',
Suriname: 'SR',
Sweden: 'SE',
Switzerland: 'CH',
Syria: 'SY',
Taiwan: 'TW',
Tajikistan: 'TJ',
Tanzania: 'TZ',
Thailand: 'TH',
Togo: 'TG',
Tonga: 'TO',
Trinidad_and_Tobago: 'TT',
Tunisia: 'TN',
Turkey: 'TR',
Turkmenistan: 'TM',
Tuvalu: 'TV',
Uganda: 'UG',
Ukraine: 'UA',
United_Arab_Emirates: 'AE',
United_Kingdom: 'GB',
United_States: 'US',
Uruguay: 'UY',
Uzbekistan: 'UZ',
Vanuatu: 'VU',
Vatican_City: 'VA',
Venezuela: 'VE',
Vietnam: 'VN',
Yemen: 'YE',
Zambia: 'ZM',
Zimbabwe: 'ZW',
};

// Create an inverse mapping
export const CODE_TO_COUNTRY: { [key: string]: string } = Object.entries(
COUNTRY_CODES,
).reduce((acc, [key, value]) => {
acc[value] = key;
return acc;
}, {} as { [key: string]: string });

export function getCountryCode(countryName: string): string | null {
return COUNTRY_CODES[countryName] || null;
}

export function getCountryName(countryCode: string): string | null {
return CODE_TO_COUNTRY[countryCode] || null;
}
22 changes: 12 additions & 10 deletions packages/api/src/crm/@lib/@utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,18 @@ export class Utils {
}

normalizeAddresses(addresses: Address[]) {
const normalizedAddresses = addresses.map((addy) => ({
...addy,
created_at: new Date(),
modified_at: new Date(),
id_crm_address: uuidv4(),
owner_type: addy.owner_type ? addy.owner_type : '',
address_type: addy.address_type === '' ? 'primary' : addy.address_type,
}));

return normalizedAddresses;
if (addresses) {
const normalizedAddresses = addresses.map((addy) => ({
...addy,
created_at: new Date(),
modified_at: new Date(),
id_crm_address: uuidv4(),
owner_type: addy.owner_type ? addy.owner_type : '',
address_type: addy.address_type === '' ? 'primary' : addy.address_type,
}));
return normalizedAddresses;
}
return [];
}

async getRemoteIdFromUserUuid(uuid: string) {
Expand Down
15 changes: 7 additions & 8 deletions packages/api/src/crm/company/services/pipedrive/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Injectable } from '@nestjs/common';
import { ICompanyService } from '@crm/company/types';
import { CrmObject } from '@crm/@lib/@types';
import axios from 'axios';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { ActionType, handle3rdPartyServiceError } from '@@core/utils/errors';
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { ApiResponse } from '@@core/utils/types';
import { SyncParam } from '@@core/utils/types/interface';
import { CrmObject } from '@crm/@lib/@types';
import { ICompanyService } from '@crm/company/types';
import { Injectable } from '@nestjs/common';
import axios from 'axios';
import { ServiceRegistry } from '../registry.service';
import { PipedriveCompanyInput, PipedriveCompanyOutput } from './types';
import { SyncParam } from '@@core/utils/types/interface';

@Injectable()
export class PipedriveService implements ICompanyService {
Expand Down
10 changes: 1 addition & 9 deletions packages/api/src/crm/contact/contact.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { BullQueueModule } from '@@core/@core-services/queues/queue.module';
import { IngestDataService } from '@@core/@core-services/unification/ingest-data.service';
import { WebhookService } from '@@core/@core-services/webhooks/panora-webhooks/webhook.service';
import { ConnectionUtils } from '@@core/connections/@utils';
import { FieldMappingService } from '@@core/field-mapping/field-mapping.service';
import { Utils } from '@crm/@lib/@utils';
import { Module } from '@nestjs/common';
Expand All @@ -22,24 +20,18 @@ import { ZendeskContactMapper } from './services/zendesk/mappers';
import { ZohoService } from './services/zoho';
import { ZohoContactMapper } from './services/zoho/mappers';
import { SyncService } from './sync/sync.service';
import { CoreUnification } from '@@core/@core-services/unification/core-unification.service';
import { IngestDataService } from '@@core/@core-services/unification/ingest-data.service';

@Module({
imports: [BullQueueModule],
controllers: [ContactController],
providers: [
ContactService,

FieldMappingService,
SyncService,
WebhookService,

ServiceRegistry,
Utils,

IngestDataService,

/* PROVIDERS SERVICES */
AttioService,
ZendeskService,
Expand Down
Loading

0 comments on commit 80376ef

Please sign in to comment.