我目前正在运行代码:
export class SystemInformationContent {
createdAt: number;
createdBy: User | mongoose.Schema.Types.ObjectId | null;
updatedAt?: number;
updatedBy?: User | mongoose.Schema.Types.ObjectId | null;
}
@Schema()
export class SystemInformation {
@Prop(
raw({
createdAt: { type: Number, required: true },
createdBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
updatedAt: { type: Number, default: 0 },
updatedBy: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
default: null,
},
}),
)
system: SystemInformationContent;
}
我没有找到任何“扩展”架构的方法SystemInformationContent
,因此raw()
在装饰器中使用了该函数@Prop()
,但我想知道是否有办法做这样的事情:
export class SystemInformationContent {
@Prop({ required: true })
createdAt: number;
@Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'User' })
createdBy: User | mongoose.Schema.Types.ObjectId | null;
@Prop({ default: 0 })
updatedAt?: number;
@Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'User', default: null })
updatedBy?: User | mongoose.Schema.Types.ObjectId | null;
}
@Schema()
export class SystemInformation {
@Prop(???)
system: SystemInformationContent;
}
SystemInformation.system
@Prop()
考虑到SystemInformationContent
.
你们知道是否有其他方法,raw
或者我是否遗漏了什么?
编辑:我的 NestJS 应用程序的所有类都在扩展 SystemInformation,所以它们看起来都像:
{
...,
system: {
createdAt: 1616778310610,
createdBy: "605e14469d860eb1f0641cad",
editedAt: 0,
createdBy: null,
},
}