Skip to content

Commit

Permalink
feat: added desunify + mappersHubspot
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Nov 15, 2023
1 parent 0a7e519 commit 98e6a0a
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ export class HubspotConnectionService {
code: string,
) {
try {
//TODO: make sure no connections already exists for {linkedUserId, projectId}
//TMP STEP = first create a linked_user and a project id
//await this.addLinkedUserAndProjectTest();
await this.addLinkedUserAndProjectTest();
//reconstruct the redirect URI that was passed in the frontend it must be the same
const REDIRECT_URI = `${config.OAUTH_REDIRECT_BASE}/connections/oauth/callback`; //tocheck
const formData = new URLSearchParams({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CrmObject } from 'src/crm/@types';
import { CrmObjectInput } from '../../types';
import { CrmObjectInput, Unified } from '../../types';

export async function desunifyFreshsales<T extends Record<string, any>>({
export async function desunifyFreshsales<T extends Unified>({
sourceObject,
targetType_,
}: {
Expand Down
17 changes: 14 additions & 3 deletions packages/api/src/@core/utils/unification/crm/hubspot/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import { CrmObject } from 'src/crm/@types';
import { CrmObjectInput } from '../../types';
import { CrmObjectInput, Unified } from '../../types';
import { mapToHubspotContact } from './mappers';

export async function desunifyHubspot<T extends Record<string, any>>({
export async function desunifyHubspot<T extends Unified>({
sourceObject,
targetType_,
}: {
sourceObject: T;
targetType_: CrmObject;
}): Promise<CrmObjectInput> {
return;
switch (targetType_) {
case CrmObject.contact:
return mapToHubspotContact(sourceObject);
case CrmObject.deal:
//return mapToHubspotDeal(sourceObject);
case CrmObject.company:
//return mapToHubspotCompany(sourceObject);
// Add other cases for different CrmObject types
default:
throw new Error(`Unsupported target type for Hubspot: ${targetType_}`);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { HubspotContactInput } from 'src/crm/@types';
import { UnifiedContactInput } from 'src/crm/contact/dto/create-contact.dto';
import { Unified } from '../../../types';

export function mapToHubspotContact<T extends Unified>(
source: T,
): 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;

return {
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
};
}
4 changes: 2 additions & 2 deletions packages/api/src/@core/utils/unification/crm/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CrmObject } from 'src/crm/@types';
import { desunifyHubspot } from './hubspot';
import { CrmObjectInput } from '../types';
import { CrmObjectInput, Unified } from '../types';
import { desunifyPipedrive } from './pipedrive';
import { desunifyZoho } from './zoho';
import { desunifyZendesk } from './zendesk';
import { desunifyFreshsales } from './freshsales';

export async function desunifyCrm<T extends Record<string, any>>({
export async function desunifyCrm<T extends Unified>({
sourceObject,
targetType_,
providerName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CrmObject } from 'src/crm/@types';
import { CrmObjectInput } from '../../types';
import { CrmObjectInput, Unified } from '../../types';

export async function desunifyPipedrive<T extends Record<string, any>>({
export async function desunifyPipedrive<T extends Unified>({
sourceObject,
targetType_,
}: {
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/@core/utils/unification/crm/zendesk/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CrmObject } from 'src/crm/@types';
import { CrmObjectInput } from '../../types';
import { CrmObjectInput, Unified } from '../../types';

export async function desunifyZendesk<T extends Record<string, any>>({
export async function desunifyZendesk<T extends Unified>({
sourceObject,
targetType_,
}: {
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/@core/utils/unification/crm/zoho/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CrmObject } from 'src/crm/@types';
import { CrmObjectInput } from '../../types';
import { CrmObjectInput, Unified } from '../../types';

export async function desunifyZoho<T extends Record<string, any>>({
export async function desunifyZoho<T extends Unified>({
sourceObject,
targetType_,
}: {
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/@core/utils/unification/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { CrmObject } from 'src/crm/@types';
import { ProviderVertical, getProviderVertical } from '../providers';
import { desunifyCrm } from './crm';
import { DesunifyReturnType, TargetObject } from './types';
import { DesunifyReturnType, TargetObject, Unified } from './types';

/* to insert data
SaaS > [Panora] > 3rdParties >
*/

export async function desunify<T extends Record<string, any>>({
export async function desunify<T extends Unified>({
sourceObject,
targetType,
providerName,
Expand Down
5 changes: 4 additions & 1 deletion packages/api/src/@core/utils/unification/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ import {
FreshsalesContactInput,
HubspotContactInput,
PipedriveContactInput,
UnifiedCrm,
ZendeskContactInput,
ZohoContactInput,
} from 'src/crm/@types';

import { HrisObject } from 'src/hris/@types';
import { AtsObject } from 'src/ats/@types';
import { AtsObject, UnifiedAts } from 'src/ats/@types';
import { AccountingObject } from 'src/accounting/@types';
import { MarketingAutomationObject } from 'src/marketing-automation/@types';
import { TicketingObject } from 'src/ticketing/@types';
import { FileStorageObject } from 'src/file-storage/@types';

export type Unified = UnifiedCrm | UnifiedAts;

// Actions TYPE
export type ContactInput =
| FreshsalesContactInput
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/ats/@types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export enum AtsObject {}

export type UnifiedAts = ''; //TODO;
5 changes: 5 additions & 0 deletions packages/api/src/crm/@types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { UnifiedContactInput } from '../contact/dto/create-contact.dto';
import { UnifiedDealInput } from '../deal/dto/create-deal.dto';

export enum CrmObject {
company = 'company',
contact = 'contact',
Expand All @@ -9,6 +12,8 @@ export enum CrmObject {
user = 'user',
}

export type UnifiedCrm = UnifiedContactInput | UnifiedDealInput;

export * from './../contact/services/freshsales/types';
export * from './../contact/services/zendesk/types';
export * from './../contact/services/hubspot/types';
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/crm/contact/contact.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ZendeskService } from './services/zendesk';
import { ZohoService } from './services/zoho';
import { PipedriveService } from './services/pipedrive';
import { HubspotService } from './services/hubspot';
import { LoggerService } from 'src/@core/logger/logger.service';

@Module({
controllers: [ContactController],
Expand All @@ -18,6 +19,7 @@ import { HubspotService } from './services/hubspot';
ZohoService,
PipedriveService,
HubspotService,
LoggerService,
],
})
export class ContactModule {}
3 changes: 2 additions & 1 deletion packages/api/src/crm/crm.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Module } from '@nestjs/common';
import { ContactModule } from './contact/contact.module';
import { DealModule } from './deal/deal.module';

@Module({
imports: [ContactModule],
imports: [ContactModule, DealModule],
})
export class CrmModule {}
7 changes: 7 additions & 0 deletions packages/api/src/crm/deal/deal.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { DealService } from './deal.service';

@Module({
providers: [DealService],
})
export class DealModule {}
18 changes: 18 additions & 0 deletions packages/api/src/crm/deal/deal.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { DealService } from './deal.service';

describe('DealService', () => {
let service: DealService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [DealService],
}).compile();

service = module.get<DealService>(DealService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
4 changes: 4 additions & 0 deletions packages/api/src/crm/deal/deal.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class DealService {}
3 changes: 3 additions & 0 deletions packages/api/src/crm/deal/dto/create-deal.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class UnifiedDealInput {
id: string;
}

0 comments on commit 98e6a0a

Please sign in to comment.