From d07f48c826501340683b0aeda1ca45b69214cf48 Mon Sep 17 00:00:00 2001 From: Maksim Sviridov Date: Wed, 15 Nov 2023 14:18:39 +0300 Subject: [PATCH] feat(GoalCriteria): change relation type between goal and criteria data tables --- trpc/router/goal.ts | 48 ++++++++------------------------------------- 1 file changed, 8 insertions(+), 40 deletions(-) diff --git a/trpc/router/goal.ts b/trpc/router/goal.ts index 5822c8908..621f1409d 100644 --- a/trpc/router/goal.ts +++ b/trpc/router/goal.ts @@ -1214,26 +1214,10 @@ export const goal = router({ }), ]); - const actualGoal = await prisma.goal.findUnique({ - where: { id: input.goalId }, - include: { - state: true, - goalAchiveCriteria: { - include: { - criteriaGoal: { - include: { state: true }, - }, - }, - }, - }, - }); - - if (actualGoal) { - await recalculateCriteriaScore(actualGoal.id) - .recalcCurrentGoalScore() - .recalcAverageProjectScore() - .run(); - } + await recalculateCriteriaScore(input.goalId) + .recalcCurrentGoalScore() + .recalcAverageProjectScore() + .run(); } } catch (error: any) { throw new TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: String(error.message), cause: error }); @@ -1266,26 +1250,10 @@ export const goal = router({ }, }); - const actualGoal = await prisma.goal.findUnique({ - where: { id: actualCriteria.goalId }, - include: { - state: true, - goalAchiveCriteria: { - include: { - criteriaGoal: { - include: { state: true }, - }, - }, - }, - }, - }); - - if (actualGoal) { - await recalculateCriteriaScore(actualGoal.id) - .recalcCurrentGoalScore() - .recalcAverageProjectScore() - .run(); - } + await recalculateCriteriaScore(actualCriteria.goalId) + .recalcCurrentGoalScore() + .recalcAverageProjectScore() + .run(); } catch (error: any) { throw new TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: String(error.message), cause: error }); }