From f002296a6944b3a853a0b333ac6377673306968f Mon Sep 17 00:00:00 2001 From: Anze Demsar Date: Mon, 10 Jun 2024 16:57:22 +0200 Subject: [PATCH 1/9] add activityRoutes resolver to route --- .../services/activity-routes.service.ts | 4 ++-- src/crags/crags.module.ts | 8 ++++++++ src/crags/resolvers/routes.resolver.ts | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/activities/services/activity-routes.service.ts b/src/activities/services/activity-routes.service.ts index 707cdf9..3e158d4 100644 --- a/src/activities/services/activity-routes.service.ts +++ b/src/activities/services/activity-routes.service.ts @@ -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) @@ -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 diff --git a/src/crags/crags.module.ts b/src/crags/crags.module.ts index 1bcb273..10b6783 100644 --- a/src/crags/crags.module.ts +++ b/src/crags/crags.module.ts @@ -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: [ @@ -98,7 +102,10 @@ import { AreaLoader } from './loaders/area.loader'; IceFallProperty, StarRatingVote, Parking, + Club, + ClubMember, ]), + forwardRef(() => ActivitiesModule), forwardRef(() => AuditModule), BullModule.registerQueue({ name: 'summary', @@ -148,6 +155,7 @@ import { AreaLoader } from './loaders/area.loader'; CragLoader, RouteLoader, ParkingsService, + ActivityRoutesService, ], controllers: [UploadController], exports: [ diff --git a/src/crags/resolvers/routes.resolver.ts b/src/crags/resolvers/routes.resolver.ts index 1785f06..09e953a 100644 --- a/src/crags/resolvers/routes.resolver.ts +++ b/src/crags/resolvers/routes.resolver.ts @@ -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) @@ -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 { return this.routesService.findOneById(id); } @@ -286,4 +292,17 @@ export class RoutesResolver { ): Promise { 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 { + return this.activityRoutesService.paginate( + { ...input, routeId: route.id }, + currentUser, + ); + } } From f5859b2fd9722f05ddf1611d2e449792ca51f258 Mon Sep 17 00:00:00 2001 From: Anze Demsar Date: Mon, 10 Jun 2024 23:25:12 +0200 Subject: [PATCH 2/9] route page: add star rating resolver --- src/crags/resolvers/routes.resolver.ts | 8 ++++++++ src/crags/services/star-rating-votes.service.ts | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/src/crags/resolvers/routes.resolver.ts b/src/crags/resolvers/routes.resolver.ts index 09e953a..995f1eb 100644 --- a/src/crags/resolvers/routes.resolver.ts +++ b/src/crags/resolvers/routes.resolver.ts @@ -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) @@ -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, @@ -257,6 +260,11 @@ export class RoutesResolver { return this.difficultyVotesService.findByRouteId(route.id); } + @ResolveField('starRatingVotes', () => [StarRatingVote]) + async starRatingVotes(@Parent() route: Route): Promise { + return this.starRatingVotesService.findByRouteId(route.id); + } + @ResolveField('crag', () => Crag) async getCrag( @Parent() route: Route, diff --git a/src/crags/services/star-rating-votes.service.ts b/src/crags/services/star-rating-votes.service.ts index 6f3a1e3..0bea768 100644 --- a/src/crags/services/star-rating-votes.service.ts +++ b/src/crags/services/star-rating-votes.service.ts @@ -18,4 +18,11 @@ export class StarRatingVotesService { .andWhere('srv.route_id IN (:...routeIds)', { routeIds }) .getMany(); } + + async findByRouteId(routeId: string): Promise { + return this.starRatingVoteRepository.find({ + where: { routeId: routeId }, + order: { stars: 'ASC' }, + }); + } } From 4a42bbf26e56768a09fc5ac62e7062b1735be6b6 Mon Sep 17 00:00:00 2001 From: salamca Date: Thu, 20 Jun 2024 18:35:32 +0200 Subject: [PATCH 3/9] 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 9649c4cc4ff3205de205454c1de5e8fcb106ae44 Mon Sep 17 00:00:00 2001 From: Anze Demsar Date: Fri, 21 Jun 2024 14:38:11 +0200 Subject: [PATCH 4/9] update test after making log ascents private --- src/activities/services/activities.service.ts | 4 +--- test/e2e/activity.e2e-spec.ts | 13 ++++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/activities/services/activities.service.ts b/src/activities/services/activities.service.ts index 6e3088a..933d32f 100644 --- a/src/activities/services/activities.service.ts +++ b/src/activities/services/activities.service.ts @@ -219,7 +219,6 @@ export class ActivitiesService { params: FindActivitiesInput = {}, currentUser: User = null, ): Promise { - const builder = this.activitiesRepository .createQueryBuilder('ac') .select('EXTRACT(YEAR FROM ac.date)', 'year') @@ -247,7 +246,6 @@ export class ActivitiesService { } as StatsActivities; }); return myStats; - } async find(params: FindActivitiesInput = {}): Promise { @@ -326,7 +324,7 @@ export class ActivitiesService { ActivityRoute, 'ar', 'ar.activity_id = a.id AND (ar."publish" IN (:...publish))', - { publish: ['log', 'public'] }, + { publish: ['public'] }, ); // Allow/disallow based on publishStatus of contained activity routes diff --git a/test/e2e/activity.e2e-spec.ts b/test/e2e/activity.e2e-spec.ts index a1579af..ccc7464 100644 --- a/test/e2e/activity.e2e-spec.ts +++ b/test/e2e/activity.e2e-spec.ts @@ -276,7 +276,7 @@ describe('Activity', () => { expect(activitiesIds).not.toContain(mockData.activities.nonCragActivity.id); }); - it('should get only public (or log) activity routes and only activities containing at least one public (or log) activity route when fetching as a guest', async () => { + it('should get only public activity routes and only activities containing at least one public activity route when fetching as a guest', async () => { const response = await request(app.getHttpServer()) .post('/graphql') .send({ @@ -304,14 +304,13 @@ describe('Activity', () => { const numOfNonPublicActivityRoutes = response.body.data.activities.items.filter( (a) => - a.routes.filter((ar) => !['log', 'public'].includes(ar.publish)) - .length > 0, + a.routes.filter((ar) => !['public'].includes(ar.publish)).length > 0, ).length; expect(numOfNonPublicActivityRoutes).toEqual(0); const numOfActivitiesWithNoPublicActivityRoutes = response.body.data.activities.items.filter( - (a) => !a.routes.some((ar) => ['log', 'public'].includes(ar.publish)), + (a) => !a.routes.some((ar) => ['public'].includes(ar.publish)), ).length; expect(numOfActivitiesWithNoPublicActivityRoutes).toEqual(0); @@ -320,7 +319,7 @@ describe('Activity', () => { const returnedActivitiesIds = response.body.data.activities.items.map( (a) => a.id, ); - expect(returnedActivitiesIds).toContain( + expect(returnedActivitiesIds).not.toContain( mockData.activities.activityWithLogRoutes.id, ); expect(returnedActivitiesIds).toContain( @@ -340,7 +339,7 @@ describe('Activity', () => { mockData.activities.activityWithPublicRoutes.activityRoutes .publicActivityRoute.id, ); - expect(returnedActivityRoutesIds).toContain( + expect(returnedActivityRoutesIds).not.toContain( mockData.activities.activityWithLogRoutes.activityRoutes.logActivityRoute .id, ); @@ -348,7 +347,7 @@ describe('Activity', () => { mockData.activities.activityWithMixedRoutes.activityRoutes .publicActivityRoute.id, ); - expect(returnedActivityRoutesIds).toContain( + expect(returnedActivityRoutesIds).not.toContain( mockData.activities.activityWithMixedRoutes.activityRoutes .logActivityRoute.id, ); From 0b8c59bf96084b5cfeab340c6b5e9c8b0c7ceff0 Mon Sep 17 00:00:00 2001 From: salamca Date: Sat, 29 Jun 2024 13:14:06 +0200 Subject: [PATCH 5/9] 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 6/9] 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 7/9] 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); From 152b842125c6bc7abc6cd91ca87bece3cbc6a613 Mon Sep 17 00:00:00 2001 From: salamca Date: Fri, 13 Sep 2024 11:43:05 +0200 Subject: [PATCH 8/9] Change case of AscentType enum keys and values to all lowercase. --- .../entities/activity-route.entity.ts | 60 +++++++++---------- .../services/activity-routes.service.ts | 22 +++---- src/crags/utils/calculate-scores.ts | 30 +++++----- src/crags/utils/convert-ascents.ts | 12 ++-- test/e2e/activity.e2e-spec.ts | 18 +++--- test/e2e/activityMutations.e2e-spec.ts | 2 +- test/e2e/activityRoutes.e2e-spec.ts | 50 +++++++--------- test/e2e/routeMigration.e2e-spec.ts | 10 ++-- test/e2e/sectorMigration.e2e-spec.ts | 8 +-- test/e2e/user-delete.e2e-spec.ts | 12 ++-- 10 files changed, 110 insertions(+), 114 deletions(-) diff --git a/src/activities/entities/activity-route.entity.ts b/src/activities/entities/activity-route.entity.ts index bd0dbd3..50019c1 100644 --- a/src/activities/entities/activity-route.entity.ts +++ b/src/activities/entities/activity-route.entity.ts @@ -15,50 +15,50 @@ import { Pitch } from '../../crags/entities/pitch.entity'; import { User } from '../../users/entities/user.entity'; export enum AscentType { - ONSIGHT = 'onsight', - FLASH = 'flash', - REDPOINT = 'redpoint', - REPEAT = 'repeat', - ALLFREE = 'allfree', - AID = 'aid', - ATTEMPT = 'attempt', - T_ONSIGHT = 't_onsight', - T_FLASH = 't_flash', - T_REDPOINT = 't_redpoint', - T_REPEAT = 't_repeat', - T_ALLFREE = 't_allfree', - T_AID = 't_aid', - T_ATTEMPT = 't_attempt', - TICK = 'tick', + onsight = 'onsight', + flash = 'flash', + redpoint = 'redpoint', + repeat = 'repeat', + allfree = 'allfree', + aid = 'aid', + attempt = 'attempt', + t_onsight = 't_onsight', + t_flash = 't_flash', + t_redpoint = 't_redpoint', + t_repeat = 't_repeat', + t_allfree = 't_allfree', + t_aid = 't_aid', + t_attempt = 't_attempt', + tick = 'tick', } registerEnumType(AscentType, { name: 'AscentType', }); export const tickAscentTypes = new Set([ - AscentType.ONSIGHT, - AscentType.FLASH, - AscentType.REDPOINT, - AscentType.REPEAT, + AscentType.onsight, + AscentType.flash, + AscentType.redpoint, + AscentType.repeat, ]); export const firstTickAscentTypes = new Set([ - AscentType.ONSIGHT, - AscentType.FLASH, - AscentType.REDPOINT, + AscentType.onsight, + AscentType.flash, + AscentType.redpoint, ]); export const trTickAscentTypes = new Set([ - AscentType.T_ONSIGHT, - AscentType.T_FLASH, - AscentType.T_REDPOINT, - AscentType.T_REPEAT, + AscentType.t_onsight, + AscentType.t_flash, + AscentType.t_redpoint, + AscentType.t_repeat, ]); export const firstTrTickAscentTypes = new Set([ - AscentType.T_ONSIGHT, - AscentType.T_FLASH, - AscentType.T_REDPOINT, + AscentType.t_onsight, + AscentType.t_flash, + AscentType.t_redpoint, ]); export enum PublishType { @@ -115,7 +115,7 @@ export class ActivityRoute extends BaseEntity { @Column({ type: 'enum', enum: AscentType, - default: AscentType.REDPOINT, + default: AscentType.redpoint, }) @Field((type) => AscentType) ascentType: AscentType; diff --git a/src/activities/services/activity-routes.service.ts b/src/activities/services/activity-routes.service.ts index 3e158d4..0877cc3 100644 --- a/src/activities/services/activity-routes.service.ts +++ b/src/activities/services/activity-routes.service.ts @@ -247,8 +247,8 @@ export class ActivityRoutesService { // boulders cannot be onsighted at all if (routeTypeId === 'boulder') { if ( - ascentType === AscentType.ONSIGHT || - ascentType === AscentType.T_ONSIGHT + ascentType === AscentType.onsight || + ascentType === AscentType.t_onsight ) return false; } @@ -256,10 +256,10 @@ export class ActivityRoutesService { // already tried routes cannot be onsighted or flashed if (routeTried) { if ( - ascentType === AscentType.ONSIGHT || - ascentType === AscentType.T_ONSIGHT || - ascentType === AscentType.FLASH || - ascentType === AscentType.T_FLASH + ascentType === AscentType.onsight || + ascentType === AscentType.t_onsight || + ascentType === AscentType.flash || + ascentType === AscentType.t_flash ) return false; } @@ -267,26 +267,26 @@ export class ActivityRoutesService { // already ticked routes cannot be redpointed (flash, sight included above) if (routeTicked) { if ( - ascentType === AscentType.REDPOINT || - ascentType === AscentType.T_REDPOINT + ascentType === AscentType.redpoint || + ascentType === AscentType.t_redpoint ) return false; } // routes one already 'ticked' on toprope cannot be tr redpointed if (routeTrTicked) { - if (ascentType === AscentType.T_REDPOINT) { + if (ascentType === AscentType.t_redpoint) { return false; } } // routes not ticked before cannot be repeated - if (ascentType === AscentType.REPEAT && !routeTicked) { + if (ascentType === AscentType.repeat && !routeTicked) { return false; } // routes not ticked (real or tr) before cannot be toprope repeated - if (ascentType === AscentType.T_REPEAT && !(routeTicked || routeTrTicked)) { + if (ascentType === AscentType.t_repeat && !(routeTicked || routeTrTicked)) { return false; } diff --git a/src/crags/utils/calculate-scores.ts b/src/crags/utils/calculate-scores.ts index 3ab230d..c703eb2 100644 --- a/src/crags/utils/calculate-scores.ts +++ b/src/crags/utils/calculate-scores.ts @@ -50,35 +50,35 @@ function calculateScore( const scoreTypeFactor = scoreType === 'order' ? 1 : 0; switch (ascentType) { - case AscentType.ONSIGHT: + case AscentType.onsight: return difficulty + 100; - case AscentType.FLASH: + case AscentType.flash: return difficulty + 50; - case AscentType.REDPOINT: + case AscentType.redpoint: return difficulty; - case AscentType.REPEAT: + case AscentType.repeat: return (difficulty - 10) * scoreTypeFactor; - case AscentType.ALLFREE: + case AscentType.allfree: return difficulty * 0.01 * scoreTypeFactor; - case AscentType.AID: + case AscentType.aid: return difficulty * 0.001 * scoreTypeFactor; - case AscentType.ATTEMPT: + case AscentType.attempt: return difficulty * 0.0001 * scoreTypeFactor; - case AscentType.T_ONSIGHT: + case AscentType.t_onsight: return (difficulty + 100) * 0.0001 * scoreTypeFactor; - case AscentType.T_FLASH: + case AscentType.t_flash: return (difficulty + 50) * 0.0001 * scoreTypeFactor; - case AscentType.T_REDPOINT: + case AscentType.t_redpoint: return difficulty * 0.0001 * scoreTypeFactor; - case AscentType.T_REPEAT: + case AscentType.t_repeat: return (difficulty - 10) * 0.0001 * scoreTypeFactor; - case AscentType.T_ALLFREE: + case AscentType.t_allfree: return difficulty * 0.01 * 0.0001 * scoreTypeFactor; - case AscentType.T_AID: + case AscentType.t_aid: return difficulty * 0.001 * 0.0001 * scoreTypeFactor; - case AscentType.T_ATTEMPT: + case AscentType.t_attempt: return difficulty * 0.0001 * 0.0001 * scoreTypeFactor; - case AscentType.TICK: + case AscentType.tick: // TODO: what is TICK ascent type, and is it even used?? prob not, 1 ar in db... suggest removal, discuss return 0; } diff --git a/src/crags/utils/convert-ascents.ts b/src/crags/utils/convert-ascents.ts index 5bc31a8..09d1164 100644 --- a/src/crags/utils/convert-ascents.ts +++ b/src/crags/utils/convert-ascents.ts @@ -49,7 +49,7 @@ async function convertFirstTickAfterToRepeat( ); // Convert it to repeat - futureTick.ascentType = AscentType.REPEAT; + futureTick.ascentType = AscentType.repeat; await queryRunner.manager.save(futureTick); sideEffects.push({ before: futureTickBeforeChange, after: futureTick }); } @@ -86,7 +86,7 @@ async function convertFirstTrTickAfterToTrRepeat( ); // Convert it to toprope repeat - futureTrTick.ascentType = AscentType.T_REPEAT; + futureTrTick.ascentType = AscentType.t_repeat; await queryRunner.manager.save(futureTrTick); sideEffects.push({ before: futureTrTickBeforeChange, @@ -110,7 +110,7 @@ async function convertFirstSightOrFlashAfterToRedpoint( .where('ar.route_id = :routeId', { routeId: routeId }) .andWhere('ar.user_id = :userId', { userId: userId }) .andWhere('ar.ascent_type IN (:...aTypes)', { - aTypes: [AscentType.ONSIGHT, AscentType.FLASH], + aTypes: [AscentType.onsight, AscentType.flash], }) .andWhere('ar.date > :arDate', { arDate: date }) .getOne(); // If data is valid there can only be one such ascent logged (or none) @@ -126,7 +126,7 @@ async function convertFirstSightOrFlashAfterToRedpoint( ); // Convert it to redpoint - futureSightOrFlash.ascentType = AscentType.REDPOINT; + futureSightOrFlash.ascentType = AscentType.redpoint; await queryRunner.manager.save(futureSightOrFlash); sideEffects.push({ before: futureSightOrFlashBeforeChange, @@ -150,7 +150,7 @@ async function convertFirstTrSightOrFlashAfterToTrRedpoint( .where('ar.route_id = :routeId', { routeId: routeId }) .andWhere('ar.user_id = :userId', { userId: userId }) .andWhere('ar.ascent_type IN (:...aTypes)', { - aTypes: [AscentType.T_ONSIGHT, AscentType.T_FLASH], + aTypes: [AscentType.t_onsight, AscentType.t_flash], }) .andWhere('ar.date > :arDate', { arDate: date }) .getOne(); // If data is valid there can only be one such ascent logged (or none) @@ -166,7 +166,7 @@ async function convertFirstTrSightOrFlashAfterToTrRedpoint( ); // Convert it to toprope redpoint - futureTrSightOrFlash.ascentType = AscentType.T_REDPOINT; + futureTrSightOrFlash.ascentType = AscentType.t_redpoint; await queryRunner.manager.save(futureTrSightOrFlash); sideEffects.push({ before: futureTrSightOrFlashBeforeChange, diff --git a/test/e2e/activity.e2e-spec.ts b/test/e2e/activity.e2e-spec.ts index eb15908..1538ca8 100644 --- a/test/e2e/activity.e2e-spec.ts +++ b/test/e2e/activity.e2e-spec.ts @@ -130,7 +130,7 @@ describe('Activity', () => { await queryRunner.query( `INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score) - VALUES ('${mockData.activities.activityWithPublicRoutes.activityRoutes.publicActivityRoute.id}', '${AscentType.ONSIGHT}', 'public', '${mockData.activities.activityWithPublicRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, + VALUES ('${mockData.activities.activityWithPublicRoutes.activityRoutes.publicActivityRoute.id}', '${AscentType.onsight}', 'public', '${mockData.activities.activityWithPublicRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, ); // add activity with only private activity routes @@ -141,7 +141,7 @@ describe('Activity', () => { await queryRunner.query( `INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score) - VALUES ('${mockData.activities.activityWithPrivateRoutes.activityRoutes.privateActivityRoute.id}', '${AscentType.REPEAT}', 'private', '${mockData.activities.activityWithPrivateRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, + VALUES ('${mockData.activities.activityWithPrivateRoutes.activityRoutes.privateActivityRoute.id}', '${AscentType.repeat}', 'private', '${mockData.activities.activityWithPrivateRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, ); // add activity with only log activity routes @@ -152,7 +152,7 @@ describe('Activity', () => { await queryRunner.query( `INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score) - VALUES ('${mockData.activities.activityWithLogRoutes.activityRoutes.logActivityRoute.id}', '${AscentType.REPEAT}', 'log', '${mockData.activities.activityWithLogRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, + VALUES ('${mockData.activities.activityWithLogRoutes.activityRoutes.logActivityRoute.id}', '${AscentType.repeat}', 'log', '${mockData.activities.activityWithLogRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, ); // add activty with mixed activity routes (public, private, log) @@ -163,15 +163,15 @@ describe('Activity', () => { await queryRunner.query( `INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score) - VALUES ('${mockData.activities.activityWithMixedRoutes.activityRoutes.publicActivityRoute.id}', '${AscentType.REPEAT}', 'public', '${mockData.activities.activityWithMixedRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, + VALUES ('${mockData.activities.activityWithMixedRoutes.activityRoutes.publicActivityRoute.id}', '${AscentType.repeat}', 'public', '${mockData.activities.activityWithMixedRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, ); await queryRunner.query( `INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score) - VALUES ('${mockData.activities.activityWithMixedRoutes.activityRoutes.logActivityRoute.id}', '${AscentType.REPEAT}', 'log', '${mockData.activities.activityWithMixedRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, + VALUES ('${mockData.activities.activityWithMixedRoutes.activityRoutes.logActivityRoute.id}', '${AscentType.repeat}', 'log', '${mockData.activities.activityWithMixedRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, ); await queryRunner.query( `INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score) - VALUES ('${mockData.activities.activityWithMixedRoutes.activityRoutes.privateActivityRoute.id}', '${AscentType.REPEAT}', 'private', '${mockData.activities.activityWithMixedRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, + VALUES ('${mockData.activities.activityWithMixedRoutes.activityRoutes.privateActivityRoute.id}', '${AscentType.repeat}', 'private', '${mockData.activities.activityWithMixedRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, ); // add activity in a draft crag @@ -181,7 +181,7 @@ describe('Activity', () => { ); await queryRunner.query( `INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score) - VALUES ('${mockData.activities.activityInDraftCrag.activityRoutes.activityRoute1.id}', '${AscentType.REPEAT}', 'public', '${mockData.activities.activityInDraftCrag.id}', '${mockData.crags.draftCrag.sectors.draftSector.routes.draftRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, + VALUES ('${mockData.activities.activityInDraftCrag.activityRoutes.activityRoute1.id}', '${AscentType.repeat}', 'public', '${mockData.activities.activityInDraftCrag.id}', '${mockData.crags.draftCrag.sectors.draftSector.routes.draftRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, ); // add activity in an in_review crag @@ -191,7 +191,7 @@ describe('Activity', () => { ); await queryRunner.query( `INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score) - VALUES ('${mockData.activities.activityInInReviewCrag.activityRoutes.activityRoute1.id}', '${AscentType.REPEAT}', 'public', '${mockData.activities.activityInInReviewCrag.id}', '${mockData.crags.inReviewCrag.sectors.inReviewSector.routes.inReviewRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, + VALUES ('${mockData.activities.activityInInReviewCrag.activityRoutes.activityRoute1.id}', '${AscentType.repeat}', 'public', '${mockData.activities.activityInInReviewCrag.id}', '${mockData.crags.inReviewCrag.sectors.inReviewSector.routes.inReviewRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, ); // add activity in a published crag and draft sector @@ -201,7 +201,7 @@ describe('Activity', () => { ); await queryRunner.query( `INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score) - VALUES ('${mockData.activities.activityInPublishedCragDraftSector.activityRoutes.activityRoute1.id}', '${AscentType.REPEAT}', 'public', '${mockData.activities.activityInPublishedCragDraftSector.id}', '${mockData.crags.publishedCrag.sectors.draftSector.routes.draftRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, + VALUES ('${mockData.activities.activityInPublishedCragDraftSector.activityRoutes.activityRoute1.id}', '${AscentType.repeat}', 'public', '${mockData.activities.activityInPublishedCragDraftSector.id}', '${mockData.crags.publishedCrag.sectors.draftSector.routes.draftRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`, ); }); diff --git a/test/e2e/activityMutations.e2e-spec.ts b/test/e2e/activityMutations.e2e-spec.ts index 6f2c1aa..1d1067a 100644 --- a/test/e2e/activityMutations.e2e-spec.ts +++ b/test/e2e/activityMutations.e2e-spec.ts @@ -104,7 +104,7 @@ describe('ActivityMutations', () => { }, routes: [ { - ascentType: "${AscentType.ONSIGHT}", + ascentType: "${AscentType.onsight}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}" diff --git a/test/e2e/activityRoutes.e2e-spec.ts b/test/e2e/activityRoutes.e2e-spec.ts index 7a633e2..182b638 100644 --- a/test/e2e/activityRoutes.e2e-spec.ts +++ b/test/e2e/activityRoutes.e2e-spec.ts @@ -60,85 +60,85 @@ describe('Activity', () => { }, routes: [ { - ascentType: "${AscentType.ONSIGHT}", + ascentType: "${AscentType.onsight}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[0].id}" }, { - ascentType: "${AscentType.FLASH}", + ascentType: "${AscentType.flash}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[1].id}" }, { - ascentType: "${AscentType.REDPOINT}", + ascentType: "${AscentType.redpoint}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[2].id}" }, { - ascentType: "${AscentType.REPEAT}", + ascentType: "${AscentType.repeat}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[2].id}" } { - ascentType: "${AscentType.ALLFREE}", + ascentType: "${AscentType.allfree}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[3].id}" }, { - ascentType: "${AscentType.AID}", + ascentType: "${AscentType.aid}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[4].id}" }, { - ascentType: "${AscentType.ATTEMPT}", + ascentType: "${AscentType.attempt}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[5].id}" }, { - ascentType: "${AscentType.T_ONSIGHT}", + ascentType: "${AscentType.t_onsight}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[6].id}" }, { - ascentType: "${AscentType.T_FLASH}", + ascentType: "${AscentType.t_flash}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[7].id}" }, { - ascentType: "${AscentType.T_REDPOINT}", + ascentType: "${AscentType.t_redpoint}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[8].id}" }, { - ascentType: "${AscentType.T_REPEAT}", + ascentType: "${AscentType.t_repeat}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[8].id}" }, { - ascentType: "${AscentType.T_ALLFREE}", + ascentType: "${AscentType.t_allfree}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[9].id}" }, { - ascentType: "${AscentType.T_AID}", + ascentType: "${AscentType.t_aid}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[10].id}" } { - ascentType: "${AscentType.T_ATTEMPT}", + ascentType: "${AscentType.t_attempt}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[11].id}" @@ -182,7 +182,7 @@ describe('Activity', () => { queryResponse.body.data.activity.routes.filter( (r) => r.route.id == mockRoutes[0].id && - !(r.ascentType.toLowerCase() == AscentType.REPEAT), + !(r.ascentType == AscentType.repeat), )[0].orderScore, ).toBe(mockRoutes[0].difficulty + 100); expect( @@ -207,15 +207,13 @@ describe('Activity', () => { expect( queryResponse.body.data.activity.routes.filter( (r) => - r.route.id == mockRoutes[2].id && - r.ascentType.toLowerCase() != AscentType.REPEAT, + r.route.id == mockRoutes[2].id && r.ascentType != AscentType.repeat, )[0].orderScore, ).toBe(mockRoutes[2].difficulty); expect( queryResponse.body.data.activity.routes.filter( (r) => - r.route.id == mockRoutes[2].id && - r.ascentType.toLowerCase() != AscentType.REPEAT, + r.route.id == mockRoutes[2].id && r.ascentType != AscentType.repeat, )[0].rankingScore, ).toBe(mockRoutes[2].difficulty); @@ -223,15 +221,13 @@ describe('Activity', () => { expect( queryResponse.body.data.activity.routes.filter( (r) => - r.route.id == mockRoutes[2].id && - r.ascentType.toLowerCase() == AscentType.REPEAT, + r.route.id == mockRoutes[2].id && r.ascentType == 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.toLowerCase() == AscentType.REPEAT, + r.route.id == mockRoutes[2].id && r.ascentType == AscentType.repeat, )[0].rankingScore, ).toBe(0); @@ -300,14 +296,14 @@ describe('Activity', () => { queryResponse.body.data.activity.routes.filter( (r) => r.route.id == mockRoutes[8].id && - r.ascentType.toLowerCase() != AscentType.T_REPEAT, + 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.toLowerCase() != AscentType.T_REPEAT, + r.ascentType.toLowerCase() != AscentType.t_repeat, )[0].rankingScore, ).toBe(0); @@ -316,14 +312,14 @@ describe('Activity', () => { queryResponse.body.data.activity.routes.filter( (r) => r.route.id == mockRoutes[8].id && - r.ascentType.toLowerCase() == AscentType.T_REPEAT, + 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.toLowerCase() == AscentType.T_REPEAT, + r.ascentType.toLowerCase() == AscentType.t_repeat, )[0].rankingScore, ).toBe(0); diff --git a/test/e2e/routeMigration.e2e-spec.ts b/test/e2e/routeMigration.e2e-spec.ts index 596dd2d..751b943 100644 --- a/test/e2e/routeMigration.e2e-spec.ts +++ b/test/e2e/routeMigration.e2e-spec.ts @@ -59,8 +59,8 @@ describe('RouteMigration', () => { await queryRunner.query( `INSERT INTO activity_route (ascent_type, publish, activity_id, route_id, user_id, date, order_score, ranking_score) VALUES - ('${AscentType.ONSIGHT}', 'log', '${mockData.activities.activityAcrossSectors.id}', '${mockData.crags.cragWithMultipleSectors.sectors.firstSector.routes.firstRoute.id}', '${mockData.users.basicUser1.id}', '${mockData.activities.activityAcrossSectors.date}', 1000, 1000), - ('${AscentType.ONSIGHT}', 'log', '${mockData.activities.activityWithDuplicateRoute.id}', '${mockData.crags.cragWithMultipleSectors.sectors.secondSector.routes.firstRoute.id}', '${mockData.users.basicUser1.id}', '${mockData.activities.activityWithDuplicateRoute.date}', 1000, 1000) + ('${AscentType.onsight}', 'log', '${mockData.activities.activityAcrossSectors.id}', '${mockData.crags.cragWithMultipleSectors.sectors.firstSector.routes.firstRoute.id}', '${mockData.users.basicUser1.id}', '${mockData.activities.activityAcrossSectors.date}', 1000, 1000), + ('${AscentType.onsight}', 'log', '${mockData.activities.activityWithDuplicateRoute.id}', '${mockData.crags.cragWithMultipleSectors.sectors.secondSector.routes.firstRoute.id}', '${mockData.users.basicUser1.id}', '${mockData.activities.activityWithDuplicateRoute.date}', 1000, 1000) `, ); @@ -164,7 +164,7 @@ describe('RouteMigration', () => { it('should change ascent types if invalid state happens after merge', async () => { const onsightAscentsOfRoute = await queryRunner.query( - `SELECT * FROM activity_route WHERE route_id = '${mockData.crags.cragWithMultipleSectors.sectors.firstSector.routes.firstRoute.id}' AND user_id = '${mockData.users.basicUser1.id}' AND ascent_type = '${AscentType.ONSIGHT}'`, + `SELECT * FROM activity_route WHERE route_id = '${mockData.crags.cragWithMultipleSectors.sectors.firstSector.routes.firstRoute.id}' AND user_id = '${mockData.users.basicUser1.id}' AND ascent_type = '${AscentType.onsight}'`, ); expect(onsightAscentsOfRoute.length).toBe(1); }); @@ -232,7 +232,7 @@ describe('RouteMigration', () => { }, routes: [ { - ascentType: "${AscentType.ONSIGHT}", + ascentType: "${AscentType.onsight}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[0].id}" @@ -315,7 +315,7 @@ describe('RouteMigration', () => { }, routes: [ { - ascentType: "${AscentType.REDPOINT}", + ascentType: "${AscentType.redpoint}", publish: "${PublishType.PUBLIC}", date: "2017-03-07", routeId: "${mockRoutes[1].id}" diff --git a/test/e2e/sectorMigration.e2e-spec.ts b/test/e2e/sectorMigration.e2e-spec.ts index 95eae4e..eac6a78 100644 --- a/test/e2e/sectorMigration.e2e-spec.ts +++ b/test/e2e/sectorMigration.e2e-spec.ts @@ -49,10 +49,10 @@ describe('SectorMigration', () => { await queryRunner.query( `INSERT INTO activity_route (ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score) VALUES - ('${AscentType.ALLFREE}', 'log', '${mockData.activities.activityAcrossSectors.id}', '${mockData.crags.cragWithMultipleSectors.sectors.firstSector.routes.firstRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000), - ('${AscentType.ALLFREE}', 'log', '${mockData.activities.activityAcrossSectors.id}', '${mockData.crags.cragWithMultipleSectors.sectors.firstSector.routes.secondRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000), - ('${AscentType.ALLFREE}', 'log', '${mockData.activities.activityAcrossSectors.id}', '${mockData.crags.cragWithMultipleSectors.sectors.secondSector.routes.firstRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000), - ('${AscentType.ALLFREE}', 'log', '${mockData.activities.activityAcrossSectors.id}', '${mockData.crags.cragWithMultipleSectors.sectors.secondSector.routes.secondRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000) + ('${AscentType.allfree}', 'log', '${mockData.activities.activityAcrossSectors.id}', '${mockData.crags.cragWithMultipleSectors.sectors.firstSector.routes.firstRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000), + ('${AscentType.allfree}', 'log', '${mockData.activities.activityAcrossSectors.id}', '${mockData.crags.cragWithMultipleSectors.sectors.firstSector.routes.secondRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000), + ('${AscentType.allfree}', 'log', '${mockData.activities.activityAcrossSectors.id}', '${mockData.crags.cragWithMultipleSectors.sectors.secondSector.routes.firstRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000), + ('${AscentType.allfree}', 'log', '${mockData.activities.activityAcrossSectors.id}', '${mockData.crags.cragWithMultipleSectors.sectors.secondSector.routes.secondRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000) `, ); }); diff --git a/test/e2e/user-delete.e2e-spec.ts b/test/e2e/user-delete.e2e-spec.ts index d66ec6f..a06f127 100644 --- a/test/e2e/user-delete.e2e-spec.ts +++ b/test/e2e/user-delete.e2e-spec.ts @@ -56,14 +56,14 @@ describe('UserDelete', () => { [ { route: mockData.crags.simpleCrag.sectors.simpleSector1.routes[0], - ascentType: AscentType.REDPOINT, + ascentType: AscentType.redpoint, publishType: PublishType.PRIVATE, votedDifficulty: 1100, votedStarRating: 2, }, { route: mockData.crags.simpleCrag.sectors.simpleSector1.routes[1], - ascentType: AscentType.ONSIGHT, + ascentType: AscentType.onsight, publishType: PublishType.PUBLIC, }, ], @@ -81,7 +81,7 @@ describe('UserDelete', () => { await logRoutes(app, mockData.users.basicUser2, mockData.crags.simpleCrag, [ { route: mockData.crags.simpleCrag.sectors.simpleSector1.routes[0], - ascentType: AscentType.REDPOINT, + ascentType: AscentType.redpoint, publishType: PublishType.PRIVATE, votedDifficulty: 1200, votedStarRating: 2, @@ -90,7 +90,7 @@ describe('UserDelete', () => { await logRoutes(app, mockData.users.basicUser3, mockData.crags.simpleCrag, [ { route: mockData.crags.simpleCrag.sectors.simpleSector1.routes[0], - ascentType: AscentType.REDPOINT, + ascentType: AscentType.redpoint, publishType: PublishType.PRIVATE, votedDifficulty: 1300, votedStarRating: 2, @@ -102,7 +102,7 @@ describe('UserDelete', () => { await logRoutes(app, mockData.users.basicUser4, mockData.crags.simpleCrag, [ { route: mockData.crags.simpleCrag.sectors.simpleSector1.routes[0], - ascentType: AscentType.REDPOINT, + ascentType: AscentType.redpoint, publishType: PublishType.PRIVATE, votedStarRating: 2, }, @@ -110,7 +110,7 @@ describe('UserDelete', () => { await logRoutes(app, mockData.users.basicUser5, mockData.crags.simpleCrag, [ { route: mockData.crags.simpleCrag.sectors.simpleSector1.routes[0], - ascentType: AscentType.REDPOINT, + ascentType: AscentType.redpoint, publishType: PublishType.PRIVATE, votedStarRating: 2, }, From 546444643246a8a68b97c5f844fc857947889d68 Mon Sep 17 00:00:00 2001 From: salamca Date: Fri, 13 Sep 2024 17:11:21 +0200 Subject: [PATCH 9/9] Change case of PublishType, Season, Orientation and WallAngle enums keys and values to all lowercase. --- .../entities/activity-route.entity.ts | 10 +++--- src/crags/entities/crag.entity.ts | 32 +++++++++---------- test/e2e/activity.e2e-spec.ts | 4 +-- test/e2e/activityMutations.e2e-spec.ts | 2 +- test/e2e/activityRoutes.e2e-spec.ts | 28 ++++++++-------- test/e2e/routeMigration.e2e-spec.ts | 4 +-- test/e2e/user-delete.e2e-spec.ts | 12 +++---- 7 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/activities/entities/activity-route.entity.ts b/src/activities/entities/activity-route.entity.ts index 50019c1..235a8f8 100644 --- a/src/activities/entities/activity-route.entity.ts +++ b/src/activities/entities/activity-route.entity.ts @@ -62,10 +62,10 @@ export const firstTrTickAscentTypes = new Set([ ]); export enum PublishType { - PUBLIC = 'public', - CLUB = 'club', - LOG = 'log', - PRIVATE = 'private', + public = 'public', + club = 'club', + log = 'log', + private = 'private', } registerEnumType(PublishType, { name: 'PublishType', @@ -123,7 +123,7 @@ export class ActivityRoute extends BaseEntity { @Column({ type: 'enum', enum: PublishType, - default: PublishType.PRIVATE, + default: PublishType.private, }) @Field((type) => PublishType) publish: PublishType; diff --git a/src/crags/entities/crag.entity.ts b/src/crags/entities/crag.entity.ts index ada4b81..f91840e 100644 --- a/src/crags/entities/crag.entity.ts +++ b/src/crags/entities/crag.entity.ts @@ -41,34 +41,34 @@ export enum CragType { } export enum Orientation { - NORTH = 'north', - NORTHEAST = 'northeast', - EAST = 'east', - SOUTHEAST = 'southeast', - SOUTH = 'south', - SOUTHWEST = 'southwest', - WEST = 'west', - NORTHWEST = 'northwest', + north = 'north', + northeast = 'northeast', + east = 'east', + southeast = 'southeast', + south = 'south', + southwest = 'southwest', + west = 'west', + northwest = 'northwest', } registerEnumType(Orientation, { name: 'Orientation', }); export enum WallAngle { - SLAB = 'slab', - VERTICAL = 'vertical', - OVERHANG = 'overhang', - ROOF = 'roof', + slab = 'slab', + vertical = 'vertical', + overhang = 'overhang', + roof = 'roof', } registerEnumType(WallAngle, { name: 'WallAngle', }); export enum Season { - SPRING = 'spring', - SUMMER = 'summer', - AUTUMN = 'autumn', - WINTER = 'winter', + spring = 'spring', + summer = 'summer', + autumn = 'autumn', + winter = 'winter', } registerEnumType(Season, { name: 'Season', diff --git a/test/e2e/activity.e2e-spec.ts b/test/e2e/activity.e2e-spec.ts index 1538ca8..ca4d626 100644 --- a/test/e2e/activity.e2e-spec.ts +++ b/test/e2e/activity.e2e-spec.ts @@ -308,7 +308,7 @@ describe('Activity', () => { response.body.data.activities.items.filter( (a) => a.routes.filter( - (ar) => ![PublishType.PUBLIC].includes(ar.publish.toLowerCase()), + (ar) => ![PublishType.public].includes(ar.publish.toLowerCase()), ).length > 0, ).length; expect(numOfNonPublicActivityRoutes).toEqual(0); @@ -317,7 +317,7 @@ describe('Activity', () => { response.body.data.activities.items.filter( (a) => !a.routes.some((ar) => - [PublishType.PUBLIC].includes(ar.publish.toLowerCase()), + [PublishType.public].includes(ar.publish.toLowerCase()), ), ).length; expect(numOfActivitiesWithNoPublicActivityRoutes).toEqual(0); diff --git a/test/e2e/activityMutations.e2e-spec.ts b/test/e2e/activityMutations.e2e-spec.ts index 1d1067a..b4d0ec6 100644 --- a/test/e2e/activityMutations.e2e-spec.ts +++ b/test/e2e/activityMutations.e2e-spec.ts @@ -105,7 +105,7 @@ describe('ActivityMutations', () => { routes: [ { ascentType: "${AscentType.onsight}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}" } diff --git a/test/e2e/activityRoutes.e2e-spec.ts b/test/e2e/activityRoutes.e2e-spec.ts index 182b638..6f10eaa 100644 --- a/test/e2e/activityRoutes.e2e-spec.ts +++ b/test/e2e/activityRoutes.e2e-spec.ts @@ -61,85 +61,85 @@ describe('Activity', () => { routes: [ { ascentType: "${AscentType.onsight}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[0].id}" }, { ascentType: "${AscentType.flash}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[1].id}" }, { ascentType: "${AscentType.redpoint}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[2].id}" }, { ascentType: "${AscentType.repeat}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[2].id}" } { ascentType: "${AscentType.allfree}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[3].id}" }, { ascentType: "${AscentType.aid}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[4].id}" }, { ascentType: "${AscentType.attempt}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[5].id}" }, { ascentType: "${AscentType.t_onsight}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[6].id}" }, { ascentType: "${AscentType.t_flash}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[7].id}" }, { ascentType: "${AscentType.t_redpoint}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[8].id}" }, { ascentType: "${AscentType.t_repeat}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[8].id}" }, { ascentType: "${AscentType.t_allfree}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[9].id}" }, { ascentType: "${AscentType.t_aid}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[10].id}" } { ascentType: "${AscentType.t_attempt}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[11].id}" } diff --git a/test/e2e/routeMigration.e2e-spec.ts b/test/e2e/routeMigration.e2e-spec.ts index 751b943..13463cf 100644 --- a/test/e2e/routeMigration.e2e-spec.ts +++ b/test/e2e/routeMigration.e2e-spec.ts @@ -233,7 +233,7 @@ describe('RouteMigration', () => { routes: [ { ascentType: "${AscentType.onsight}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[0].id}" } @@ -316,7 +316,7 @@ describe('RouteMigration', () => { routes: [ { ascentType: "${AscentType.redpoint}", - publish: "${PublishType.PUBLIC}", + publish: "${PublishType.public}", date: "2017-03-07", routeId: "${mockRoutes[1].id}" } diff --git a/test/e2e/user-delete.e2e-spec.ts b/test/e2e/user-delete.e2e-spec.ts index a06f127..52d56ea 100644 --- a/test/e2e/user-delete.e2e-spec.ts +++ b/test/e2e/user-delete.e2e-spec.ts @@ -57,14 +57,14 @@ describe('UserDelete', () => { { route: mockData.crags.simpleCrag.sectors.simpleSector1.routes[0], ascentType: AscentType.redpoint, - publishType: PublishType.PRIVATE, + publishType: PublishType.private, votedDifficulty: 1100, votedStarRating: 2, }, { route: mockData.crags.simpleCrag.sectors.simpleSector1.routes[1], ascentType: AscentType.onsight, - publishType: PublishType.PUBLIC, + publishType: PublishType.public, }, ], ); @@ -82,7 +82,7 @@ describe('UserDelete', () => { { route: mockData.crags.simpleCrag.sectors.simpleSector1.routes[0], ascentType: AscentType.redpoint, - publishType: PublishType.PRIVATE, + publishType: PublishType.private, votedDifficulty: 1200, votedStarRating: 2, }, @@ -91,7 +91,7 @@ describe('UserDelete', () => { { route: mockData.crags.simpleCrag.sectors.simpleSector1.routes[0], ascentType: AscentType.redpoint, - publishType: PublishType.PRIVATE, + publishType: PublishType.private, votedDifficulty: 1300, votedStarRating: 2, }, @@ -103,7 +103,7 @@ describe('UserDelete', () => { { route: mockData.crags.simpleCrag.sectors.simpleSector1.routes[0], ascentType: AscentType.redpoint, - publishType: PublishType.PRIVATE, + publishType: PublishType.private, votedStarRating: 2, }, ]); @@ -111,7 +111,7 @@ describe('UserDelete', () => { { route: mockData.crags.simpleCrag.sectors.simpleSector1.routes[0], ascentType: AscentType.redpoint, - publishType: PublishType.PRIVATE, + publishType: PublishType.private, votedStarRating: 2, }, ]);