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

1.2.0 • Public • Published

@miaooo/nestjs-take-type

version downloads license dependencies coveralls

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.

/@miaooo/nestjs-take-type/

    Package Sidebar

    Install

    npm i @miaooo/nestjs-take-type

    Weekly Downloads

    15

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    11 kB

    Total Files

    22

    Last publish

    Collaborators

    • val.istar.guo