fix: Bereitschaft überspringt ein Los, dessen Mittel zwischen zwei Lesungen verschwand

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) <[email protected]>
This commit is contained in:
Nick.RosenloecherandClaude Opus 5.5 committed 2026-10-16 19:34:04 +02:00
1 parent f307e7da66
commit 848ce168da
2 files changed
+17 -2

No files matched your search

@@ -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(
[],
@@ -57,12 +57,16 @@ export async function loadLots(db: DbClient): Promise<ReadinessLots> {
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,