File

src/vehicles/dto/create-vehicle.dto.ts

Index

Properties

Properties

Optional description
Type : string
Decorators :
@ApiPropertyOptional()
@IsOptional()
@IsString()
@MaxLength(500)
Optional driverId
Type : string
Decorators :
@ApiPropertyOptional()
@IsOptional()
@IsString()
Optional fuelType
Type : string
Decorators :
@ApiPropertyOptional()
@IsOptional()
@IsString()
@MaxLength(40)
Optional homeSite
Type : string
Decorators :
@ApiPropertyOptional()
@IsOptional()
@IsString()
@MaxLength(120)
Optional licensePlate
Type : string
Decorators :
@ApiPropertyOptional()
@IsOptional()
@IsString()
@MaxLength(20)
Optional make
Type : string
Decorators :
@ApiPropertyOptional()
@IsOptional()
@IsString()
@MaxLength(60)
Optional maxVolume
Type : number
Decorators :
@ApiPropertyOptional({description: 'Max cargo volume in m³'})
@IsOptional()
@Type(undefined)
@IsNumber()
@IsPositive()
@Max(500)
Optional maxWeight
Type : number
Decorators :
@ApiPropertyOptional({description: 'Max payload weight in kg'})
@IsOptional()
@Type(undefined)
@IsNumber()
@IsPositive()
@Max(200000)
Optional model
Type : string
Decorators :
@ApiPropertyOptional()
@IsOptional()
@IsString()
@MaxLength(60)
Optional name
Type : string
Decorators :
@ApiPropertyOptional()
@IsOptional()
@IsString()
@MaxLength(80)
Optional securityGroup
Type : string
Decorators :
@ApiPropertyOptional()
@IsOptional()
@IsString()
@MaxLength(60)
Optional telematicsId
Type : string
Decorators :
@ApiPropertyOptional({description: 'Provider-side device ID for GPS pairing'})
@IsOptional()
@IsString()
@MaxLength(80)
Optional telematicsProvider
Type : string
Decorators :
@ApiPropertyOptional({example: 'mix_telematics'})
@IsOptional()
@IsString()
@MaxLength(40)
Optional transporterId
Type : string
Decorators :
@ApiPropertyOptional()
@IsOptional()
@IsString()
type
Type : VehicleType
Decorators :
@ApiProperty({enum: VehicleType})
@IsEnum(VehicleType)
unitNumber
Type : string
Decorators :
@ApiProperty({example: 'TRK-001'})
@IsString()
@IsNotEmpty()
@MaxLength(40)
Optional vehicleClassId
Type : string
Decorators :
@ApiPropertyOptional()
@IsOptional()
@IsString()
Optional vin
Type : string
Decorators :
@ApiPropertyOptional({example: '1HGCM82633A123456'})
@IsOptional()
@IsString()
@Matches(/^[A-HJ-NPR-Z0-9]{17}$/, {message: 'vin must be exactly 17 characters (no I, O, or Q)'})

Vehicle Identification Number — strict 17-character alphanumeric per ISO 3779. The DB has a UNIQUE constraint on this column so duplicates 500 here instead of leaking the constraint name in the error.

Optional year
Type : number
Decorators :
@ApiPropertyOptional({example: 2022})
@IsOptional()
@Type(undefined)
@IsNumber()
@Min(1980)
@Max(undefined)
import {
  IsNotEmpty,
  IsString,
  IsOptional,
  IsEnum,
  IsNumber,
  IsPositive,
  Matches,
  Max,
  Min,
  MaxLength,
} from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { VehicleType } from '@prisma/client';

const CURRENT_YEAR = new Date().getFullYear();

export class CreateVehicleDto {
  @ApiProperty({ example: 'TRK-001' })
  @IsString()
  @IsNotEmpty()
  @MaxLength(40)
  unitNumber: string;

  @ApiProperty({ enum: VehicleType })
  @IsEnum(VehicleType)
  type: VehicleType;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  @MaxLength(60)
  make?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  @MaxLength(60)
  model?: string;

  @ApiPropertyOptional({ example: 2022 })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @Min(1980)
  @Max(CURRENT_YEAR + 1)
  year?: number;

  /**
   * Vehicle Identification Number — strict 17-character alphanumeric per
   * ISO 3779. The DB has a UNIQUE constraint on this column so duplicates
   * 500 here instead of leaking the constraint name in the error.
   */
  @ApiPropertyOptional({ example: '1HGCM82633A123456' })
  @IsOptional()
  @IsString()
  @Matches(/^[A-HJ-NPR-Z0-9]{17}$/, {
    message: 'vin must be exactly 17 characters (no I, O, or Q)',
  })
  vin?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  @MaxLength(20)
  licensePlate?: string;

  @ApiPropertyOptional({ description: 'Max payload weight in kg' })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @IsPositive()
  @Max(200_000)
  maxWeight?: number;

  @ApiPropertyOptional({ description: 'Max cargo volume in m³' })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @IsPositive()
  @Max(500)
  maxVolume?: number;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  @MaxLength(40)
  fuelType?: string;

  @ApiPropertyOptional({ example: 'mix_telematics' })
  @IsOptional()
  @IsString()
  @MaxLength(40)
  telematicsProvider?: string;

  @ApiPropertyOptional({ description: 'Provider-side device ID for GPS pairing' })
  @IsOptional()
  @IsString()
  @MaxLength(80)
  telematicsId?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  driverId?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  vehicleClassId?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  transporterId?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  @MaxLength(120)
  homeSite?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  @MaxLength(80)
  name?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  @MaxLength(500)
  description?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  @MaxLength(60)
  securityGroup?: string;
}

results matching ""

    No results matching ""