From 40c115a98960a8d4abb02f7f78d4350a5b833d60 Mon Sep 17 00:00:00 2001 From: Zoran Date: Mon, 18 Sep 2023 19:10:43 +0200 Subject: [PATCH] Wrong difficulty for multipitch routes in statistics Fixes #164 --- src/activities/services/activity-routes.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/activities/services/activity-routes.service.ts b/src/activities/services/activity-routes.service.ts index 9cdac0a..76eff7b 100644 --- a/src/activities/services/activity-routes.service.ts +++ b/src/activities/services/activity-routes.service.ts @@ -515,7 +515,7 @@ export class ActivityRoutesService { const builder = this.activityRoutesRepository .createQueryBuilder('ar') .select('EXTRACT(YEAR FROM ar.date)', 'year') - .addSelect('r.difficulty', 'difficulty') + .addSelect('coalesce(p.difficulty, r.difficulty)', 'difficulty') .addSelect('ar.ascent_type', 'ascent_type') .addSelect('count(ar.id)', 'nr_ascents') .addSelect('count(r.id)', 'nr_routes') @@ -532,8 +532,8 @@ export class ActivityRoutesService { "(r.publish_status IN ('published', 'in_review') OR (r.publish_status = 'draft' AND ar.user_id = :userId))", { userId: currentUser.id }, ) - .groupBy("r.difficulty").addGroupBy("EXTRACT(YEAR FROM ar.date)").addGroupBy("ar.ascent_type") - .orderBy('r.difficulty', 'ASC') + .groupBy("p.difficulty").addGroupBy(("r.difficulty")).addGroupBy("EXTRACT(YEAR FROM ar.date)").addGroupBy("ar.ascent_type") + .orderBy('coalesce(p.difficulty, r.difficulty)', 'ASC') .addOrderBy('year', 'ASC'); setBuilderCache(builder, 'getRawAndEntities');