Skip to content

Commit

Permalink
✨ Add Microsoft Dynamics 365 Sales CRM {Company, Contact, Deal, Note,…
Browse files Browse the repository at this point in the history
… Task, User} objects
  • Loading branch information
mit-27 committed Aug 26, 2024
1 parent 66be9ac commit cc1f8ef
Show file tree
Hide file tree
Showing 31 changed files with 2,398 additions and 22 deletions.
3 changes: 2 additions & 1 deletion packages/api/scripts/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ CREATE TABLE connector_sets
ecom_amazon boolean NULL,
ecom_squarespace boolean NULL,
ats_ashby boolean NULL,
CONSTRAINT PK_project_connector PRIMARY KEY ( id_connector_set )
crm_microsoftdynamicssales 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) VALUES
('1709da40-17f7-4d3a-93a0-96dc5da6ddd7', 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),
('aed0f856-f802-4a79-8640-66d441581a99', 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) VALUES
('1709da40-17f7-4d3a-93a0-96dc5da6ddd7', 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),
('aed0f856-f802-4a79-8640-66d441581a99', 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
36 changes: 24 additions & 12 deletions packages/api/src/@core/utils/types/original/original.crm.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
import { MicrosoftdynamicssalesTaskInput, MicrosoftdynamicssalesTaskOutput } from '@crm/task/services/microsoftdynamicssales/types';

import { MicrosoftdynamicssalesNoteInput, MicrosoftdynamicssalesNoteOutput } from '@crm/note/services/microsoftdynamicssales/types';

import { MicrosoftdynamicssalesDealInput, MicrosoftdynamicssalesDealOutput } from '@crm/deal/services/microsoftdynamicssales/types';

import { MicrosoftdynamicssalesContactInput, MicrosoftdynamicssalesContactOutput } from '@crm/contact/services/microsoftdynamicssales/types';

import { MicrosoftdynamicssalesCompanyInput, MicrosoftdynamicssalesCompanyOutput } from '@crm/company/services/microsoftdynamicssales/types';

import { MicrosoftdynamicssalesUserInput, MicrosoftdynamicssalesUserOutput } from '@crm/user/services/microsoftdynamicssales/types';

import { AttioCompanyOutput } from '@crm/company/services/attio/types';
import { HubspotCompanyOutput } from '@crm/company/services/hubspot/types';
import { PipedriveCompanyOutput } from '@crm/company/services/pipedrive/types';
Expand Down Expand Up @@ -148,7 +160,7 @@ export type OriginalContactInput =
| ZendeskContactInput
| PipedriveContactInput
| AttioContactInput
| CloseContactInput;
| CloseContactInput | MicrosoftdynamicssalesContactInput;

/* deal */
export type OriginalDealInput =
Expand All @@ -157,7 +169,7 @@ export type OriginalDealInput =
| ZendeskDealOutput
| PipedriveDealOutput
| CloseDealOutput
| AttioDealInput;
| AttioDealInput | MicrosoftdynamicssalesDealInput;

/* company */
export type OriginalCompanyInput =
Expand All @@ -166,7 +178,7 @@ export type OriginalCompanyInput =
| ZendeskCompanyOutput
| PipedriveCompanyOutput
| AttioCompanyOutput
| CloseCompanyOutput;
| CloseCompanyOutput | MicrosoftdynamicssalesCompanyInput;

/* engagement */
export type OriginalEngagementInput =
Expand All @@ -183,7 +195,7 @@ export type OriginalNoteInput =
| ZendeskNoteInput
| PipedriveNoteInput
| CloseNoteInput
| AttioNoteInput;
| AttioNoteInput | MicrosoftdynamicssalesNoteInput;

/* task */
export type OriginalTaskInput =
Expand All @@ -192,7 +204,7 @@ export type OriginalTaskInput =
| ZendeskTaskInput
| PipedriveTaskInput
| CloseTaskInput
| AttioTaskInput;
| AttioTaskInput | MicrosoftdynamicssalesTaskInput;

/* stage */
export type OriginalStageInput =
Expand All @@ -210,7 +222,7 @@ export type OriginalUserInput =
| ZohoUserInput
| ZendeskUserInput
| PipedriveUserInput
| CloseUserOutput;
| CloseUserOutput | MicrosoftdynamicssalesUserInput;

export type CrmObjectInput =
| OriginalContactInput
Expand All @@ -230,7 +242,7 @@ export type OriginalContactOutput =
| ZendeskContactOutput
| PipedriveContactOutput
| AttioContactOutput
| CloseContactOutput;
| CloseContactOutput | MicrosoftdynamicssalesContactOutput;

/* deal */
export type OriginalDealOutput =
Expand All @@ -239,7 +251,7 @@ export type OriginalDealOutput =
| ZendeskDealOutput
| PipedriveDealOutput
| CloseDealOutput
| AttioDealOutput;
| AttioDealOutput | MicrosoftdynamicssalesDealOutput;

/* company */
export type OriginalCompanyOutput =
Expand All @@ -248,7 +260,7 @@ export type OriginalCompanyOutput =
| ZendeskCompanyOutput
| PipedriveCompanyOutput
| AttioCompanyOutput
| CloseCompanyOutput;
| CloseCompanyOutput | MicrosoftdynamicssalesCompanyOutput;

/* engagement */
export type OriginalEngagementOutput =
Expand All @@ -265,7 +277,7 @@ export type OriginalNoteOutput =
| ZendeskNoteOutput
| PipedriveNoteOutput
| CloseNoteOutput
| AttioNoteOutput;
| AttioNoteOutput | MicrosoftdynamicssalesNoteOutput;

/* task */
export type OriginalTaskOutput =
Expand All @@ -274,7 +286,7 @@ export type OriginalTaskOutput =
| ZendeskTaskOutput
| PipedriveTaskOutput
| CloseTaskOutput
| AttioTaskOutput;
| AttioTaskOutput | MicrosoftdynamicssalesTaskOutput;

/* stage */
export type OriginalStageOutput =
Expand All @@ -293,7 +305,7 @@ export type OriginalUserOutput =
| ZendeskUserOutput
| PipedriveUserOutput
| CloseUserInput
| AttioUserOutput;
| AttioUserOutput | MicrosoftdynamicssalesUserOutput;

export type CrmObjectOutput =
| OriginalContactOutput
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 { MicrosoftdynamicssalesCompanyMapper } from './services/microsoftdynamicssales/mappers';
import { MicrosoftdynamicssalesService } from './services/microsoftdynamicssales';
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';
Expand Down Expand Up @@ -52,6 +54,8 @@ import { SyncService } from './sync/sync.service';
PipedriveCompanyMapper,
ZendeskCompanyMapper,
ZohoCompanyMapper,
MicrosoftdynamicssalesService,
MicrosoftdynamicssalesCompanyMapper,
],
exports: [SyncService, ServiceRegistry, WebhookService],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { Injectable } from '@nestjs/common';
import axios from 'axios';
import { CrmObject } from '@crm/@lib/@types';
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 { ApiResponse } from '@@core/utils/types';
import { ICompanyService } from '@crm/company/types';
import { ServiceRegistry } from '../registry.service';
import { MicrosoftdynamicssalesCompanyInput, MicrosoftdynamicssalesCompanyOutput } from './types';
import { SyncParam } from '@@core/utils/types/interface';
import { OriginalCompanyOutput } from '@@core/utils/types/original/original.crm';

