rrScratch3 - Capture external DMS Id
This commit is contained in:
@@ -3698,6 +3698,7 @@
|
|||||||
- deliverchecklist
|
- deliverchecklist
|
||||||
- depreciation_taxes
|
- depreciation_taxes
|
||||||
- dms_allocation
|
- dms_allocation
|
||||||
|
- dms_id
|
||||||
- driveable
|
- driveable
|
||||||
- employee_body
|
- employee_body
|
||||||
- employee_csr
|
- employee_csr
|
||||||
@@ -3975,6 +3976,7 @@
|
|||||||
- deliverchecklist
|
- deliverchecklist
|
||||||
- depreciation_taxes
|
- depreciation_taxes
|
||||||
- dms_allocation
|
- dms_allocation
|
||||||
|
- dms_id
|
||||||
- driveable
|
- driveable
|
||||||
- employee_body
|
- employee_body
|
||||||
- employee_csr
|
- employee_csr
|
||||||
@@ -4264,6 +4266,7 @@
|
|||||||
- deliverchecklist
|
- deliverchecklist
|
||||||
- depreciation_taxes
|
- depreciation_taxes
|
||||||
- dms_allocation
|
- dms_allocation
|
||||||
|
- dms_id
|
||||||
- driveable
|
- driveable
|
||||||
- employee_body
|
- employee_body
|
||||||
- employee_csr
|
- employee_csr
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
-- Could not auto-generate a down migration.
|
||||||
|
-- Please write an appropriate down migration for the SQL below:
|
||||||
|
-- alter table "public"."jobs" add column "dms_id" text
|
||||||
|
-- null;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
alter table "public"."jobs" add column "dms_id" text
|
||||||
|
null;
|
||||||
@@ -2195,8 +2195,6 @@ mutation UPDATE_BILLS($billids: [uuid!]!, $bill: bills_set_input!, $logs: [expor
|
|||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
exports.UPDATE_OLD_TRANSITION = `mutation UPDATE_OLD_TRANSITION($jobid: uuid!, $existingTransition: transitions_set_input!){
|
exports.UPDATE_OLD_TRANSITION = `mutation UPDATE_OLD_TRANSITION($jobid: uuid!, $existingTransition: transitions_set_input!){
|
||||||
update_transitions(where:{jobid:{_eq:$jobid}, end:{_is_null:true
|
update_transitions(where:{jobid:{_eq:$jobid}, end:{_is_null:true
|
||||||
}}, _set:$existingTransition){
|
}}, _set:$existingTransition){
|
||||||
@@ -3173,3 +3171,10 @@ mutation INSERT_MEDIA_ANALYTICS($mediaObject: media_analytics_insert_input!) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports.SET_JOB_DMS_ID = `mutation SetJobDmsId($id: uuid!, $dms_id: String!) {
|
||||||
|
update_jobs_by_pk(pk_columns: { id: $id }, _set: { dms_id: $dms_id }) {
|
||||||
|
id
|
||||||
|
dms_id
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const CreateRRLogEvent = require("./rr-logger-event");
|
|||||||
const { extractRrResponsibilityCenters } = require("./rr-responsibility-centers");
|
const { extractRrResponsibilityCenters } = require("./rr-responsibility-centers");
|
||||||
const CdkCalculateAllocations = require("./rr-calculate-allocations").default;
|
const CdkCalculateAllocations = require("./rr-calculate-allocations").default;
|
||||||
const { resolveRROpCodeFromBodyshop } = require("./rr-utils");
|
const { resolveRROpCodeFromBodyshop } = require("./rr-utils");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Derive RR status information from response object.
|
* Derive RR status information from response object.
|
||||||
* @param rrRes
|
* @param rrRes
|
||||||
|
|||||||
@@ -123,6 +123,47 @@ const getBodyshopForSocket = async ({ bodyshopId, socket }) => {
|
|||||||
return bodyshop;
|
return bodyshop;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GraphQL mutation to set job.dms_id
|
||||||
|
* @param socket
|
||||||
|
* @param jobId
|
||||||
|
* @param dmsId
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
const setJobDmsIdForSocket = async ({ socket, jobId, dmsId }) => {
|
||||||
|
if (!jobId || !dmsId) {
|
||||||
|
CreateRRLogEvent(socket, "WARN", "setJobDmsIdForSocket called without jobId or dmsId", {
|
||||||
|
jobId,
|
||||||
|
dmsId
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const endpoint = process.env.GRAPHQL_ENDPOINT;
|
||||||
|
if (!endpoint) throw new Error("GRAPHQL_ENDPOINT not configured");
|
||||||
|
|
||||||
|
const token = (socket?.data && socket.data.authToken) || (socket?.handshake?.auth && socket.handshake.auth.token);
|
||||||
|
if (!token) throw new Error("Missing auth token for setJobDmsIdForSocket");
|
||||||
|
|
||||||
|
const client = new GraphQLClient(endpoint, {});
|
||||||
|
await client
|
||||||
|
.setHeaders({ Authorization: `Bearer ${token}` })
|
||||||
|
.request(queries.SET_JOB_DMS_ID, { id: jobId, dms_id: String(dmsId) });
|
||||||
|
|
||||||
|
CreateRRLogEvent(socket, "INFO", "Linked job.dms_id to RR RO", {
|
||||||
|
jobId,
|
||||||
|
dmsId: String(dmsId)
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
CreateRRLogEvent(socket, "ERROR", "Failed to set job.dms_id after RR create/update", {
|
||||||
|
jobId,
|
||||||
|
dmsId,
|
||||||
|
message: err?.message || String(err),
|
||||||
|
stack: err?.stack
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* Build advisors cache namespace and field
|
* Build advisors cache namespace and field
|
||||||
* @param bodyshopId
|
* @param bodyshopId
|
||||||
@@ -608,6 +649,22 @@ const registerRREvents = ({ socket, redisHelpers }) => {
|
|||||||
|
|
||||||
const outsdRoNo = data?.outsdRoNo ?? job?.ro_number ?? job?.id ?? null;
|
const outsdRoNo = data?.outsdRoNo ?? job?.ro_number ?? job?.id ?? null;
|
||||||
|
|
||||||
|
// ✅ Persist DMS RO number on the job (jobs.dms_id)
|
||||||
|
if (dmsRoNo) {
|
||||||
|
await setJobDmsIdForSocket({ socket, jobId: rid, dmsId: dmsRoNo });
|
||||||
|
} else {
|
||||||
|
CreateRRLogEvent(socket, "WARN", "RR export succeeded but no DMS RO number was returned", {
|
||||||
|
jobId: rid,
|
||||||
|
resultPreview: {
|
||||||
|
roNo: result?.roNo,
|
||||||
|
data: {
|
||||||
|
dmsRoNo: data?.dmsRoNo,
|
||||||
|
outsdRoNo: data?.outsdRoNo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await redisHelpers.setSessionTransactionData(
|
await redisHelpers.setSessionTransactionData(
|
||||||
socket.id,
|
socket.id,
|
||||||
ns,
|
ns,
|
||||||
|
|||||||
Reference in New Issue
Block a user