None of these numeric business fields had a lower bound, so a negative honey weight, jar count, feeding amount, mite count, or stock quantity was silently accepted - each would corrupt whatever total or statistic it later feeds into. Added @Min(0): - Harvest: honeySuperCount, grossWeight, netWeight - HoneyBatch: amount (+ @Max(100) on waterContent, a percentage) - HoneyMeasurement: waterContent (+ @Max(100)) - Feeding: amount - Extraction: amount (+ @Max(100) on waterContent) - StockItem: quantity, minThreshold - VarroaMeasurement: durationMinutes, miteCount, calculatedValue Left temperature fields alone (extraction, inspection) - genuinely can be negative (winter inspections, outdoor storage) and no confident domain bound exists to apply instead. Update DTOs for these entities all extend PartialType(PickType(Create...Dto, [...])) from @nestjs/swagger, which preserves validation decorators, so no separate change was needed there. Co-Authored-By: Claude Sonnet 5 <[email protected]>
56 lines
881 B
TypeScript
56 lines
881 B
TypeScript
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
import {
|
|
ArrayMinSize,
|
|
IsArray,
|
|
IsDateString,
|
|
IsInt,
|
|
IsNumber,
|
|
IsOptional,
|
|
IsString,
|
|
Min,
|
|
} from 'class-validator';
|
|
|
|
export class CreateHarvestDto {
|
|
@ApiProperty()
|
|
@IsString()
|
|
apiaryId!: string;
|
|
|
|
@ApiProperty()
|
|
@IsDateString()
|
|
date!: string;
|
|
|
|
@ApiProperty({ type: [String] })
|
|
@IsArray()
|
|
@ArrayMinSize(1)
|
|
@IsString({ each: true })
|
|
colonyIds!: string[];
|
|
|
|
@ApiPropertyOptional()
|
|
@IsOptional()
|
|
@IsString()
|
|
honeyType?: string;
|
|
|
|
@ApiPropertyOptional()
|
|
@IsOptional()
|
|
@IsInt()
|
|
@Min(0)
|
|
honeySuperCount?: number;
|
|
|
|
@ApiPropertyOptional()
|
|
@IsOptional()
|
|
@IsNumber()
|
|
@Min(0)
|
|
grossWeight?: number;
|
|
|
|
@ApiPropertyOptional()
|
|
@IsOptional()
|
|
@IsNumber()
|
|
@Min(0)
|
|
netWeight?: number;
|
|
|
|
@ApiPropertyOptional()
|
|
@IsOptional()
|
|
@IsString()
|
|
notes?: string;
|
|
}
|