Skip to content

Commit

Permalink
✨ Update all objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mit-27 committed Sep 6, 2024
1 parent 95e2ddb commit 9e8abdd
Show file tree
Hide file tree
Showing 21 changed files with 294 additions and 207 deletions.
1 change: 1 addition & 0 deletions packages/api/scripts/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ CREATE TABLE connector_sets
ats_ashby boolean NULL,
ecom_webflow boolean NULL,
crm_microsoftdynamicssales boolean NULL,
crm_affinity boolean NULL,
CONSTRAINT PK_project_connector PRIMARY KEY ( id_connector_set )
);

Expand Down
8 changes: 4 additions & 4 deletions packages/api/scripts/seed.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
INSERT INTO users (id_user, identification_strategy, email, password_hash, first_name, last_name) VALUES
('0ce39030-2901-4c56-8db0-5e326182ec6b', 'b2c','[email protected]', '$2b$10$Y7Q8TWGyGuc5ecdIASbBsuXMo3q/Rs3/cnY.mLZP4tUgfGUOCUBlG', 'local', 'Panora');

INSERT INTO connector_sets (id_connector_set, crm_hubspot, crm_zoho, crm_pipedrive, crm_attio, crm_zendesk, crm_close, tcg_zendesk, tcg_gorgias, tcg_front, tcg_jira, tcg_gitlab, fs_box, tcg_github, hris_deel, hris_sage, ats_ashby, crm_microsoftdynamicssales, ecom_webflow, tcg_linear, ecom_shopify, ecom_woocommerce, ecom_amazon, ecom_squarespace, hris_gusto) VALUES
('1709da40-17f7-4d3a-93a0-96dc5da6ddd7', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
('852dfff8-ab63-4530-ae49-e4b2924407f8', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
('aed0f856-f802-4a79-8640-66d441581a99', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
INSERT INTO connector_sets (id_connector_set, crm_hubspot, crm_zoho, crm_pipedrive, crm_attio, crm_zendesk, crm_close, tcg_zendesk, tcg_gorgias, tcg_front, tcg_jira, tcg_gitlab, fs_box, tcg_github, hris_deel, hris_sage, ats_ashby, crm_microsoftdynamicssales, ecom_webflow, tcg_linear, ecom_shopify, ecom_woocommerce, ecom_amazon, ecom_squarespace, hris_gusto, crm_affinity) VALUES
('1709da40-17f7-4d3a-93a0-96dc5da6ddd7', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
('852dfff8-ab63-4530-ae49-e4b2924407f8', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
('aed0f856-f802-4a79-8640-66d441581a99', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);

INSERT INTO projects (id_project, name, sync_mode, id_user, id_connector_set) VALUES
('1e468c15-aa57-4448-aa2b-7fed640d1e3d', 'Project 1', 'pull', '0ce39030-2901-4c56-8db0-5e326182ec6b', '1709da40-17f7-4d3a-93a0-96dc5da6ddd7'),
Expand Down
10 changes: 8 additions & 2 deletions packages/api/src/@core/utils/types/original/original.crm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@


import { MicrosoftdynamicssalesEngagementInput, MicrosoftdynamicssalesEngagementOutput } from '@crm/engagement/services/microsoftdynamicssales/types';

import { MicrosoftdynamicssalesTaskInput, MicrosoftdynamicssalesTaskOutput } from '@crm/task/services/microsoftdynamicssales/types';
Expand Down Expand Up @@ -153,12 +154,17 @@ import {
ZendeskUserInput,
ZendeskUserOutput,
} from '@ticketing/user/services/zendesk/types';
import { AffinityCompanyInput, AffinityCompanyOutput } from '@crm/company/services/affinity/types';
import { AffinityDealInput, AffinityDealOutput } from '@crm/deal/services/affinity/types';
import { AffinityNoteInput, AffinityNoteOutput } from '@crm/note/services/affinity/types';
import { AffinityUserInput, AffinityUserOutput } from '@crm/user/services/affinity/types';
import { AffinityContactInput, AffinityContactOutput } from '@crm/contact/services/affinity/types';

/* INPUT */

/* contact */
export type OriginalContactInput =
| AffinityContactInput
| AffinityCompanyInput
| HubspotContactInput
| ZohoContactInput
| ZendeskContactInput
Expand Down Expand Up @@ -245,7 +251,7 @@ export type CrmObjectInput =
/* OUTPUT */

export type OriginalContactOutput =
| AffinityContactOutput
| AffinityContactInput
| HubspotContactOutput
| ZohoContactOutput
| ZendeskContactOutput
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/crm/company/company.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AffinityCompanyMapper } from './services/affinity/mappers';
import { AffinityService } from './services/affinity';
import { MicrosoftdynamicssalesCompanyMapper } from './services/microsoftdynamicssales/mappers';
import { MicrosoftdynamicssalesService } from './services/microsoftdynamicssales';
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
Expand Down Expand Up @@ -57,6 +59,8 @@ import { SyncService } from './sync/sync.service';
ZohoCompanyMapper,
MicrosoftdynamicssalesService,
MicrosoftdynamicssalesCompanyMapper,
AffinityService,
AffinityCompanyMapper,
],
exports: [SyncService, ServiceRegistry, WebhookService],
})
Expand Down
31 changes: 10 additions & 21 deletions packages/api/src/crm/company/services/affinity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
import { Injectable } from '@nestjs/common';
import axios from 'axios';
import { CrmObject } from '@crm/@lib/@types';
import { PrismaService } from '@@core/prisma/prisma.service';
import { LoggerService } from '@@core/logger/logger.service';
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/encryption/encryption.service';
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { ApiResponse } from '@@core/utils/types';
import { ICompanyService } from '@crm/company/types';
import { ServiceRegistry } from '../registry.service';
import { AffinityCompanyInput, AffinityCompanyOutput } from './types';
import { SyncParam } from '@@core/utils/types/interface';
import { OriginalCompanyOutput } from '@@core/utils/types/original/original.crm';

@Injectable()
export class AffinityService implements ICompanyService {
Expand All @@ -24,7 +26,6 @@ export class AffinityService implements ICompanyService {
);
this.registry.registerService('affinity', this);
}

async addCompany(
companyData: AffinityCompanyInput,
linkedUserId: string,
Expand Down Expand Up @@ -58,20 +59,14 @@ export class AffinityService implements ICompanyService {
statusCode: 201,
};
} catch (error) {
handle3rdPartyServiceError(
error,
this.logger,
'Affinity',
CrmObject.company,
ActionType.POST,
);
throw error;
}
}

