add dto validation and swagger schemas

This commit is contained in:
2026-05-12 16:17:39 +03:30
parent abb387e743
commit 460537090b
21 changed files with 510 additions and 0 deletions
@@ -1,4 +1,17 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsOptional, IsString, Matches, MaxLength } from 'class-validator';
export class AssignBusinessOwnerDto {
@ApiProperty({ example: '09111111111' })
@IsString()
@Matches(/^(\+?\d{10,15}|09\d{9})$/, {
message: 'mobile must be a valid mobile number',
})
mobile!: string;
@ApiPropertyOptional({ example: 'Business Admin', nullable: true })
@IsOptional()
@IsString()
@MaxLength(150)
fullName?: string | null;
}
@@ -1,12 +1,68 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
IsBoolean,
IsLatitude,
IsLongitude,
IsOptional,
IsString,
IsUUID,
Matches,
MaxLength,
} from 'class-validator';
export class CreateBusinessDto {
@ApiProperty({ example: 'Shine Carwash' })
@IsString()
@MaxLength(150)
title!: string;
@ApiProperty({ example: 'shine-carwash' })
@IsString()
@MaxLength(120)
@Matches(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, {
message: 'slug must be lowercase words separated by hyphens',
})
slug!: string;
@ApiProperty({ format: 'uuid' })
@IsUUID()
categoryId!: string;
@ApiPropertyOptional({ example: 'Premium carwash service' })
@IsOptional()
@IsString()
@MaxLength(500)
description?: string;
@ApiPropertyOptional({ example: '09123456789' })
@IsOptional()
@IsString()
@MaxLength(20)
contactPhone?: string;
@ApiPropertyOptional({ example: 'Main street' })
@IsOptional()
@IsString()
@MaxLength(500)
address?: string;
@ApiPropertyOptional({ example: 35.6892 })
@IsOptional()
@IsLatitude()
latitude?: number;
@ApiPropertyOptional({ example: 51.389 })
@IsOptional()
@IsLongitude()
longitude?: number;
@ApiPropertyOptional({ format: 'uuid' })
@IsOptional()
@IsUUID()
ownerId?: string;
@ApiPropertyOptional({ example: true })
@IsOptional()
@IsBoolean()
isActive?: boolean;
}
@@ -1,12 +1,71 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import {
IsBoolean,
IsLatitude,
IsLongitude,
IsOptional,
IsString,
IsUUID,
Matches,
MaxLength,
} from 'class-validator';
export class UpdateBusinessDto {
@ApiPropertyOptional({ example: 'Shine Carwash' })
@IsOptional()
@IsString()
@MaxLength(150)
title?: string;
@ApiPropertyOptional({ example: 'shine-carwash' })
@IsOptional()
@IsString()
@MaxLength(120)
@Matches(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, {
message: 'slug must be lowercase words separated by hyphens',
})
slug?: string;
@ApiPropertyOptional({ format: 'uuid' })
@IsOptional()
@IsUUID()
categoryId?: string;
@ApiPropertyOptional({ example: 'Premium carwash service', nullable: true })
@IsOptional()
@IsString()
@MaxLength(500)
description?: string | null;
@ApiPropertyOptional({ example: '09123456789', nullable: true })
@IsOptional()
@IsString()
@MaxLength(20)
contactPhone?: string | null;
@ApiPropertyOptional({ example: 'Main street', nullable: true })
@IsOptional()
@IsString()
@MaxLength(500)
address?: string | null;
@ApiPropertyOptional({ example: 35.6892, nullable: true })
@IsOptional()
@IsLatitude()
latitude?: number | null;
@ApiPropertyOptional({ example: 51.389, nullable: true })
@IsOptional()
@IsLongitude()
longitude?: number | null;
@ApiPropertyOptional({ format: 'uuid', nullable: true })
@IsOptional()
@IsUUID()
ownerId?: string | null;
@ApiPropertyOptional({ example: true })
@IsOptional()
@IsBoolean()
isActive?: boolean;
}