From 4a42bbf26e56768a09fc5ac62e7062b1735be6b6 Mon Sep 17 00:00:00 2001 From: salamca Date: Thu, 20 Jun 2024 18:35:32 +0200 Subject: [PATCH 1/4] Register ascenttype and publishtype enum types --- src/activities/entities/activity-route.entity.ts | 12 +++++++++--- src/activities/resolvers/activity-routes.resolver.ts | 1 - 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/activities/entities/activity-route.entity.ts b/src/activities/entities/activity-route.entity.ts index b80d71a..bd0dbd3 100644 --- a/src/activities/entities/activity-route.entity.ts +++ b/src/activities/entities/activity-route.entity.ts @@ -8,7 +8,7 @@ import { ManyToOne, Index, } from 'typeorm'; -import { ObjectType, Field } from '@nestjs/graphql'; +import { ObjectType, Field, registerEnumType } from '@nestjs/graphql'; import { Route } from '../../crags/entities/route.entity'; import { Activity } from './activity.entity'; import { Pitch } from '../../crags/entities/pitch.entity'; @@ -31,6 +31,9 @@ export enum AscentType { T_ATTEMPT = 't_attempt', TICK = 'tick', } +registerEnumType(AscentType, { + name: 'AscentType', +}); export const tickAscentTypes = new Set([ AscentType.ONSIGHT, @@ -64,6 +67,9 @@ export enum PublishType { LOG = 'log', PRIVATE = 'private', } +registerEnumType(PublishType, { + name: 'PublishType', +}); /** * Has Triggers: @@ -111,7 +117,7 @@ export class ActivityRoute extends BaseEntity { enum: AscentType, default: AscentType.REDPOINT, }) - @Field() + @Field((type) => AscentType) ascentType: AscentType; @Column({ @@ -119,7 +125,7 @@ export class ActivityRoute extends BaseEntity { enum: PublishType, default: PublishType.PRIVATE, }) - @Field() + @Field((type) => PublishType) publish: PublishType; @Column({ nullable: true }) diff --git a/src/activities/resolvers/activity-routes.resolver.ts b/src/activities/resolvers/activity-routes.resolver.ts index 7203c65..d35d75f 100644 --- a/src/activities/resolvers/activity-routes.resolver.ts +++ b/src/activities/resolvers/activity-routes.resolver.ts @@ -131,7 +131,6 @@ export class ActivityRoutesResolver { return this.activityRoutesService.getStats(input, currentUser); } - @UseGuards(UserAuthGuard) @Query(() => [ActivityRoute]) myCragSummary( From 0b8c59bf96084b5cfeab340c6b5e9c8b0c7ceff0 Mon Sep 17 00:00:00 2001 From: salamca Date: Sat, 29 Jun 2024 13:14:06 +0200 Subject: [PATCH 2/4] Add search/filter-param to diff votes and star votes field resolvers. --- src/crags/dtos/find-difficulty-votes.input.ts | 9 +++++++++ src/crags/dtos/find-star-rating-votes.input.ts | 9 +++++++++ src/crags/resolvers/routes.resolver.ts | 16 ++++++++++++---- src/crags/services/difficulty-votes.service.ts | 13 +++++++++++-- src/crags/services/star-rating-votes.service.ts | 13 +++++++++++-- 5 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 src/crags/dtos/find-difficulty-votes.input.ts create mode 100644 src/crags/dtos/find-star-rating-votes.input.ts diff --git a/src/crags/dtos/find-difficulty-votes.input.ts b/src/crags/dtos/find-difficulty-votes.input.ts new file mode 100644 index 0000000..35c95ce --- /dev/null +++ b/src/crags/dtos/find-difficulty-votes.input.ts @@ -0,0 +1,9 @@ +import { InputType, Field } from '@nestjs/graphql'; +import { IsOptional } from 'class-validator'; + +@InputType() +export class FindDifficultyVotesInput { + @Field({ nullable: true }) + @IsOptional() + userId?: string; +} diff --git a/src/crags/dtos/find-star-rating-votes.input.ts b/src/crags/dtos/find-star-rating-votes.input.ts new file mode 100644 index 0000000..32148c4 --- /dev/null +++ b/src/crags/dtos/find-star-rating-votes.input.ts @@ -0,0 +1,9 @@ +import { InputType, Field } from '@nestjs/graphql'; +import { IsOptional } from 'class-validator'; + +@InputType() +export class FindStarRatingVotesInput { + @Field({ nullable: true }) + @IsOptional() + userId?: string; +} diff --git a/src/crags/resolvers/routes.resolver.ts b/src/crags/resolvers/routes.resolver.ts index 995f1eb..aecd72a 100644 --- a/src/crags/resolvers/routes.resolver.ts +++ b/src/crags/resolvers/routes.resolver.ts @@ -54,6 +54,8 @@ import { ActivityRoutesService } from '../../activities/services/activity-routes 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'; +import { FindDifficultyVotesInput } from '../dtos/find-difficulty-votes.input'; +import { FindStarRatingVotesInput } from '../dtos/find-star-rating-votes.input'; @Resolver(() => Route) @UseInterceptors(DataLoaderInterceptor) @@ -256,13 +258,19 @@ export class RoutesResolver { } @ResolveField('difficultyVotes', () => [DifficultyVote]) - async difficultyVotes(@Parent() route: Route): Promise { - return this.difficultyVotesService.findByRouteId(route.id); + async difficultyVotes( + @Parent() route: Route, + @Args('input', { nullable: true }) input: FindDifficultyVotesInput = {}, + ): Promise { + return this.difficultyVotesService.findByRouteId(route.id, input); } @ResolveField('starRatingVotes', () => [StarRatingVote]) - async starRatingVotes(@Parent() route: Route): Promise { - return this.starRatingVotesService.findByRouteId(route.id); + async starRatingVotes( + @Parent() route: Route, + @Args('input', { nullable: true }) input: FindStarRatingVotesInput = {}, + ): Promise { + return this.starRatingVotesService.findByRouteId(route.id, input); } @ResolveField('crag', () => Crag) diff --git a/src/crags/services/difficulty-votes.service.ts b/src/crags/services/difficulty-votes.service.ts index fff6bf5..6de81b3 100644 --- a/src/crags/services/difficulty-votes.service.ts +++ b/src/crags/services/difficulty-votes.service.ts @@ -7,6 +7,7 @@ import { setBuilderCache } from '../../core/utils/entity-cache/entity-cache-help import { LatestDifficultyVotesInputServiceInput } from '../dtos/latest-difficulty-votes-service.input'; import { DifficultyVote } from '../entities/difficulty-vote.entity'; import { PaginatedDifficultyVotes } from '../utils/paginated-difficulty-votes'; +import { FindDifficultyVotesInput } from '../dtos/find-difficulty-votes.input'; @Injectable() export class DifficultyVotesService { @@ -15,9 +16,17 @@ export class DifficultyVotesService { private difficultyVoteRepository: Repository, ) {} - async findByRouteId(routeId: string): Promise { + async findByRouteId( + routeId: string, + input: FindDifficultyVotesInput = {}, + ): Promise { + const where = { + ...(input.userId && { userId: input.userId }), + ...{ routeId }, + }; + const grades = this.difficultyVoteRepository.find({ - where: { routeId: routeId }, + where, order: { difficulty: 'ASC' }, }); diff --git a/src/crags/services/star-rating-votes.service.ts b/src/crags/services/star-rating-votes.service.ts index 0bea768..a921868 100644 --- a/src/crags/services/star-rating-votes.service.ts +++ b/src/crags/services/star-rating-votes.service.ts @@ -3,6 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { User } from '../../users/entities/user.entity'; import { StarRatingVote } from '../entities/star-rating-vote.entity'; +import { FindStarRatingVotesInput } from '../dtos/find-star-rating-votes.input'; @Injectable() export class StarRatingVotesService { @@ -19,9 +20,17 @@ export class StarRatingVotesService { .getMany(); } - async findByRouteId(routeId: string): Promise { + async findByRouteId( + routeId: string, + input: FindStarRatingVotesInput = {}, + ): Promise { + const where = { + ...(input.userId && { userId: input.userId }), + ...{ routeId }, + }; + return this.starRatingVoteRepository.find({ - where: { routeId: routeId }, + where, order: { stars: 'ASC' }, }); } From bd5dc17b75ac4f256edfa1f893281477283e01a5 Mon Sep 17 00:00:00 2001 From: Anze Demsar Date: Sat, 7 Sep 2024 20:59:53 +0200 Subject: [PATCH 3/4] change docker-compose command --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8dddd05..2344793 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: ls ${{ github.workspace }} - name: Install and prepare run: | - docker-compose -f docker-compose.e2e.yml up -d + docker compose -f docker-compose.e2e.yml up -d npm install - name: Run tests run: | From c103dbd7280a06dfa0c061d0b110a2031b3f4db9 Mon Sep 17 00:00:00 2001 From: salamca Date: Tue, 10 Sep 2024 20:03:41 +0200 Subject: [PATCH 4/4] Fix tests because of new gql enums (PublishType, AscentType). --- test/e2e/activity.e2e-spec.ts | 14 +++++++++++--- test/e2e/activityRoutes.e2e-spec.ts | 26 +++++++++++++++++--------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/test/e2e/activity.e2e-spec.ts b/test/e2e/activity.e2e-spec.ts index ccc7464..eb15908 100644 --- a/test/e2e/activity.e2e-spec.ts +++ b/test/e2e/activity.e2e-spec.ts @@ -6,7 +6,10 @@ import { MailService } from '../../src/notification/services/mail.service'; import { initializeDbConn, prepareEnvironment, seedDatabase } from './helpers'; import { UsersModule } from '../../src/users/users.module'; import { CragsModule } from '../../src/crags/crags.module'; -import { AscentType } from '../../src/activities/entities/activity-route.entity'; +import { + AscentType, + PublishType, +} from '../../src/activities/entities/activity-route.entity'; import { Activity, ActivityType, @@ -304,13 +307,18 @@ describe('Activity', () => { const numOfNonPublicActivityRoutes = response.body.data.activities.items.filter( (a) => - a.routes.filter((ar) => !['public'].includes(ar.publish)).length > 0, + a.routes.filter( + (ar) => ![PublishType.PUBLIC].includes(ar.publish.toLowerCase()), + ).length > 0, ).length; expect(numOfNonPublicActivityRoutes).toEqual(0); const numOfActivitiesWithNoPublicActivityRoutes = response.body.data.activities.items.filter( - (a) => !a.routes.some((ar) => ['public'].includes(ar.publish)), + (a) => + !a.routes.some((ar) => + [PublishType.PUBLIC].includes(ar.publish.toLowerCase()), + ), ).length; expect(numOfActivitiesWithNoPublicActivityRoutes).toEqual(0); diff --git a/test/e2e/activityRoutes.e2e-spec.ts b/test/e2e/activityRoutes.e2e-spec.ts index 9bc2b8b..7a633e2 100644 --- a/test/e2e/activityRoutes.e2e-spec.ts +++ b/test/e2e/activityRoutes.e2e-spec.ts @@ -182,7 +182,7 @@ describe('Activity', () => { queryResponse.body.data.activity.routes.filter( (r) => r.route.id == mockRoutes[0].id && - !(r.ascentType == AscentType.REPEAT), + !(r.ascentType.toLowerCase() == AscentType.REPEAT), )[0].orderScore, ).toBe(mockRoutes[0].difficulty + 100); expect( @@ -207,13 +207,15 @@ describe('Activity', () => { expect( queryResponse.body.data.activity.routes.filter( (r) => - r.route.id == mockRoutes[2].id && r.AscentType != AscentType.REPEAT, + r.route.id == mockRoutes[2].id && + r.ascentType.toLowerCase() != AscentType.REPEAT, )[0].orderScore, ).toBe(mockRoutes[2].difficulty); expect( queryResponse.body.data.activity.routes.filter( (r) => - r.route.id == mockRoutes[2].id && r.AscentType != AscentType.REPEAT, + r.route.id == mockRoutes[2].id && + r.ascentType.toLowerCase() != AscentType.REPEAT, )[0].rankingScore, ).toBe(mockRoutes[2].difficulty); @@ -221,13 +223,15 @@ describe('Activity', () => { expect( queryResponse.body.data.activity.routes.filter( (r) => - r.route.id == mockRoutes[2].id && r.ascentType == AscentType.REPEAT, + r.route.id == mockRoutes[2].id && + r.ascentType.toLowerCase() == AscentType.REPEAT, )[0].orderScore, ).toBe(mockRoutes[2].difficulty - 10); expect( queryResponse.body.data.activity.routes.filter( (r) => - r.route.id == mockRoutes[2].id && r.ascentType == AscentType.REPEAT, + r.route.id == mockRoutes[2].id && + r.ascentType.toLowerCase() == AscentType.REPEAT, )[0].rankingScore, ).toBe(0); @@ -295,13 +299,15 @@ describe('Activity', () => { expect( queryResponse.body.data.activity.routes.filter( (r) => - r.route.id == mockRoutes[8].id && r.AscentType != AscentType.T_REPEAT, + r.route.id == mockRoutes[8].id && + r.ascentType.toLowerCase() != AscentType.T_REPEAT, )[0].orderScore, ).toBe(mockRoutes[8].difficulty * 0.0001); expect( queryResponse.body.data.activity.routes.filter( (r) => - r.route.id == mockRoutes[8].id && r.AscentType != AscentType.T_REPEAT, + r.route.id == mockRoutes[8].id && + r.ascentType.toLowerCase() != AscentType.T_REPEAT, )[0].rankingScore, ).toBe(0); @@ -309,13 +315,15 @@ describe('Activity', () => { expect( queryResponse.body.data.activity.routes.filter( (r) => - r.route.id == mockRoutes[8].id && r.ascentType == AscentType.T_REPEAT, + r.route.id == mockRoutes[8].id && + r.ascentType.toLowerCase() == AscentType.T_REPEAT, )[0].orderScore, ).toBe((mockRoutes[8].difficulty - 10) * 0.0001); expect( queryResponse.body.data.activity.routes.filter( (r) => - r.route.id == mockRoutes[8].id && r.ascentType == AscentType.T_REPEAT, + r.route.id == mockRoutes[8].id && + r.ascentType.toLowerCase() == AscentType.T_REPEAT, )[0].rankingScore, ).toBe(0);