Files
CRM_Montzar/apps/api/src/users/dto.ts
T

75 lines
1.4 KiB
TypeScript
Raw Normal View History

import { Type } from 'class-transformer';
import {
2026-09-15 17:33:05 +03:30
IsBoolean,
IsIn,
IsNumber,
2026-09-15 17:33:05 +03:30
IsOptional,
IsString,
Matches,
Max,
MaxLength,
Min,
MinLength,
ValidateIf,
} from 'class-validator';
const INVITE_ROLES = ['admin', 'sales', 'support'] as const;
const ALL_ROLES = ['owner', 'admin', 'sales', 'support'] as const;
export class InviteUserDto {
@IsString()
@Matches(/^09\d{9}$|^\+98\d{10}$|^98\d{10}$|^9\d{9}$/, {
message: 'شماره موبایل معتبر نیست',
})
mobile!: string;
@IsString()
@MinLength(2)
@MaxLength(120)
fullName!: string;
@IsOptional()
@ValidateIf((_, value) => typeof value === 'string' && value.length > 0)
@IsString()
@MinLength(8)
@MaxLength(72)
password?: string;
2026-09-15 17:33:05 +03:30
@IsOptional()
@IsIn(INVITE_ROLES)
2026-09-15 17:33:05 +03:30
role?: (typeof INVITE_ROLES)[number];
@IsOptional()
@IsString()
orgRoleId?: string;
}
export class UpdateUserRoleDto {
2026-09-15 17:33:05 +03:30
@IsOptional()
@IsIn(ALL_ROLES)
2026-09-15 17:33:05 +03:30
role?: (typeof ALL_ROLES)[number];
@IsOptional()
@IsString()
orgRoleId?: string;
}
export class UpdateUserStatusDto {
@Type(() => Boolean)
@IsBoolean()
isActive!: boolean;
}
export class UpdateUserCommissionDto {
@Type(() => Number)
@IsNumber()
@Min(0)
@Max(100)
commissionPercent!: number;
}
export class UpdateUserVisibilityDto {
@IsIn(['own', 'team', 'org'])
dataVisibility!: 'own' | 'team' | 'org';
}