This commit is contained in:
2025-11-10 12:39:41 +03:30
parent 06f814b331
commit 45ca2fde06
24 changed files with 794 additions and 586 deletions
+96
View File
@@ -0,0 +1,96 @@
import { IsOptional, IsString, IsNumber, Min, IsEnum, IsIn } from 'class-validator';
import { Type } from 'class-transformer';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { EducationLevel, User } from '../entities/user.entity';
// Define the valid sort directions
const sortOrderOptions = ['asc', 'desc'] as const;
type SortOrder = (typeof sortOrderOptions)[number];
export class FindUsersDto {
/**
* The page number to retrieve.
* @default 1
*/
@ApiPropertyOptional({
description: 'The page number to retrieve.',
type: Number,
default: 1,
minimum: 1,
})
@IsOptional()
@IsNumber()
@Min(1)
@Type(() => Number)
page?: number = 1;
/**
* The number of items per page.
* @default 10
*/
@ApiPropertyOptional({
description: 'The number of items per page.',
type: Number,
default: 10,
minimum: 1,
})
@IsOptional()
@IsNumber()
@Min(1)
@Type(() => Number)
limit?: number = 10;
/**
* A general search term to filter by.
* Searches firstName, lastName, phone, and nationalCode.
*/
@ApiPropertyOptional({
description: 'A general search term (firstName, lastName, phone, nationalCode).',
type: String,
example: 'John Doe',
})
@IsOptional()
@IsString()
search?: string;
/**
* Filter by a specific education level.
*/
@ApiPropertyOptional({
description: 'Filter by a specific education level.',
enum: EducationLevel, // Use the actual enum
example: EducationLevel.bachelor,
})
@IsOptional()
@IsEnum(EducationLevel)
education?: EducationLevel;
/**
* The field to sort the results by.
* @default "createdAt"
*/
@ApiPropertyOptional({
description: 'The field to sort the results by.',
type: String,
default: 'createdAt',
// You can provide a list of valid keys for better documentation
// You must ensure 'keyof User' is correctly exported/available here
example: 'lastName',
})
@IsOptional()
@IsString()
orderBy?: keyof User = 'createdAt';
/**
* The direction to sort the results.
* @default "desc"
*/
@ApiPropertyOptional({
description: 'The direction to sort the results.',
enum: sortOrderOptions, // Use the constant array
default: 'desc',
})
@IsOptional()
@IsIn(sortOrderOptions)
order?: SortOrder = 'desc';
}
+63
View File
@@ -0,0 +1,63 @@
import { IsString, IsNotEmpty, IsBoolean, IsNumber, IsEnum, MinLength } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { EducationLevel } from '../entities/user.entity';
export class UpdateUserDto {
@ApiProperty({ example: ' ', description: "User's first name" })
@IsNotEmpty()
@IsString()
firstName: string;
@ApiProperty({ example: ' ', description: "User's last name" })
@IsNotEmpty()
@IsString()
lastName: string;
@ApiProperty({ example: ' ', description: "User's father's name" })
@IsNotEmpty()
@IsString()
fatherName: string;
// --- Personal Details ---
@ApiPropertyOptional({ example: true, description: 'Gender: true for male, false for female' })
@IsNotEmpty()
@IsBoolean()
isMale: boolean;
@ApiPropertyOptional({ example: '1234567890', description: 'Unique national code' })
@IsNotEmpty()
@MinLength(10)
nationalCode: string;
@ApiPropertyOptional({ example: '1001', description: 'Employee personal code' })
@IsNotEmpty()
@IsString()
personalCode: string;
// --- Employment Details ---
@ApiPropertyOptional({ example: 'قراردادی', description: 'Type of hire (e.g., permanent, temporary)' })
@IsNotEmpty()
@IsString()
hireType: string;
@ApiPropertyOptional({ example: 'اراک', description: 'Primary work location' })
@IsNotEmpty()
@IsString()
workLocation: string;
@ApiPropertyOptional({ example: 5, description: 'Years of work experience' })
@IsNotEmpty()
@IsNumber()
workExperienceYear: number;
@ApiPropertyOptional({
enum: EducationLevel,
example: EducationLevel.master,
description: 'Highest level of education achieved',
})
@IsNotEmpty()
@IsEnum(EducationLevel)
education: EducationLevel;
}