mobx-class-transformer-validator
A simple plugin for class-transformer and class-validator which combines them in a nice and programmer-friendly API.
Installation
Module installation
npm install mobx-class-transformer-validator --save
(or the short way):
npm i -S mobx-class-transformer-validator
Peer dependencies
This package is only a simple plugin/wrapper, so you have to install the required modules too because it can't work without them. See detailed installation instruction for the modules installation:
Usage
The usage of this module is very simple.
import { IsEmail } from 'class-validator';
import { transformAndValidate } from 'mobx-class-transformer-validator';
class UserDto {
@IsString()
fullname: string;
}
class UserModel {
@observable firstName: string;
@observable lastName: string;
@computed get fullname() {
return `${this.firstName} ${this.lastName}`;
}
}
const user = new UserModel();
transformAndValidate(UserDto, UserModel)
.then((userDto: UserDto) => {
console.log(`Hello ${userDto.fullname}`);
})
.catch((err) => {
console.error(err);
});