返回 AiToEarn
pager.dto.ts
根目录 / project / aitoearn-electron / server / src / common / dto / pager.dto.ts
1 /*
2 * @Author: nevin
3 * @Date: 2025-01-20 16:36:41
4 * @LastEditTime: 2025-02-22 18:09:51
5 * @LastEditors: nevin
6 * @Description:
7 */
8 import { ApiProperty } from '@nestjs/swagger';
9 import { Expose, Transform } from 'class-transformer';
10 import {
11 Allow,
12 IsEnum,
13 IsInt,
14 IsOptional,
15 IsString,
16 Max,
17 Min,
18 } from 'class-validator';
19
20 export enum Order {
21 ASC = 'ASC',
22 DESC = 'DESC',
23 }
24
25 // eslint-disable-next-line @typescript-eslint/no-unused-vars
26 export class PagerDto<T = any> {
27 @ApiProperty({ minimum: 1, default: 1 })
28 @Min(1)
29 @IsInt()
30 @Expose()
31 @IsOptional({ always: true })
32 @Transform(({ value: val }) => (val ? Number.parseInt(val) : 1), {
33 toClassOnly: true,
34 })
35 page: number = 1;
36
37 @ApiProperty({ minimum: 1, maximum: 100, default: 20 })
38 @Min(1)
39 @Max(100)
40 @IsInt()
41 @IsOptional({ always: true })
42 @Expose()
43 @Transform(({ value: val }) => (val ? Number.parseInt(val) : 20), {
44 toClassOnly: true,
45 })
46 pageSize: number = 20;
47
48 @ApiProperty({ required: false })
49 @IsString()
50 @IsOptional()
51 field?: string;
52
53 @ApiProperty({ enum: Order, required: false })
54 @IsEnum(Order)
55 @IsOptional()
56 @Transform(({ value }) => (value === 'asc' ? Order.ASC : Order.DESC))
57 order?: Order;
58
59 @Allow()
60 _t?: number;
61 }
62
62 lines TYPESCRIPT