Skip to content

Commit

Permalink
fix: don't update scores with 0 point difference
Browse files Browse the repository at this point in the history
  • Loading branch information
FreekBes committed Jan 28, 2025
1 parent a195100 commit 581ab8a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/handlers/points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,14 @@ export const handleFixedPointScore = async function(prisma: PrismaClient, type:
});

if (existingScores._sum.amount !== null) {
console.log(`Score(s) already exist for type ${type.type} and typeIntraId ${typeIntraId}. Calculating point difference and handing out the difference as a new score...`);
// Score(s) were already given for this type and typeIntraId in the past.
// Calculate the point difference and hand out the difference as a new score.
const pointDifference = points - existingScores._sum.amount;
const pointDifference = Math.floor(points - existingScores._sum.amount);
if (pointDifference === 0) {
console.log(`Score(s) already exist for type ${type.type} and typeIntraId ${typeIntraId}. Point difference is 0, no need to create a new score.`);
return null; // No difference in points, no need to create a new score
}
console.log(`Score(s) already exist for type ${type.type} and typeIntraId ${typeIntraId}. Point difference is ${pointDifference}, handing out the difference as a new score...`);
return await createScore(prisma, type, typeIntraId, userId, pointDifference, reason, scoreDate);
}
}
Expand Down

0 comments on commit 581ab8a

Please sign in to comment.