Validation - Transform
Eicrud's transformations happen at the controller level (between the client, and your services).
Entities and commands DTOs are transformed the same way.
Note
Transform happens before validation.
You can use the following decorators to transform your arguments.
$Transform
Transform an argument with the specified function.
import { $Transform } from '@eicrud/core/validation'
export class CmdDto {
@$Transform((value: string) => value.toUpperCase())
message: string;
}
You can specify the desired behavior on arrays.
export class CmdDto {
@$Transform((value: string[]) => value[0])
array_a: string[];
@$Transform((value: string) => value.toUpperCase(), { each: true })
array_b: string[];
}
$ToLowerCase
Transform a string argument to lowercasing.
import { $ToLowerCase } from '@eicrud/core/validation'
export class CmdDto {
@$ToLowerCase()
email: string;
}
$Trim
Trim a string argument.
$Delete
Delete an argument.
import { $Delete } from '@eicrud/core/validation'
export class CmdDto {
@$Delete()
frontEndProperty: string;
}