Fortellis logic deduplication

This commit is contained in:
Patrick Fic
2025-12-16 14:30:29 -08:00
parent 7ea81465ee
commit faf00ca845
6 changed files with 131 additions and 30 deletions

View File

@@ -312,6 +312,27 @@ function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function writeFortellisLogToFile(logObject) {
try {
const logsDir = path.join(process.cwd(), 'logs');
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
const filename = `fortellis-${timestamp}.json`;
const filepath = path.join(logsDir, filename);
console.log(`[writeFortellisLogToFile] Writing to: ${filepath}`);
console.log(`[writeFortellisLogToFile] process.cwd(): ${process.cwd()}`);
// Ensure logs directory exists
await fs.mkdir(logsDir, { recursive: true });
// Write log object to file
await fs.writeFile(filepath, JSON.stringify(logObject, null, 2), 'utf8');
console.log(`Fortellis log written to: ${filepath}`,);
} catch (err) {
console.error('Failed to write Fortellis log to file:', err);
}
}
async function WriteToIOEventLog({ apiName, type, fullUrl, bodyshopid, useremail, logger, socket }) {
try {
@@ -351,6 +372,7 @@ async function WriteToIOEventLog({ apiName, type, fullUrl, bodyshopid, useremail
}
}
const isProduction = process.env.NODE_ENV === "production";
//Get requests should have the trailing slash as they are used that way in the calls.
@@ -427,8 +449,10 @@ const FortellisActions = {
},
GetCOA: {
type: "get",
apiName: "CDK Drive Post Accounts GL WIP",
url: `https://api.fortellis.io/cdk-test/drive/chartofaccounts/v2/bulk/`,
apiName: "CDK Drive Get Chart of Accounts",
url: isProduction
? "https://api.fortellis.io/cdk/drive/chartofaccounts/v2/bulk"
: "https://api.fortellis.io/cdk-test/drive/chartofaccounts/v2/bulk",
waitForResult: true
},
StartWip: {