IO-3498 Remove setNewRefreshToken and replace forEach with map
Signed-off-by: Allan Carr <allan@imexsystems.ca>
This commit is contained in:
@@ -57,14 +57,3 @@ exports.refresh = async (oauthClient, req) => {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.setNewRefreshToken = async (email, apiResponse) => {
|
||||
// Deprecated - tokens are now auto-updated in the oauthClient and the token isn't pushed back from QBO API calls anymore
|
||||
|
||||
// logger.log("qbo-token-updated", "DEBUG", email, null, {apiResponse: apiResponse});
|
||||
|
||||
// await client.request(queries.SET_QBO_AUTH, {
|
||||
// email,
|
||||
// qbo_auth: { ...apiResponse.token, createdAt: Date.now() }
|
||||
// });
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ const Dinero = require("dinero.js");
|
||||
const DineroQbFormat = require("../accounting-constants").DineroQbFormat;
|
||||
const apiGqlClient = require("../../graphql-client/graphql-client").client;
|
||||
const queries = require("../../graphql-client/queries");
|
||||
const { refresh: refreshOauthToken, setNewRefreshToken } = require("./qbo-callback");
|
||||
const { refresh: refreshOauthToken } = require("./qbo-callback");
|
||||
const OAuthClient = require("intuit-oauth");
|
||||
const moment = require("moment-timezone");
|
||||
const findTaxCode = require("../qb-receivables-lines").findTaxCode;
|
||||
@@ -150,7 +150,7 @@ async function QueryVendorRecord(oauthClient, qbo_realmId, req, bill) {
|
||||
bodyshopid: bill.job.shopid,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
|
||||
return result.json?.QueryResponse?.Vendor?.[0];
|
||||
} catch (error) {
|
||||
logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, {
|
||||
@@ -184,7 +184,7 @@ async function InsertVendorRecord(oauthClient, qbo_realmId, req, bill) {
|
||||
bodyshopid: bill.job.shopid,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
|
||||
if (result.status >= 400) {
|
||||
throw new Error(JSON.stringify(result.json.Fault));
|
||||
}
|
||||
@@ -335,7 +335,7 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor, bodyshop)
|
||||
bodyshopid: bill.job.shopid,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
|
||||
if (result.status >= 400) {
|
||||
throw new Error(JSON.stringify(result.json.Fault));
|
||||
}
|
||||
@@ -420,7 +420,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid) {
|
||||
bodyshopid,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, accounts);
|
||||
|
||||
const taxCodes = await oauthClient.makeApiCall({
|
||||
url: urlBuilder(qbo_realmId, "query", `select * From TaxCode`),
|
||||
method: "POST",
|
||||
@@ -451,20 +451,14 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid) {
|
||||
bodyshopid,
|
||||
email: req.user.email
|
||||
});
|
||||
const taxCodeMapping = {};
|
||||
taxCodes.json?.QueryResponse?.TaxCode?.forEach((t) => {
|
||||
taxCodeMapping[t.Name] = t.Id;
|
||||
});
|
||||
|
||||
const accountMapping = {};
|
||||
accounts.json?.QueryResponse?.Account?.forEach((t) => {
|
||||
accountMapping[t.FullyQualifiedName] = t.Id;
|
||||
});
|
||||
const taxCodeMapping = Object.fromEntries((taxCodes.json?.QueryResponse?.TaxCode || []).map((t) => [t.Name, t.Id]));
|
||||
|
||||
const classMapping = {};
|
||||
classes.json?.QueryResponse?.Class?.forEach((t) => {
|
||||
classMapping[t.Name] = t.Id;
|
||||
});
|
||||
const accountMapping = Object.fromEntries(
|
||||
(accounts.json?.QueryResponse?.Account || []).map((t) => [t.FullyQualifiedName, t.Id])
|
||||
);
|
||||
|
||||
const classMapping = Object.fromEntries((classes.json?.QueryResponse?.Class || []).map((c) => [c.Name, c.Id]));
|
||||
|
||||
return {
|
||||
accounts: accountMapping,
|
||||
|
||||
@@ -3,7 +3,7 @@ const Dinero = require("dinero.js");
|
||||
|
||||
const apiGqlClient = require("../../graphql-client/graphql-client").client;
|
||||
const queries = require("../../graphql-client/queries");
|
||||
const { refresh: refreshOauthToken, setNewRefreshToken } = require("./qbo-callback");
|
||||
const { refresh: refreshOauthToken } = require("./qbo-callback");
|
||||
const OAuthClient = require("intuit-oauth");
|
||||
const moment = require("moment-timezone");
|
||||
const {
|
||||
@@ -246,7 +246,7 @@ async function InsertPayment(oauthClient, qbo_realmId, req, payment, parentRef)
|
||||
bodyshopid: payment.job.shopid,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
|
||||
if (result.status >= 400) {
|
||||
throw new Error(JSON.stringify(result.json.Fault));
|
||||
}
|
||||
@@ -292,7 +292,6 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
||||
bodyshopid,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, paymentMethods);
|
||||
|
||||
// const classes = await oauthClient.makeApiCall({
|
||||
// url: urlBuilder(qbo_realmId, "query", `select * From Class`),
|
||||
@@ -302,11 +301,9 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
||||
// },
|
||||
// });
|
||||
|
||||
const paymentMethodMapping = {};
|
||||
|
||||
paymentMethods.json?.QueryResponse?.PaymentMethod?.forEach((t) => {
|
||||
paymentMethodMapping[t.Name] = t.Id;
|
||||
});
|
||||
const paymentMethodMapping = Object.fromEntries(
|
||||
(paymentMethods.json?.QueryResponse?.PaymentMethod || []).map((t) => [t.Name, t.Id])
|
||||
);
|
||||
|
||||
// const accountMapping = {};
|
||||
|
||||
@@ -355,18 +352,10 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
||||
bodyshopid,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, items);
|
||||
|
||||
const itemMapping = {};
|
||||
const taxCodeMapping = Object.fromEntries((taxCodes.json?.QueryResponse?.TaxCode || []).map((t) => [t.Name, t.Id]));
|
||||
|
||||
items.json?.QueryResponse?.Item?.forEach((t) => {
|
||||
itemMapping[t.Name] = t.Id;
|
||||
});
|
||||
const taxCodeMapping = {};
|
||||
|
||||
taxCodes.json?.QueryResponse?.TaxCode?.forEach((t) => {
|
||||
taxCodeMapping[t.Name] = t.Id;
|
||||
});
|
||||
const itemMapping = Object.fromEntries((items.json?.QueryResponse?.Item || []).map((item) => [item.Name, item.Id]));
|
||||
|
||||
ret = {
|
||||
...ret,
|
||||
@@ -456,7 +445,7 @@ async function InsertCreditMemo(oauthClient, qbo_realmId, req, payment, parentRe
|
||||
bodyshopid: req.user.bodyshopid,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
|
||||
if (result.status >= 400) {
|
||||
throw new Error(JSON.stringify(result.json.Fault));
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ const StandardizeName = require("./qbo").StandardizeName;
|
||||
const logger = require("../../utils/logger");
|
||||
const apiGqlClient = require("../../graphql-client/graphql-client").client;
|
||||
const queries = require("../../graphql-client/queries");
|
||||
const { refresh: refreshOauthToken, setNewRefreshToken } = require("./qbo-callback");
|
||||
const { refresh: refreshOauthToken } = require("./qbo-callback");
|
||||
const OAuthClient = require("intuit-oauth");
|
||||
const CreateInvoiceLines = require("../qb-receivables-lines").default;
|
||||
const moment = require("moment-timezone");
|
||||
@@ -233,7 +233,7 @@ async function QueryInsuranceCo(oauthClient, qbo_realmId, req, job) {
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
|
||||
return result.json?.QueryResponse?.Customer?.[0];
|
||||
} catch (error) {
|
||||
logger.log("qbo-receivables-error", "DEBUG", req.user.email, job.id, {
|
||||
@@ -283,7 +283,7 @@ async function InsertInsuranceCo(oauthClient, qbo_realmId, req, job, bodyshop) {
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
|
||||
return result.json?.Customer;
|
||||
} catch (error) {
|
||||
logger.log("qbo-receivables-error", "DEBUG", req.user.email, job.id, {
|
||||
@@ -318,7 +318,7 @@ async function QueryOwner(oauthClient, qbo_realmId, req, job, parentTierRef) {
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
|
||||
return result.json?.QueryResponse?.Customer?.find((x) => x.ParentRef?.value === parentTierRef?.Id);
|
||||
}
|
||||
|
||||
@@ -364,7 +364,7 @@ async function InsertOwner(oauthClient, qbo_realmId, req, job, isThreeTier, pare
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
|
||||
return result.json?.Customer;
|
||||
} catch (error) {
|
||||
logger.log("qbo-receivables-error", "DEBUG", req.user.email, job.id, {
|
||||
@@ -398,7 +398,7 @@ async function QueryJob(oauthClient, qbo_realmId, req, job, parentTierRef) {
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
|
||||
const customers = result.json?.QueryResponse?.Customer;
|
||||
return customers && (parentTierRef ? customers.find((x) => x.ParentRef.value === parentTierRef.Id) : customers[0]);
|
||||
}
|
||||
@@ -440,7 +440,7 @@ async function InsertJob(oauthClient, qbo_realmId, req, job, parentTierRef) {
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
|
||||
if (result.status >= 400) {
|
||||
throw new Error(JSON.stringify(result.json.Fault));
|
||||
}
|
||||
@@ -474,7 +474,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid, jobid) {
|
||||
jobid: jobid,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, items);
|
||||
|
||||
const taxCodes = await oauthClient.makeApiCall({
|
||||
url: urlBuilder(qbo_realmId, "query", `select * From TaxCode where active = true`),
|
||||
method: "POST",
|
||||
@@ -508,20 +508,11 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid, jobid) {
|
||||
email: req.user.email
|
||||
});
|
||||
|
||||
const taxCodeMapping = {};
|
||||
taxCodes.json?.QueryResponse?.TaxCode?.forEach((t) => {
|
||||
taxCodeMapping[t.Name] = t.Id;
|
||||
});
|
||||
const taxCodeMapping = Object.fromEntries((taxCodes.json?.QueryResponse?.TaxCode || []).map((t) => [t.Name, t.Id]));
|
||||
|
||||
const itemMapping = {};
|
||||
items.json?.QueryResponse?.Item?.forEach((t) => {
|
||||
itemMapping[t.Name] = t.Id;
|
||||
});
|
||||
const itemMapping = Object.fromEntries((items.json?.QueryResponse?.Item || []).map((item) => [item.Name, item.Id]));
|
||||
|
||||
const classMapping = {};
|
||||
classes.json?.QueryResponse?.Class?.forEach((t) => {
|
||||
classMapping[t.Name] = t.Id;
|
||||
});
|
||||
const classMapping = Object.fromEntries((classes.json?.QueryResponse?.Class || []).map((c) => [c.Name, c.Id]));
|
||||
|
||||
return {
|
||||
items: itemMapping,
|
||||
@@ -630,7 +621,7 @@ async function InsertInvoice(oauthClient, qbo_realmId, req, job, bodyshop, paren
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
|
||||
if (result.status >= 400) {
|
||||
throw new Error(JSON.stringify(result.json.Fault));
|
||||
}
|
||||
@@ -758,7 +749,7 @@ async function InsertInvoiceMultiPayerInvoice(
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
|
||||
if (result.status >= 400) {
|
||||
throw new Error(JSON.stringify(result.json.Fault));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user