update food
This commit is contained in:
@@ -13,7 +13,7 @@ export class FoodRatingCronService {
|
||||
private readonly em: EntityManager,
|
||||
private readonly foodRepository: FoodRepository,
|
||||
private readonly reviewRepository: ReviewRepository,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
/**
|
||||
* Cron job that runs at midnight every day (00:00:00 UTC)
|
||||
@@ -55,8 +55,8 @@ export class FoodRatingCronService {
|
||||
averageRating = sum / reviews.length;
|
||||
}
|
||||
|
||||
// Update food rate
|
||||
food.rate = parseFloat(averageRating.toFixed(2));
|
||||
// Update food score
|
||||
food.score = parseFloat(averageRating.toFixed(2));
|
||||
this.em.persist(food);
|
||||
|
||||
updatedCount++;
|
||||
|
||||
@@ -21,7 +21,7 @@ export class ReviewService {
|
||||
private readonly foodRepository: FoodRepository,
|
||||
private readonly userRepository: UserRepository,
|
||||
private readonly em: EntityManager,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async create(userId: string, createReviewDto: CreateReviewDto): Promise<Review> {
|
||||
const { foodId, orderId, rating, comment, positivePoints, negativePoints } = createReviewDto;
|
||||
@@ -176,7 +176,7 @@ export class ReviewService {
|
||||
if (reviews.length === 0) {
|
||||
const food = await this.foodRepository.findOne({ id: foodId });
|
||||
if (food) {
|
||||
food.rate = 0;
|
||||
food.score = 0;
|
||||
await this.em.persistAndFlush(food);
|
||||
}
|
||||
return;
|
||||
@@ -186,7 +186,7 @@ export class ReviewService {
|
||||
|
||||
const food = await this.foodRepository.findOne({ id: foodId });
|
||||
if (food) {
|
||||
food.rate = parseFloat(averageRating.toFixed(2));
|
||||
food.score = parseFloat(averageRating.toFixed(2));
|
||||
await this.em.persistAndFlush(food);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user