-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:Add integration with Close CRM #484
Changes from 1 commit
f88d7e4
dcba333
799529b
07eaccf
a92304e
6a04bf2
e0c7798
6f22484
413c5bc
7974e13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,32 +20,33 @@ export class CloseDealMapper implements IDealMapper { | |
remote_id: string; | ||
}[], | ||
): Promise<CloseDealInput> { | ||
const emptyPromise = new Promise<string>((resolve) => { | ||
return resolve(''); | ||
}); | ||
const promises = []; | ||
|
||
promises.push( | ||
source.company_id | ||
? await this.utils.getRemoteIdFromCompanyUuid(source.company_id) | ||
: emptyPromise, | ||
); | ||
|
||
promises.push( | ||
source.stage_id | ||
? await this.utils.getStageIdFromStageUuid(source.stage_id) | ||
: emptyPromise, | ||
); | ||
const [lead_id, status_id] = await Promise.all(promises); | ||
const result: CloseDealInput = { | ||
note: source.description, | ||
confidence: 0, | ||
value: source.amount || 0, | ||
value_period: 'one_time', | ||
value_period: 'monthly', | ||
custom: {}, | ||
lead_id: '', | ||
lead_id, | ||
status_id, | ||
}; | ||
|
||
if (source.company_id) { | ||
const lead_id = await this.utils.getRemoteIdFromCompanyUuid( | ||
source.company_id, | ||
); | ||
if (lead_id) { | ||
result.lead_id = lead_id; | ||
} | ||
} | ||
if (source.stage_id) { | ||
const stage_id = await this.utils.getStageIdFromStageUuid( | ||
source.company_id, | ||
); | ||
if (stage_id) { | ||
result.status_id = stage_id; | ||
} | ||
} | ||
|
||
if (customFieldMappings && source.field_mappings) { | ||
for (const [k, v] of Object.entries(source.field_mappings)) { | ||
const mapping = customFieldMappings.find( | ||
|
@@ -91,51 +92,38 @@ export class CloseDealMapper implements IDealMapper { | |
} | ||
} | ||
|
||
let opts: any = {}; | ||
if (deal.user_id) { | ||
const owner_id = await this.utils.getUserUuidFromRemoteId( | ||
deal.user_id, | ||
'close', | ||
); | ||
if (owner_id) { | ||
opts = { | ||
...opts, | ||
user_id: owner_id, | ||
}; | ||
} | ||
} | ||
if (deal.lead_id) { | ||
const lead_id = await this.utils.getCompanyUuidFromRemoteId( | ||
deal.lead_id, | ||
'close', | ||
); | ||
if (lead_id) { | ||
opts = { | ||
...opts, | ||
company_id: lead_id, | ||
}; | ||
} | ||
} | ||
if (deal.contact_id) { | ||
const contact_id = await this.utils.getContactUuidFromRemoteId( | ||
deal.contact_id, | ||
'close', | ||
); | ||
if (contact_id) { | ||
opts = { | ||
...opts, | ||
contact_id: contact_id, | ||
}; | ||
} | ||
} | ||
const emptyPromise = new Promise<string>((resolve) => { | ||
return resolve(''); | ||
}); | ||
const promises = []; | ||
|
||
promises.push( | ||
deal.user_id | ||
? await this.utils.getUserUuidFromRemoteId(deal.user_id, 'close') | ||
: emptyPromise, | ||
); | ||
promises.push( | ||
deal.lead_id | ||
? await this.utils.getCompanyUuidFromRemoteId(deal.lead_id, 'close') | ||
: emptyPromise, | ||
); | ||
promises.push( | ||
deal.status_id | ||
? await this.utils.getCompanyUuidFromRemoteId(deal.status_id, 'close') | ||
: emptyPromise, | ||
); | ||
|
||
const [user_id, company_id, stage_id] = await Promise.all(promises); | ||
|
||
return { | ||
remote_id: deal.id, | ||
name: deal.note, | ||
description: deal.note, // Placeholder if there's no direct mapping | ||
amount: parseFloat(`${deal.value || 0}`), | ||
//TODO; stage_id: deal.properties.dealstage, | ||
field_mappings, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove or implement the TODO comment for |
||
...opts, | ||
user_id, | ||
company_id, | ||
stage_id, | ||
}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ export class CloseService implements IStageService { | |
const res = await this.prisma.crm_deals.findUnique({ | ||
where: { id_crm_deal: deal_id }, | ||
}); | ||
const baseURL = `${connection.account_url}/activity/status_change/opportunity/?opportunity_id=${res.remote_id}`; | ||
const baseURL = `${connection.account_url}/activity/status_change/opportunity/?opportunity_id=${res?.remote_id}`; | ||
|
||
const resp = await axios.get(baseURL, { | ||
headers: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return a meaningful error response or status code in the catch block to inform the caller of the failure. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding error handling for the asynchronous operations to ensure robustness.