我已经创建了这个并一直在使用这个模型。但是现在我已经添加了 @pre<Offer>("save"
,因为我想在保存之前对数据进行一些检查并相应地调整值。
我的问题是,当我首先进行更新时,控制台日志永远不会得到输出。然后我永远无法设置this.isOfferLive = false;
如果我发布isOfferLive:true
所以pre
永远不会被调用
我想念你什么?
我在用
"reflect-metadata": "^0.1.13",
"typegoose": "^5.7.2",
"mongoose": "^5.6.3",
emitDecoratorMetadata and experimentalDecorators are be enabled in tsconfig.json
我注意到的一件事是,在查看 consoe 日志时hooks
会被调用Model.create
但不会被调用。Model.updateOne
我如何让它们也适用于更新
我的课
@pre<Offer>("save", function(next: HookNextFunction) {
console.log("[**** save]: " + this.isOfferLive);
this.isOfferLive = false;
if (!isOfferValid(this)) {
this.isOfferLive = false;
}
next();
})
export class Offer extends Typegoose {
@prop({ required: true, default: false })
public isOfferLive: boolean;
}
export const Model = new Offer().getModelForClass(Offer);