feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration / RRScratch2 / Math Adjustments / DMS State cleaning on Page load

This commit is contained in:
Dave
2025-11-25 14:58:53 -05:00
parent 2b1836d450
commit ec29a22984
4 changed files with 103 additions and 5 deletions

View File

@@ -115,6 +115,33 @@ function SetLegacyWebsocketHandlers(io) {
socket.on("disconnect", () => {
createLogEvent(socket, "DEBUG", `User disconnected.`);
});
// DMS reset for legacy WS (CDK / PBS)
socket.on("dms-reset-context", ({ jobId, mode } = {}, ack) => {
try {
// Clear any per-socket DMS state that can leak across jobs
socket.selectedCustomerId = null; // CDK / PBS AR
socket.txEnvelope = null; // PBS AP export
socket.apAllocations = null; // PBS AP allocations
createLogEvent(
socket,
"DEBUG",
`DMS reset-context (legacy WS): cleared per-socket state` +
(jobId ? ` (jobId=${jobId})` : "") +
(mode ? ` (mode=${mode})` : "")
);
if (typeof ack === "function") {
ack({ ok: true });
}
} catch (error) {
createLogEvent(socket, "ERROR", `DMS reset-context (legacy WS) failed: ${error.message}`);
if (typeof ack === "function") {
ack({ ok: false, error: error.message });
}
}
});
});
}