64 lines
2.1 KiB
JavaScript
64 lines
2.1 KiB
JavaScript
const path = require("path");
|
|
const fs = require("fs");
|
|
const { store } = require("../electron-store");
|
|
const log = require("electron-log");
|
|
const fsPromises = fs.promises;
|
|
const { DecodeEstimate } = require("../decoder/decoder");
|
|
const axios = require("axios");
|
|
const TestJson = require("./A.json");
|
|
const { BrowserWindow } = require("electron");
|
|
|
|
|
|
async function ScrubEstimate({ job }) {
|
|
//TODO: Fetch these from ImEX Online API.
|
|
const basicAuthUser = "Imex";
|
|
const basicAuthpassword = "Patrick";
|
|
const estimateScrubberUrl = "https://insurtechtoolkit.com/api/sendems";
|
|
const sendingEntityId = '87330f61-412b-4251-baaa-d026565b23c5'
|
|
|
|
//Perform data manipulation on the job object
|
|
if (!job) {
|
|
console.error("No job provided to ScrubEstimate");
|
|
return;
|
|
}
|
|
|
|
//Set shop metrics
|
|
job.sending_entity_id = sendingEntityId;
|
|
job.sending_entity_accept_terms_of_use = true;
|
|
job.association_switch = "ATAM";
|
|
job.rf_ph1 = "R0G 1Z0";
|
|
job.rf_zip = "2043792253";
|
|
job.g_ttl_amt = job.clm_total;
|
|
|
|
|
|
console.log("*** ~ ScrubEstimate ~ job:", job);
|
|
//Build the JSON Form Data
|
|
const fileName = `RPSTest-${job.id}-${Date.now()}`;
|
|
const formData = new FormData();
|
|
const jsonString = JSON.stringify(job);
|
|
formData.append("file", new Blob([jsonString], { type: "application/json" }), `${fileName}.json`);
|
|
|
|
const result = await axios.post(estimateScrubberUrl, formData, {
|
|
auth: {
|
|
username: basicAuthUser,
|
|
password: basicAuthpassword
|
|
},
|
|
headers: formData.getHeaders ? formData.getHeaders() : {}
|
|
});
|
|
console.log("*** ~ handleScrub ~ result:", result.data);
|
|
|
|
const resultPDFUrl = result?.data?.[0] || `https://www.insurtechtoolkit.com/analysis/${fileName}.pdf`;
|
|
|
|
console.log("*** ~ handleScrub ~ resultPDFUrl:", resultPDFUrl);
|
|
const pdfWindow = new BrowserWindow({
|
|
|
|
webPreferences: {
|
|
plugins: true, // Enable PDF viewing
|
|
},
|
|
});
|
|
|
|
pdfWindow.loadURL(resultPDFUrl);
|
|
pdfWindow.focus();
|
|
return resultPDFUrl
|
|
}
|
|
exports.ScrubEstimate = ScrubEstimate |