async syncCompanies(
linkedUserId: string,
): Promise<ApiResponse<AffinityCompanyOutput[]>> {
async sync(data: SyncParam): Promise<ApiResponse<AffinityCompanyOutput[]>> {
try {
const { linkedUserId } = data;

const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
Expand All @@ -96,13 +91,7 @@ export class AffinityService implements ICompanyService {
statusCode: 200,
};
} catch (error) {
handle3rdPartyServiceError(
error,
this.logger,
'Affinity',
CrmObject.company,
ActionType.GET,
);
throw error;
}
}
}
30 changes: 19 additions & 11 deletions packages/api/src/crm/company/services/affinity/mappers.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { AffinityCompanyInput, AffinityCompanyOutput } from './types';
import {
UnifiedCompanyInput,
UnifiedCompanyOutput,
UnifiedCrmCompanyInput,
UnifiedCrmCompanyOutput,
} from '@crm/company/types/model.unified';
import { ICompanyMapper } from '@crm/company/types';
import { Utils } from '@crm/@lib/@utils';
import { Injectable } from '@nestjs/common';
import { MappersRegistry } from '@@core/utils/registry/mappings.registry';
import { MappersRegistry } from '@@core/@core-services/registries/mappers.registry';
import { getCountryCode, getCountryName } from '@@core/utils/types';

