我目前正在运行以下代码:
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
模式的方法,因此在 @Prop()
装饰器中使用了 raw()
函数,但我想知道是否有一种类似于这样的方法:
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;
}
我没有找到任何有效的方法来将考虑 SystemInformationContent 模式的内容放入 SystemInformation.system @Prop() 中。
你们知道除了 raw 之外还有其他方法吗?或者我有什么遗漏吗?
编辑:我的 NestJS 应用程序中的所有类都在扩展 SystemInformation,因此它们都如下所示:
{
...,
system: {
createdAt: 1616778310610,
createdBy: "605e14469d860eb1f0641cad",
editedAt: 0,
createdBy: null,
},
}
emitDecoratorMetadata
已启用,但我认为 NestJS Typegoose 不是这样工作的... - Falcort