feature/IO-3255-simplified-parts-management - Soft Deletes
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user