11import { applyDecorators , Type } from '@nestjs/common'
2- import { ApiExtraModels , ApiQuery , getSchemaPath } from '@nestjs/swagger'
3- import { ApiOkResponse } from '@nestjs/swagger/dist/decorators/api-response.decorator'
4- import { PaginatedDto } from '~/_common/dto/paginated.dto'
2+ import { ApiExtraModels , getSchemaPath } from '@nestjs/swagger'
3+ import { ApiOkResponse , ApiResponseOptions } from '@nestjs/swagger/dist/decorators/api-response.decorator'
4+ import { PaginatedResponseDto } from '~/_common/dto/paginated-response .dto'
55
6- const DEFAULT_OPTIONS = {
7- queryPagination : true ,
8- }
9-
10- export interface ApiPaginatedResponseOptions {
11- queryPagination ?: boolean
12- }
13-
14- export const ApiPaginatedResponse = < TModel extends Type < any > > (
6+ export const ApiPaginatedResponseDecorator = < TModel extends Type < any > > (
157 model : TModel ,
16- options ?: ApiPaginatedResponseOptions | null | undefined ,
8+ options ?: ApiResponseOptions | null | undefined ,
179) => {
18- options = { ...DEFAULT_OPTIONS , ...options }
19- const extraDecorators = [ ]
20- if ( options ?. queryPagination ) {
21- extraDecorators . push (
22- ApiQuery ( { name : 'limit' , type : Number , required : false } ) ,
23- ApiQuery ( { name : 'skip' , type : Number , required : false } ) ,
24- )
25- }
2610 return applyDecorators (
2711 ApiExtraModels ( model ) ,
2812 ApiOkResponse ( {
2913 schema : {
3014 allOf : [
31- { $ref : getSchemaPath ( PaginatedDto ) } ,
15+ { $ref : getSchemaPath ( PaginatedResponseDto ) } ,
3216 {
3317 properties : {
3418 data : {
@@ -39,7 +23,7 @@ export const ApiPaginatedResponse = <TModel extends Type<any>>(
3923 } ,
4024 ] ,
4125 } ,
26+ ...options ,
4227 } ) ,
43- ...extraDecorators ,
4428 )
4529}
0 commit comments