Files
bodyshop/server/rr/rr-lookup.js

89 lines
3.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// -----------------------------------------------------------------------------
// Reynolds & Reynolds (RR) lookup helpers.
// Uses MakeRRCall + RRActions from rr-helpers, and shared response validation
// from rr-error.
//
// Whats still missing / to confirm against the Rome/RR PDFs:
// - Final query param names and value formats for the “combined search”
// (customer + vehicle), advisors directory, and parts lookup.
// - Any RR-required headers (dealer/site/location ids) — add in rr-helpers
// via the MakeRRCall default headers if needed.
// - Final success envelope checks in assertRrOk.
// -----------------------------------------------------------------------------
const { MakeRRCall, RRActions } = require("./rr-helpers");
const { assertRrOk } = require("./rr-error");
/**
* RR Combined Search (Customer + Vehicle).
*
* @param {Object} deps
* @param {Socket|ExpressRequest} deps.socket
* @param {Object} deps.redisHelpers
* @param {string|number} deps.jobid - for correlation/logging only
* @param {Array<[string,string]>} [deps.params=[]]
* Example: [["vin", "1HGBH41JXMN109186"], ["lastName","DOE"]]
* @returns {Promise<any>} RR response (envelope TBD)
*/
async function RrCombinedSearch({ socket, redisHelpers, jobid, params = [] }) {
const data = await MakeRRCall({
...RRActions.CombinedSearch, // GET /search/v1/customer-vehicle
requestSearchParams: params,
type: "get",
redisHelpers,
socket,
jobid
});
// allowEmpty=true because searches may legitimately return 0 rows
return assertRrOk(data, { apiName: "RR Combined Search", allowEmpty: true });
}
/**
* RR Get Advisors.
*
* @param {Object} deps
* @param {Socket|ExpressRequest} deps.socket
* @param {Object} deps.redisHelpers
* @param {string|number} deps.jobid
* @param {Array<[string,string]>} [deps.params=[]]
* Example: [["active","true"]]
* @returns {Promise<any>} RR response (envelope TBD)
*/
async function RrGetAdvisors({ socket, redisHelpers, jobid, params = [] }) {
const data = await MakeRRCall({
...RRActions.GetAdvisors, // GET /advisors/v1
requestSearchParams: params,
type: "get",
redisHelpers,
socket,
jobid
});
return assertRrOk(data, { apiName: "RR Get Advisors", allowEmpty: true });
}
/**
* RR Get Parts.
*
* @param {Object} deps
* @param {Socket|ExpressRequest} deps.socket
* @param {Object} deps.redisHelpers
* @param {string|number} deps.jobid
* @param {Array<[string,string]>} [deps.params=[]]
* Example: [["sku","ABC123"], ["page","1"], ["pageSize","50"]]
* @returns {Promise<any>} RR response (envelope TBD)
*/
async function RrGetParts({ socket, redisHelpers, jobid, params = [] }) {
const data = await MakeRRCall({
...RRActions.GetParts, // GET /parts/v1
requestSearchParams: params,
type: "get",
redisHelpers,
socket,
jobid
});
return assertRrOk(data, { apiName: "RR Get Parts", allowEmpty: true });
}
module.exports = { RrCombinedSearch, RrGetAdvisors, RrGetParts };