generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ORV2-1700 Changes for Pagination, API Specification And Permit Endpoi…
…nt (#929) Co-authored-by: Krishnan Subramanian <[email protected]>
- Loading branch information
1 parent
efb7216
commit 83f1e5c
Showing
16 changed files
with
193 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { applyDecorators, Type } from '@nestjs/common'; | ||
import { ApiExtraModels, ApiOkResponse, getSchemaPath } from '@nestjs/swagger'; | ||
import { PaginationDto } from '../dto/paginate/pagination'; | ||
|
||
export const ApiPaginatedResponse = <TModel extends Type<unknown>>( | ||
model: TModel, | ||
) => { | ||
return applyDecorators( | ||
ApiExtraModels(PaginationDto), | ||
ApiOkResponse({ | ||
description: 'Successfully received model list', | ||
schema: { | ||
allOf: [ | ||
{ $ref: getSchemaPath(PaginationDto) }, | ||
{ | ||
properties: { | ||
items: { | ||
type: 'array', | ||
items: { $ref: getSchemaPath(model) }, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { PageMetaDtoParameters } from '../../interface/pagination.interface'; | ||
|
||
export class PageMetaDto { | ||
@ApiProperty() | ||
readonly page: number; | ||
|
||
@ApiProperty() | ||
readonly take: number; | ||
|
||
@ApiProperty() | ||
readonly totalItems: number; | ||
|
||
@ApiProperty() | ||
readonly pageCount: number; | ||
|
||
@ApiProperty() | ||
readonly hasPreviousPage: boolean; | ||
|
||
@ApiProperty() | ||
readonly hasNextPage: boolean; | ||
|
||
constructor({ pageOptionsDto, totalItems }: PageMetaDtoParameters) { | ||
this.page = pageOptionsDto.page; | ||
this.take = pageOptionsDto.take; | ||
this.totalItems = totalItems; | ||
this.pageCount = Math.ceil(this.totalItems / this.take); | ||
this.hasPreviousPage = this.page > 1; | ||
this.hasNextPage = this.page < this.pageCount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ApiPropertyOptional } from '@nestjs/swagger'; | ||
import { Type } from 'class-transformer'; | ||
import { IsInt, IsOptional, Max, Min } from 'class-validator'; | ||
|
||
export class PageOptionsDto { | ||
@ApiPropertyOptional({ | ||
minimum: 1, | ||
default: 1, | ||
}) | ||
@Type(() => Number) | ||
@IsInt() | ||
@Min(1) | ||
@IsOptional() | ||
readonly page?: number = 1; | ||
|
||
@ApiPropertyOptional({ | ||
minimum: 1, | ||
maximum: 25, | ||
default: 10, | ||
}) | ||
@Type(() => Number) | ||
@IsInt() | ||
@Min(1) | ||
@Max(25) | ||
@IsOptional() | ||
readonly take?: number = 10; | ||
|
||
get skip(): number { | ||
return (this.page - 1) * this.take; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsArray } from 'class-validator'; | ||
import { PageMetaDto } from './page-meta'; | ||
|
||
export class PaginationDto<T> { | ||
@IsArray() | ||
@ApiProperty({ isArray: true }) | ||
readonly items: T[]; | ||
|
||
@ApiProperty({ type: () => PageMetaDto }) | ||
readonly meta: PageMetaDto; | ||
|
||
constructor(items: T[], meta: PageMetaDto) { | ||
this.items = items; | ||
this.meta = meta; | ||
} | ||
} |
Oops, something went wrong.