Skip to content

Commit

Permalink
add auth conditions to crags resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
demshy committed Feb 24, 2024
1 parent 62272c1 commit 606c42b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/crags/resolvers/crags.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { ImagesService } from '../services/images.service';
import { Roles } from '../../auth/decorators/roles.decorator';
import { Area } from '../entities/area.entity';
import { AreaLoader } from '../loaders/area.loader';
import { FindCragsServiceInput } from '../dtos/find-crags-service.input';

@Resolver(() => Crag)
@UseInterceptors(DataLoaderInterceptor)
Expand Down Expand Up @@ -86,11 +87,17 @@ export class CragsResolver {
});
}

@AllowAny()
@UseGuards(UserAuthGuard)
// TODO: add conditions for showing 'public' crags to everyone (in service)
@Query(() => [Crag])
async crags(): Promise<Crag[]> {
return this.cragsService.findAll();
async crags(
@CurrentUser() user: User,
@Args('input', { nullable: true }) input: FindCragsServiceInput = {},
): Promise<Crag[]> {
return this.cragsService.find({
...input,
user,
});
}

/* MUTATIONS */
Expand Down

0 comments on commit 606c42b

Please sign in to comment.