Final changes for pbs.

This commit is contained in:
Patrick Fic
2025-10-01 13:59:11 -07:00
parent 9ff3311579
commit 93e137c84e
2 changed files with 36 additions and 17 deletions

View File

@@ -21,7 +21,7 @@ axios.interceptors.request.use((x) => {
}; };
const printable = `${new Date()} | Request: ${x.method.toUpperCase()} | ${x.url const printable = `${new Date()} | Request: ${x.method.toUpperCase()} | ${x.url
} | ${JSON.stringify(x.data)} | ${JSON.stringify(headers)}`; } | ${JSON.stringify(x.data)} | ${JSON.stringify(headers)}`;
//console.log(printable); //logRequestToFile(printable);
CdkBase.createJsonEvent(socket, "DEBUG", `Raw Request: ${printable}`, x.data); CdkBase.createJsonEvent(socket, "DEBUG", `Raw Request: ${printable}`, x.data);
@@ -31,13 +31,29 @@ axios.interceptors.request.use((x) => {
axios.interceptors.response.use((x) => { axios.interceptors.response.use((x) => {
const socket = x.config.socket; const socket = x.config.socket;
const printable = `${new Date()} | Response: ${x.status} | ${JSON.stringify(x.data)}`; const printable = `${new Date()} | Response: ${x.status} ${x.statusText} |${JSON.stringify(x.data)}`;
//console.log(printable); //logRequestToFile(printable);
CdkBase.createJsonEvent(socket, "DEBUG", `Raw Response: ${printable}`, x.data); CdkBase.createJsonEvent(socket, "DEBUG", `Raw Response: ${printable}`, x.data);
return x; return x;
}); });
const fs = require('fs');
const path = require("path");
function logRequestToFile(printable) {
try {
const logDir = path.join(process.cwd(), "logs");
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir, { recursive: true });
}
const logFile = path.join(logDir, "pbs-http.log");
fs.appendFileSync(logFile, `${printable}\n`);
} catch (err) {
console.error("Unexpected error in logRequestToFile:", err);
}
}
exports.default = async function (socket, { txEnvelope, jobid }) { exports.default = async function (socket, { txEnvelope, jobid }) {
socket.logEvents = []; socket.logEvents = [];
socket.recordid = jobid; socket.recordid = jobid;
@@ -90,16 +106,19 @@ exports.PbsSelectedCustomer = async function PbsSelectedCustomer(socket, selecte
"INFO", "INFO",
`Contact and Vehicle updates disabled. Skipping to accounting data insert.` `Contact and Vehicle updates disabled. Skipping to accounting data insert.`
); );
const ownerRef = await QueryCustomerBycodeFromDms(socket, selectedCustomerId); if (!socket.ownerRef) {
socket.ownerRef = ownerRef; const ownerRef = (await QueryCustomerBycodeFromDms(socket, selectedCustomerId))?.[0];
socket.ownerRef = ownerRef;
}
CdkBase.createLogEvent(socket, "INFO", `Upserting vehicle information to DMS for ${socket.JobData.v_vin}`); CdkBase.createLogEvent(socket, "INFO", `Upserting vehicle information to DMS for ${socket.JobData.v_vin}`);
const vehicleRef = await GetVehicleData(socket, ownerRef.ReferenceId); const vehicleRef = await GetVehicleData(socket, socket.ownerRef?.ReferenceId || socket.selectedCustomerId);
socket.vehicleRef = vehicleRef; socket.vehicleRef = vehicleRef;
} }
CdkBase.createLogEvent(socket, "INFO", `Inserting accounting posting data..`); CdkBase.createLogEvent(socket, "INFO", `Inserting accounting posting data..`);
const insertResponse = await InsertAccountPostingData(socket); const insertResponse = await InsertAccountPostingData(socket);
if (insertResponse.WasSuccessful) { if (insertResponse.WasSuccessful) {
await CreateRepairOrderInPBS(socket, socket.ownerRef, socket.vehicleRef)
CdkBase.createLogEvent(socket, "INFO", `Marking job as exported.`); CdkBase.createLogEvent(socket, "INFO", `Marking job as exported.`);
await MarkJobExported(socket, socket.JobData.id); await MarkJobExported(socket, socket.JobData.id);
if (socket.jobData.bodyshop.pbs_configuration.ro_posting) { if (socket.jobData.bodyshop.pbs_configuration.ro_posting) {
@@ -478,7 +497,7 @@ async function UpsertVehicleData(socket, ownerRef) {
async function GetVehicleData(socket, ownerRef) { async function GetVehicleData(socket, ownerRef) {
try { try {
const { data: Vehicles } = await axios.post( const { data: { Vehicles } } = await axios.post(
PBS_ENDPOINTS.VehicleGet, PBS_ENDPOINTS.VehicleGet,
{ {
SerialNumber: socket.JobData.bodyshop.pbs_serialnumber, SerialNumber: socket.JobData.bodyshop.pbs_serialnumber,
@@ -714,7 +733,7 @@ async function RepairOrderGet(socket) {
// "Tag": "String", // "Tag": "String",
//"ContactRef": socket.contactRef, //"ContactRef": socket.contactRef,
// "ContactRefList": ["00000000000000000000000000000000"], // "ContactRefList": ["00000000000000000000000000000000"],
"VehicleRef": socket.vehicleRef?.ReferenceId, "VehicleRef": socket.vehicleRef?.ReferenceId || socket.vehicleRef?.VehicleId,
// "VehicleRefList": ["00000000000000000000000000000000"], // "VehicleRefList": ["00000000000000000000000000000000"],
// "Status": "String", // "Status": "String",
// "CashieredSince": "0001-01-01T00:00:00.0000000Z", // "CashieredSince": "0001-01-01T00:00:00.0000000Z",
@@ -760,8 +779,8 @@ async function RepairOrderChange(socket) {
// "CSRRef": "00000000000000000000000000000000", // "CSRRef": "00000000000000000000000000000000",
// "BookingUser": "String", // "BookingUser": "String",
// "BookingUserRef": "00000000000000000000000000000000", // "BookingUserRef": "00000000000000000000000000000000",
"ContactRef": socket.ownerRef?.ReferenceId, "ContactRef": socket.ownerRef?.ReferenceId || socket.ownerRef?.ContactId,
"VehicleRef": socket.vehicleRef?.ReferenceId, "VehicleRef": socket.vehicleRef?.ReferenceId || socket.vehicleRef?.VehicleId,
"MileageIn": socket.JobData.km_in, "MileageIn": socket.JobData.km_in,
"Tag": "BODYSHOP", "Tag": "BODYSHOP",
//"Status": "CLOSED", //Values here do not impact the status. Confirmed by PBS support. //"Status": "CLOSED", //Values here do not impact the status. Confirmed by PBS support.

View File

@@ -420,6 +420,8 @@ query QUERY_JOBS_FOR_PBS_EXPORT($id: uuid!) {
v_make_desc v_make_desc
v_color v_color
ca_customer_gst ca_customer_gst
scheduled_completion
actual_completion
vehicle { vehicle {
v_trimcode v_trimcode
v_makecode v_makecode
@@ -2155,18 +2157,16 @@ exports.UPDATE_OLD_TRANSITION = `mutation UPDATE_OLD_TRANSITION($jobid: uuid!, $
exports.INSERT_NEW_TRANSITION = ( exports.INSERT_NEW_TRANSITION = (
includeOldTransition includeOldTransition
) => `mutation INSERT_NEW_TRANSITION($newTransition: transitions_insert_input!, ${ ) => `mutation INSERT_NEW_TRANSITION($newTransition: transitions_insert_input!, ${includeOldTransition ? `$oldTransitionId: uuid!, $duration: numeric` : ""
includeOldTransition ? `$oldTransitionId: uuid!, $duration: numeric` : "" }) {
}) {
insert_transitions_one(object: $newTransition) { insert_transitions_one(object: $newTransition) {
id id
} }
${ ${includeOldTransition
includeOldTransition ? `update_transitions(where: {id: {_eq: $oldTransitionId}}, _set: {duration: $duration}) {
? `update_transitions(where: {id: {_eq: $oldTransitionId}}, _set: {duration: $duration}) {
affected_rows affected_rows
}` }`
: "" : ""
} }
}`; }`;