feature/Reynolds-and-Reynolds-DMS-API-Integration -Expand

This commit is contained in:
Dave
2025-10-01 17:11:34 -04:00
parent 42027f0858
commit 24f017bfd2
11 changed files with 744 additions and 333 deletions

View File

@@ -1,28 +1,65 @@
// -----------------------------------------------------------------------------
// RR Customer endpoints (create/update) wired through MakeRRCall.
// Shapes are mapped via rr-mappers.js and validated via rr-error.js.
//
// Whats still missing (complete when you wire to the PDFs):
// - Final request envelopes & field names in rr-mappers.js
// - Definitive success/error envelope checks in rr-error.js
// - Any RR-specific headers (dealer/tenant/site) once known
// -----------------------------------------------------------------------------
const { MakeRRCall, RRActions } = require("./rr-helpers");
const { assertRrOk } = require("./rr-error");
const { mapCustomerInsert, mapCustomerUpdate } = require("./rr-mappers");
/**
* Create a customer in RR.
*
* @param {Object} deps
* @param {Socket|ExpressRequest} deps.socket
* @param {Object} deps.redisHelpers - redisHelpers API (not used here directly)
* @param {Object} deps.JobData - Rome Job data used to build the payload
* @returns {Promise<any>} RR response (envelope TBD)
*/
async function RrCustomerInsert({ socket, redisHelpers, JobData }) {
// Map JobData -> RR "Customer Insert" request body
const body = mapCustomerInsert(JobData);
const data = await MakeRRCall({
...RRActions.CreateCustomer,
...RRActions.CreateCustomer, // POST /customer/v1/
body,
redisHelpers,
socket,
jobid: JobData.id
jobid: JobData?.id
});
// TODO: assertRrOk should be updated once RRs success envelope is finalized
return assertRrOk(data, { apiName: "RR Create Customer" });
}
/**
* Update an existing customer in RR.
*
* @param {Object} deps
* @param {Socket|ExpressRequest} deps.socket
* @param {Object} deps.redisHelpers
* @param {Object} deps.JobData - context only (job id for correlation)
* @param {Object} deps.existingCustomer - Current RR customer record
* @param {Object} deps.patch - Minimal delta from UI to apply onto existingCustomer
* @returns {Promise<any>} RR response
*/
async function RrCustomerUpdate({ socket, redisHelpers, JobData, existingCustomer, patch }) {
// Build a merged/normalized payload for RR Update
const body = mapCustomerUpdate(existingCustomer, patch);
const data = await MakeRRCall({
...RRActions.UpdateCustomer, // add to RRActions
...RRActions.UpdateCustomer, // PUT /customer/v1/ (append id inside body/path per final spec)
body,
redisHelpers,
socket,
jobid: JobData.id
jobid: JobData?.id
});
return assertRrOk(data, { apiName: "RR Update Customer" });
}