Almost matching export.
This commit is contained in:
@@ -27,6 +27,7 @@ import DecodeVeh from "./decode-veh";
|
||||
import { DecodedVeh } from "./decode-veh.interface";
|
||||
import { DecodedEnv } from "./decode-env.interface";
|
||||
import DecodeEnv from "./decode-env";
|
||||
import fs from "fs";
|
||||
|
||||
async function ImportJob(filepath: string): Promise<void> {
|
||||
const parsedFilePath = path.parse(filepath);
|
||||
@@ -43,30 +44,51 @@ async function ImportJob(filepath: string): Promise<void> {
|
||||
const ad1: DecodedAd1 = await DecodeAD1(extensionlessFilePath);
|
||||
const ad2: DecodedAD2 = await DecodeAD2(extensionlessFilePath);
|
||||
const veh: DecodedVeh = await DecodeVeh(extensionlessFilePath);
|
||||
const lin: DecodedLin[] = await DecodeLin(extensionlessFilePath);
|
||||
const lin: DecodedLin = await DecodeLin(extensionlessFilePath);
|
||||
const pfh: DecodedPfh = await DecodePfh(extensionlessFilePath);
|
||||
const pfl: DecodedPfl = await DecodePfl(extensionlessFilePath);
|
||||
const pft: DecodedPft = await DecodePft(extensionlessFilePath);
|
||||
const pfm: DecodedPfm = await DecodePfm(extensionlessFilePath);
|
||||
const pfo: DecodedPfo = await DecodePfo(extensionlessFilePath); // TODO: This will be the `cieca_pfo` object
|
||||
const stl: DecodedStl[] = await DecodeStl(extensionlessFilePath); // TODO: This will be the `cieca_stl` object
|
||||
const stl: DecodedStl = await DecodeStl(extensionlessFilePath); // TODO: This will be the `cieca_stl` object
|
||||
const ttl: DecodedTtl = await DecodeTtl(extensionlessFilePath);
|
||||
const pfp: DecodedPfp = await DecodePfp(extensionlessFilePath);
|
||||
|
||||
log.debug("Job Object", {
|
||||
const jobObject = {
|
||||
...env,
|
||||
...ad1,
|
||||
...ad2,
|
||||
...veh,
|
||||
joblines: { data: lin },
|
||||
...lin,
|
||||
...pfh,
|
||||
cieca_pfl: pfl,
|
||||
cieca_pft: pft,
|
||||
materials: pfm,
|
||||
cieca_pfo: pfo,
|
||||
...pfl,
|
||||
...pft,
|
||||
...pfm,
|
||||
...pfo,
|
||||
...stl,
|
||||
...ttl,
|
||||
parts_tax_rates: pfp,
|
||||
...pfp,
|
||||
};
|
||||
|
||||
// Save jobObject to a timestamped JSON file
|
||||
const timestamp = new Date()
|
||||
.toISOString()
|
||||
.replace(/:/g, "-")
|
||||
.replace(/\..+/, "");
|
||||
const fileName = `job_${timestamp}_${parsedFilePath.name}.json`;
|
||||
const logsDir = path.join(process.cwd(), "logs");
|
||||
|
||||
// Create logs directory if it doesn't exist
|
||||
if (!fs.existsSync(logsDir)) {
|
||||
fs.mkdirSync(logsDir, { recursive: true });
|
||||
}
|
||||
|
||||
const filePath = path.join(logsDir, fileName);
|
||||
fs.writeFileSync(filePath, JSON.stringify(jobObject, null, 2), "utf8");
|
||||
log.info(`Job data saved to: ${filePath}`);
|
||||
|
||||
log.debug("Job Object", {
|
||||
jobObject,
|
||||
});
|
||||
} catch (error) {
|
||||
log.error("Error encountered while decoding job. ", errorTypeCheck(error));
|
||||
|
||||
Reference in New Issue
Block a user