IO-3498 QBO Changes due to oauthClient response change

Signed-off-by: Allan Carr <allan@imexsystems.ca>
This commit is contained in:
Allan Carr
2026-01-15 16:10:42 -08:00
parent 997aebddb0
commit f40af8cba4
3 changed files with 87 additions and 97 deletions

View File

@@ -71,7 +71,7 @@ exports.default = async (req, res) => {
if (isThreeTier || (!isThreeTier && twoTierPref === "name")) {
//Insert the name/owner and account for whether the source should be the ins co in 3 tier..
ownerCustomerTier = await QueryOwner(oauthClient, qbo_realmId, req, job, isThreeTier, insCoCustomerTier);
ownerCustomerTier = await QueryOwner(oauthClient, qbo_realmId, req, job, insCoCustomerTier);
//Query for the owner itself.
if (!ownerCustomerTier) {
ownerCustomerTier = await InsertOwner(oauthClient, qbo_realmId, req, job, isThreeTier, insCoCustomerTier);
@@ -108,7 +108,7 @@ exports.default = async (req, res) => {
//do the thing.
//Create the source level.
let insCoCustomerTier, ownerCustomerTier, jobTier;
let insCoCustomerTier, jobTier;
//Insert the insurance company tier.
//Query for top level customer, the insurance company name.
@@ -150,7 +150,7 @@ exports.default = async (req, res) => {
// //No error. Mark the job exported & insert export log.
if (elgen) {
const result = await client
await client
.setHeaders({ Authorization: BearerToken })
.request(queries.QBO_MARK_JOB_EXPORTED, {
jobId: job.id,
@@ -187,7 +187,7 @@ exports.default = async (req, res) => {
});
//Add the export log error.
if (elgen) {
const result = await client.setHeaders({ Authorization: BearerToken }).request(queries.INSERT_EXPORT_LOG, {
await client.setHeaders({ Authorization: BearerToken }).request(queries.INSERT_EXPORT_LOG, {
logs: [
{
bodyshopid: bodyshop.id,
@@ -221,10 +221,7 @@ async function QueryInsuranceCo(oauthClient, qbo_realmId, req, job) {
url: urlBuilder(
qbo_realmId,
"query",
`select *
From Customer
where DisplayName = '${StandardizeName(job.ins_co_nm.trim())}'
and Active = true`
`select * From Customer where DisplayName = '${StandardizeName(job.ins_co_nm.trim())}' and Active = true`
),
method: "POST",
headers: {
@@ -308,16 +305,13 @@ async function InsertInsuranceCo(oauthClient, qbo_realmId, req, job, bodyshop) {
exports.InsertInsuranceCo = InsertInsuranceCo;
async function QueryOwner(oauthClient, qbo_realmId, req, job, isThreeTier, parentTierRef) {
async function QueryOwner(oauthClient, qbo_realmId, req, job, parentTierRef) {
const ownerName = generateOwnerTier(job, true, null);
const result = await oauthClient.makeApiCall({
url: urlBuilder(
qbo_realmId,
"query",
`select *
From Customer
where DisplayName = '${StandardizeName(ownerName)}'
and Active = true`
`select * From Customer where DisplayName = '${StandardizeName(ownerName)}' and Active = true`
),
method: "POST",
headers: {
@@ -402,10 +396,7 @@ async function QueryJob(oauthClient, qbo_realmId, req, job, parentTierRef) {
url: urlBuilder(
qbo_realmId,
"query",
`select *
From Customer
where DisplayName = '${job.ro_number}'
and Active = true`
`select * From Customer where DisplayName = '${job.ro_number}' and Active = true`
),
method: "POST",
headers: {
@@ -464,17 +455,21 @@ async function InsertJob(oauthClient, qbo_realmId, req, job, parentTierRef) {
platform: "QBO",
method: "POST",
name: "InsertCustomer",
status: result.response?.status,
status: result.status,
bodyshopid: job.shopid,
jobid: job.id,
email: req.user.email
});
setNewRefreshToken(req.user.email, result);
return result && result.json.Customer;
if (result.status >= 400) {
throw new Error(JSON.stringify(result.json.Fault));
}
if (result.status === 200) return result?.json;
} catch (error) {
logger.log("qbo-receivables-error", "DEBUG", req.user.email, job.id, {
error,
method: "InsertOwner"
method: "InsertOwner",
validationError: error.message,
stack: error.stack
});
throw error;
}
@@ -500,7 +495,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid, jobid) {
platform: "QBO",
method: "POST",
name: "QueryItems",
status: items.response?.status,
status: items.status,
bodyshopid,
jobid: jobid,
email: req.user.email
@@ -523,7 +518,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid, jobid) {
platform: "QBO",
method: "POST",
name: "QueryTaxCodes",
status: taxCodes.response?.status,
status: taxCodes.status,
bodyshopid,
jobid: jobid,
email: req.user.email
@@ -544,7 +539,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid, jobid) {
platform: "QBO",
method: "POST",
name: "QueryClasses",
status: classes.response?.status,
status: classes.status,
bodyshopid,
jobid: jobid,
email: req.user.email
@@ -679,19 +674,22 @@ async function InsertInvoice(oauthClient, qbo_realmId, req, job, bodyshop, paren
platform: "QBO",
method: "POST",
name: "InsertInvoice",
status: result.response?.status,
status: result.status,
bodyshopid: job.shopid,
jobid: job.id,
email: req.user.email
});
setNewRefreshToken(req.user.email, result);
return result && result.json && result.json.Invoice;
if (result.status >= 400) {
throw new Error(JSON.stringify(result.json.Fault));
}
if (result.status === 200) return result?.json;
} catch (error) {
logger.log("qbo-receivables-error", "DEBUG", req.user.email, job.id, {
error,
method: "InsertInvoice",
validationError: JSON.stringify(error?.response?.data),
accountmeta: JSON.stringify({ items, taxCodes, classes })
validationError: error.message,
accountmeta: JSON.stringify({ items, taxCodes, classes }),
stack: error.stack
});
throw error;
}
@@ -805,18 +803,23 @@ async function InsertInvoiceMultiPayerInvoice(
logger.LogIntegrationCall({
platform: "QBO",
method: "POST",
name: "InsertInvoice",
status: result.response?.status,
name: "InsertInvoiceMultiPayerInvoice",
status: result.status,
bodyshopid: job.shopid,
jobid: job.id,
email: req.user.email
});
setNewRefreshToken(req.user.email, result);
return result && result.json && result.json.Invoice;
if (result.status >= 400) {
throw new Error(JSON.stringify(result.json.Fault));
}
if (result.status === 200) return result?.json;
} catch (error) {
logger.log("qbo-receivables-error", "DEBUG", req.user.email, job.id, {
error,
method: "InsertOwner"
method: "InsertInvoiceMultiPayerInvoice",
validationError: error.message,
accountmeta: JSON.stringify({ items, taxCodes, classes }),
stack: error.stack
});
throw error;
}