Итак, у меня есть вопрос: как заставить промежуточное ПО работать на двух разных хуках? Я хочу заменить этот код:
userSchema.pre('save', function(next) {
if (!this.localAuth.password) next();
this.localAuth.password = this.generateHash(this.localAuth.password);
next();
})
userSchema.pre('update', function(next) {
if (!this.localAuth.password) next();
this.localAuth.password = this.generateHash(this.localAuth.password);
next();
})
на что-то вроде этого:
userSchema.pre('saveOrUpdate', function(next) {
if (!this.localAuth.password) next();
this.localAuth.password = this.generateHash(this.localAuth.password);
next();
})
Обратите внимание, что функции одинаковы, мне просто нужен хук, который запускается при сохранении и обновлении , Любая помощь приветствуется. Спасибо!