@Injectable()
export class MicrosoftdynamicssalesService implements ICompanyService {
constructor(
private prisma: PrismaService,
private logger: LoggerService,
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
) {
this.logger.setContext(
CrmObject.company.toUpperCase() + ':' + MicrosoftdynamicssalesService.name,
);
this.registry.registerService('microsoftdynamicssales', this);
}
async addCompany(
companyData: MicrosoftdynamicssalesCompanyInput,
linkedUserId: string,
): Promise<ApiResponse<MicrosoftdynamicssalesCompanyOutput>> {
try {
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'microsoftdynamicssales',
vertical: 'crm',
},
});

const resp = await axios.post(
`${connection.account_url}/api/data/v9.2/accounts`,
JSON.stringify({
data: companyData,
}),
{
headers: {
Authorization: `Bearer ${this.cryptoService.decrypt(
connection.access_token,
)}`,
'Content-Type': 'application/json',
},
},
);
return {
data: resp.data.value,
message: 'Microsoftdynamicssales company created',
statusCode: 201,
};
} catch (error) {
throw error;
}
}

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

const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'microsoftdynamicssales',
vertical: 'crm',
},
});
const resp = await axios.get(
`${connection.account_url}/api/data/v9.2/accounts`,
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.cryptoService.decrypt(
connection.access_token,
)}`,
},
},
);
return {
data: resp.data.value,
message: 'Microsoftdynamicssales companies retrieved',
statusCode: 200,
};
} catch (error) {
throw error;
}
}
}
Loading

0 comments on commit cc1f8ef

Please sign in to comment.