diff --git a/server/integrations/partsManagement/endpoints/vehicleDamageEstimateChgRq.js b/server/integrations/partsManagement/endpoints/vehicleDamageEstimateChgRq.js index d38d0a162..254224385 100644 --- a/server/integrations/partsManagement/endpoints/vehicleDamageEstimateChgRq.js +++ b/server/integrations/partsManagement/endpoints/vehicleDamageEstimateChgRq.js @@ -8,7 +8,7 @@ const { extractPartsTaxRates } = require("./lib/extractPartsTaxRates"); const { GET_JOB_BY_CLAIM, UPDATE_JOB_BY_ID, - DELETE_JOBLINES_BY_IDS, + SOFT_DELETE_JOBLINES_BY_IDS, INSERT_JOBLINES } = require("../partsManagement.queries"); @@ -207,13 +207,13 @@ const partsManagementVehicleDamageEstimateChgRq = async (req, res) => { // Build a set of unq_seq that will be updated (replaced). We delete them first to avoid duplicates. const updatedSeqs = Array.from( - new Set((updatedLines || []).map((l) => l && l.unq_seq).filter((v) => Number.isInteger(v))) + new Set((updatedLines || []).map((l) => l?.unq_seq).filter((v) => Number.isInteger(v))) ); - if ((deletedLineIds && deletedLineIds.length) || (updatedSeqs && updatedSeqs.length)) { + if (deletedLineIds?.length || updatedSeqs?.length) { const allToDelete = Array.from(new Set([...(deletedLineIds || []), ...(updatedSeqs || [])])); if (allToDelete.length) { - await client.request(DELETE_JOBLINES_BY_IDS, { jobid: job.id, unqSeqs: allToDelete }); + await client.request(SOFT_DELETE_JOBLINES_BY_IDS, { jobid: job.id, unqSeqs: allToDelete }); } } diff --git a/server/integrations/partsManagement/partsManagement.queries.js b/server/integrations/partsManagement/partsManagement.queries.js index 4e8fb2107..3e682c4f8 100644 --- a/server/integrations/partsManagement/partsManagement.queries.js +++ b/server/integrations/partsManagement/partsManagement.queries.js @@ -102,6 +102,18 @@ const DELETE_JOBLINES_BY_IDS = ` } `; +// Soft delete joblines by marking removed=true instead of hard-deleting +const SOFT_DELETE_JOBLINES_BY_IDS = ` + mutation SoftDeleteJoblinesByIds($jobid: uuid!, $unqSeqs: [Int!]!) { + update_joblines( + where: { jobid: { _eq: $jobid }, unq_seq: { _in: $unqSeqs } }, + _set: { removed: true } + ) { + affected_rows + } + } +`; + const INSERT_JOBLINES = ` mutation InsertJoblines($joblines: [joblines_insert_input!]!) { insert_joblines(objects: $joblines) { @@ -243,6 +255,7 @@ module.exports = { UPSERT_JOBLINES, DELETE_JOBLINES_BY_JOBID, DELETE_JOBLINES_BY_IDS, + SOFT_DELETE_JOBLINES_BY_IDS, INSERT_JOBLINES, CHECK_EXTERNAL_SHOP_ID, CREATE_SHOP,