-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPage.dto.ts
More file actions
65 lines (58 loc) · 1.32 KB
/
Page.dto.ts
File metadata and controls
65 lines (58 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { ApiProperty } from '@nestjs/swagger';
import {
IsArray,
IsBoolean,
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
ValidateNested,
} from 'class-validator';
export class PageDto<T> {
@IsNotEmpty()
@IsNumber({
allowNaN: false,
allowInfinity: false,
maxDecimalPlaces: 0,
})
@ApiProperty({ example: 150, description: 'Total number of items available' })
total: number;
@IsNotEmpty()
@IsNumber({
allowNaN: false,
allowInfinity: false,
maxDecimalPlaces: 0,
})
@ApiProperty({ example: 1, description: 'Current page number' })
page: number;
@IsNotEmpty()
@IsNumber({
allowNaN: false,
allowInfinity: false,
maxDecimalPlaces: 0,
})
@ApiProperty({ example: 20, description: 'Number of items per page' })
limit: number;
@IsOptional()
@IsString()
@ApiProperty({ example: 'createdAt', description: 'Field used for sorting' })
sort?: string;
@IsNotEmpty()
@IsBoolean()
@ApiProperty({
example: false,
description: 'Sort order: true for ascending, false for descending',
})
order: boolean;
@IsNotEmpty()
@IsArray()
@ValidateNested({ each: true })
@ApiProperty({
description: 'Array of items for the current page',
isArray: true,
})
content: T[];
constructor(partial: Partial<PageDto<T>>) {
Object.assign(this, partial);
}
}