algoan / nestjs-components

A list of useful components for NestJS applications
https://www.algoan.com
254 stars 40 forks source link

[CLASS_TRANSFORMERS] Extends class-transform package with EnumFallback decorator #837

Closed amarlankri closed 10 months ago

amarlankri commented 11 months ago

Description

Create class-transformers package with new decorator EnumFallback. This decorator can be used as follows:

import { EnumFallback } from '@algoan/nestjs-class-transformers';

export enum UserRole {
  ADMIN = 'ADMIN',
  READER = 'READER',
}

class User {
  @EnumFallback({
    type: UserRole,
    fallback: (value: UserRole) => UserRole.READER // if the role is not "ADMIN" or "READER", then the role will be "READER".
  })
  public role?: UserRole;
}

Finishes implementation started in #836

Motivation and Context

Fix #834

Types of changes