Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/val-istar-guo/nestjs-take-type

A type helper extend from @nestjs/swagger
https://github.com/val-istar-guo/nestjs-take-type

Last synced: about 1 month ago
JSON representation

A type helper extend from @nestjs/swagger

Awesome Lists containing this project

README

        

# @miaooo/nestjs-take-type

[![version](https://img.shields.io/npm/v/@miaooo/nestjs-take-type.svg?style=flat-square)](https://www.npmjs.com/package/@miaooo/nestjs-take-type)
[![downloads](https://img.shields.io/npm/dm/@miaooo/nestjs-take-type.svg?style=flat-square)](https://www.npmjs.com/package/@miaooo/nestjs-take-type)
[![license](https://img.shields.io/npm/l/@miaooo/nestjs-take-type.svg?style=flat-square)](https://www.npmjs.com/package/@miaooo/nestjs-take-type)
[![dependencies](https://img.shields.io/librariesio/github/Val-istar-Guo/nestjs-take-type.svg?style=flat-square)](https://www.npmjs.com/package/@miaooo/nestjs-take-type)
[![coveralls](https://img.shields.io/coveralls/github/Val-istar-Guo/nestjs-take-type.svg?style=flat-square)](https://coveralls.io/github/Val-istar-Guo/nestjs-take-type)

NestJS helper function that combined PartialType and PickType,
reduce duplicate definitions of parameters in dto.

## Usage

```typescript
// 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;
}
```

```typescript
// 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](.github/CODE_OF_CONDUCT.md) and [CONTRIBUTING](.github/CONTRIBUTING.md).