feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Checkpoint
This commit is contained in:
@@ -5,21 +5,7 @@ const { FortellisJobExport, FortellisSelectedCustomer } = require("../fortellis/
|
||||
const CdkCalculateAllocations = require("../cdk/cdk-calculate-allocations").default;
|
||||
const { exportJobToRome } = require("../rr/rr-job-export");
|
||||
const lookupApi = require("../rr/rr-lookup");
|
||||
|
||||
function resolveRRConfigFrom(payload = {}) {
|
||||
// Back-compat: allow txEnvelope.config from old callers
|
||||
const cfg = payload.config || payload.bodyshopConfig || payload.txEnvelope?.config || {};
|
||||
return {
|
||||
baseUrl: cfg.baseUrl || process.env.RR_BASE_URL,
|
||||
username: cfg.username || process.env.RR_USERNAME,
|
||||
password: cfg.password || process.env.RR_PASSWORD,
|
||||
ppsysId: cfg.ppsysId || process.env.RR_PPSYSID,
|
||||
dealer_number: cfg.dealer_number || process.env.RR_DEALER_NUMBER,
|
||||
store_number: cfg.store_number || process.env.RR_STORE_NUMBER,
|
||||
branch_number: cfg.branch_number || process.env.RR_BRANCH_NUMBER,
|
||||
rrTransport: (cfg.rrTransport || process.env.RR_TRANSPORT || "STAR").toUpperCase()
|
||||
};
|
||||
}
|
||||
const { getRRConfigForBodyshop } = require("../rr/rr-config");
|
||||
|
||||
const redisSocketEvents = ({
|
||||
io,
|
||||
@@ -349,7 +335,7 @@ const redisSocketEvents = ({
|
||||
});
|
||||
|
||||
socket.on("task-deleted", (payload) => {
|
||||
if (!payload || !payload.id) return;
|
||||
if (!payload?.id) return;
|
||||
const room = getBodyshopRoom(socket.bodyshopId);
|
||||
io.to(room).emit("bodyshop-message", { type: "task-deleted", payload });
|
||||
});
|
||||
@@ -359,11 +345,13 @@ const redisSocketEvents = ({
|
||||
// Orchestrated Export (Customer → Vehicle → Repair Order)
|
||||
socket.on("rr-export-job", async (payload = {}) => {
|
||||
try {
|
||||
// Back-compat: old callers: { jobid, txEnvelope }; new: { job, config, options }
|
||||
// Prefer direct job/config, otherwise try txEnvelope.{job,config}
|
||||
// Back-compat: old callers: { jobid, txEnvelope }; new: { job, options }
|
||||
// Prefer direct job, otherwise try txEnvelope.job
|
||||
const job = payload.job || payload.txEnvelope?.job;
|
||||
const options = payload.options || payload.txEnvelope?.options || {};
|
||||
const cfg = resolveRRConfigFrom(payload);
|
||||
// Resolve per-bodyshop RR config strictly from DB:
|
||||
const bodyshopId = payload.bodyshopId || socket.bodyshopId || job?.shopid;
|
||||
const cfg = await getRRConfigForBodyshop(bodyshopId);
|
||||
|
||||
if (!job) {
|
||||
RRLogger(socket, "error", "RR export missing job payload");
|
||||
@@ -383,7 +371,7 @@ const redisSocketEvents = ({
|
||||
// Combined search
|
||||
socket.on("rr-lookup-combined", async ({ jobid, params } = {}, cb) => {
|
||||
try {
|
||||
const cfg = resolveRRConfigFrom({}); // if you want per-call overrides, pass them in the payload and merge here
|
||||
const cfg = await getRRConfigForBodyshop(socket.bodyshopId);
|
||||
const data = await lookupApi.combinedSearch(socket, params || {}, cfg);
|
||||
cb?.(data);
|
||||
} catch (e) {
|
||||
@@ -395,7 +383,7 @@ const redisSocketEvents = ({
|
||||
// Get Advisors
|
||||
socket.on("rr-get-advisors", async ({ jobid, params } = {}, cb) => {
|
||||
try {
|
||||
const cfg = resolveRRConfigFrom({});
|
||||
const cfg = await getRRConfigForBodyshop(socket.bodyshopId);
|
||||
const data = await lookupApi.getAdvisors(socket, params || {}, cfg);
|
||||
cb?.(data);
|
||||
} catch (e) {
|
||||
@@ -407,7 +395,7 @@ const redisSocketEvents = ({
|
||||
// Get Parts
|
||||
socket.on("rr-get-parts", async ({ jobid, params } = {}, cb) => {
|
||||
try {
|
||||
const cfg = resolveRRConfigFrom({});
|
||||
const cfg = await getRRConfigForBodyshop(socket.bodyshopId);
|
||||
const data = await lookupApi.getParts(socket, params || {}, cfg);
|
||||
cb?.(data);
|
||||
} catch (e) {
|
||||
@@ -419,9 +407,6 @@ const redisSocketEvents = ({
|
||||
// (Optional) Selected customer — only keep this if you actually implement it for RR
|
||||
socket.on("rr-selected-customer", async ({ jobid, selectedCustomerId } = {}) => {
|
||||
try {
|
||||
// If you don’t have an RRSelectedCustomer implementation now, either:
|
||||
// 1) no-op with a log, or
|
||||
// 2) emit a structured event UI can handle as "not supported".
|
||||
RRLogger(socket, "info", "rr-selected-customer not implemented for RR (no-op)", {
|
||||
jobid,
|
||||
selectedCustomerId
|
||||
|
||||
Reference in New Issue
Block a user