-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add users pagination, sort and search (#533)
- Loading branch information
1 parent
4fa21c6
commit d7d3ed3
Showing
4 changed files
with
105 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ApiQuery } from '@nestjs/swagger' | ||
import { applyDecorators } from '@nestjs/common' | ||
|
||
export function PersonQueryDecorator() { | ||
return applyDecorators( | ||
ApiQuery({ name: 'pageindex', required: false, type: Number }), | ||
ApiQuery({ name: 'pagesize', required: false, type: Number }), | ||
ApiQuery({ name: 'search', required: false, type: String }), | ||
ApiQuery({ name: 'sortBy', required: false, type: String }), | ||
ApiQuery({ name: 'sortOrder', required: false, type: String }), | ||
) | ||
} |
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,46 @@ | ||
import { Expose, Transform } from 'class-transformer' | ||
import { IsOptional } from 'class-validator' | ||
|
||
export class PersonQueryDto { | ||
@Expose() | ||
@IsOptional() | ||
@Transform(({ value }) => falsyToUndefined(value)) | ||
search?: string | ||
|
||
@Expose() | ||
@IsOptional() | ||
@Transform(({ value }) => falsyToUndefined(value)) | ||
sortBy?: string | ||
|
||
@Expose() | ||
@IsOptional() | ||
@Transform(({ value }) => falsyToUndefined(value)) | ||
sortOrder?: string | ||
|
||
@Expose() | ||
@IsOptional() | ||
@Transform(({ value }) => toNumber(value)) | ||
pageindex?: number | ||
|
||
@Expose() | ||
@IsOptional() | ||
@Transform(({ value }) => toNumber(value)) | ||
pagesize?: number | ||
} | ||
|
||
function toNumber(value: string): number | undefined { | ||
if (!value || Number.isNaN(value)) { | ||
return undefined | ||
} | ||
|
||
const newValue: number = Number.parseInt(value) | ||
return newValue | ||
} | ||
|
||
function falsyToUndefined(value: unknown): unknown | undefined { | ||
if (!value || value === 'undefined') { | ||
return undefined | ||
} | ||
|
||
return value | ||
} |
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