Succesful test imports to IO.

This commit is contained in:
Patrick Fic
2025-03-21 15:17:00 -07:00
parent d14137dc44
commit b312532121
8 changed files with 165 additions and 65 deletions

View File

@@ -5,6 +5,7 @@ import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
import { DecodedVeh, VehicleRecordInterface } from "./decode-veh.interface";
import errorTypeCheck from "../../util/errorTypeCheck";
import store from "../store/store";
import typeCaster from "../../util/typeCaster";
const DecodeVeh = async (
extensionlessFilePath: string,
@@ -28,35 +29,43 @@ const DecodeVeh = async (
//AD2 will always have only 1 row.
//Commented lines have been cross referenced with existing partner fields.
const rawVehData: VehicleRecordInterface = deepLowerCaseKeys(
_.pick(rawDBFRecord[0], [
//TODO: Add typings for EMS File Formats.
"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",
]),
//typeCaster is required as the previous partner sent some of these values toString, and the database was made accordingly rather than keeping their original type.
//Alternative is to change the database schema to match the original type.
const rawVehData: VehicleRecordInterface = typeCaster(
deepLowerCaseKeys(
_.pick(rawDBFRecord[0], [
//TODO: Add typings for EMS File Formats.
"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",
]),
),
{
v_tone: "string",
v_stage: "string",
},
);
//Apply business logic transfomrations.
@@ -69,13 +78,16 @@ const DecodeVeh = async (
delete rawVehData.v_model;
//Consolidate Area of Damage.
rawVehData.area_of_damage = {
const area_of_damage = {
impact1: rawVehData.impact_1 ?? "",
impact2: rawVehData.impact_2 ?? "",
};
delete rawVehData.impact_1;
delete rawVehData.impact_2;
const kmin = rawVehData.v_mileage ?? 0;
delete rawVehData.v_mileage;
//Consolidate Paint Code information.
rawVehData.v_paint_codes = {
paint_cd1: rawVehData.paint_cd1 ?? "",
@@ -97,8 +109,8 @@ const DecodeVeh = async (
v_make_desc: rawVehData.v_make_desc,
v_model_desc: rawVehData.v_model_desc,
v_color: rawVehData.v_color,
kmin: rawVehData.v_mileage,
area_of_damage: rawVehData.area_of_damage,
kmin: kmin,
area_of_damage: area_of_damage,
vehicle: {
data: rawVehData,
},