From 209701aa34b43b7b5ae7ad24dfc3dbf188b764cb Mon Sep 17 00:00:00 2001 From: Abubeker Yasin Date: Fri, 3 Jul 2026 15:23:32 +0300 Subject: [PATCH] fix: passenger dob error --- .../src/modules/bookings/bookings.dto.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/edr-passenger-api/src/modules/bookings/bookings.dto.ts b/apps/edr-passenger-api/src/modules/bookings/bookings.dto.ts index 4062acddc..5df5f7107 100644 --- a/apps/edr-passenger-api/src/modules/bookings/bookings.dto.ts +++ b/apps/edr-passenger-api/src/modules/bookings/bookings.dto.ts @@ -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',