Files
bodyshop-desktop/src/main/decoder/decoder.ts
2025-03-17 15:45:45 -07:00

35 lines
1.4 KiB
TypeScript

import log from "electron-log/main";
import path from "path";
import errorTypeCheck from "../../util/errorTypeCheck";
import DecodeAD1 from "./decode-ad1";
import { DecodedAd1 } from "./decode-ad1.interface";
import DecodeAD2 from "./decode-ad2";
import { DecodedAD2 } from "./decode-ad2.interface";
import DecodeLin from "./decode-lin";
import { DecodedLin } from "./decode-lin.interface";
import DecodeVeh from "./decode-veh";
import { DecodedVeh } from "./decode-veh.interface";
async function ImportJob(filepath: string): Promise<void> {
const parsedFilePath = path.parse(filepath);
const extensionlessFilePath = path.join(
parsedFilePath.dir,
parsedFilePath.name
);
log.debug("Importing Job", extensionlessFilePath);
try {
//The below all end up returning parts of the job object.
//Some of them return additional info - e.g. owner or vehicle record data at both the job and corresponding table level.
const ad1: DecodedAd1 = await DecodeAD1(extensionlessFilePath);
const ad2: DecodedAD2 = await DecodeAD2(extensionlessFilePath);
const veh: DecodedVeh = await DecodeVeh(extensionlessFilePath);
const lin: DecodedLin[] = await DecodeLin(extensionlessFilePath);
log.debug("EMS Object", { ad1, ad2, veh, lin });
} catch (error) {
log.error("Error encountered while decoding job. ", errorTypeCheck(error));
}
}
export default ImportJob;