@betsys-nestjs/decorators
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

@betsys-nestjs/decorators

This is a simple library containing decorators helping you to validate types of properites

Dependencies

Package Version
@nestjs/common ^10.0.0
class-validator ^0.13.2

Usage

The basic usage is similar to the class-validator. Use decorators in your DTOs or commands.

An example of usage - imagine a DTO as following:

export class SomeNiceDto {
    booleanProperty!: boolean;
    intProperty!: number;
};

Which you want to use in the following controller while it is automatically converted from the request:

import { Body, Controller, Post, Req } from '@nestjs/common';
import { Request } from 'express';

@Controller()
export class SomeController {
    @Post('/some-url')
    saveKittens(@Req() request: Request, @Body() body: SomeNiceDto) {
        ...
    }
}

For the DTO you want to be sure, that booleanProperty is of type boolan as well as that intProperty is really an integer.

You can easily enforce that by using the decorators from this lib:

import { IsFieldBoolean, IsFieldInteger, Language } from '@betsys-nestjs/decorators';

export class SomeNiceDto {
    @IsFieldBoolean('booleanProperty', Language.PL)
    booleanProperty!: boolean;

    @IsFieldInteger('intProperty', Language.EN)
    intProperty!: number;
};

The language settings concern the error message. If you do not provide any language, English is returned.

Readme

Keywords

none

Package Sidebar

Install

npm i @betsys-nestjs/decorators

Weekly Downloads

2

Version

2.0.0

License

MIT

Unpacked Size

8.7 kB

Total Files

16

Last publish

Collaborators

  • betsys-development
  • pawelnowak1
  • andrejsoucek
  • jammie88
  • jiraspe2
  • jakubschneller
  • javor454
  • krizacekcz
  • flyrell