From 74516ede1e5786f609dfb1ecb465bea24ed54a5a Mon Sep 17 00:00:00 2001 From: enlineawork Date: Wed, 9 Sep 2026 09:20:59 -0300 Subject: [PATCH] =?UTF-8?q?feat(f6):=20agregar=20DTOs=20de=20campos=20t?= =?UTF-8?q?=C3=A9cnicos=20por=20clasificaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/inventory-family-attribute.dto.ts | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 api-v3/src/asset-master/dto/inventory-family-attribute.dto.ts diff --git a/api-v3/src/asset-master/dto/inventory-family-attribute.dto.ts b/api-v3/src/asset-master/dto/inventory-family-attribute.dto.ts new file mode 100644 index 0000000..316029a --- /dev/null +++ b/api-v3/src/asset-master/dto/inventory-family-attribute.dto.ts @@ -0,0 +1,103 @@ +import { Transform, Type } from 'class-transformer'; +import { + ArrayMaxSize, + IsArray, + IsBoolean, + IsIn, + IsInt, + IsOptional, + IsString, + Matches, + Max, + MaxLength, + Min, + MinLength, + ValidateIf, +} from 'class-validator'; + +const DATA_TYPES = ['TEXT','NUMBER','BOOLEAN','DATE','DATETIME','SELECT'] as const; +export type InventoryFamilyAttributeDataType = typeof DATA_TYPES[number]; + +export class CreateInventoryFamilyAttributeDto { + @Transform(({ value }) => typeof value === 'string' ? value.trim().toLowerCase() : value) + @IsString() + @Matches(/^[a-z][a-z0-9_]*$/) + @MaxLength(80) + code!: string; + + @Transform(({ value }) => typeof value === 'string' ? value.trim() : value) + @IsString() + @MinLength(1) + @MaxLength(160) + name!: string; + + @IsIn(DATA_TYPES) + dataType!: InventoryFamilyAttributeDataType; + + @IsOptional() + @IsBoolean() + isRequired?: boolean; + + @IsOptional() + @Transform(({ value }) => typeof value === 'string' ? value.trim() || null : value) + @ValidateIf((_object, value) => value !== null && value !== undefined) + @IsString() + @MaxLength(40) + unit?: string | null; + + @ValidateIf((object) => object.dataType === 'SELECT') + @IsArray() + @ArrayMaxSize(200) + @IsString({ each: true }) + @MaxLength(160, { each: true }) + options?: string[]; + + @IsOptional() + @Type(() => Number) + @IsInt() + @Min(0) + @Max(10000) + sortOrder?: number; +} + +export class UpdateInventoryFamilyAttributeDto { + @IsOptional() + @Transform(({ value }) => typeof value === 'string' ? value.trim() : value) + @IsString() + @MinLength(1) + @MaxLength(160) + name?: string; + + @IsOptional() + @IsIn(DATA_TYPES) + dataType?: InventoryFamilyAttributeDataType; + + @IsOptional() + @IsBoolean() + isRequired?: boolean; + + @IsOptional() + @IsBoolean() + isActive?: boolean; + + @IsOptional() + @Transform(({ value }) => typeof value === 'string' ? value.trim() || null : value) + @ValidateIf((_object, value) => value !== null && value !== undefined) + @IsString() + @MaxLength(40) + unit?: string | null; + + @IsOptional() + @IsArray() + @ArrayMaxSize(200) + @IsString({ each: true }) + @MaxLength(160, { each: true }) + options?: string[] | null; + + @IsOptional() + @Type(() => Number) + @IsInt() + @Min(0) + @Max(10000) + sortOrder?: number; +}