refresh EKAP document counts from detail

This commit is contained in:
2026-09-06 19:46:56 +03:00
parent ce072997ac
commit cdf6e988e4
4 changed files with 57 additions and 3 deletions
+14 -2
View File
@@ -14,6 +14,12 @@ import { searchTenders, ekapPost, getIhaleDetay } from './ekap-v2.mjs';
import { officialDateFields } from './tender-quality.mjs';
const UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36';
const documentCount = (record, fallback = 0) => {
const declared = Number(record?.dokumanSayisi);
const listed = Array.isArray(record?.dokumanListe) ? record.dokumanListe.length : 0;
const fallbackCount = Number(fallback);
return Math.max(Number.isFinite(declared) ? declared : 0, listed, Number.isFinite(fallbackCount) ? fallbackCount : 0);
};
/** IKN'den taze bir EKAP kaydı bulur (id token anlıktır, saklanamaz). */
export async function findByIkn(ikn) {
@@ -28,6 +34,10 @@ export async function findByIkn(ikn) {
/** İhale dokümanlarının EKAP görüntüleme/indirme adresini üretir. */
export async function documentUrl(ikn) {
const t = await findByIkn(ikn);
// Arama yanıtındaki doküman sayısı gecikebilir; detay kaydı güncel
// doküman listesini taşıyorsa kullanıcıya onu göster.
let detail = null;
try { detail = await getIhaleDetay(t.id); } catch { /* yönlendirme yine üretilebilir */ }
const d = await ekapPost('/b_ihalearama/api/EkapDokumanYonlendirme/GetDokumanUrl', {
islemId: '1',
ihaleId: t.id,
@@ -40,8 +50,8 @@ export async function documentUrl(ikn) {
ikn: t.ikn,
ihaleAdi: t.ihaleAdi,
idareAdi: t.idareAdi,
dokumanSayisi: t.dokumanSayisi ?? 0,
dokumanListe: t.dokumanListe || [],
dokumanSayisi: documentCount(detail, t.dokumanSayisi),
dokumanListe: detail?.dokumanListe || t.dokumanListe || [],
};
}
@@ -82,6 +92,8 @@ export async function ilanMetni(ikn) {
idareAdi: d?.idareAdi || t.idareAdi,
ilanSayisi: ilanlar.length,
okasSayisi: okas.length,
dokumanSayisi: documentCount(d, t.dokumanSayisi),
dokumanListe: d?.dokumanListe || t.dokumanListe || [],
...officialDate,
metin: parcalar.join('\n'),
};