Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions 4-natours/after-section-11/models/reviewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,8 @@ reviewSchema.post('save', function() {

// findByIdAndUpdate
// findByIdAndDelete
reviewSchema.pre(/^findOneAnd/, async function(next) {
this.r = await this.findOne();
// console.log(this.r);
next();
});

reviewSchema.post(/^findOneAnd/, async function() {
// await this.findOne(); does NOT work here, query has already executed
await this.r.constructor.calcAverageRatings(this.r.tour);
reviewSchema.post(/^findOneAnd/, async function (doc) {
await this.model.calcAverageRatings(doc.tour);
});

const Review = mongoose.model('Review', reviewSchema);
Expand Down