-
Notifications
You must be signed in to change notification settings - Fork 228
/
sample.dto.ts
33 lines (25 loc) · 838 Bytes
/
sample.dto.ts
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
import { Transform, TransformFnParams } from 'class-transformer';
import { IsDateString, IsNotEmpty, IsNumber, IsOptional, IsString } from 'class-validator';
import { DateService } from '../providers';
/**
* https://github.com/typestack/class-validator#validation-decorators
* https://docs.nestjs.com/techniques/serialization
*/
export class SampleDto {
@IsNumber()
public id!: number;
@IsString()
public title!: string;
@IsOptional()
@IsString()
public content?: string; // optional value
@IsDateString() // ISO 8601
public date: string = new Date().toISOString(); // default value
@IsString() // Change date format
@Transform(({ value }: TransformFnParams) => DateService.format(String(value)))
public datetime!: string;
@IsNotEmpty()
public something!: string;
@IsNumber()
public page = 1;
}