100 lines
2.7 KiB
JavaScript
100 lines
2.7 KiB
JavaScript
/**
|
|
* @file rr-customer.js
|
|
* @description Rome (Reynolds & Reynolds) Customer Insert / Update integration.
|
|
* Maps internal customer objects to Rome XML schemas and executes RCI calls.
|
|
*/
|
|
|
|
const { MakeRRCall } = require("./rr-helpers");
|
|
const { mapCustomerInsert, mapCustomerUpdate } = require("./rr-mappers");
|
|
const RRLogger = require("./rr-logger");
|
|
const { RrApiError } = require("./rr-error");
|
|
|
|
/**
|
|
* Insert a new customer into Rome.
|
|
* @param {Socket} socket - WebSocket connection for logging context
|
|
* @param {Object} customer - Hasura customer record
|
|
* @param {Object} bodyshopConfig - DMS configuration
|
|
* @returns {Promise<Object>} result
|
|
*/
|
|
async function insertCustomer(socket, customer, bodyshopConfig) {
|
|
const action = "InsertCustomer";
|
|
const template = "InsertCustomer";
|
|
|
|
try {
|
|
RRLogger(socket, "info", `Starting RR ${action} for customer ${customer.id}`);
|
|
|
|
const data = mapCustomerInsert(customer, bodyshopConfig);
|
|
|
|
const resultXml = await MakeRRCall({
|
|
action,
|
|
body: { template, data },
|
|
socket,
|
|
dealerConfig: bodyshopConfig,
|
|
jobid: customer.id
|
|
});
|
|
|
|
RRLogger(socket, "debug", `${action} completed successfully`, { customerId: customer.id });
|
|
|
|
return {
|
|
success: true,
|
|
dms: "Rome",
|
|
action,
|
|
customerId: customer.id,
|
|
xml: resultXml
|
|
};
|
|
} catch (error) {
|
|
RRLogger(socket, "error", `Error in ${action} for customer ${customer.id}`, {
|
|
message: error.message,
|
|
stack: error.stack
|
|
});
|
|
throw new RrApiError(`RR InsertCustomer failed: ${error.message}`, "INSERT_CUSTOMER_ERROR");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update an existing customer in Rome.
|
|
* @param {Socket} socket
|
|
* @param {Object} customer
|
|
* @param {Object} bodyshopConfig
|
|
* @returns {Promise<Object>}
|
|
*/
|
|
async function updateCustomer(socket, customer, bodyshopConfig) {
|
|
const action = "UpdateCustomer";
|
|
const template = "UpdateCustomer";
|
|
|
|
try {
|
|
RRLogger(socket, "info", `Starting RR ${action} for customer ${customer.id}`);
|
|
|
|
const data = mapCustomerUpdate(customer, bodyshopConfig);
|
|
|
|
const resultXml = await MakeRRCall({
|
|
action,
|
|
body: { template, data },
|
|
socket,
|
|
dealerConfig: bodyshopConfig,
|
|
jobid: customer.id
|
|
});
|
|
|
|
RRLogger(socket, "debug", `${action} completed successfully`, { customerId: customer.id });
|
|
|
|
return {
|
|
success: true,
|
|
dms: "Rome",
|
|
action,
|
|
customerId: customer.id,
|
|
xml: resultXml
|
|
};
|
|
} catch (error) {
|
|
RRLogger(socket, "error", `Error in ${action} for customer ${customer.id}`, {
|
|
message: error.message,
|
|
stack: error.stack
|
|
});
|
|
throw new RrApiError(`RR UpdateCustomer failed: ${error.message}`, "UPDATE_CUSTOMER_ERROR");
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
insertCustomer,
|
|
updateCustomer
|
|
};
|