diff --git a/models/stories/review.ts b/models/stories/review.ts index 78a01a1..01a0748 100644 --- a/models/stories/review.ts +++ b/models/stories/review.ts @@ -57,13 +57,20 @@ CommentSchema.virtual("story", { foreignField: "_id", justOne: true, }); - -CommentSchema.pre("findOne", populate("replies")) - .pre("find", populate("replies")) - .pre("findOne", populate("commentAuthor")) - .pre("find", populate("commentAuthor")) - .pre("findOne", populateSelected("replyingTo", "-replies")) - .pre("find", populateSelected("replyingTo", "-replies")); +const modelName = "Review"; +CommentSchema + // .pre("findOne", populateSelected("replyingTo", modelName, "-replies -author")) + // .pre("find", populateSelected("replyingTo", modelName, "-replies -author")) + .pre("findOne", populate("replies", modelName)) + .pre("find", populate("replies", modelName)) + .pre( + "findOne", + populateSelected("author", "User", "profile username _id blocked"), + ) + .pre( + "find", + populateSelected("author", "User", "profile username _id blocked"), + ); hasMigrated && !mongoose.models.Review && @@ -71,7 +78,7 @@ hasMigrated && export const Review: Model = /* mongoose.models.Review || */ mongoose.model( - "Review", + modelName, CommentSchema, "reviews", );