Skip to content

Commit

Permalink
fix(ProjectScore): recalc score after move goal into archive
Browse files Browse the repository at this point in the history
  • Loading branch information
LamaEats committed Jul 25, 2023
1 parent 1abcd38 commit 5132a60
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export const updateGoalWithCalculatedWeight = async (goalId: string) => {
await ctx.$executeRaw`
UPDATE "Project"
SET "averageScore" = (SELECT AVG("completedCriteriaWeight") FROM "Goal"
WHERE "projectId" = ${updatedGoal.projectId})
WHERE "projectId" = ${updatedGoal.projectId} AND "archived" IS NOT true)
WHERE "id" = ${updatedGoal.projectId};
`;
}
Expand Down
6 changes: 5 additions & 1 deletion trpc/router/goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ export const goal = router({
}

try {
const updatedGoal = prisma.goal.update({
const updatedGoal = await prisma.goal.update({
where: { id },
data: {
archived,
Expand All @@ -723,6 +723,10 @@ export const goal = router({
},
});

if (updatedGoal) {
await updateGoalWithCalculatedWeight(updatedGoal.id);
}

const recipients = Array.from(
new Set(
[...actualGoal.participants, ...actualGoal.watchers, actualGoal.activity, actualGoal.owner]
Expand Down

0 comments on commit 5132a60

Please sign in to comment.