Skip to content

Commit

Permalink
route page: add star rating resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
demshy committed Jun 10, 2024
1 parent f002296 commit f5859b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/crags/resolvers/routes.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import { SectorsService } from '../services/sectors.service';
import { PaginatedActivityRoutes } from '../../activities/utils/paginated-activity-routes.class';
import { ActivityRoutesService } from '../../activities/services/activity-routes.service';
import { FindActivityRoutesInput } from '../../activities/dtos/find-activity-routes.input';
import { StarRatingVotesService } from '../services/star-rating-votes.service';
import { StarRatingVote } from '../entities/star-rating-vote.entity';

@Resolver(() => Route)
@UseInterceptors(DataLoaderInterceptor)
Expand All @@ -60,6 +62,7 @@ export class RoutesResolver {
private routesService: RoutesService,
private sectorsService: SectorsService,
private difficultyVotesService: DifficultyVotesService,
private starRatingVotesService: StarRatingVotesService,
private entityPropertiesService: EntityPropertiesService,
private notificationService: NotificationService,
private activityRoutesService: ActivityRoutesService,
Expand Down Expand Up @@ -257,6 +260,11 @@ export class RoutesResolver {
return this.difficultyVotesService.findByRouteId(route.id);
}

@ResolveField('starRatingVotes', () => [StarRatingVote])
async starRatingVotes(@Parent() route: Route): Promise<StarRatingVote[]> {
return this.starRatingVotesService.findByRouteId(route.id);
}

@ResolveField('crag', () => Crag)
async getCrag(
@Parent() route: Route,
Expand Down
7 changes: 7 additions & 0 deletions src/crags/services/star-rating-votes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ export class StarRatingVotesService {
.andWhere('srv.route_id IN (:...routeIds)', { routeIds })
.getMany();
}

async findByRouteId(routeId: string): Promise<StarRatingVote[]> {
return this.starRatingVoteRepository.find({
where: { routeId: routeId },
order: { stars: 'ASC' },
});
}
}

0 comments on commit f5859b2

Please sign in to comment.