From baf95fe27e971432f1816a41b05dfe2cc5bdca60 Mon Sep 17 00:00:00 2001 From: mit-27 <meetsuthar64@gmail.com> Date: Wed, 28 Aug 2024 21:40:17 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Tested=20all=20objects=20and=20fix?= =?UTF-8?q?=20bugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/microsoftdynamicssales/index.ts | 24 ++++++++++++---- .../services/microsoftdynamicssales/index.ts | 23 +++++++++++---- .../services/microsoftdynamicssales/index.ts | 28 +++++++++++++++---- .../microsoftdynamicssales/mappers.ts | 6 ++-- .../services/microsoftdynamicssales/index.ts | 20 +++++++++++-- .../services/microsoftdynamicssales/index.ts | 18 ++++++++++-- .../microsoftdynamicssales/mappers.ts | 4 +-- packages/shared/src/connectors/metadata.ts | 2 +- 8 files changed, 100 insertions(+), 25 deletions(-) diff --git a/packages/api/src/crm/company/services/microsoftdynamicssales/index.ts b/packages/api/src/crm/company/services/microsoftdynamicssales/index.ts index b04664a29..4ff25e07d 100644 --- a/packages/api/src/crm/company/services/microsoftdynamicssales/index.ts +++ b/packages/api/src/crm/company/services/microsoftdynamicssales/index.ts @@ -39,11 +39,9 @@ export class MicrosoftdynamicssalesService implements ICompanyService { }, }); - const resp = await axios.post( + const respToPost = await axios.post( `${connection.account_url}/api/data/v9.2/accounts`, - JSON.stringify({ - data: companyData, - }), + JSON.stringify(companyData), { headers: { Authorization: `Bearer ${this.cryptoService.decrypt( @@ -53,8 +51,24 @@ export class MicrosoftdynamicssalesService implements ICompanyService { }, }, ); + + const postCompanyId = respToPost.headers['location'].split("/").pop(); + // console.log(res.headers['location'].split('(')[1].split(')')[0]) + + const resp = await axios.get( + `${connection.account_url}/api/data/v9.2/${postCompanyId}`, + { + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${this.cryptoService.decrypt( + connection.access_token, + )}`, + }, + }, + ); + return { - data: resp.data.value, + data: resp.data, message: 'Microsoftdynamicssales company created', statusCode: 201, }; diff --git a/packages/api/src/crm/contact/services/microsoftdynamicssales/index.ts b/packages/api/src/crm/contact/services/microsoftdynamicssales/index.ts index f585e6966..caeeb9891 100644 --- a/packages/api/src/crm/contact/services/microsoftdynamicssales/index.ts +++ b/packages/api/src/crm/contact/services/microsoftdynamicssales/index.ts @@ -38,11 +38,9 @@ export class MicrosoftdynamicssalesService implements IContactService { }, }); - const resp = await axios.post( + const respToPost = await axios.post( `${connection.account_url}/api/data/v9.2/contacts`, - JSON.stringify({ - data: contactData, - }), + JSON.stringify(contactData), { headers: { 'Content-Type': 'application/json', @@ -52,8 +50,23 @@ export class MicrosoftdynamicssalesService implements IContactService { }, }, ); + + const postContactId = respToPost.headers['location'].split("/").pop(); + + const resp = await axios.get( + `${connection.account_url}/api/data/v9.2/${postContactId}`, + { + headers: { + accept: 'application/json', + 'Content-Type': 'application/json', + Authorization: `Bearer ${this.cryptoService.decrypt( + connection.access_token, + )}`, + }, + }, + ); return { - data: resp.data.value, + data: resp.data, message: 'microsoftdynamicssales contact created', statusCode: 201, }; diff --git a/packages/api/src/crm/deal/services/microsoftdynamicssales/index.ts b/packages/api/src/crm/deal/services/microsoftdynamicssales/index.ts index 12979121b..fd93e9d74 100644 --- a/packages/api/src/crm/deal/services/microsoftdynamicssales/index.ts +++ b/packages/api/src/crm/deal/services/microsoftdynamicssales/index.ts @@ -37,11 +37,9 @@ export class MicrosoftdynamicssalesService implements IDealService { }, }); - const resp = await axios.post( + const respToPost = await axios.post( `${connection.account_url}/api/data/v9.2/opportunities`, - JSON.stringify({ - data: dealData, - }), + JSON.stringify(dealData), { headers: { Authorization: `Bearer ${this.cryptoService.decrypt( @@ -51,8 +49,28 @@ export class MicrosoftdynamicssalesService implements IDealService { }, }, ); + + const postDealId = respToPost.headers['location'].split("/").pop(); + + const resp = await axios.get( + `${connection.account_url}/api/data/v9.2/${postDealId}`, + { + headers: { + accept: 'application/json', + 'Content-Type': 'application/json', + Authorization: `Bearer ${this.cryptoService.decrypt( + connection.access_token, + )}`, + }, + }, + ); + + + + + return { - data: resp.data.value, + data: resp.data, message: 'Microsoftdynamicssales deal created', statusCode: 201, }; diff --git a/packages/api/src/crm/deal/services/microsoftdynamicssales/mappers.ts b/packages/api/src/crm/deal/services/microsoftdynamicssales/mappers.ts index b8e64523d..a1ca99212 100644 --- a/packages/api/src/crm/deal/services/microsoftdynamicssales/mappers.ts +++ b/packages/api/src/crm/deal/services/microsoftdynamicssales/mappers.ts @@ -24,7 +24,7 @@ export class MicrosoftdynamicssalesDealMapper implements IDealMapper { const result: MicrosoftdynamicssalesDealInput = { name: source.name, description: source.description, - totalamount: source.amount + budgetamount: source.amount } @@ -103,9 +103,9 @@ export class MicrosoftdynamicssalesDealMapper implements IDealMapper { } } - if (deal._accountid_value) { + if (deal._customerid_value) { const company_id = await this.utils.getCompanyUuidFromRemoteId( - deal._accountid_value, + deal._customerid_value, connectionId ); if (company_id) { diff --git a/packages/api/src/crm/note/services/microsoftdynamicssales/index.ts b/packages/api/src/crm/note/services/microsoftdynamicssales/index.ts index 8a17ca8d7..475fba1e5 100644 --- a/packages/api/src/crm/note/services/microsoftdynamicssales/index.ts +++ b/packages/api/src/crm/note/services/microsoftdynamicssales/index.ts @@ -36,7 +36,7 @@ export class MicrosoftdynamicssalesService implements INoteService { vertical: 'crm', }, }); - const resp = await axios.post( + const respToPost = await axios.post( `${connection.account_url}/api/data/v9.2/annotations`, JSON.stringify(noteData), { @@ -48,8 +48,24 @@ export class MicrosoftdynamicssalesService implements INoteService { }, }, ); + + const postNoteId = respToPost.headers['location'].split("/").pop(); + + const resp = await axios.get( + `${connection.account_url}/api/data/v9.2/${postNoteId}` + , { + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${this.cryptoService.decrypt( + connection.access_token, + )}`, + }, + }); + + + return { - data: resp?.data.value, + data: resp?.data, message: 'Microsoftdynamicssales note created', statusCode: 201, }; diff --git a/packages/api/src/crm/task/services/microsoftdynamicssales/index.ts b/packages/api/src/crm/task/services/microsoftdynamicssales/index.ts index b536fc781..3888854b6 100644 --- a/packages/api/src/crm/task/services/microsoftdynamicssales/index.ts +++ b/packages/api/src/crm/task/services/microsoftdynamicssales/index.ts @@ -36,7 +36,7 @@ export class MicrosoftdynamicssalesService implements ITaskService { vertical: 'crm', }, }); - const resp = await axios.post( + const respToPost = await axios.post( `${connection.account_url}/api/data/v9.2/tasks`, JSON.stringify(taskData), { @@ -49,8 +49,22 @@ export class MicrosoftdynamicssalesService implements ITaskService { }, ); + const postTaskId = respToPost.headers['location'].split("/").pop(); + + const resp = await axios.get( + `${connection.account_url}/api/data/v9.2/${postTaskId}`, { + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${this.cryptoService.decrypt( + connection.access_token, + )}`, + }, + }); + + + return { - data: resp?.data?.value, + data: resp?.data, message: 'Microsoftdynamicssales task created', statusCode: 201, }; diff --git a/packages/api/src/crm/task/services/microsoftdynamicssales/mappers.ts b/packages/api/src/crm/task/services/microsoftdynamicssales/mappers.ts index 794a2e2fd..28020d540 100644 --- a/packages/api/src/crm/task/services/microsoftdynamicssales/mappers.ts +++ b/packages/api/src/crm/task/services/microsoftdynamicssales/mappers.ts @@ -31,11 +31,11 @@ export class MicrosoftdynamicssalesTaskMapper implements ITaskMapper { } if (source.due_date) { - result.scheduledend = source.due_date.toUTCString(); + result.scheduledend = new Date(source.due_date).toUTCString(); } if (source.finished_date) { - result.actualend = source.finished_date.toUTCString(); + result.actualend = new Date(source.finished_date).toUTCString(); } // User have to provide either company_id or deal_id which will be associated with current task diff --git a/packages/shared/src/connectors/metadata.ts b/packages/shared/src/connectors/metadata.ts index b31075d44..b5baeafac 100644 --- a/packages/shared/src/connectors/metadata.ts +++ b/packages/shared/src/connectors/metadata.ts @@ -3090,4 +3090,4 @@ export const CONNECTORS_METADATA: ProvidersConfig = { } }, } -}; \ No newline at end of file +};