fix: bind bid prices and review to source content
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// Prices belong to a specific source row, never to its current array position.
|
||||
export function sourceRows(tender, results) {
|
||||
const items = tender?.items?.length
|
||||
? tender.items.map(k => ({ ...k, name: k.ad, quantity: `${k.miktar} ${k.birim || ''}`, keySpecs: k.keySpecs || [] }))
|
||||
: (Array.isArray(results?.itemsAndSpecs) ? results.itemsAndSpecs : []);
|
||||
const occurrences = new Map();
|
||||
return items.map(k => {
|
||||
const identity = JSON.stringify([k.id ?? k.no ?? null, k.kisim ?? null, k.name, k.quantity, k.keySpecs || []]);
|
||||
const occurrence = occurrences.get(identity) || 0;
|
||||
occurrences.set(identity, occurrence + 1);
|
||||
return { ...k, priceKey: JSON.stringify([identity, occurrence]) };
|
||||
});
|
||||
}
|
||||
|
||||
// Exact canonical content, not a lossy hash. Reordering distinct rows is harmless;
|
||||
// a changed quantity, specification, announcement or document requirement is not.
|
||||
export function bidSourceSnapshot(tender, results, rows = sourceRows(tender, results)) {
|
||||
return JSON.stringify({
|
||||
tender: tender?.ikn || tender?.id,
|
||||
announcement: tender?.aciklama || '',
|
||||
deadline: [tender?.tarih || '', tender?.saat || ''],
|
||||
documentVersion: results?.documentVersion ?? tender?.documentVersion ?? null,
|
||||
rows: rows.map(r => r.priceKey).sort(),
|
||||
documents: results?.documentChecklist || [],
|
||||
});
|
||||
}
|
||||
|
||||
export function restoreBidPrices(draft = {}) {
|
||||
// Old positional prices cannot safely be assigned without their original rows.
|
||||
return draft.priceSchema === 1 && draft.pricesBySource ? draft.pricesBySource : {};
|
||||
}
|
||||
Reference in New Issue
Block a user