file.dto.ts
1.08 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
import { IsNumber, IsNotEmpty, ValidateIf, IsInt, Matches, isString, IsEnum, IsDefined, isEnum, IsOptional, } from 'class-validator'
import { ApiProperty } from '@nestjs/swagger'
import { Transform } from 'class-transformer'
import { DocTypes } from '../common/enums'
import { BaseDto } from './base.dto'
export class FileQueryDto extends BaseDto {
@ApiProperty({
type: String,
description: '文件名称',
required: false,
default: ''
})
filename?: string
@ApiProperty({
type: String,
description: '文件类型',
required: false,
default: ''
})
@IsOptional() // 允许为空
@IsEnum(DocTypes) // 非空时必须为 DocTypes 枚举中的一个值
type?: DocTypes
}
export class FileDeleteDto {
@ApiProperty({
type: Number,
description: '文件记录表主键Id',
default: 0
})
@Transform(({ value }) => (isString(value) && !isNaN(Number(value)) ? value : undefined), {
toClassOnly: true,
})
@Matches(/[0-9]+$/, { message: 'id must be a numeric string' })
@IsNotEmpty({ message: 'id不能为空' })
id: number | string
}