feature/IO-3558-Reynolds-Part-2 - Initial
This commit is contained in:
@@ -86,8 +86,9 @@ const buildMessageJSONString = ({ error, classification, result, fallback }) =>
|
||||
/**
|
||||
* Success: mark job exported + (optionally) insert a success log.
|
||||
* Uses queries.MARK_JOB_EXPORTED (same shape as Fortellis/PBS).
|
||||
* @param {boolean} isEarlyRo - If true, only logs success but does NOT change job status (for early RO creation)
|
||||
*/
|
||||
const markRRExportSuccess = async ({ socket, jobId, job, bodyshop, result, metaExtra = {} }) => {
|
||||
const markRRExportSuccess = async ({ socket, jobId, job, bodyshop, result, metaExtra = {}, isEarlyRo = false }) => {
|
||||
const endpoint = process.env.GRAPHQL_ENDPOINT;
|
||||
if (!endpoint) throw new Error("GRAPHQL_ENDPOINT not configured");
|
||||
const token = getAuthToken(socket);
|
||||
@@ -96,11 +97,40 @@ const markRRExportSuccess = async ({ socket, jobId, job, bodyshop, result, metaE
|
||||
const client = new GraphQLClient(endpoint, {});
|
||||
client.setHeaders({ Authorization: `Bearer ${token}` });
|
||||
|
||||
const meta = buildRRExportMeta({ result, extra: metaExtra });
|
||||
|
||||
// For early RO, we only insert a log but do NOT change job status or mark as exported
|
||||
if (isEarlyRo) {
|
||||
try {
|
||||
await client.request(queries.INSERT_EXPORT_LOG, {
|
||||
logs: [
|
||||
{
|
||||
bodyshopid: bodyshop?.id || job?.bodyshop?.id,
|
||||
jobid: jobId,
|
||||
successful: true,
|
||||
useremail: socket?.user?.email || null,
|
||||
metadata: meta,
|
||||
message: buildMessageJSONString({ result, fallback: "RR early RO created" })
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
CreateRRLogEvent(socket, "INFO", "RR early RO: success log inserted (job status unchanged)", {
|
||||
jobId
|
||||
});
|
||||
} catch (e) {
|
||||
CreateRRLogEvent(socket, "ERROR", "RR early RO: failed to insert success log", {
|
||||
jobId,
|
||||
error: e?.message
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Full export: mark job as exported and insert success log
|
||||
const exportedStatus =
|
||||
job?.bodyshop?.md_ro_statuses?.default_exported || bodyshop?.md_ro_statuses?.default_exported || "Exported*";
|
||||
|
||||
const meta = buildRRExportMeta({ result, extra: metaExtra });
|
||||
|
||||
try {
|
||||
await client.request(queries.MARK_JOB_EXPORTED, {
|
||||
jobId,
|
||||
|
||||
Reference in New Issue
Block a user