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:
32
server/rr/resolveRRConfigHttp.js
Normal file
32
server/rr/resolveRRConfigHttp.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const { getRRConfigForBodyshop } = require("./rr-config");
|
||||
const { RrApiError } = require("./rr-error");
|
||||
|
||||
/**
|
||||
* Extracts bodyshopId from body, job, or header and loads RR config.
|
||||
* @returns {Promise<{ bodyshopId: string, config: any }>}
|
||||
*/
|
||||
async function resolveRRConfigHttp(req) {
|
||||
const body = req?.body || {};
|
||||
|
||||
const fromBody = body.bodyshopId;
|
||||
const fromJob = body.job && (body.job.shopid || body.job.bodyshopId);
|
||||
const fromHeader = typeof req.get === "function" ? req.get("x-bodyshop-id") : undefined;
|
||||
|
||||
const bodyshopId = fromBody || fromJob || fromHeader;
|
||||
|
||||
if (!bodyshopId) {
|
||||
throw new RrApiError(
|
||||
"Missing bodyshopId (expected in body.bodyshopId, body.job.shopid/bodyshopId, or x-bodyshop-id header)",
|
||||
"BAD_REQUEST"
|
||||
);
|
||||
}
|
||||
|
||||
const config = await getRRConfigForBodyshop(bodyshopId);
|
||||
if (!config?.dealerNumber) {
|
||||
throw new RrApiError(`RR config not found for bodyshopId=${bodyshopId} (missing dealerNumber)`, "NOT_CONFIGURED");
|
||||
}
|
||||
|
||||
return { bodyshopId, config };
|
||||
}
|
||||
|
||||
module.exports = { resolveRRConfigHttp };
|
||||
Reference in New Issue
Block a user