From a4960fa4388d08af7c433b26fdcb49586af833b3 Mon Sep 17 00:00:00 2001 From: Daniel Henkel Date: Wed, 29 May 2024 12:58:02 +0200 Subject: [PATCH] remove achievement state hack --- common/achievement/get.ts | 6 +++--- common/achievement/util.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/achievement/get.ts b/common/achievement/get.ts index 6c2f5a05b..eccc84950 100644 --- a/common/achievement/get.ts +++ b/common/achievement/get.ts @@ -159,12 +159,12 @@ const assembleAchievementData = async (userAchievements: achievements_with_templ let currentAchievementIndex = userAchievements.findIndex((ua) => !ua.achievedAt); currentAchievementIndex = currentAchievementIndex >= 0 ? currentAchievementIndex : userAchievements.length - 1; - let achievementTemplates = await prisma.achievement_template.findMany({ + const achievementTemplates = await prisma.achievement_template.findMany({ where: { group: userAchievements[currentAchievementIndex].template.group, isActive: true }, orderBy: { groupOrder: 'asc' }, }); const derivedTemplates = deriveAchievementTemplates(userAchievements[currentAchievementIndex].template.group); - achievementTemplates = [...achievementTemplates, ...derivedTemplates]; + achievementTemplates.push(...derivedTemplates); achievementTemplates.sort((left, right) => left.groupOrder - right.groupOrder); let maxValue: number = achievementTemplates.length; @@ -202,7 +202,7 @@ const assembleAchievementData = async (userAchievements: achievements_with_templ maxValue = Object.keys(conditionDataAggregations).reduce((acc, key) => acc + conditionDataAggregations[key].valueToAchieve, 0); } - const state: AchievementState = getAchievementState(userAchievements, currentAchievementIndex, achievementTemplates); + const state: AchievementState = getAchievementState(userAchievements, currentAchievementIndex); const isNewAchievement = state === AchievementState.COMPLETED && !userAchievements[currentAchievementIndex].isSeen; const achievementContext = transformPrismaJson( diff --git a/common/achievement/util.ts b/common/achievement/util.ts index 830e101aa..3a443f3d5 100644 --- a/common/achievement/util.ts +++ b/common/achievement/util.ts @@ -166,10 +166,10 @@ export function renderAchievementWithContext( return currentAchievementContext as achievement_template; } -export function getAchievementState(userAchievements: user_achievement[], currentAchievementIndex: number, templates: achievement_template[]) { +export function getAchievementState(userAchievements: user_achievement[], currentAchievementIndex: number) { return userAchievements.length === 0 ? AchievementState.INACTIVE - : userAchievements.length === templates.length && userAchievements[currentAchievementIndex].achievedAt + : userAchievements[currentAchievementIndex].achievedAt ? AchievementState.COMPLETED : AchievementState.ACTIVE; }