Skip to content

Commit

Permalink
fix featured review route for undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
js0mmer committed Nov 11, 2024
1 parent 5def90b commit 702bb23
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions api/src/controllers/reviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,15 @@ const reviewsRouter = router({
const featuredReviewCriteria = [desc(review.content), desc(voteSubQuery.score), desc(review.verified)];

const field = input.type === 'course' ? review.courseId : review?.professorId;
const featuredReview = (
await db
.select()
.from(review)
.where(eq(field, input.id))
.leftJoin(voteSubQuery, eq(voteSubQuery.reviewId, review.id))
.orderBy(...featuredReviewCriteria)
.limit(1)
)[0];
const featuredReview = await db
.select()
.from(review)
.where(eq(field, input.id))
.leftJoin(voteSubQuery, eq(voteSubQuery.reviewId, review.id))
.orderBy(...featuredReviewCriteria)
.limit(1);

return datesToStrings(featuredReview.review) as FeaturedReviewData;
return featuredReview.length > 0 ? (datesToStrings(featuredReview[0].review) as FeaturedReviewData) : undefined;
}),

/**
Expand Down

0 comments on commit 702bb23

Please sign in to comment.