forked from MettaChain/PropChain-BackEnd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpagination.dto.ts
More file actions
92 lines (78 loc) · 1.79 KB
/
Copy pathpagination.dto.ts
File metadata and controls
92 lines (78 loc) · 1.79 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { IsInt, IsOptional, Min, Max, IsString, IsIn } from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
/**
* Query parameters for pagination
*/
export class PaginationQueryDto {
@ApiPropertyOptional({
description: 'Page number (1-indexed)',
example: 1,
default: 1,
})
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
page: number = 1;
@ApiPropertyOptional({
description: 'Number of items per page',
example: 10,
minimum: 1,
maximum: 100,
default: 10,
})
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
@Max(100)
limit: number = 10;
@ApiPropertyOptional({
description: 'Field to sort by',
example: 'createdAt',
default: 'createdAt',
})
@IsOptional()
@IsString()
sortBy: string = 'createdAt';
@ApiPropertyOptional({
description: 'Sort order',
example: 'desc',
enum: ['asc', 'desc'],
default: 'desc',
})
@IsOptional()
@IsIn(['asc', 'desc'])
sortOrder: 'asc' | 'desc' = 'desc';
}
/**
* Pagination metadata included in list responses
*/
export class PaginationMetadataDto {
@ApiProperty({ example: 100 })
total: number;
@ApiProperty({ example: 1 })
page: number;
@ApiProperty({ example: 10 })
limit: number;
@ApiProperty({ example: 10 })
pages: number;
@ApiProperty({ example: true })
hasNext: boolean;
@ApiProperty({ example: false })
hasPrev: boolean;
@ApiProperty({ example: 'createdAt' })
sortBy: string;
@ApiProperty({ example: 'desc' })
sortOrder: 'asc' | 'desc';
}
/**
* Generic paginated response wrapper
*/
export class PaginatedResponseDto<T> {
@ApiProperty({ isArray: true })
data: T[];
@ApiProperty({ type: PaginationMetadataDto })
meta: PaginationMetadataDto;
}