mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
fixed making revisions to Hubspot push up
This commit is contained in:
parent
dca1ce61cf
commit
ff2bfc67b2
2 changed files with 46 additions and 21 deletions
|
|
@ -227,6 +227,8 @@ export async function POST(
|
|||
measureName: r.measureName,
|
||||
approvedByEmail: r.approvedByEmail ?? "unknown",
|
||||
})),
|
||||
actedByEmail: session.user.email,
|
||||
actedAt: now,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,29 +68,52 @@ export async function syncContractorDocUploadToHubSpot(params: {
|
|||
export async function syncMeasureApprovalsToHubSpot(params: {
|
||||
hubspotDealId: string;
|
||||
approvedMeasures: Array<{ measureName: string; approvedByEmail: string }>;
|
||||
actedByEmail: string;
|
||||
actedAt: Date;
|
||||
}): Promise<void> {
|
||||
try {
|
||||
const client = getHubSpotClient();
|
||||
const dateStr = params.actedAt.toLocaleString("en-GB", {
|
||||
day: "2-digit",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
timeZone: "UTC",
|
||||
timeZoneName: "short",
|
||||
});
|
||||
|
||||
const log =
|
||||
params.approvedMeasures.length === 0
|
||||
? "No measures currently approved"
|
||||
: [
|
||||
"Approved measures:",
|
||||
...params.approvedMeasures.map(
|
||||
(m) => `- ${m.measureName} (approved by ${m.approvedByEmail})`,
|
||||
),
|
||||
].join("\n");
|
||||
const log =
|
||||
params.approvedMeasures.length === 0
|
||||
? `All measures unapproved by ${params.actedByEmail} on ${dateStr}`
|
||||
: [
|
||||
`Approved measures (updated by ${params.actedByEmail} on ${dateStr}):`,
|
||||
...params.approvedMeasures.map((m) => `- ${m.measureName}`),
|
||||
].join("\n");
|
||||
|
||||
await client.crm.deals.basicApi.update(params.hubspotDealId, {
|
||||
properties: {
|
||||
client_measures_approval_log: log,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("[HubSpot] syncMeasureApprovalsToHubSpot failed", {
|
||||
dealId: params.hubspotDealId,
|
||||
error: err,
|
||||
});
|
||||
const maxAttempts = 3;
|
||||
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
||||
try {
|
||||
const client = getHubSpotClient();
|
||||
await client.crm.deals.basicApi.update(params.hubspotDealId, {
|
||||
properties: {
|
||||
client_measures_approval_log: log,
|
||||
},
|
||||
});
|
||||
return;
|
||||
} catch (err) {
|
||||
const isReset =
|
||||
err instanceof Error &&
|
||||
"code" in err &&
|
||||
(err as NodeJS.ErrnoException).code === "ECONNRESET";
|
||||
if (isReset && attempt < maxAttempts) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 200 * attempt));
|
||||
continue;
|
||||
}
|
||||
console.error("[HubSpot] syncMeasureApprovalsToHubSpot failed", {
|
||||
dealId: params.hubspotDealId,
|
||||
attempt,
|
||||
error: err,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue