feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Checkpoint - Remove old attempt at Reynolds Integration in favor of new library.
This commit is contained in:
@@ -1,99 +1,17 @@
|
||||
/**
|
||||
* @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 { withClient } = require("../rr/withClient");
|
||||
|
||||
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");
|
||||
}
|
||||
async function insertCustomer({ bodyshopId, payload }) {
|
||||
return withClient(bodyshopId, async (client, routing) => {
|
||||
const res = await client.insertCustomer(payload, { routing });
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
async function updateCustomer({ bodyshopId, payload }) {
|
||||
return withClient(bodyshopId, async (client, routing) => {
|
||||
const res = await client.updateCustomer(payload, { routing });
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
insertCustomer,
|
||||
updateCustomer
|
||||
};
|
||||
module.exports = { insertCustomer, updateCustomer };
|
||||
|
||||
Reference in New Issue
Block a user