@miaooo/nestjs-take-type
v1.2.0
Published
NestJS helper function that combined PartialType and PickType
Downloads
40
Maintainers
Readme
@miaooo/nestjs-take-type
NestJS helper function that combined PartialType and PickType, reduce duplicate definitions of parameters in dto.
Usage
// my-entity.entity.ts
import { Entity, Column, PriamryGeneratedColumn } from 'typeorm'
import { IsString, IsNumber } from 'class-transformer'
@Entity()
export class MyEntity {
@PrimaryGeneratedColumn()
id: number;
@IsString()
@Column()
type: string;
@IsNumber()
@Column()
age: number;
}
// my-entity.filter.dto.ts
import { TakeType } from '@miaooo/nestjs-take-type'
import { IsString, IsNumber } from 'class-transformer'
export class MyEntityFilerDTO extends TakeType(
MyEntity,
// required params
['type'],
// optional params
['age'],
) {}
// this is equal to
export class MyEntityFilerDTO {
@IsString()
type!: string;
@IsOptional()
@IsNumber()
age?: number;
}
Contributing & Development
If there is any doubt, it is very welcome to discuss the issue together. Please read Contributor Covenant Code of Conduct and CONTRIBUTING.