100 lines
2.7 KiB
JavaScript
100 lines
2.7 KiB
JavaScript
/**
|
|
* @file rr-repair-orders.js
|
|
* @description Rome (Reynolds & Reynolds) Repair Order Integration.
|
|
* Handles creation and updates of repair orders (BSMRepairOrderRq/Resp).
|
|
*/
|
|
|
|
const { MakeRRCall } = require("./rr-helpers");
|
|
const { mapRepairOrderCreate, mapRepairOrderUpdate } = require("./rr-mappers");
|
|
const RRLogger = require("./rr-logger");
|
|
const { RrApiError } = require("./rr-error");
|
|
|
|
/**
|
|
* Create a new repair order in Rome.
|
|
* @param {Socket} socket - active socket connection
|
|
* @param {Object} job - Hasura job object (including vehicle, customer, joblines)
|
|
* @param {Object} bodyshopConfig - DMS config for current bodyshop
|
|
* @returns {Promise<Object>} normalized result
|
|
*/
|
|
async function createRepairOrder(socket, job, bodyshopConfig) {
|
|
const action = "CreateRepairOrder";
|
|
const template = "CreateRepairOrder"; // maps to xml-templates/CreateRepairOrder.xml
|
|
|
|
try {
|
|
RRLogger(socket, "info", `Starting RR ${action} for job ${job.id}`);
|
|
|
|
const data = mapRepairOrderCreate(job, bodyshopConfig);
|
|
|
|
const resultXml = await MakeRRCall({
|
|
action,
|
|
body: { template, data },
|
|
socket,
|
|
dealerConfig: bodyshopConfig,
|
|
jobid: job.id
|
|
});
|
|
|
|
RRLogger(socket, "debug", `${action} completed successfully`, { jobid: job.id });
|
|
|
|
return {
|
|
success: true,
|
|
dms: "Rome",
|
|
jobid: job.id,
|
|
action,
|
|
xml: resultXml
|
|
};
|
|
} catch (error) {
|
|
RRLogger(socket, "error", `Error in ${action} for job ${job.id}`, {
|
|
message: error.message,
|
|
stack: error.stack
|
|
});
|
|
throw new RrApiError(`RR CreateRepairOrder failed: ${error.message}`, "CREATE_RO_ERROR");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update an existing repair order in Rome.
|
|
* @param {Socket} socket
|
|
* @param {Object} job
|
|
* @param {Object} bodyshopConfig
|
|
* @returns {Promise<Object>}
|
|
*/
|
|
async function updateRepairOrder(socket, job, bodyshopConfig) {
|
|
const action = "UpdateRepairOrder";
|
|
const template = "UpdateRepairOrder";
|
|
|
|
try {
|
|
RRLogger(socket, "info", `Starting RR ${action} for job ${job.id}`);
|
|
|
|
const data = mapRepairOrderUpdate(job, bodyshopConfig);
|
|
|
|
const resultXml = await MakeRRCall({
|
|
action,
|
|
body: { template, data },
|
|
socket,
|
|
dealerConfig: bodyshopConfig,
|
|
jobid: job.id
|
|
});
|
|
|
|
RRLogger(socket, "debug", `${action} completed successfully`, { jobid: job.id });
|
|
|
|
return {
|
|
success: true,
|
|
dms: "Rome",
|
|
jobid: job.id,
|
|
action,
|
|
xml: resultXml
|
|
};
|
|
} catch (error) {
|
|
RRLogger(socket, "error", `Error in ${action} for job ${job.id}`, {
|
|
message: error.message,
|
|
stack: error.stack
|
|
});
|
|
throw new RrApiError(`RR UpdateRepairOrder failed: ${error.message}`, "UPDATE_RO_ERROR");
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
createRepairOrder,
|
|
updateRepairOrder
|
|
};
|