Improve EMS interfaces and add LIN decoding.
This commit is contained in:
@@ -2,24 +2,24 @@ import { DBFFile } from "dbffile";
|
||||
import log from "electron-log/main";
|
||||
import _ from "lodash";
|
||||
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
||||
import { ParsedAD2 } from "./decode-ad2.interface";
|
||||
import { ParsedVeh } from "./decode-veh.interface";
|
||||
import { DecodedVeh, VehicleRecordInterface } from "./decode-veh.interface";
|
||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||
|
||||
const DecodeVeh = async (extensionlessFilePath: string): Promise<ParsedVeh> => {
|
||||
let dbf;
|
||||
const DecodeVeh = async (
|
||||
extensionlessFilePath: string
|
||||
): Promise<DecodedVeh> => {
|
||||
let dbf: DBFFile;
|
||||
try {
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}B.AD2`);
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}V.VEH`);
|
||||
} catch (error) {
|
||||
log.error("Error opening AD2 File.", error);
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}.AD2`);
|
||||
log.log("Found AD2 file using regular CIECA Id.");
|
||||
log.error("Error opening VEH File.", errorTypeCheck(error));
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}.VEH`);
|
||||
log.log("Found VEH file using regular CIECA Id.");
|
||||
}
|
||||
|
||||
if (!dbf) {
|
||||
log.error(`Could not find any AD2 files at ${extensionlessFilePath}`);
|
||||
return {
|
||||
id: 0,
|
||||
};
|
||||
log.error(`Could not find any VEH files at ${extensionlessFilePath}`);
|
||||
throw new Error(`Could not find any VEH files at ${extensionlessFilePath}`);
|
||||
}
|
||||
|
||||
const rawDBFRecord = await dbf.readRecords(1);
|
||||
@@ -27,122 +27,84 @@ const DecodeVeh = async (extensionlessFilePath: string): Promise<ParsedVeh> => {
|
||||
//AD2 will always have only 1 row.
|
||||
//Commented lines have been cross referenced with existing partner fields.
|
||||
|
||||
const rawAd2Data = deepLowerCaseKeys(
|
||||
const rawVehData: VehicleRecordInterface = deepLowerCaseKeys(
|
||||
_.pick(rawDBFRecord[0], [
|
||||
//TODO: Add typings for EMS File Formats.
|
||||
"CLMT_LN",
|
||||
"CLMT_FN",
|
||||
"CLMT_TITLE",
|
||||
"CLMT_CO_NM",
|
||||
"CLMT_ADDR1",
|
||||
"CLMT_ADDR2",
|
||||
"CLMT_CITY",
|
||||
"CLMT_ST",
|
||||
"CLMT_ZIP",
|
||||
"CLMT_CTRY",
|
||||
"CLMT_PH1",
|
||||
//"CLMT_PH1X",
|
||||
"CLMT_PH2",
|
||||
//"CLMT_PH2X",
|
||||
//"CLMT_FAX",
|
||||
//"CLMT_FAXX",
|
||||
"CLMT_EA",
|
||||
"EST_CO_ID",
|
||||
"EST_CO_NM",
|
||||
"EST_ADDR1",
|
||||
"EST_ADDR2",
|
||||
"EST_CITY",
|
||||
"EST_ST",
|
||||
"EST_ZIP",
|
||||
"EST_CTRY",
|
||||
"EST_PH1",
|
||||
//"EST_PH1X",
|
||||
//"EST_PH2",
|
||||
//"EST_PH2X",
|
||||
//"EST_FAX",
|
||||
//"EST_FAXX",
|
||||
"EST_CT_LN",
|
||||
"EST_CT_FN",
|
||||
"EST_EA",
|
||||
//"EST_LIC_NO",
|
||||
//"EST_FILENO",
|
||||
// "INSP_CT_LN",
|
||||
// "INSP_CT_FN",
|
||||
// "INSP_ADDR1",
|
||||
// "INSP_ADDR2",
|
||||
// "INSP_CITY",
|
||||
// "INSP_ST",
|
||||
// "INSP_ZIP",
|
||||
// "INSP_CTRY",
|
||||
// "INSP_PH1",
|
||||
// "INSP_PH1X",
|
||||
// "INSP_PH2",
|
||||
// "INSP_PH2X",
|
||||
// "INSP_FAX",
|
||||
// "INSP_FAXX",
|
||||
// "INSP_EA",
|
||||
// "INSP_CODE",
|
||||
// "INSP_DESC",
|
||||
"INSP_DATE", //RENAME TO date_estimated
|
||||
// "INSP_TIME",
|
||||
// "RF_CO_ID",
|
||||
// "RF_CO_NM",
|
||||
// "RF_ADDR1",
|
||||
// "RF_ADDR2",
|
||||
// "RF_CITY",
|
||||
// "RF_ST",
|
||||
// "RF_ZIP",
|
||||
// "RF_CTRY",
|
||||
// "RF_PH1",
|
||||
// "RF_PH1X",
|
||||
// "RF_PH2",
|
||||
// "RF_PH2X",
|
||||
// "RF_FAX",
|
||||
// "RF_FAXX",
|
||||
// "RF_CT_LN",
|
||||
// "RF_CT_FN",
|
||||
// "RF_EA",
|
||||
// "RF_TAX_ID",
|
||||
// "RF_LIC_NO",
|
||||
// "RF_BAR_NO",
|
||||
// "RO_IN_DATE",
|
||||
// "RO_IN_TIME",
|
||||
// "TAR_DATE",
|
||||
// "TAR_TIME",
|
||||
// "RO_CMPDATE",
|
||||
// "RO_CMPTIME",
|
||||
// "DATE_OUT",
|
||||
// "TIME_OUT",
|
||||
// "RF_ESTIMTR",
|
||||
// "MKTG_TYPE",
|
||||
// "MKTG_SRC",
|
||||
// "LOC_NM",
|
||||
// "LOC_ADDR1",
|
||||
// "LOC_ADDR2",
|
||||
// "LOC_CITY",
|
||||
// "LOC_ST",
|
||||
// "LOC_ZIP",
|
||||
// "LOC_CTRY",
|
||||
// "LOC_PH1",
|
||||
// "LOC_PH1X",
|
||||
// "LOC_PH2",
|
||||
// "LOC_PH2X",
|
||||
// "LOC_FAX",
|
||||
// "LOC_FAXX",
|
||||
// "LOC_CT_LN",
|
||||
// "LOC_CT_FN",
|
||||
// "LOC_TITLE",
|
||||
// "LOC_PH",
|
||||
// "LOC_PHX",
|
||||
// "LOC_EA",
|
||||
"IMPACT_1",
|
||||
"IMPACT_2",
|
||||
"DB_V_CODE",
|
||||
"PLATE_NO",
|
||||
"PLATE_ST",
|
||||
"V_VIN",
|
||||
"V_COND",
|
||||
"V_PROD_DT",
|
||||
"V_MODEL_YR",
|
||||
"V_MAKECODE",
|
||||
"V_MAKEDESC",
|
||||
"V_MODEL",
|
||||
"V_TYPE",
|
||||
"V_BSTYLE",
|
||||
"V_TRIMCODE",
|
||||
"TRIM_COLOR",
|
||||
"V_MLDGCODE",
|
||||
"V_ENGINE",
|
||||
"V_MILEAGE",
|
||||
"V_COLOR",
|
||||
"V_TONE",
|
||||
"V_STAGE",
|
||||
"PAINT_CD1",
|
||||
"PAINT_CD2",
|
||||
"PAINT_CD3",
|
||||
])
|
||||
);
|
||||
|
||||
//Apply business logic transfomrations.
|
||||
//We don't have an inspection date, we instead have `date_estimated`
|
||||
rawAd2Data.date_estimated = rawAd2Data.insp_date;
|
||||
delete rawAd2Data.insp_date;
|
||||
|
||||
return null;
|
||||
//An old error where the column had an extra underscore.
|
||||
rawVehData.v_make_desc = rawVehData.v_makedesc || rawVehData.v_makecode; //Fallback for US.
|
||||
delete rawVehData.v_makedesc;
|
||||
//An old error where the column had an extra underscore.
|
||||
rawVehData.v_model_desc = rawVehData.v_model;
|
||||
delete rawVehData.v_model;
|
||||
|
||||
//Consolidate Area of Damage.
|
||||
rawVehData.area_of_damage = {
|
||||
impact1: rawVehData.impact_1 ?? "",
|
||||
impact2: rawVehData.impact_2 ?? "",
|
||||
};
|
||||
delete rawVehData.impact_1;
|
||||
delete rawVehData.impact_2;
|
||||
|
||||
//Consolidate Paint Code information.
|
||||
rawVehData.paint_codes = {
|
||||
paint_cd1: rawVehData.paint_cd1 ?? "",
|
||||
paint_cd2: rawVehData.paint_cd2 ?? "",
|
||||
paint_cd3: rawVehData.paint_cd3 ?? "",
|
||||
};
|
||||
delete rawVehData.paint_cd1;
|
||||
delete rawVehData.paint_cd2;
|
||||
delete rawVehData.paint_cd3;
|
||||
|
||||
rawVehData.shopid = "UUID"; //TODO: Pass down the shopid for generation.
|
||||
|
||||
//Aggregate the vehicle data to be stamped onto the job record.
|
||||
const jobVehiclData = {
|
||||
plate_no: rawVehData.plate_no,
|
||||
plate_st: rawVehData.plate_st,
|
||||
v_vin: rawVehData.v_vin,
|
||||
v_model_yr: rawVehData.v_model_yr,
|
||||
v_make_desc: rawVehData.v_make_desc,
|
||||
v_model_desc: rawVehData.v_model_desc,
|
||||
v_color: rawVehData.v_color,
|
||||
kmin: rawVehData.v_mileage,
|
||||
};
|
||||
|
||||
return {
|
||||
...jobVehiclData,
|
||||
vehicle: {
|
||||
data: rawVehData,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default DecodeVeh;
|
||||
|
||||
Reference in New Issue
Block a user