refactor(db/models): remove existence guard/check from models
This commit is contained in:
		
							parent
							
								
									b5454e9363
								
							
						
					
					
						commit
						b21aab4940
					
				@ -57,13 +57,20 @@ CommentSchema.virtual("story", {
 | 
				
			|||||||
	foreignField: "_id",
 | 
						foreignField: "_id",
 | 
				
			||||||
	justOne: true,
 | 
						justOne: true,
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					const modelName = "Review";
 | 
				
			||||||
CommentSchema.pre("findOne", populate("replies"))
 | 
					CommentSchema
 | 
				
			||||||
	.pre("find", populate("replies"))
 | 
						// .pre("findOne", populateSelected("replyingTo", modelName, "-replies -author"))
 | 
				
			||||||
	.pre("findOne", populate("commentAuthor"))
 | 
						// .pre("find", populateSelected("replyingTo", modelName, "-replies -author"))
 | 
				
			||||||
	.pre("find", populate("commentAuthor"))
 | 
						.pre("findOne", populate("replies", modelName))
 | 
				
			||||||
	.pre("findOne", populateSelected("replyingTo", "-replies"))
 | 
						.pre("find", populate("replies", modelName))
 | 
				
			||||||
	.pre("find", populateSelected("replyingTo", "-replies"));
 | 
						.pre(
 | 
				
			||||||
 | 
							"findOne",
 | 
				
			||||||
 | 
							populateSelected("author", "User", "profile username _id blocked"),
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						.pre(
 | 
				
			||||||
 | 
							"find",
 | 
				
			||||||
 | 
							populateSelected("author", "User", "profile username _id blocked"),
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
hasMigrated &&
 | 
					hasMigrated &&
 | 
				
			||||||
	!mongoose.models.Review &&
 | 
						!mongoose.models.Review &&
 | 
				
			||||||
@ -71,7 +78,7 @@ hasMigrated &&
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export const Review: Model<IReview> =
 | 
					export const Review: Model<IReview> =
 | 
				
			||||||
	/* mongoose.models.Review || */ mongoose.model(
 | 
						/* mongoose.models.Review || */ mongoose.model(
 | 
				
			||||||
		"Review",
 | 
							modelName,
 | 
				
			||||||
		CommentSchema,
 | 
							CommentSchema,
 | 
				
			||||||
		"reviews",
 | 
							"reviews",
 | 
				
			||||||
	);
 | 
						);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user