Succesful test imports to IO.
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import { UUID } from "crypto";
|
||||
import { Notification } from "electron";
|
||||
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 {
|
||||
INSERT_AVAILABLE_JOB_TYPED,
|
||||
InsertAvailableJobResult,
|
||||
QUERY_JOB_BY_CLM_NO_TYPED,
|
||||
QUERY_VEHICLE_BY_VIN_TYPED,
|
||||
QueryJobByClmNoResult,
|
||||
@@ -77,6 +80,7 @@ async function ImportJob(filepath: string): Promise<void> {
|
||||
...stl,
|
||||
...ttl,
|
||||
...pfp,
|
||||
shopid: store.get("app.bodyshop.id") as UUID,
|
||||
};
|
||||
|
||||
// Save jobObject to a timestamped JSON file
|
||||
@@ -100,11 +104,8 @@ async function ImportJob(filepath: string): Promise<void> {
|
||||
jobObject,
|
||||
});
|
||||
|
||||
//Build the request object
|
||||
|
||||
//Insert it
|
||||
const newAvailableJob: AvailableJobSchema = {
|
||||
uploaded_by: store.get("app.user.email"),
|
||||
uploaded_by: store.get("user.email"),
|
||||
bodyshopid: store.get("app.bodyshop.id"),
|
||||
cieca_id: jobObject.ciecaid,
|
||||
est_data: jobObject,
|
||||
@@ -141,8 +142,28 @@ async function ImportJob(filepath: string): Promise<void> {
|
||||
newAvailableJob.issupplement = true;
|
||||
newAvailableJob.jobid = existingJobRecord.jobs[0].id;
|
||||
}
|
||||
|
||||
const insertRecordResult: InsertAvailableJobResult = await client.request(
|
||||
INSERT_AVAILABLE_JOB_TYPED,
|
||||
{
|
||||
jobInput: [newAvailableJob],
|
||||
},
|
||||
);
|
||||
new Notification({
|
||||
title: "Job Imported",
|
||||
body: `Job ${newAvailableJob.cieca_id} imported successfully`,
|
||||
actions: [{ text: "View Job", type: "button" }],
|
||||
subtitle: newAvailableJob.ownr_name,
|
||||
}).show();
|
||||
|
||||
log.debug("Job inserted", insertRecordResult);
|
||||
} catch (error) {
|
||||
log.error("Error encountered while decoding job. ", errorTypeCheck(error));
|
||||
new Notification({
|
||||
title: "Job Upload Failure",
|
||||
body: errorTypeCheck(error).message, //TODO: Remove after debug.
|
||||
actions: [{ text: "View Job", type: "button" }],
|
||||
}).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,6 +184,7 @@ export interface RawJobDataObject
|
||||
DecodedTtl,
|
||||
DecodedPfp {
|
||||
vehicleid?: UUID;
|
||||
shopid: UUID;
|
||||
}
|
||||
|
||||
export interface AvailableJobSchema {
|
||||
|
||||
Reference in New Issue
Block a user