Jerarquía física definitiva, compatibilidades N↔N de clasificaciones, Hallazgos y campos técnicos por familia, navegación WEB/Android y APK F6 0.14.0-debug.
104 lines
2.2 KiB
TypeScript
104 lines
2.2 KiB
TypeScript
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;
|
|
}
|