Data-integrity fixes found in a systematic review of ApiCore: - Bottling booked the honey batch amount from a value read outside the transaction and wrote an absolute result back, so two concurrent bottlings (double tap, two devices) could both pass the check and one deduction was lost. Bookings now use a conditional UPDATE inside the transaction; corrections and deletions give amounts back atomically. - Outgoing stock movements could drive stock below zero; the removal is now a conditional decrement that refuses when stock is insufficient. - Weak, conspicuous and queenless colonies were treated as "not active" and could not be moved, split or merged - uniting a queenless colony is the textbook merge. Only terminal statuses lock a colony now; merging a colony into itself and dissolving twice are rejected. - Moving a queen to another colony failed on the unique currentQueenId because the old colony kept pointing at her. The old colony now releases her (and becomes QUEENLESS); a queenless colony receiving a queen becomes ACTIVE; dissolved colonies cannot receive a queen. - Completing a task twice moved completedAt and re-sent the webhook; reopening a task kept completedAt. Recurring templates created tasks without a due date and caught up missed weeks one stale task at a time. - Automation rules created a new task and warning on every trigger (every stock removal below minimum). Tasks now record their source trigger and at most one open task per rule and object exists. The varroa threshold (mites per day) is only compared with natural-mite-fall rates, not with sample-based counts in another unit. - New opt-in Idempotency-Key support for record-creating endpoints, so the offline queue can retry after a lost response without duplicates. - Permission catalog sync crashed replicas booting concurrently on a fresh database (unique violation); it now uses createMany/skipDuplicates. - Server-side validation for inspection rating scales (1-5), unique colony/harvest lists and net weight <= gross weight. - Stale e2e expectations updated (permission count, trigger list, real PNG fixture for the file-signature check). Migration is additive only (nullable Task column, new table). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|
import { RequirePermission } from '../auth/decorators/require-permission.decorator';
|
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
|
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
|
import { CreateInspectionDto } from './dto/create-inspection.dto';
|
|
import { CreateTaskFromInspectionDto } from './dto/create-task-from-inspection.dto';
|
|
import { UpdateInspectionDto } from './dto/update-inspection.dto';
|
|
import { InspectionsService } from './inspections.service';
|
|
import { Idempotent } from '../common/idempotency/idempotent.decorator';
|
|
|
|
@ApiTags('inspections')
|
|
@ApiBearerAuth()
|
|
@Controller('inspections')
|
|
export class InspectionsController {
|
|
constructor(private readonly inspectionsService: InspectionsService) {}
|
|
|
|
@RequirePermission('inspections:read')
|
|
@Get()
|
|
findAll() {
|
|
return this.inspectionsService.findAll();
|
|
}
|
|
|
|
@RequirePermission('inspections:read')
|
|
@Get(':id')
|
|
findOne(@Param('id') id: string) {
|
|
return this.inspectionsService.findById(id);
|
|
}
|
|
|
|
@RequirePermission('inspections:create')
|
|
@Idempotent()
|
|
@Post()
|
|
create(
|
|
@Body() dto: CreateInspectionDto,
|
|
@CurrentUser() actor: AuthenticatedUser,
|
|
) {
|
|
return this.inspectionsService.create(dto, actor.id);
|
|
}
|
|
|
|
@RequirePermission('inspections:update')
|
|
@Patch(':id')
|
|
update(
|
|
@Param('id') id: string,
|
|
@Body() dto: UpdateInspectionDto,
|
|
@CurrentUser() actor: AuthenticatedUser,
|
|
) {
|
|
return this.inspectionsService.update(id, dto, actor.id);
|
|
}
|
|
|
|
@RequirePermission('tasks:create')
|
|
@Post(':id/create-task')
|
|
createTask(
|
|
@Param('id') id: string,
|
|
@Body() dto: CreateTaskFromInspectionDto,
|
|
@CurrentUser() actor: AuthenticatedUser,
|
|
) {
|
|
return this.inspectionsService.createTaskFromInspection(id, dto, actor.id);
|
|
}
|
|
}
|