aladov3.13.0

Docs/DTOs

@validateProperty

DTOs are plain TypeScript classes with decorated properties. They define how request data is validated, transformed, and documented.

A DTO class may extend another one: it has the decorated properties of its parents as well as its own (class UserDto extends ContactDto), and a property decorated again in the subclass replaces the parent's definition.

validateProperty

Validates an incoming property value. Runs before your handler.

TypeScript
import { validateProperty } from 'alado';

class CredentialsDto {
  @validateProperty({
    required: true,
    handler: (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value),
    error: {
      statusCode: 400,
      message: 'Invalid email address',
    },
  })
  email: string = 'user@example.com';
}
  • handler receives the raw value and must return boolean | Promise<boolean>
  • returning false → framework returns the configured error automatically
  • handler is called with this bound to the full Request object — you can access this.auth, this.query, etc.
  • do not use arrow functions if you need access to this
  • required: true refuses a request without the field. A validator built with .required() does the same, so validate.string().email().required().build() needs no required: true next to it. Before 3.9.20 such a field was optional: a validator runs only on a value that is present, so a request without the field passed
  • a validator built with validate also gives the field's OpenAPI schema: see @documentProperty