feat: allow a honey batch to be split across multiple storage containers
A batch that doesn't fit in one container (e.g. 125 kg across 5 x 25 kg buckets) had no way to be represented - HoneyBatch.storageContainerId is a single nullable FK. Adds HoneyBatchContainerAllocation as an additive join table (container + amount per batch), independent of the existing single-container/relocate() flow which still covers the simple one-container case unchanged. - GET/PUT/DELETE /honey-batches/:id/containers[/:containerId], reusing the existing honey-batches:relocate permission. - Assigning a container is an upsert (@@unique on batch+container), and the total assigned is validated against the batch's own amount when known. - New "Aufteilung auf mehrere Behälter" card on the honey batch detail page, alongside (not replacing) the existing storage card. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
1 parent
c91dc9ebf1
commit
1054a845ef
10 files changed
+579
-7
No files matched your search
@@ -1,10 +1,12 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
@@ -16,6 +18,7 @@ import { CreateHoneyBatchDto } from './dto/create-honey-batch.dto';
|
||||
import { UpdateHoneyBatchDto } from './dto/update-honey-batch.dto';
|
||||
import { CreateHoneyMeasurementDto } from './dto/create-honey-measurement.dto';
|
||||
import { RelocateHoneyBatchDto } from './dto/relocate-honey-batch.dto';
|
||||
import { SetHoneyBatchContainerAllocationDto } from './dto/set-honey-batch-container-allocation.dto';
|
||||
import { HoneyBatchesService } from './honey-batches.service';
|
||||
|
||||
@ApiTags('honey-batches')
|
||||
@@ -48,6 +51,42 @@ export class HoneyBatchesController {
|
||||
return this.honeyBatchesService.findRelocations(id);
|
||||
}
|
||||
|
||||
@RequirePermission('honey-batches:read')
|
||||
@Get(':id/containers')
|
||||
listContainerAllocations(@Param('id') id: string) {
|
||||
return this.honeyBatchesService.listContainerAllocations(id);
|
||||
}
|
||||
|
||||
@RequirePermission('honey-batches:relocate')
|
||||
@Put(':id/containers/:containerId')
|
||||
setContainerAllocation(
|
||||
@Param('id') id: string,
|
||||
@Param('containerId') containerId: string,
|
||||
@Body() dto: SetHoneyBatchContainerAllocationDto,
|
||||
@CurrentUser() actor: AuthenticatedUser,
|
||||
) {
|
||||
return this.honeyBatchesService.setContainerAllocation(
|
||||
id,
|
||||
containerId,
|
||||
dto,
|
||||
actor.id,
|
||||
);
|
||||
}
|
||||
|
||||
@RequirePermission('honey-batches:relocate')
|
||||
@Delete(':id/containers/:containerId')
|
||||
removeContainerAllocation(
|
||||
@Param('id') id: string,
|
||||
@Param('containerId') containerId: string,
|
||||
@CurrentUser() actor: AuthenticatedUser,
|
||||
) {
|
||||
return this.honeyBatchesService.removeContainerAllocation(
|
||||
id,
|
||||
containerId,
|
||||
actor.id,
|
||||
);
|
||||
}
|
||||
|
||||
@RequirePermission('honey-batches:relocate')
|
||||
@Post(':id/relocate')
|
||||
relocate(
|
||||
|
||||
Reference in new issue
Block a user