Skip to content

Commit

Permalink
✨ Tested all objects and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
mit-27 committed Aug 29, 2024
1 parent 3352942 commit baf95fe
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
};
Expand Down
28 changes: 23 additions & 5 deletions packages/api/src/crm/deal/services/microsoftdynamicssales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class MicrosoftdynamicssalesDealMapper implements IDealMapper {
const result: MicrosoftdynamicssalesDealInput = {
name: source.name,
description: source.description,
totalamount: source.amount
budgetamount: source.amount
}


Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 18 additions & 2 deletions packages/api/src/crm/note/services/microsoftdynamicssales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
{
Expand All @@ -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,
};
Expand Down
18 changes: 16 additions & 2 deletions packages/api/src/crm/task/services/microsoftdynamicssales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
{
Expand All @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/connectors/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3090,4 +3090,4 @@ export const CONNECTORS_METADATA: ProvidersConfig = {
}
},
}
};
};

0 comments on commit baf95fe

Please sign in to comment.