Skip to content

Commit

Permalink
add platform wide reviews endpoint (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
adelinaenache authored Jun 5, 2024
1 parent e2acc45 commit 99370c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/reviews/reviews.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export class ReviewsController {
): Promise<ReviewDto | undefined> {
return this.reviewsService.getReviewByUserForUser(user.id, userId);
}
/**
* Get latest platform-wide reviews.
*/

@Get('/latest')
async getLatestReviews(@CurrentUser() user: User): Promise<ReviewDto[]> {
return this.reviewsService.getLatestReviews(user.id);
}

/**
* Get the reviews posted by the current user
Expand Down
12 changes: 12 additions & 0 deletions src/reviews/reviews.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,16 @@ export class ReviewsService {

return reviews.map((r) => this.transformReview(r, currentUserId));
}

async getLatestReviews(currentUserId: User['id']): Promise<ReviewDto[]> {
const reviews = await this.prisma.review.findMany({
include: this.includeWithReview(currentUserId),
orderBy: {
createdAt: 'desc',
},
take: 25,
});

return reviews.map((r) => this.transformReview(r, currentUserId));
}
}

0 comments on commit 99370c4

Please sign in to comment.