-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPageQuery.dto.ts
More file actions
71 lines (63 loc) · 1.35 KB
/
PageQuery.dto.ts
File metadata and controls
71 lines (63 loc) · 1.35 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
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import {
IsBoolean,
IsEnum,
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
Max,
Min,
} from 'class-validator';
import { TIMESPANS } from '@nbw/config';
import type { TimespanType } from '../../song/dto/types';
export class PageQueryDTO {
@Min(1)
@ApiProperty({
example: 1,
description: 'page',
})
page?: number = 1;
@IsNotEmpty()
@IsNumber({
allowNaN: false,
allowInfinity: false,
maxDecimalPlaces: 0,
})
@Min(1)
@Max(100)
@ApiProperty({
example: 20,
description: 'limit',
})
limit?: number;
@IsString()
@IsOptional()
@ApiProperty({
example: 'field',
description: 'Sorts the results by the specified field.',
required: false,
})
sort?: string = 'createdAt';
@IsBoolean()
@Transform(({ value }) => value === 'true')
@ApiProperty({
example: false,
description:
'Sorts the results in ascending order if true; in descending order if false.',
required: false,
})
order?: boolean = false;
@IsEnum(TIMESPANS)
@IsOptional()
@ApiProperty({
example: 'hour',
description: 'Filters the results by the specified timespan.',
required: false,
})
timespan?: TimespanType;
constructor(partial: Partial<PageQueryDTO>) {
Object.assign(this, partial);
}
}