我是 NestJS 的初学者,我想为以下结构编写 DTO -
{
something: {
info: {
title: string,
score: number,
description: string,
time: string,
DateOfCreation: string
},
Store: {
item: {
question: string,
options: {
item: {
answer: string,
description: string,
id: string,
key: string,
option: string
}
}
}
}
}
}
我想为该嵌套数据对象编写一个 DTO。我找不到在 NestJS 中编写嵌套 DTO 的可靠示例。我是 NestJS 的初学者,以前从未使用过 DTO。所以请不要假设我知道什么。我正在将它与猫鼬一起使用。
您必须为架构中的每个对象创建单独的类和一个将导入所有类的主类。
class Info {
readonly title:string
readonly score:number
readonly description:string
readonly dateOfCreation:Date
}
export class SampleDto {
@Type(() => Info)
@ValidatedNested()
readonly info: Info
...Follow same for the rest of schema
}
参考:https : //github.com/typestack/class-validator#validating-nested-objects
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句