@@ -246,13 +246,23 @@ router.get('/:id/linked-work-orders', verifyToken, async (req, res) => {
|
||||
router.get('/linked-work-orders/all', verifyToken, async (req, res) => {
|
||||
try {
|
||||
const wos = await workOrderStore().listWorkOrders({});
|
||||
const map = {};
|
||||
const map = {}; // non-rejected only — whole-row/whole-document lock (Edit/Delete gating)
|
||||
const allMap = {}; // every non-deleted status, REJECTED included — used only to keep a
|
||||
// batch's own Batch No. (and its row) from being changed/removed once
|
||||
// ANY Work Order, even a rejected one awaiting edit+resubmit, already
|
||||
// references it by that number. Without this, correcting other fields
|
||||
// on a rejected batch's row (which IS meant to stay editable) could also
|
||||
// let the Batch No. itself drift, silently breaking the (productCode,
|
||||
// batchNumber) link back to that rejected Work Order.
|
||||
wos.forEach(w => {
|
||||
if (!w.intimationId || w.isDeleted || w.status === 'REJECTED') return;
|
||||
if (!w.intimationId || w.isDeleted) return;
|
||||
const k = String(w.intimationId);
|
||||
(map[k] || (map[k] = [])).push({ id: w.id, woNo: w.woNo, productCode: w.productCode || '', batchNumber: w.batchNumber || '' });
|
||||
const entry = { id: w.id, woNo: w.woNo, productCode: w.productCode || '', batchNumber: w.batchNumber || '' };
|
||||
(allMap[k] || (allMap[k] = [])).push(entry);
|
||||
if (w.status === 'REJECTED') return;
|
||||
(map[k] || (map[k] = [])).push(entry);
|
||||
});
|
||||
res.json({ success: true, data: map });
|
||||
res.json({ success: true, data: map, allData: allMap });
|
||||
} catch (err) { res.status(500).json({ success: false, message: err.message }); }
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user