Nestjs class transformers
Extends class-transformers package with additional features.
Installation
npm install --save @algoan/nestjs-class-transformers
EnumFallback
Usage
import { EnumFallback } from '@algoan/nestjs-class-transformers';
export enum UserRole {
ADMIN = 'ADMIN',
READER = 'READER',
}
class User {
@EnumFallback({
type: UserRole,
fallback: (value: UserRole) => UserRole.READER
})
public role?: UserRole;
}
It works with array too:
import { EnumFallback } from '@algoan/nestjs-class-transformers';
export enum UserRole {
ADMIN = 'ADMIN',
READER = 'READER',
}
class User {
@EnumFallback({
type: UserRole,
fallback: (value: UserRole) => UserRole.READER
})
public roles: UserRole[];
}