feature/IO-3255-simplified-parts-management - Change From Claim to JobID (chgrq)
This commit is contained in:
@@ -6,7 +6,7 @@ const { parseXml, normalizeXmlObject } = require("../partsManagementUtils");
|
||||
const { extractPartsTaxRates } = require("./lib/extractPartsTaxRates");
|
||||
|
||||
const {
|
||||
GET_JOB_BY_CLAIM,
|
||||
GET_JOB_BY_ID,
|
||||
UPDATE_JOB_BY_ID,
|
||||
SOFT_DELETE_JOBLINES_BY_IDS,
|
||||
INSERT_JOBLINES,
|
||||
@@ -16,13 +16,13 @@ const {
|
||||
/**
|
||||
* Finds a job by shop ID and claim number.
|
||||
* @param shopId
|
||||
* @param claimNum
|
||||
* @param jobId
|
||||
* @param logger
|
||||
* @returns {Promise<*|null>}
|
||||
*/
|
||||
const findJob = async (shopId, claimNum, logger) => {
|
||||
const findJob = async (shopId, jobId, logger) => {
|
||||
try {
|
||||
const { jobs } = await client.request(GET_JOB_BY_CLAIM, { shopid: shopId, clm_no: claimNum });
|
||||
const { jobs } = await client.request(GET_JOB_BY_ID, { shopid: shopId, jobid: jobId });
|
||||
return jobs?.[0] || null;
|
||||
} catch (err) {
|
||||
logger.log("parts-job-lookup-failed", "error", null, null, { error: err });
|
||||
@@ -214,11 +214,12 @@ const partsManagementVehicleDamageEstimateChgRq = async (req, res) => {
|
||||
if (!rq) return res.status(400).send("Missing <VehicleDamageEstimateChgRq>");
|
||||
|
||||
const shopId = rq.ShopID;
|
||||
const claimNum = rq.ClaimInfo?.ClaimNum;
|
||||
const jobId = rq.JobID;
|
||||
|
||||
if (!shopId || !claimNum) return res.status(400).send("Missing ShopID or ClaimNum");
|
||||
if (!shopId || !jobId) return res.status(400).send("Missing ShopID or JobID");
|
||||
|
||||
const job = await findJob(shopId, jobId, logger);
|
||||
|
||||
const job = await findJob(shopId, claimNum, logger);
|
||||
if (!job) return res.status(404).send("Job not found");
|
||||
|
||||
// --- Get updated lines and their unq_seq ---
|
||||
|
||||
@@ -44,6 +44,18 @@ const GET_JOB_BY_CLAIM = `
|
||||
}
|
||||
`;
|
||||
|
||||
const GET_JOB_BY_ID = `
|
||||
query GetJobByID($shopid: uuid!, $jobid: uuid!) {
|
||||
jobs(
|
||||
where: { shopid: { _eq: $shopid }, id: { _eq: $jobid } }
|
||||
order_by: { created_at: desc }
|
||||
limit: 1
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const UPDATE_JOB_BY_ID = `
|
||||
mutation UpdateJobById($id: uuid!, $job: jobs_set_input!) {
|
||||
update_jobs_by_pk(pk_columns: { id: $id }, _set: $job) {
|
||||
@@ -228,5 +240,6 @@ module.exports = {
|
||||
DELETE_JOBLINES_BY_JOB_IDS,
|
||||
DELETE_JOBS_BY_IDS,
|
||||
DELETE_AUDIT_TRAIL_BY_SHOP,
|
||||
GET_JOBLINES_NOTES_BY_JOBID_UNQSEQ
|
||||
GET_JOBLINES_NOTES_BY_JOBID_UNQSEQ,
|
||||
GET_JOB_BY_ID
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user