Add watcher status and additional typing.

This commit is contained in:
Patrick Fic
2025-03-21 11:28:30 -07:00
parent 6da5822197
commit 14e7c64eab
19 changed files with 385 additions and 81 deletions

View File

@@ -1,10 +1,22 @@
import { UUID } from "crypto";
import log from "electron-log/main";
import fs from "fs";
import path from "path";
import errorTypeCheck from "../../util/errorTypeCheck";
import client from "../graphql/graphql-client";
import {
QUERY_JOB_BY_CLM_NO_TYPED,
QUERY_VEHICLE_BY_VIN_TYPED,
QueryJobByClmNoResult,
VehicleQueryResult,
} from "../graphql/queries";
import store from "../store/store";
import DecodeAD1 from "./decode-ad1";
import { DecodedAd1 } from "./decode-ad1.interface";
import DecodeAD2 from "./decode-ad2";
import { DecodedAD2 } from "./decode-ad2.interface";
import DecodeEnv from "./decode-env";
import { DecodedEnv } from "./decode-env.interface";
import DecodeLin from "./decode-lin";
import { DecodedLin } from "./decode-lin.interface";
import DecodePfh from "./decode-pfh";
@@ -25,17 +37,12 @@ import DecodeTtl from "./decode-ttl";
import { DecodedTtl } from "./decode-ttl.interface";
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";
import store from "../store/store";
import client from "../graphql/graphql-client";
async function ImportJob(filepath: string): Promise<void> {
const parsedFilePath = path.parse(filepath);
const extensionlessFilePath = path.join(
parsedFilePath.dir,
parsedFilePath.name
parsedFilePath.name,
);
log.debug("Importing Job", extensionlessFilePath);
@@ -56,7 +63,7 @@ async function ImportJob(filepath: string): Promise<void> {
const ttl: DecodedTtl = await DecodeTtl(extensionlessFilePath);
const pfp: DecodedPfp = await DecodePfp(extensionlessFilePath);
const jobObject = {
const jobObject: RawJobDataObject = {
...env,
...ad1,
...ad2,
@@ -96,17 +103,7 @@ async function ImportJob(filepath: string): Promise<void> {
//Build the request object
//Insert it
const newAvailableJob = {
// newJob.uploaded_by = Auth.authlink.User.Email;
// newJob.bodyshopid = AppMetaData.ActiveShopId;
// newJob.cieca_id = item.Job.ciecaid;
// newJob.est_data = item.Job;
// newJob.ownr_name = item.Job.ownr_fn?.Value + " " + item.Job.ownr_ln?.Value + " " + item.Job.ownr_co_nm?.Value;
// newJob.ins_co_nm = item.Job.ins_co_nm?.Value;
// newJob.vehicle_info = item.Job.vehicle.data.v_model_yr?.Value + " " + item.Job.vehicle.data.v_make_desc?.Value + " " + item.Job.vehicle.data.v_model_desc?.Value;
// newJob.clm_no = item.Job.clm_no?.Value;
// newJob.clm_amt = item.Job.clm_total?.Value;
// newJob.source_system = item.Job.source_system?.Value;
const newAvailableJob: AvailableJobSchema = {
uploaded_by: store.get("app.user.email"),
bodyshopid: store.get("app.bodyshop.id"),
cieca_id: jobObject.ciecaid,
@@ -117,30 +114,68 @@ async function ImportJob(filepath: string): Promise<void> {
clm_no: jobObject.clm_no,
clm_amt: jobObject.clm_total,
// source_system: jobObject.source_system, //TODO: Add back source system if needed.
issupplement: false,
jobid: null,
};
const existingVehicleId: uuid = await client.query ()
// var vehuuid = await Utils.Queries.VehicleQueries.GetVehicleUuidByVin(item?.Job?.vehicle?.data?.v_vin?.Value ?? "");
// if (!string.IsNullOrEmpty(vehuuid))
// {
// newJob.est_data.vehicle = null;
// newJob.est_data.vehicleid = vehuuid;
// }
const existingVehicleRecord: VehicleQueryResult = await client.request(
QUERY_VEHICLE_BY_VIN_TYPED,
{
vin: jobObject.v_vin,
},
);
if (existingVehicleRecord.vehicles.length > 0) {
delete newAvailableJob.est_data.vehicle;
newAvailableJob.est_data.vehicleid = existingVehicleRecord.vehicles[0].id;
}
// string jobId = await Utils.Queries.JobsQueries.CheckSupplementByClaimNo(item.Job.clm_no?.Value ?? "");
console.log(newAvailableJob);
// if (!string.IsNullOrEmpty(jobId))
// {
// newJob.issupplement = true;
// newJob.jobid = jobId;
// };
//Check if the vehicle exists, if it does, use that UUID, if not, keep it to insert it.
const existingJobRecord: QueryJobByClmNoResult = await client.request(
QUERY_JOB_BY_CLM_NO_TYPED,
{ clm_no: jobObject.clm_no },
);
if (existingJobRecord.jobs.length > 0) {
newAvailableJob.issupplement = true;
newAvailableJob.jobid = existingJobRecord.jobs[0].id;
}
} catch (error) {
log.error("Error encountered while decoding job. ", errorTypeCheck(error));
}
}
export default ImportJob;
export interface RawJobDataObject
extends DecodedEnv,
DecodedAd1,
DecodedAD2,
DecodedVeh,
DecodedLin,
DecodedPfh,
DecodedPfl,
DecodedPft,
DecodedPfm,
DecodedPfo,
DecodedStl,
DecodedTtl,
DecodedPfp {
vehicleid?: UUID;
}
export interface AvailableJobSchema {
uploaded_by: string;
bodyshopid: UUID;
cieca_id?: string;
est_data: RawJobDataObject;
ownr_name: string;
ins_co_nm?: string;
vehicle_info: string;
clm_no?: string;
clm_amt: number;
source_system?: string | null;
issupplement: boolean;
jobid: UUID | null;
}