1.7.6 • Published 9 months ago

wemacu-nestjs v1.7.6

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Nestjs Swagger & Utils Helper

본 라이브러리는 @nestjs/swagger의 사용 간소화 및 기타 유틸성 기능을 제공하는 라이브러리입니다.

Swagger

@RequestApi(swaggerOptions : SwaggerOptions)

스웨거 Request 옵션

  • SwaggerOptions
    • summary?: ApiOperationOptions;
    • headers?: ApiHeaderOptions | ApiHeaderOptions[];
    • params?: ApiParamOptions | ApiParamOptions[];
    • query?: ApiQueryOptions | ApiQueryOptions[];
    • body?: ApiBodyOptions;

@ResponseApi(options: ApiResponseOptions & { isPaging?: boolean },code = 200 as HttpStatus)

스웨거 Response 옵션

  • ApiResponseOptions = ApiResponseMetadata | ApiResponseSchemaHost

  • ApiResponseMetadata

    • status?: number | 'default';
    • type?: Type | Function | Function | string;
    • isArray?: boolean;
    • description?: string;
  • ApiResponseSchemaHost

    • schema: SchemaObject & Partial;
    • status?: number;
    • description?: string;

@ApiFile(fieldName = "file")

스웨거 및 인터셉터 파일 업로드

@Auth(guard: Function, name = 'access-token')

스웨거 및 UseGuards 가드 사용

@Property({ apiProperty = {}, validation, overrideExisting, typeOptions = {} }: PropertyProps)

DTO 스웨거 명세 및 Validation (class-transformer, class-validation)

  • Property
    • apiProperty?: ApiPropertyOptions;
    • validation?: ValidationOptions;
    • overrideExisting?: boolean;
    • typeOptions?: TypeOptions;

페이징 관련

Request Swagger 용

export class PagingDTO {
  @Property({ apiProperty: { type: 'number', minimum: 1, default: 1 } })
  page?: number;

  @Property({ apiProperty: { type: 'number', minimum: 20, default: 20 } })
  limit?: number;

  constructor(page: number, limit: number) {
    this.page = page;
    this.limit = limit;
  }

  public getSkipTake(): SkipTake {
    const take = Number(this.limit) || 20;
    const skip = (Number(this.page) - 1) * take;

    return { skip, take };
  }
}

Response 데이터 전처리 용

export class PaginationDTO<T extends object> {
  @Property({ apiProperty: { isArray: true } })
  data: T[];

  @Property({ apiProperty: { type: PagingMetaDTO } })
  paging: PagingMetaDTO;

  constructor(data: T[], { paging, count }: PagingMetaDTOInterface) {
    this.data = data;
    this.paging = new PagingMetaDTO({ paging, count });
  }
}

미들웨어 적용

app.use(PaginationMiddleware);

Paging Params Decorator

async function example(@Paging() paging: PagingDTO) {}
1.7.3

10 months ago

1.6.4

10 months ago

1.5.5

11 months ago

1.7.2

10 months ago

1.5.4

11 months ago

1.7.1

10 months ago

1.6.2

11 months ago

1.5.3

11 months ago

1.6.1

11 months ago

1.6.0

11 months ago

1.5.1

11 months ago

1.6.9

10 months ago

1.6.8

10 months ago

1.7.6

9 months ago

1.6.7

10 months ago

1.5.8

11 months ago

1.7.5

9 months ago

1.6.6

10 months ago

1.5.7

11 months ago

1.7.4

10 months ago

1.6.5

10 months ago

1.5.6

11 months ago

1.5.0

11 months ago

1.4.81

11 months ago

1.4.8

11 months ago

1.4.7

11 months ago

1.4.6

11 months ago

1.4.5

11 months ago

1.4.4

11 months ago

1.4.3

11 months ago

1.4.2

11 months ago

1.4.1

11 months ago

1.4.0

11 months ago

1.3.0

11 months ago

1.2.6

11 months ago

1.2.5

11 months ago

1.2.4

11 months ago

1.2.3

11 months ago

1.2.2

11 months ago

1.2.1

11 months ago

1.2.0

11 months ago

1.1.0

11 months ago

1.0.0

11 months ago