feat(backend): Lagerbehälter-Umlagerung für Honigchargen (Modul 32)

Neues HoneyBatchRelocation-Modell dokumentiert jede Umlagerung einer
Honigcharge zwischen Lagerbehältern (von/nach, Zeitpunkt, Benutzer,
Notiz). HoneyBatchesService.relocate() aktualisiert
HoneyBatch.storageContainerId transaktional zusammen mit dem
Historieneintrag; wirft NotFoundException bei unbekanntem Zielbehälter.

Neue Endpunkte: POST /honey-batches/:id/relocate,
GET /honey-batches/:id/relocations. honeyBatchInclude liefert jetzt
zusätzlich den aktuell zugeordneten storageContainer mit.

Unit- und E2E-Tests ergänzt (Mehrfachumlagerung, Historienreihenfolge,
404 bei unbekanntem Behälter). Migration auf Dev- und Test-Datenbank
angewendet.
This commit is contained in:
Nick Szaunig committed 2026-08-24 16:55:15 +02:00
1 parent fa13543578
commit 59a320ae36
7 files changed
+328 -44

No files matched your search

@@ -10,6 +10,13 @@ interface HoneyBatchBody {
id: string;
batchNumber: string;
measurements: { id: string }[];
storageContainerId: string | null;
}
interface RelocationBody {
id: string;
fromStorageContainerId: string | null;
toStorageContainerId: string;
}
interface TraceabilityBody {
@@ -33,6 +40,8 @@ describe('Honey batches (e2e)', () => {
let harvestId: string;
let extractionId: string;
let honeyBatchId: string;
let containerAId: string;
let containerBId: string;
beforeAll(async () => {
app = await createTestApp();
@@ -79,13 +88,27 @@ describe('Honey batches (e2e)', () => {
await prisma.extractionHarvest.create({
data: { extractionId, harvestId },
});
const containerA = await prisma.storageContainer.create({
data: { code: `LB-A-${Date.now()}` },
});
containerAId = containerA.id;
const containerB = await prisma.storageContainer.create({
data: { code: `LB-B-${Date.now()}` },
});
containerBId = containerB.id;
});
afterAll(async () => {
if (honeyBatchId) {
await prisma.honeyBatchRelocation.deleteMany({
where: { honeyBatchId },
});
await prisma.honeyMeasurement.deleteMany({ where: { honeyBatchId } });
await prisma.honeyBatch.deleteMany({ where: { id: honeyBatchId } });
}
await prisma.storageContainer.deleteMany({
where: { id: { in: [containerAId, containerBId] } },
});
await prisma.extractionHarvest.deleteMany({ where: { extractionId } });
await prisma.extraction.deleteMany({ where: { id: extractionId } });
await prisma.harvestColony.deleteMany({ where: { harvestId } });
@@ -142,4 +165,41 @@ describe('Honey batches (e2e)', () => {
expect(trace.extraction.id).toBe(extractionId);
expect(trace.harvests[0]?.colonies[0]?.code).toBeDefined();
});
it('relocates the honey batch into a storage container', async () => {
const response = await request(app.getHttpServer())
.post(`/api/v1/honey-batches/${honeyBatchId}/relocate`)
.set('Authorization', `Bearer ${staffToken}`)
.send({ storageContainerId: containerAId, notes: 'Erstbefüllung' })
.expect(201);
const honeyBatch = response.body as HoneyBatchBody;
expect(honeyBatch.storageContainerId).toBe(containerAId);
});
it('rejects relocation to a nonexistent storage container', () => {
return request(app.getHttpServer())
.post(`/api/v1/honey-batches/${honeyBatchId}/relocate`)
.set('Authorization', `Bearer ${staffToken}`)
.send({ storageContainerId: 'does-not-exist' })
.expect(404);
});
it('relocates the honey batch again and records both moves in history', async () => {
await request(app.getHttpServer())
.post(`/api/v1/honey-batches/${honeyBatchId}/relocate`)
.set('Authorization', `Bearer ${staffToken}`)
.send({ storageContainerId: containerBId })
.expect(201);
const response = await request(app.getHttpServer())
.get(`/api/v1/honey-batches/${honeyBatchId}/relocations`)
.set('Authorization', `Bearer ${staffToken}`)
.expect(200);
const relocations = response.body as RelocationBody[];
expect(relocations).toHaveLength(2);
expect(relocations[0].toStorageContainerId).toBe(containerBId);
expect(relocations[0].fromStorageContainerId).toBe(containerAId);
expect(relocations[1].toStorageContainerId).toBe(containerAId);
expect(relocations[1].fromStorageContainerId).toBeNull();
});
});