fix: passenger dob error

This commit is contained in:
Abubeker Yasin
2026-07-03 15:23:32 +03:00
parent 91e59abf0e
commit 209701aa34

View File

@@ -1,4 +1,4 @@
import { IsString, IsArray, ValidateNested, IsOptional, IsInt, IsEnum, IsDateString, MaxDate } from 'class-validator';
import { IsString, IsArray, ValidateNested, IsOptional, IsInt, IsEnum, IsDate, MaxDate } from 'class-validator';
import { Type, Transform } from 'class-transformer';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Currency, IdDocumentType } from '@prisma/client';
@@ -10,10 +10,12 @@ export class PassengerInputDto {
@ApiPropertyOptional({ example: 'ret-leg2-seat-uuid', description: '**ROUND_TRIP_TRANSIT:** Return leg-2 seat ID' }) @IsOptional() @IsString() returnLeg2SeatId?: string;
@ApiProperty({ example: 'Abebe Kebede' }) @IsString() passengerName: string;
@ApiProperty({ example: '1990-05-15', description: 'Date of birth (YYYY-MM-DD). Must not be a future date.' })
@IsDateString()
@Transform(({ value }) => value)
// Incoming value is an ISO date string (YYYY-MM-DD); transform to a Date so
// @MaxDate (which requires an actual Date instance) evaluates correctly.
@Transform(({ value }) => (value ? new Date(value) : value))
@IsDate()
@MaxDate(() => new Date(), { message: 'Date of birth cannot be in the future' })
dateOfBirth: string;
dateOfBirth: Date;
@ApiProperty({ example: 'NATIONAL_ID', enum: IdDocumentType, description: 'NATIONAL_ID for Ethiopians (Verifayda verified), PASSPORT for others' }) @IsEnum(IdDocumentType) idDocumentType: IdDocumentType;
@ApiPropertyOptional({ example: 'ET123456789', description: 'Ethiopian national ID - verified via Verifayda 2.0 (NOT stored in database)' }) @IsOptional() @IsString() idDocumentNumber?: string;
@ApiPropertyOptional({ example: 'P1234567', description: 'Passport number for non-Ethiopian passengers (no verification)' }) @IsOptional() @IsString() passportNumber?: string;
@@ -44,10 +46,12 @@ export class RoundTripPassengerDto {
example: '1990-05-15',
description: 'Date of birth (YYYY-MM-DD). Must not be a future date.'
})
@IsDateString()
@Transform(({ value }) => value)
// Incoming value is an ISO date string (YYYY-MM-DD); transform to a Date so
// @MaxDate (which requires an actual Date instance) evaluates correctly.
@Transform(({ value }) => (value ? new Date(value) : value))
@IsDate()
@MaxDate(() => new Date(), { message: 'Date of birth cannot be in the future' })
dateOfBirth: string;
dateOfBirth: Date;
@ApiProperty({
example: 'NATIONAL_ID',