fix(topic): add vaildation
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
import { IsOptional, IsString, MaxLength } from 'class-validator'
|
||||
import {
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
IsUrl,
|
||||
MaxLength,
|
||||
} from 'class-validator'
|
||||
import slugify from 'slugify'
|
||||
|
||||
import { index, modelOptions, prop } from '@typegoose/typegoose'
|
||||
|
||||
@@ -14,16 +21,42 @@ export class TopicModel extends BaseModel {
|
||||
@prop({ default: '' })
|
||||
@MaxLength(400, { message: '描述信息最多 400 个字符' })
|
||||
@IsOptional()
|
||||
@IsString({ message: '描述信息必须是字符串' })
|
||||
@IsString()
|
||||
description?: string
|
||||
|
||||
@prop()
|
||||
@IsString({ message: '简介必须是字符串' })
|
||||
@IsString()
|
||||
introduce: string
|
||||
|
||||
@prop({ unique: true })
|
||||
@IsString()
|
||||
@IsNotEmpty({
|
||||
message: '话题名称不能为空',
|
||||
})
|
||||
@MaxLength(50)
|
||||
name: string
|
||||
|
||||
@prop({ unique: true })
|
||||
id: string
|
||||
@prop({
|
||||
unique: true,
|
||||
set(val) {
|
||||
return slugify(val)
|
||||
},
|
||||
})
|
||||
@IsString({
|
||||
message: '路径必须是字符串',
|
||||
})
|
||||
@IsNotEmpty()
|
||||
slug: string
|
||||
|
||||
@IsUrl(
|
||||
{
|
||||
require_protocol: true,
|
||||
},
|
||||
{
|
||||
message: '请输入正确的 URL',
|
||||
},
|
||||
)
|
||||
@prop()
|
||||
@IsOptional()
|
||||
icon?: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user