From 848ce168daec8784f8630fbc270abcecaf727120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Rosenl=C3=B6cher?= Date: Fri, 16 Oct 2026 19:34:04 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Bereitschaft=20=C3=BCberspringt=20ein=20?= =?UTF-8?q?Los,=20dessen=20Mittel=20zwischen=20zwei=20Lesungen=20verschwan?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prisma liest das Mittel in einer zweiten Abfrage; ein gleichzeitig mit seinem Mittel gelöschtes Los kam mit medicine null zurück und führte zu 500 (CI-Lauf 836, compliance-readiness). Co-Authored-By: Claude Opus 5.5 (1M context) --- .../compliance/readiness/loaders/lots.loader.spec.ts | 11 +++++++++++ .../src/compliance/readiness/loaders/lots.loader.ts | 8 ++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ApiCore-Backend/src/compliance/readiness/loaders/lots.loader.spec.ts b/ApiCore-Backend/src/compliance/readiness/loaders/lots.loader.spec.ts index 4088886..677f73b 100644 --- a/ApiCore-Backend/src/compliance/readiness/loaders/lots.loader.spec.ts +++ b/ApiCore-Backend/src/compliance/readiness/loaders/lots.loader.spec.ts @@ -65,6 +65,17 @@ describe('loadLots', () => { }); }); + it('leaves out a lot whose medicine vanished between the two reads', async () => { + const { db } = fakeDb( + [lotRow({ id: 'l1' }), lotRow({ id: 'gone', medicine: null })], + [], + ); + + const { lots } = await loadLots(db); + + expect(lots.map((lot) => lot.id)).toEqual(['l1']); + }); + it('reads only active medicines', async () => { const { db } = fakeDb( [], diff --git a/ApiCore-Backend/src/compliance/readiness/loaders/lots.loader.ts b/ApiCore-Backend/src/compliance/readiness/loaders/lots.loader.ts index 659386f..844d708 100644 --- a/ApiCore-Backend/src/compliance/readiness/loaders/lots.loader.ts +++ b/ApiCore-Backend/src/compliance/readiness/loaders/lots.loader.ts @@ -57,12 +57,16 @@ export async function loadLots(db: DbClient): Promise { orderBy: [{ name: 'asc' }, { id: 'asc' }], }), ]); + // Prisma reads the medicine in a second query: a lot deleted together with + // its medicine in between comes back with medicine null (CI run 836, 500). + // Such a lot is gone, so it is left out. + const present = rows.filter((row) => (row.medicine as unknown) !== null); const totals = await lotTotals( db, - rows.map((row) => row.id), + present.map((row) => row.id), ); return { - lots: rows.map((row): ReadinessLot => ({ + lots: present.map((row): ReadinessLot => ({ id: row.id, medicineId: row.medicineId, medicineName: row.medicine.name,