Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Decorators to copy swagger & class-validator metadata from one class to another

License

NotificationsYou must be signed in to change notification settings

Re-Quant/api-entity-ref

Repository files navigation

Build statusNPM versionCode CoverageLicense: GPL v3

Decorators to copy@nestjs/swagger,class-validator andclass-transformer metadata from one class to another.

Notice: If you have any propositions feel free to make an issue or create a pull request.

How to use

Installing

yarn add @z-brain/api-entity-ref
or
npm i -s @z-brain/api-entity-ref

Usage example

dtos/account-base.dto.ts

import{ApiPropertyRef}from'@z-brain/api-entity-ref';import{Account}from'../types';exportabstractclassAccountBaseDtoimplementsOmit<Account,'id'>{  @ApiPropertyRef()publicemail!:string;  @ApiPropertyRef()publicfirstName?:string;}

dtos/account-create.dto.ts

import{ApiEntityRef,ApiPropertyRef}from'@z-brain/api-entity-ref';import{EEntityValidationGroup}from'@lib/common/enums';import{Account}from'../types';import{AccountBaseDto}from'./account-base.dto';@ApiEntityRef(Account,{groups:[EEntityValidationGroup.Create]})exportclassAccountCreateDtoextendsAccountBaseDto{  @ApiPropertyRef()publiclastName?:string;}

dtos/account-update.dto.ts

import{Allow,IsNotEmpty}from'class-validator';import{ApiEntityRef}from'@z-brain/api-entity-ref';import{IDInt}from'@lib/common/types';import{EEntityValidationGroup}from'@lib/common/enums';import{Account}from'../types';import{AccountBaseDto}from'./account-base.dto';@ApiEntityRef(Account,{groups:[EEntityValidationGroup.Update]})exportclassAccountUpdateDtoextendsAccountBaseDtoimplementsOmit<Account,'fullName'>{  @Allow()  @IsNotEmpty()publicid!:IDInt;}

types/account.entity.ts

import{ApiProperty,ApiPropertyOptional,ApiResponseProperty}from'@nestjs/swagger';import{IsEmail,IsOptional,IsString,Length}from'class-validator';lmport{Type}from'class-transformer';import{IDInt}from'@lib/common/types';import{DEFAULT_EMAIL_MAX_LEN,DEFAULT_EMAIL_MIN_LEN,DEFAULT_NAME_MAX_LEN,DEFAULT_NAME_MIN_LEN,}from'@lib/common/db.constants';import{IsUnique}from'@lib/common/validators';import{EEntityValidationGroup}from'@lib/common/enums';classFirstLast{  @ApiPropertyOptional({example:'Ivan',maxLength:DEFAULT_NAME_MAX_LEN,minLength:DEFAULT_NAME_MIN_LEN,})  @IsOptional({always:true})  @IsString({always:true})  @Length(DEFAULT_NAME_MIN_LEN,DEFAULT_NAME_MAX_LEN,{always:true})  @Column({length:DEFAULT_NAME_MAX_LEN,nullable:true})publicfirst!:string;  @ApiPropertyOptional({example:'Trump',maxLength:DEFAULT_NAME_MAX_LEN,minLength:DEFAULT_NAME_MIN_LEN,})  @IsOptional({always:true})  @IsString({always:true})  @Length(DEFAULT_NAME_MIN_LEN,DEFAULT_NAME_MAX_LEN,{always:true})  @Column({length:DEFAULT_NAME_MAX_LEN,nullable:true})publiclast!:string;}@Entity()exportclassAccount{publicstaticreadonlyNAMELESS_FULL_NAME:string='Nameless User';  @ApiResponseProperty({example:1234})  @PrimaryGeneratedColumn('increment',{unsigned:true})publicid!:IDInt;  @ApiProperty({example:'ivan@gmail.com',maxLength:DEFAULT_NAME_MAX_LEN,minLength:DEFAULT_NAME_MIN_LEN,uniqueItems:true,})  @Column({length:DEFAULT_EMAIL_MAX_LEN,unique:true})  @IsOptional({groups:[EEntityValidationGroup.Update]})  @IsEmail(undefined,{always:true})  @IsUnique(Account,undefined,{always:true})  @Length(DEFAULT_EMAIL_MIN_LEN,DEFAULT_EMAIL_MAX_LEN,{always:true})publicemail!:string;  @Column(()=>Name)  @Type(()=>Name)publicname:FirstLast;  @ApiResponseProperty({example:'Ivan Trump',})publicgetfullName():string{returnthis.name.first&&this.name.last           ?`${this.name.first}${this.name.last}`           :this.name.first||this.name.last||(this.constructorastypeofAccount).NAMELESS_FULL_NAME;}}

Development notes

Quick Start

cd /code/z-braingit clone git@github.com:z-brain/api-entity-ref.gitcd api-entity-refyarn install

How to use NodeJS version from the.nvmrc

  1. Install NVM

  2. Use.nvmrc file one of the next ways:

    • Executenvm use in the project root directory
    • InstallNVM Loader and your .nvmrc will be loaded automatically when you open the terminal.NVM Loader demo

How to make a build

npm run build

How to run lint

  • Just show problemsnpm run lint
  • Fix problems if it is possiblenpm run lint:fix

How to run tests

  • All tests

    npm run test
    npm run test:watch

  • Specific tests

    npm run test -- src/my.spec.ts
    npm run test:watch -- src/my.spec.ts

How to build and publish NPM package

NPM Token:npm_ggEB......6ZRs

CI configuration details here:.github/workflows/npmpublish.yml

npm run pre-push \&& npm version patch -m'Update package version version to %s' \&& npm run gen-public-package.json \&& cp README.md dist/ \&& npm publish dist --access public \&& git push --no-verify&& git push --tags --no-verify

How to build package to local installation

  1. yarn run build:local
  2. Then you can install a local package build from pathfile:.../api-entity-ref/dist.

Author


Anton Korniychuk

About

Decorators to copy swagger & class-validator metadata from one class to another

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp