Merge remote-tracking branch 'origin/feature/IO-3498-QBO-Auth-Token' into hotfix/2026-01-15
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -174,7 +174,6 @@ exports.default = async (req, res) => {
|
||||
|
||||
res.status(200).json(ret);
|
||||
} catch (error) {
|
||||
//console.log(error);
|
||||
logger.log("qbo-payment-create-error", "ERROR", req.user.email, null, {
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
@@ -253,16 +252,20 @@ async function InsertPayment(oauthClient, qbo_realmId, req, payment, parentRef)
|
||||
method: "POST",
|
||||
name: "InsertPayment",
|
||||
paymentid: payment.id,
|
||||
status: result.response?.status,
|
||||
status: result.status,
|
||||
bodyshopid: payment.job.shopid,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
return result && result.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, payment.id, {
|
||||
error: error && error.message,
|
||||
method: "InsertPayment"
|
||||
method: "InsertPayment",
|
||||
validationError: error.message,
|
||||
stack: error.stack
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
@@ -273,9 +276,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select *
|
||||
From Invoice
|
||||
where DocNumber like '${ro_number}%'`
|
||||
`select * From Invoice where DocNumber like '${ro_number}%'`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -286,8 +287,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
||||
platform: "QBO",
|
||||
method: "POST",
|
||||
name: "QueryInvoice",
|
||||
|
||||
status: invoice.response?.status,
|
||||
status: invoice.status,
|
||||
bodyshopid,
|
||||
email: req.user.email
|
||||
});
|
||||
@@ -295,8 +295,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select *
|
||||
From PaymentMethod`
|
||||
`select * From PaymentMethod`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -307,7 +306,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
||||
platform: "QBO",
|
||||
method: "POST",
|
||||
name: "QueryPaymentMethod",
|
||||
status: paymentMethods.response?.status,
|
||||
status: paymentMethods.status,
|
||||
bodyshopid,
|
||||
email: req.user.email
|
||||
});
|
||||
@@ -351,8 +350,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select *
|
||||
From TaxCode`
|
||||
`select * From TaxCode`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -363,8 +361,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
||||
platform: "QBO",
|
||||
method: "POST",
|
||||
name: "QueryTaxCode",
|
||||
|
||||
status: taxCodes.response?.status,
|
||||
status: taxCodes.status,
|
||||
bodyshopid,
|
||||
email: req.user.email
|
||||
});
|
||||
@@ -372,8 +369,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select *
|
||||
From Item`
|
||||
`select * From Item`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -384,7 +380,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
||||
platform: "QBO",
|
||||
method: "POST",
|
||||
name: "QueryItems",
|
||||
status: items.response?.status,
|
||||
status: items.status,
|
||||
bodyshopid,
|
||||
email: req.user.email
|
||||
});
|
||||
@@ -494,18 +490,21 @@ async function InsertCreditMemo(oauthClient, qbo_realmId, req, payment, parentRe
|
||||
method: "POST",
|
||||
name: "InsertCreditMemo",
|
||||
paymentid: payment.id,
|
||||
status: result.response?.status,
|
||||
status: result.status,
|
||||
bodyshopid: req.user.bodyshopid,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
return result && result.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, payment.id, {
|
||||
error: error,
|
||||
validationError: JSON.stringify(error?.response?.data),
|
||||
method: "InsertCreditMemo",
|
||||
validationError: error.message,
|
||||
accountmeta: JSON.stringify({ items, taxCodes }),
|
||||
method: "InsertCreditMemo"
|
||||
stack: error.stack
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user