29 lines
666 B
TypeScript
29 lines
666 B
TypeScript
import { ApiPropertyOptional } from '@nestjs/swagger';
|
|
import { Type } from 'class-transformer';
|
|
import { IsInt, IsOptional, Min } from 'class-validator';
|
|
|
|
export class PaginationDto {
|
|
@ApiPropertyOptional({ description: '页码,从 1 开始', default: 1 })
|
|
@IsOptional()
|
|
@Type(() => Number)
|
|
@IsInt()
|
|
@Min(1)
|
|
page = 1;
|
|
|
|
@ApiPropertyOptional({ description: '每页条数', default: 10 })
|
|
@IsOptional()
|
|
@Type(() => Number)
|
|
@IsInt()
|
|
@Min(0)
|
|
pageSize = 20;
|
|
|
|
get skip(): number {
|
|
return (this.page - 1) * this.pageSize;
|
|
}
|
|
|
|
get take(): number | undefined {
|
|
if (this.pageSize === 0) return undefined;
|
|
return this.pageSize;
|
|
}
|
|
}
|