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

@@ -136,9 +136,7 @@ async function QueryVendorRecord(oauthClient, qbo_realmId, req, bill) {
url: urlBuilder(
qbo_realmId,
"query",
`select *
From vendor
where DisplayName = '${StandardizeName(bill.vendor.name)}'`
`select * From vendor where DisplayName = '${StandardizeName(bill.vendor.name)}'`
),
method: "POST",
headers: {
@@ -150,21 +148,17 @@ async function QueryVendorRecord(oauthClient, qbo_realmId, req, bill) {
method: "POST",
name: "QueryVendorRecord",
billid: bill.id,
status: result.response?.status,
status: result.status,
bodyshopid: bill.job.shopid,
email: req.user.email
});
setNewRefreshToken(req.user.email, result);
return (
result.json &&
result.json.QueryResponse &&
result.json.QueryResponse.Vendor &&
result.json.QueryResponse.Vendor[0]
);
return result.json?.QueryResponse?.Vendor[0];
} catch (error) {
logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, {
error: (error && error.authResponse && error.authResponse.body) || (error && error.message),
method: "QueryVendorRecord"
method: "QueryVendorRecord",
error: error.message,
stack: error.stack
});
throw error;
}
@@ -188,16 +182,20 @@ async function InsertVendorRecord(oauthClient, qbo_realmId, req, bill) {
method: "POST",
name: "InsertVendorRecord",
billid: bill.id,
status: result.response?.status,
status: result.status,
bodyshopid: bill.job.shopid,
email: req.user.email
});
setNewRefreshToken(req.user.email, result);
return result && result.json && result.json.Vendor;
if (result.status >= 400) {
throw new Error(JSON.stringify(result.json.Fault));
}
if (result.status === 200) return result?.json;
} catch (error) {
logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, {
error: (error && error.authResponse && error.authResponse.body) || (error && error.message),
method: "InsertVendorRecord"
method: "InsertVendorRecord",
validationError: error.message,
stack: error.stack
});
throw error;
}
@@ -274,7 +272,6 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor, bodyshop)
)
})
.percentage(bill.federal_tax_rate)
.toFormat(DineroQbFormat)
});
}
@@ -332,18 +329,21 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor, bodyshop)
method: "POST",
name: "InsertBill",
billid: bill.id,
status: result.response?.status,
status: result.status,
bodyshopid: bill.job.shopid,
email: req.user.email
});
setNewRefreshToken(req.user.email, result);
return result && result.json && result.json.Bill;
if (result.status >= 400) {
throw new Error(JSON.stringify(result.json.Fault));
}
if (result.status === 200) return result?.json;
} catch (error) {
logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, {
error: error, //(error && error.authResponse && error.authResponse.body) || (error && error.message),
validationError: JSON.stringify(error?.response?.data),
method: "InsertBill",
validationError: error.message,
accountmeta: JSON.stringify({ accounts, taxCodes, classes }),
method: "InsertBill"
stack: error.stack
});
throw error;
}
@@ -403,9 +403,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid) {
url: urlBuilder(
qbo_realmId,
"query",
`select *
From Account
where AccountType in ('Cost of Goods Sold', 'Other Current Liability')`
`select * From Account where AccountType in ('Cost of Goods Sold', 'Other Current Liability')`
),
method: "POST",
headers: {
@@ -416,18 +414,13 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid) {
platform: "QBO",
method: "POST",
name: "QueryAccountType",
status: accounts.response?.status,
status: accounts.status,
bodyshopid,
email: req.user.email
});
setNewRefreshToken(req.user.email, accounts);
const taxCodes = await oauthClient.makeApiCall({
url: urlBuilder(
qbo_realmId,
"query",
`select *
From TaxCode`
),
url: urlBuilder(qbo_realmId, "query", `select * From TaxCode`),
method: "POST",
headers: {
"Content-Type": "application/json"
@@ -442,12 +435,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid) {
email: req.user.email
});
const classes = await oauthClient.makeApiCall({
url: urlBuilder(
qbo_realmId,
"query",
`select *
From Class`
),
url: urlBuilder(qbo_realmId, "query", `select * From Class`),
method: "POST",
headers: {
"Content-Type": "application/json"