IO-3498 Remove setNewRefreshToken and replace forEach with map
Signed-off-by: Allan Carr <allan@imexsystems.ca>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user