Skip to content

Commit

Permalink
✨ Tested Tasks, Deals, Users
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Jul 17, 2024
1 parent a014a4e commit d3dfd9e
Show file tree
Hide file tree
Showing 66 changed files with 452 additions and 249 deletions.
1 change: 1 addition & 0 deletions packages/api/src/crm/company/services/attio/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export class AttioCompanyMapper implements ICompanyMapper {

return {
remote_id: company.id.record_id,
remote_data: company,
name: company.values.name[0]?.value,
industry:
typeof company.values.categories[0]?.option === 'string'
Expand Down
17 changes: 8 additions & 9 deletions packages/api/src/crm/company/services/close/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
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 {
commonCompanyCloseProperties,
CloseCompanyInput,
CloseCompanyOutput,
commonCompanyCloseProperties,
} from './types';
import { SyncParam } from '@@core/utils/types/interface';

@Injectable()
export class CloseService implements ICompanyService {
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/company/services/close/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class CloseCompanyMapper implements ICompanyMapper {
}
return {
remote_id: company.id,
remote_data: company,
name: company.name,
number_of_employees: company?.custom?.employees || null,
addresses: company?.addresses?.map((address) => ({
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/company/services/hubspot/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export class HubspotCompanyMapper implements ICompanyMapper {

return {
remote_id: company.id,
remote_data: company,
name: company.properties.name,
industry: company.properties.industry,
number_of_employees: company.properties.numberofemployees,
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/company/services/pipedrive/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class PipedriveCompanyMapper implements ICompanyMapper {
}
return {
name: company.name,
remote_data: company,
industry: null,
number_of_employees: company.people_count ?? null,
field_mappings,
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/company/services/zendesk/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export class ZendeskCompanyMapper implements ICompanyMapper {

return {
remote_id: String(company.id),
remote_data: company,
name: company.name,
email_addresses,
phone_numbers,
Expand Down
7 changes: 4 additions & 3 deletions packages/api/src/crm/company/services/zoho/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export class ZohoCompanyMapper implements ICompanyMapper {
}

if (source.user_id) {
result.Owner.id = await this.utils.getRemoteIdFromUserUuid(
source.user_id,
);
result.Owner = {
id: await this.utils.getRemoteIdFromUserUuid(source.user_id),
};
}

if (customFieldMappings && source.field_mappings) {
Expand Down Expand Up @@ -112,6 +112,7 @@ export class ZohoCompanyMapper implements ICompanyMapper {

return {
remote_id: company.id,
remote_data: company,
name: company.Account_Name,
phone_numbers: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/crm/company/services/zoho/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
interface ZohoCompany {
Owner: PersonDetail;
Owner: Partial<PersonDetail>;
$currency_symbol: string;
Account_Type: string;
SIC_Code: string | null;
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/contact/services/attio/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export class AttioContactMapper implements IContactMapper {

return {
remote_id: contact.id.record_id,
remote_data: contact,
first_name: contact.values.name[0]?.first_name,
last_name: contact.values.name[0]?.last_name,
email_addresses: contact.values.email_addresses?.map((e) => ({
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/contact/services/close/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export class CloseContactMapper implements IContactMapper {

return {
remote_id: contact.id,
remote_data: contact,
first_name: contact.name,
last_name: null,
email_addresses: contact.emails?.map(({ email, type }) => ({
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/contact/services/hubspot/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export class HubspotContactMapper implements IContactMapper {

return {
remote_id: contact.id,
remote_data: contact,
first_name: contact.properties.firstname,
last_name: contact.properties.lastname,
email_addresses: [
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/contact/services/pipedrive/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export class PipedriveContactMapper implements IContactMapper {

return {
remote_id: String(contact.id),
remote_data: contact,
first_name: contact.first_name,
last_name: contact.last_name,
email_addresses: contact.email.map((e) => ({
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/contact/services/zendesk/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export class ZendeskContactMapper implements IContactMapper {

return {
remote_id: String(contact.id),
remote_data: contact,
first_name: contact.first_name,
last_name: contact.last_name,
email_addresses,
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/contact/services/zoho/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export class ZohoContactMapper implements IContactMapper {

return {
remote_id: String(contact.id),
remote_data: contact,
first_name: contact.First_Name ?? null,
last_name: contact.Last_Name ?? null,
email_addresses,
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/deal/services/attio/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export class AttioDealMapper implements IDealMapper {

return {
remote_id: deal.id.record_id,
remote_data: deal,
name: deal.values.name.length > 0 ? deal.values.name[0].value : null,
description: '',
field_mappings,
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/deal/services/close/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export class CloseDealMapper implements IDealMapper {
}
return {
remote_id: deal.id,
remote_data: deal,
name: deal.note,
description: deal.note || '',
amount: parseFloat(`${deal.value || 0}`),
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/deal/services/hubspot/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export class HubspotDealMapper implements IDealMapper {

return {
remote_id: deal.id,
remote_data: deal,
name: deal.properties.dealname,
description: '',
field_mappings,
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/deal/services/pipedrive/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export class PipedriveDealMapper implements IDealMapper {

return {
remote_id: String(deal.id),
remote_data: deal,
name: deal.title,
amount: deal.value,
description: '', //todo null
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/deal/services/zendesk/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class ZendeskDealMapper implements IDealMapper {

return {
remote_id: String(deal.id),
remote_data: deal,
name: deal.name,
amount:
typeof deal.value === 'string' ? parseFloat(deal.value) : deal.value,
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/crm/deal/services/zoho/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class ZohoDealMapper implements IDealMapper {
}
const res: UnifiedDealOutput = {
remote_id: deal.id,
remote_data: deal,
name: deal.Deal_Name,
description: deal.Description ?? '', // todo null
amount: deal.Amount,
Expand Down
15 changes: 7 additions & 8 deletions packages/api/src/crm/engagement/services/close/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Injectable } from '@nestjs/common';
import { IEngagementService } from '@crm/engagement/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 { IEngagementService } from '@crm/engagement/types';
import { Injectable } from '@nestjs/common';
import axios from 'axios';
import { ServiceRegistry } from '../registry.service';
import {
CloseEngagementCallInput,
Expand All @@ -18,7 +18,6 @@ import {
CloseEngagementMeetingOutput,
CloseEngagementOutput,
} from './types';
import { SyncParam } from '@@core/utils/types/interface';

@Injectable()
export class CloseService implements IEngagementService {
Expand Down
15 changes: 8 additions & 7 deletions packages/api/src/crm/engagement/services/close/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@ export class CloseEngagementMapper implements IEngagementMapper {
new Date(source.start_at).getTime()
: 0;
const result: CloseEngagementCallInput = {
note_html: source.content || null,
note: source.content || null,
duration: Math.floor(diffInMilliseconds / (1000 * 60)),
};
if (source.direction) {
result.direction = this.reverseMapToTaskDirection(
source.direction as EngagementDirection,
);
result.direction = source.direction.toLowerCase();
}

// Map HubSpot owner ID from user ID
Expand All @@ -99,8 +97,8 @@ export class CloseEngagementMapper implements IEngagementMapper {
source.company_id,
);
}
if (source?.contacts && source?.contacts?.length) {
const contactId = await this.utils.getRemoteIdFromUserUuid(
if (source?.contacts && source?.contacts?.length > 0) {
const contactId = await this.utils.getRemoteIdFromContactUuid(
source.contacts[0],
);
if (contactId) {
Expand Down Expand Up @@ -348,10 +346,11 @@ export class CloseEngagementMapper implements IEngagementMapper {
}
}
if (engagement.direction) {
opts.direction = this.mapToTaskDirection(engagement.direction as any);
opts.direction = engagement.direction.toUpperCase();
}
return {
remote_id: engagement.id,
remote_data: engagement,
content: engagement.note_html || engagement.note,
subject: engagement.note,
start_at: new Date(engagement.date_created),
Expand Down Expand Up @@ -428,6 +427,7 @@ export class CloseEngagementMapper implements IEngagementMapper {
}
return {
remote_id: engagement.id,
remote_data: engagement,
content: engagement.note,
subject: engagement.title,
start_at: new Date(engagement.starts_at),
Expand Down Expand Up @@ -497,6 +497,7 @@ export class CloseEngagementMapper implements IEngagementMapper {

return {
remote_id: engagement.id,
remote_data: engagement,
content: engagement.body_html,
subject: engagement.subject,
start_at: new Date(engagement.date_created),
Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/crm/engagement/services/close/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ interface Call {
user_id: string;
direction: string;
status: string;
note_html: string;
note_html?: string;
note: string;
duration: number;
phone: string;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { CoreUnification } from '@@core/@core-services/unification/core-unification.service';
import { IngestDataService } from '@@core/@core-services/unification/ingest-data.service';
import { WebhookService } from '@@core/@core-services/webhooks/panora-webhooks/webhook.service';
import { FieldMappingService } from '@@core/field-mapping/field-mapping.service';
import { ApiResponse } from '@@core/utils/types';
Expand All @@ -9,14 +11,10 @@ import { Injectable } from '@nestjs/common';
import { v4 as uuidv4 } from 'uuid';
import { IEngagementService } from '../types';
import {
EngagementDirection,
EngagementType,
UnifiedEngagementInput,
UnifiedEngagementOutput,
} from '../types/model.unified';
import { ServiceRegistry } from './registry.service';
import { CoreUnification } from '@@core/@core-services/unification/core-unification.service';
import { IngestDataService } from '@@core/@core-services/unification/ingest-data.service';

@Injectable()
export class EngagementService {
Expand Down
19 changes: 9 additions & 10 deletions packages/api/src/crm/engagement/services/hubspot/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Injectable } from '@nestjs/common';
import { IEngagementService } from '@crm/engagement/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 { IEngagementService } from '@crm/engagement/types';
import { Injectable } from '@nestjs/common';
import axios from 'axios';
import { ServiceRegistry } from '../registry.service';
import {
HubspotEngagementCallInput,
Expand All @@ -21,7 +21,6 @@ import {
commonEmailHubspotProperties,
commonMeetingHubspotProperties,
} from './types';
import { SyncParam } from '@@core/utils/types/interface';

@Injectable()
export class HubspotService implements IEngagementService {
Expand Down Expand Up @@ -119,7 +118,7 @@ export class HubspotService implements IEngagementService {
properties: engagementData,
};
const resp = await axios.post(
`${connection.account_url}/objects/calls`,
`${connection.account_url}/objects/meetings`,
JSON.stringify(dataBody),
{
headers: {
Expand Down Expand Up @@ -156,7 +155,7 @@ export class HubspotService implements IEngagementService {
properties: engagementData,
};
const resp = await axios.post(
`https://api.hubapi.com/crm/v3/objects/emails`,
`${connection.account_url}/objects/emails`,
JSON.stringify(dataBody),
{
headers: {
Expand Down
Loading

0 comments on commit d3dfd9e

Please sign in to comment.