Skip to content

Commit

Permalink
add activityRoutes resolver to route
Browse files Browse the repository at this point in the history
  • Loading branch information
demshy committed Jun 10, 2024
1 parent bea16ec commit f002296
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/activities/services/activity-routes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ export class ActivityRoutesService {
if (!currentUser) {
// Allow showing only public ascents to guests
builder.andWhere('ar."publish" IN (:...publish)', {
publish: ['log', 'public'],
publish: ['public'],
});

// Allow showing only published routes (no drafts or in_reviews)
Expand All @@ -657,7 +657,7 @@ export class ActivityRoutesService {
'(ar.user_id = :userId OR ar."publish" IN (:...publish))',
{
userId: currentUser.id,
publish: ['log', 'public'],
publish: ['public'],
},
);
// TODO: should also allow showing club ascents
Expand Down
8 changes: 8 additions & 0 deletions src/crags/crags.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ import { RouteEvent } from './entities/route-event.entity';
import { Parking } from './entities/parking.entity';
import { ParkingsService } from './services/parkings.service';
import { AreaLoader } from './loaders/area.loader';
import { ActivityRoutesService } from '../activities/services/activity-routes.service';
import { ActivitiesModule } from '../activities/activities.module';
import { ClubMember } from '../users/entities/club-member.entity';
import { Club } from '../users/entities/club.entity';

@Module({
imports: [
Expand Down Expand Up @@ -98,7 +102,10 @@ import { AreaLoader } from './loaders/area.loader';
IceFallProperty,
StarRatingVote,
Parking,
Club,
ClubMember,
]),
forwardRef(() => ActivitiesModule),
forwardRef(() => AuditModule),
BullModule.registerQueue({
name: 'summary',
Expand Down Expand Up @@ -148,6 +155,7 @@ import { AreaLoader } from './loaders/area.loader';
CragLoader,
RouteLoader,
ParkingsService,
ActivityRoutesService,
],
controllers: [UploadController],
exports: [
Expand Down
19 changes: 19 additions & 0 deletions src/crags/resolvers/routes.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ import { LatestDifficultyVotesInput } from '../dtos/latest-difficulty-votes.inpu
import { PaginatedDifficultyVotes } from '../utils/paginated-difficulty-votes';
import { MoveRouteToSectorInput } from '../dtos/move-route-to-sector.input';
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';

@Resolver(() => Route)
@UseInterceptors(DataLoaderInterceptor)
Expand All @@ -59,12 +62,15 @@ export class RoutesResolver {
private difficultyVotesService: DifficultyVotesService,
private entityPropertiesService: EntityPropertiesService,
private notificationService: NotificationService,
private activityRoutesService: ActivityRoutesService,
) {}

/* QUERIES */

@Query(() => Route)
@UseFilters(NotFoundFilter)
@AllowAny()
@UseGuards(UserAuthGuard)
async route(@Args('id') id: string): Promise<Route> {
return this.routesService.findOneById(id);
}
Expand Down Expand Up @@ -286,4 +292,17 @@ export class RoutesResolver {
): Promise<RouteType> {
return loader.load(route.routeTypeId);
}

@ResolveField('activityRoutes', () => PaginatedActivityRoutes)
@UseGuards(UserAuthGuard)
async activityRoutes(
@Parent() route: Route,
@Args('input', { nullable: true }) input: FindActivityRoutesInput = {},
@CurrentUser() currentUser: User,
): Promise<PaginatedActivityRoutes> {
return this.activityRoutesService.paginate(
{ ...input, routeId: route.id },
currentUser,
);
}
}

0 comments on commit f002296

Please sign in to comment.