@Injectable()
export class AffinityCompanyMapper implements ICompanyMapper {
constructor(private mappersRegistry: MappersRegistry, private utils: Utils) {
this.mappersRegistry.registerService('crm', 'company', 'affinity', this);
}

async desunify(
source: UnifiedCompanyInput,
source: UnifiedCrmCompanyInput,
customFieldMappings?: {
slug: string;
remote_id: string;
Expand Down Expand Up @@ -44,29 +44,39 @@ export class AffinityCompanyMapper implements ICompanyMapper {

async unify(
source: AffinityCompanyOutput | AffinityCompanyOutput[],
connectionId: string,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): Promise<UnifiedCompanyOutput | UnifiedCompanyOutput[]> {
): Promise<UnifiedCrmCompanyOutput | UnifiedCrmCompanyOutput[]> {
if (!Array.isArray(source)) {
return this.mapSingleCompanyToUnified(source, customFieldMappings);
return this.mapSingleCompanyToUnified(
source,
connectionId,
customFieldMappings,
);
}
// Handling array of AffinityCompanyOutput
return Promise.all(
source.map((company) =>
this.mapSingleCompanyToUnified(company, customFieldMappings),
this.mapSingleCompanyToUnified(
company,
connectionId,
customFieldMappings,
),
),
);
}

private async mapSingleCompanyToUnified(
company: AffinityCompanyOutput,
connectionId: string,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): Promise<UnifiedCompanyOutput> {
): Promise<UnifiedCrmCompanyOutput> {
const field_mappings: { [key: string]: any } = {};
if (customFieldMappings) {
for (const mapping of customFieldMappings) {
Expand All @@ -76,8 +86,6 @@ export class AffinityCompanyMapper implements ICompanyMapper {

let opts: any = {};



return {
remote_id: company.id,
name: company.name,
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/crm/contact/contact.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AffinityContactMapper } from './services/affinity/mappers';
import { AffinityService } from './services/affinity';

import { MicrosoftdynamicssalesContactMapper } from './services/microsoftdynamicssales/mappers';
import { MicrosoftdynamicssalesService } from './services/microsoftdynamicssales';
Expand Down Expand Up @@ -50,6 +52,8 @@ import { SyncService } from './sync/sync.service';
ZohoContactMapper,
MicrosoftdynamicssalesService,
MicrosoftdynamicssalesContactMapper,
AffinityService,
AffinityContactMapper,
],
exports: [SyncService, ServiceRegistry, WebhookService],
})
Expand Down
34 changes: 9 additions & 25 deletions packages/api/src/crm/contact/services/affinity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { Injectable } from '@nestjs/common';
import { IContactService } from '@crm/contact/types';
import { CrmObject } from '@crm/@lib/@types';
import axios from 'axios';
import { PrismaService } from '@@core/prisma/prisma.service';
import { LoggerService } from '@@core/logger/logger.service';
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/encryption/encryption.service';
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { ApiResponse } from '@@core/utils/types';
import { ServiceRegistry } from '../registry.service';
import { AffinityContactInput, AffinityContactOutput } from './types';
import { SyncParam } from '@@core/utils/types/interface';

@Injectable()
export class AffinityService implements IContactService {
Expand Down Expand Up @@ -57,30 +58,21 @@ export class AffinityService implements IContactService {
statusCode: 201,
};
} catch (error) {
handle3rdPartyServiceError(
error,
this.logger,
'Affinity',
CrmObject.contact,
ActionType.POST,
);
throw error;
}
return;
}

async syncContacts(
linkedUserId: string,
): Promise<ApiResponse<AffinityContactOutput[]>> {
async sync(data: SyncParam): Promise<ApiResponse<AffinityContactOutput[]>> {
try {
const { linkedUserId } = data;

const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'affinity',
vertical: 'crm',
},
});
// console.log('Before Axios');
// console.log(this.cryptoService.decrypt(connection.access_token));

const resp = await axios.get(
`${connection.account_url}/persons`,
Expand All @@ -95,21 +87,13 @@ export class AffinityService implements IContactService {
},
);

console.log('After Axios');

return {
data: resp.data,
message: 'Affinity contacts retrieved',
statusCode: 200,
};
} catch (error) {
handle3rdPartyServiceError(
error,
this.logger,
'Affinity',
CrmObject.contact,
ActionType.GET,
);
throw error;
}
}
}
Loading

0 comments on commit 9e8abdd

Please sign in to comment.