feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Expanded Logs / Formatting change
This commit is contained in:
@@ -1,45 +1,33 @@
|
||||
// server/rr/rr-config.js
|
||||
// Build RR client configuration from bodyshop settings or env
|
||||
|
||||
function requireString(v, name) {
|
||||
/**
|
||||
* Ensure a value is a non-empty string, else throw
|
||||
* @param v
|
||||
* @param name
|
||||
* @returns {string}
|
||||
*/
|
||||
const requireString = (v, name) => {
|
||||
const s = (v ?? "").toString().trim();
|
||||
if (!s || s.toLowerCase() === "undefined" || s.toLowerCase() === "null") {
|
||||
throw new Error(`RR config missing: ${name}`);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Extract RR connection + routing from a bodyshop record (preferred)
|
||||
* Falls back to process.env for any missing bits.
|
||||
*
|
||||
* Bodyshop fields expected:
|
||||
* - rr_dealerid -> dealerNumber
|
||||
* - rr_configuration: { storeNumber, branchNumber } -> storeNumber, areaNumber
|
||||
*
|
||||
* Env fallbacks:
|
||||
* RR_BASE_URL, RR_USERNAME, RR_PASSWORD,
|
||||
* RR_DEALER_NUMBER, RR_STORE_NUMBER, RR_BRANCH_NUMBER
|
||||
* Get RR config from bodyshop record, with env fallbacks
|
||||
* @param bodyshop
|
||||
* @returns {{baseUrl: string, username: string, password: string, routing: {dealerNumber: string, storeNumber: string, areaNumber: string}, timeoutMs: number, retries: {max: number}}}
|
||||
*/
|
||||
function getRRConfigFromBodyshop(bodyshop) {
|
||||
const getRRConfigFromBodyshop = (bodyshop) => {
|
||||
const baseUrl = process.env.RR_BASE_URL;
|
||||
const username = process.env.RR_USERNAME;
|
||||
const password = process.env.RR_PASSWORD;
|
||||
|
||||
// NOTE: your schema uses rr_dealerid and rr_configuration JSON
|
||||
const dealerNumber = bodyshop?.rr_dealerid ?? process.env.RR_DEALER_NUMBER;
|
||||
|
||||
const bsCfg = bodyshop?.rr_configuration || {};
|
||||
const storeNumber =
|
||||
bsCfg?.storeNumber ??
|
||||
bodyshop?.rr_store_number ?? // legacy fallback if present
|
||||
process.env.RR_STORE_NUMBER;
|
||||
|
||||
const areaNumber =
|
||||
bsCfg?.branchNumber ??
|
||||
bsCfg?.areaNumber ?? // accept either key
|
||||
bodyshop?.rr_branch_number ?? // legacy fallback if present
|
||||
process.env.RR_BRANCH_NUMBER;
|
||||
const storeNumber = bsCfg?.storeNumber;
|
||||
const areaNumber = bsCfg?.branchNumber ?? bsCfg?.areaNumber;
|
||||
|
||||
return {
|
||||
baseUrl: requireString(baseUrl, "baseUrl"),
|
||||
@@ -54,6 +42,6 @@ function getRRConfigFromBodyshop(bodyshop) {
|
||||
timeoutMs: Number(process.env.RR_TIMEOUT_MS || 30000),
|
||||
retries: { max: Number(process.env.RR_RETRIES_MAX || 2) }
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { getRRConfigFromBodyshop };
|
||||
|
||||
Reference in New Issue
Block a user