Files
edr-platform/apps/edr-freight-api/src/modules/first-mile/dto/create-first-mile.dto.ts
natib21 07abe9b679 fix
2026-07-02 08:51:21 +00:00

67 lines
1.9 KiB
TypeScript

import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsBoolean, IsIn, IsNumber, IsOptional, IsUUID, Min } from 'class-validator';
import { FIRST_MILE_STATUSES, FirstMileStatus } from '../entities/first-mile.entity';
const toNumber = ({ value }: { value: unknown }) =>
value === '' || value == null ? undefined : Number(value);
export class CreateFirstMileDto {
@ApiProperty({ description: 'Booking this first-mile leg belongs to (FK → bookings.id)' })
@IsUUID()
bookingId!: string;
@ApiPropertyOptional({
enum: FIRST_MILE_STATUSES,
default: 'PAYMENT_PENDING',
})
@IsOptional()
@IsIn(FIRST_MILE_STATUSES as unknown as string[])
status?: FirstMileStatus;
@ApiPropertyOptional({ description: 'Amount already paid in advance', example: 4200 })
@IsOptional()
@Transform(toNumber)
@IsNumber()
@Min(0)
advancedPayment?: number;
@ApiPropertyOptional({ description: 'Outstanding balance to be collected', example: 1800 })
@IsOptional()
@Transform(toNumber)
@IsNumber()
@Min(0)
remainingPayment?: number;
@ApiPropertyOptional({ description: 'Planned distance for the leg, in km', example: 42.5 })
@IsOptional()
@Transform(toNumber)
@IsNumber()
@Min(0)
estimatedKm?: number;
@ApiPropertyOptional({ description: 'Actual distance travelled, in km', example: 44.1 })
@IsOptional()
@Transform(toNumber)
@IsNumber()
@Min(0)
exactKm?: number;
@ApiPropertyOptional({
type: String,
format: 'uuid',
description: 'Assigned vehicle (FK → vehicles.id). May be null until assigned.',
nullable: true,
})
@IsOptional()
@Transform(({ value }) => (value === '' ? undefined : value))
@IsUUID()
vehicleId?: string | null;
@ApiPropertyOptional({ description: 'Invoice payment status', default: false })
@IsOptional()
@IsBoolean()
paid?: boolean;
}