/** * @CustomValidate 使用示例 * * 这个文件包含了各种使用场景的示例代码 */ import { Repository } from 'typeorm'; import { ValidationContext } from '../validators/custom-validate.validator'; export declare class Example1_InlineValidation { price: number; code: string; maxPrice: number; minPrice: number; } export declare class Example2_EntityMethod { version: string; publishedAt: Date; createdAt: Date; validateVersion(value: string): boolean; checkDates(value: Date, context: ValidationContext): Promise; } export declare class ExampleValidationService { private readonly userRepository; constructor(userRepository: Repository); /** * 检查用户名是否可用 */ usernameAvailable(username: string): Promise; /** * 检查邮箱格式 */ validateEmail(email: string): boolean; /** * 检查数值范围(带额外参数) */ checkRange(value: number, context: ValidationContext, min: number, max: number): boolean; /** * 复杂的业务验证 */ validateBusinessRule(value: any, context: ValidationContext): Promise; } export declare class Example3_ServiceValidation { username: string; email: string; age: number; businessField: string; userId: string; } export declare class Example4_LazyReference { username: string; } export declare class Example5_ComplexValidation { password: string; confirmPassword: string; approverId?: string; requiresApproval: boolean; } export declare class FileValidationService { private readonly allowedMimeTypes; private readonly maxFileSize; checkFileType(mimeType: string): boolean; checkFileSize(size: number, context: ValidationContext, maxSize?: number): boolean; checkFileHash(hash: string): Promise; } export declare class Example6_FileUpload { mimeType: string; size: number; hash: string; } export declare class Example7_DynamicMessage { discount: number; } export declare class ThirdPartyValidationService { /** * 验证地址是否真实存在 */ validateAddress(address: string): Promise; /** * 验证税号是否有效 */ validateTaxId(taxId: string, context: ValidationContext): Promise; } export declare class Example8_ThirdPartyAPI { address: string; taxId: string; country: string; } export declare class CachedValidationService { private cache; private readonly cacheTTL; expensiveValidation(value: string): Promise; private doExpensiveCheck; private cleanExpiredCache; } export declare class Example9_CachedValidation { field: string; }