File

src/drivers/dto/create-driver.dto.ts

Index

Properties

Properties

Optional email
Type : string
Decorators :
@ApiPropertyOptional()
@IsOptional()
@IsEmail()
@MaxLength(120)
firstName
Type : string
Decorators :
@ApiProperty({example: 'Mike'})
@IsString()
@IsNotEmpty()
@MaxLength(60)
lastName
Type : string
Decorators :
@ApiProperty({example: 'Johnson'})
@IsString()
@IsNotEmpty()
@MaxLength(60)
Optional licenseExpiry
Type : string
Decorators :
@ApiPropertyOptional({example: '2027-06-30'})
@IsOptional()
@IsDateString()

Licence expiry. We accept any valid date and let the UI flag soon-to- expire / already-expired with a warning badge — we do NOT block past dates outright because some fleets onboard drivers whose licence just expired and is being renewed.

Optional licenseNumber
Type : string
Decorators :
@ApiPropertyOptional({description: 'Driver's licence number'})
@IsOptional()
@IsString()
@MaxLength(40)
Optional phone
Type : string
Decorators :
@ApiPropertyOptional({example: '+254712345678'})
@IsOptional()
@IsString()
@MaxLength(30)
@Matches(/^\+?[0-9 ()\-]{7,}$/, {message: 'phone must be 7+ digits, optionally with +, spaces, dashes, or parentheses'})

Permissive phone validation — accepts E.164 (+254712345678) or local formats with optional separators. We don't insist on E.164 because driver onboarding is typically a paper process and admins type what the licence shows.

import {
  IsNotEmpty,
  IsString,
  IsOptional,
  IsEmail,
  IsDateString,
  Matches,
  MaxLength,
} from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export class CreateDriverDto {
  @ApiProperty({ example: 'Mike' })
  @IsString()
  @IsNotEmpty()
  @MaxLength(60)
  firstName: string;

  @ApiProperty({ example: 'Johnson' })
  @IsString()
  @IsNotEmpty()
  @MaxLength(60)
  lastName: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsEmail()
  @MaxLength(120)
  email?: string;

  /**
   * Permissive phone validation — accepts E.164 (+254712345678) or local
   * formats with optional separators. We don't insist on E.164 because
   * driver onboarding is typically a paper process and admins type what
   * the licence shows.
   */
  @ApiPropertyOptional({ example: '+254712345678' })
  @IsOptional()
  @IsString()
  @MaxLength(30)
  @Matches(/^\+?[0-9 ()\-]{7,}$/, {
    message: 'phone must be 7+ digits, optionally with +, spaces, dashes, or parentheses',
  })
  phone?: string;

  @ApiPropertyOptional({ description: "Driver's licence number" })
  @IsOptional()
  @IsString()
  @MaxLength(40)
  licenseNumber?: string;

  /**
   * Licence expiry. We accept any valid date and let the UI flag soon-to-
   * expire / already-expired with a warning badge — we do NOT block past
   * dates outright because some fleets onboard drivers whose licence
   * just expired and is being renewed.
   */
  @ApiPropertyOptional({ example: '2027-06-30' })
  @IsOptional()
  @IsDateString()
  licenseExpiry?: string;
}

results matching ""

    No results matching ""