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,136 +1,24 @@
|
||||
/**
|
||||
* @file rr-lookup.js
|
||||
* @description Rome (Reynolds & Reynolds) lookup operations — Advisors, Parts, and CombinedSearch
|
||||
*/
|
||||
const { withClient } = require("./withClient");
|
||||
|
||||
const { MakeRRCall, parseRRResponse } = require("./rr-helpers");
|
||||
const { mapAdvisorLookup, mapPartsLookup, mapCombinedSearch } = require("./rr-mappers");
|
||||
const RRLogger = require("./rr-logger");
|
||||
const { RrApiError } = require("./rr-error");
|
||||
|
||||
/**
|
||||
* Get a list of service advisors from Rome.
|
||||
*/
|
||||
async function getAdvisors(socket, criteria = {}, bodyshopConfig) {
|
||||
const action = "GetAdvisors";
|
||||
const template = "GetAdvisors";
|
||||
|
||||
try {
|
||||
RRLogger(socket, "info", `Starting RR ${action} lookup`);
|
||||
const data = mapAdvisorLookup(criteria, bodyshopConfig);
|
||||
|
||||
const resultXml = await MakeRRCall({
|
||||
action,
|
||||
body: { template, data },
|
||||
socket,
|
||||
dealerConfig: bodyshopConfig
|
||||
});
|
||||
|
||||
const parsed = parseRRResponse(resultXml);
|
||||
if (!parsed.success) throw new RrApiError(parsed.message, parsed.code);
|
||||
|
||||
const advisors = parsed.parsed?.Advisors?.Advisor || parsed.parsed?.AdvisorList?.Advisor || [];
|
||||
const advisorList = Array.isArray(advisors) ? advisors : [advisors];
|
||||
|
||||
RRLogger(socket, "debug", `${action} lookup returned ${advisorList.length} advisors`);
|
||||
return { success: true, dms: "Rome", action, advisors: advisorList };
|
||||
} catch (error) {
|
||||
RRLogger(socket, "error", `Error in ${action} lookup`, {
|
||||
message: error.message,
|
||||
stack: error.stack
|
||||
});
|
||||
throw new RrApiError(`RR ${action} failed: ${error.message}`, "GET_ADVISORS_ERROR");
|
||||
}
|
||||
async function getAdvisors({ bodyshopId, ...criteria }) {
|
||||
return withClient(bodyshopId, async (client, routing) => {
|
||||
const res = await client.getAdvisors(criteria, { routing });
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parts information from Rome.
|
||||
*/
|
||||
async function getParts(socket, criteria = {}, bodyshopConfig) {
|
||||
const action = "GetParts";
|
||||
const template = "GetParts";
|
||||
|
||||
try {
|
||||
RRLogger(socket, "info", `Starting RR ${action} lookup`);
|
||||
const data = mapPartsLookup(criteria, bodyshopConfig);
|
||||
|
||||
const resultXml = await MakeRRCall({
|
||||
action,
|
||||
body: { template, data },
|
||||
socket,
|
||||
dealerConfig: bodyshopConfig
|
||||
});
|
||||
|
||||
const parsed = parseRRResponse(resultXml);
|
||||
if (!parsed.success) throw new RrApiError(parsed.message, parsed.code);
|
||||
|
||||
const parts = parsed.parsed?.Parts?.Part || parsed.parsed?.PartList?.Part || [];
|
||||
const partList = Array.isArray(parts) ? parts : [parts];
|
||||
|
||||
RRLogger(socket, "debug", `${action} lookup returned ${partList.length} parts`);
|
||||
return { success: true, dms: "Rome", action, parts: partList };
|
||||
} catch (error) {
|
||||
RRLogger(socket, "error", `Error in ${action} lookup`, {
|
||||
message: error.message,
|
||||
stack: error.stack
|
||||
});
|
||||
throw new RrApiError(`RR ${action} failed: ${error.message}`, "GET_PARTS_ERROR");
|
||||
}
|
||||
async function getParts({ bodyshopId, ...criteria }) {
|
||||
return withClient(bodyshopId, async (client, routing) => {
|
||||
const res = await client.getParts(criteria, { routing });
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a combined customer / vehicle / company search.
|
||||
* Equivalent to Rome CombinedSearchRq / Resp.
|
||||
* @param {Socket} socket
|
||||
* @param {Object} criteria - { VIN, LicensePlate, CustomerName, Phone, Email }
|
||||
* @param {Object} bodyshopConfig
|
||||
* @returns {Promise<Object>} { customers, vehicles, companies }
|
||||
*/
|
||||
async function combinedSearch(socket, criteria = {}, bodyshopConfig) {
|
||||
const action = "CombinedSearch";
|
||||
const template = "CombinedSearch";
|
||||
|
||||
try {
|
||||
RRLogger(socket, "info", `Starting RR ${action} request`);
|
||||
const data = mapCombinedSearch(criteria, bodyshopConfig);
|
||||
|
||||
const resultXml = await MakeRRCall({
|
||||
action,
|
||||
body: { template, data },
|
||||
socket,
|
||||
dealerConfig: bodyshopConfig
|
||||
});
|
||||
|
||||
const parsed = parseRRResponse(resultXml);
|
||||
if (!parsed.success) throw new RrApiError(parsed.message, parsed.code);
|
||||
|
||||
const customers = parsed.parsed?.Customers?.Customer || [];
|
||||
const vehicles = parsed.parsed?.Vehicles?.ServiceVehicle || [];
|
||||
const companies = parsed.parsed?.Companies?.Company || [];
|
||||
|
||||
const result = {
|
||||
customers: Array.isArray(customers) ? customers : [customers],
|
||||
vehicles: Array.isArray(vehicles) ? vehicles : [vehicles],
|
||||
companies: Array.isArray(companies) ? companies : [companies]
|
||||
};
|
||||
|
||||
RRLogger(
|
||||
socket,
|
||||
"debug",
|
||||
`${action} returned ${result.customers.length} customers, ${result.vehicles.length} vehicles, ${result.companies.length} companies`
|
||||
);
|
||||
return { success: true, dms: "Rome", action, ...result };
|
||||
} catch (error) {
|
||||
RRLogger(socket, "error", `Error in ${action}`, {
|
||||
message: error.message,
|
||||
stack: error.stack
|
||||
});
|
||||
throw new RrApiError(`RR ${action} failed: ${error.message}`, "COMBINED_SEARCH_ERROR");
|
||||
}
|
||||
async function combinedSearch({ bodyshopId, ...query }) {
|
||||
return withClient(bodyshopId, async (client, routing) => {
|
||||
const res = await client.combinedSearch(query, { routing });
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getAdvisors,
|
||||
getParts,
|
||||
combinedSearch
|
||||
};
|
||||
module.exports = { getAdvisors, getParts, combinedSearch };
|
||||
|
||||
Reference in New Issue
Block a user