This repository has been archived by the owner on Feb 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add pagination (search, take, sort, skip)
- Loading branch information
ludovicGendre
committed
Jan 14, 2022
1 parent
c8204fb
commit de861fa
Showing
12 changed files
with
127 additions
and
74 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,46 @@ | ||
export class FilterDto { | ||
import { ApiPropertyOptional } from '@nestjs/swagger'; | ||
import { Type } from 'class-transformer'; | ||
import { IsEnum, IsInt, IsOptional, Max, Min } from 'class-validator'; | ||
|
||
export enum Order { | ||
ASC = 'asc', | ||
DESC = 'desc', | ||
} | ||
export class FilterDto<T> { | ||
@ApiPropertyOptional() | ||
public search?: string | null; | ||
|
||
@ApiPropertyOptional() | ||
public disablePagination?: true | null; | ||
|
||
public skip?: number | null; | ||
@ApiPropertyOptional({ | ||
minimum: 1, | ||
default: 1, | ||
}) | ||
@Type(() => String) | ||
@IsInt() | ||
@Min(1) | ||
@IsOptional() | ||
public page?: string; | ||
|
||
public take?: number | null; | ||
@ApiPropertyOptional({ | ||
minimum: 1, | ||
maximum: 50, | ||
default: 10, | ||
}) | ||
@Type(() => Number) | ||
@IsInt() | ||
@Min(1) | ||
@Max(50) | ||
@IsOptional() | ||
public take?: string | null; | ||
|
||
public sort?: 'ASC' | 'DESC'; | ||
@ApiPropertyOptional({ enum: Order, default: Order.ASC }) | ||
@IsEnum(Order) | ||
@IsOptional() | ||
public order?: Order; | ||
|
||
public orderBy?: string; | ||
get skip(): string { | ||
return ((parseInt(this.page) - 1) * parseInt(this.take)).toString(); | ||
} | ||
} |
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
Oops, something went wrong.