feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Expanded Logs / Formatting change

This commit is contained in:
Dave
2025-11-12 17:01:54 -05:00
parent 556cd993b9
commit 90f653c0b7
13 changed files with 444 additions and 254 deletions

View File

@@ -3,12 +3,11 @@ const queries = require("../graphql-client/queries");
const CreateRRLogEvent = require("./rr-logger-event");
/** Get bearer token from the socket (same approach used elsewhere) */
function getAuthToken(socket) {
return (socket?.data && socket.data.authToken) || (socket?.handshake?.auth && socket.handshake.auth.token) || null;
}
const getAuthToken = (socket) =>
(socket?.data && socket.data.authToken) || (socket?.handshake?.auth && socket.handshake.auth.token) || null;
/** Compact metadata for RR */
function buildRRExportMeta({ result, extra = {} }) {
const buildRRExportMeta = ({ result, extra = {} }) => {
const roStatus = result?.roStatus || result?.data?.roStatus || null;
return {
provider: "rr",
@@ -25,10 +24,10 @@ function buildRRExportMeta({ result, extra = {} }) {
parsed: result?.parsed,
...extra
};
}
};
/** Build a stringified JSON array for the `message` text column */
function buildMessageJSONString({ error, classification, result, fallback }) {
const buildMessageJSONString = ({ error, classification, result, fallback }) => {
const msgs = [];
const clean = (v) => {
@@ -63,13 +62,13 @@ function buildMessageJSONString({ error, classification, result, fallback }) {
const arr = msgs.length ? msgs : ["RR export failed"];
return JSON.stringify(arr);
}
};
/**
* Success: mark job exported + (optionally) insert a success log.
* Uses queries.MARK_JOB_EXPORTED (same shape as Fortellis/PBS).
*/
async function markRRExportSuccess({ socket, jobId, job, bodyshop, result, metaExtra = {} }) {
const markRRExportSuccess = async ({ socket, jobId, job, bodyshop, result, metaExtra = {} }) => {
const endpoint = process.env.GRAPHQL_ENDPOINT;
if (!endpoint) throw new Error("GRAPHQL_ENDPOINT not configured");
const token = getAuthToken(socket);
@@ -114,13 +113,13 @@ async function markRRExportSuccess({ socket, jobId, job, bodyshop, result, metaE
error: e?.message
});
}
}
};
/**
* Failure: insert failure ExportsLog with `message` as JSON **string** (text column).
* Uses queries.INSERT_EXPORT_LOG($logs: [exportlog_insert_input!]!).
*/
async function insertRRFailedExportLog({ socket, jobId, job, bodyshop, error, classification, result }) {
const insertRRFailedExportLog = async ({ socket, jobId, job, bodyshop, error, classification, result }) => {
const endpoint = process.env.GRAPHQL_ENDPOINT;
if (!endpoint) throw new Error("GRAPHQL_ENDPOINT not configured");
const token = getAuthToken(socket);
@@ -163,7 +162,7 @@ async function insertRRFailedExportLog({ socket, jobId, job, bodyshop, error, cl
error: e?.message
});
}
}
};
module.exports = {
markRRExportSuccess,