voting ending fixed

This commit is contained in:
Kalle (Sendou) 2021-03-22 19:19:51 +02:00
parent 9598723795
commit d55aa397f8
2 changed files with 11 additions and 11 deletions

View File

@ -11,7 +11,7 @@ import { vouchSchema } from "utils/validators/vouch";
import * as z from "zod";
// null, +1, +2, +3
const VOUCH_CRITERIA = [-1, 90, 80, 80] as const;
const VOUCH_CRITERIA = [-1, 90, 85, 80] as const;
export type PlusStatuses = Prisma.PromiseReturnType<typeof getPlusStatuses>;
@ -138,11 +138,7 @@ const getVotingSummariesByMonthAndTier = async ({
),
};
})
.sort((a, b) => b.percentage - a.percentage)
.map((summary) => ({
...summary,
percentage: parseFloat(summary.percentage.toFixed(1)),
}));
.sort((a, b) => b.percentage - a.percentage);
};
const getMostRecentVotingWithResultsMonth = async () => {
@ -699,8 +695,9 @@ const endVoting = async (userId: number) => {
await Promise.all([
prisma.plusBallot.deleteMany({ where: { isStale: true } }),
prisma.plusStatus.updateMany({ data: { canVouchFor: null } }),
prisma.plusStatus.updateMany({ data: { vouchTier: null } }),
prisma.plusStatus.updateMany({
data: { canVouchFor: null },
}),
]);
const now = new Date();
@ -749,7 +746,7 @@ const endVoting = async (userId: number) => {
data: { canVouchFor: 3 },
}),
prisma.plusStatus.updateMany({
where: { userId: { in: canVouch[3] } },
where: { userId: { in: vouchRevoked } },
data: {
canVouchAgainAfter: new Date(now.getFullYear(), now.getMonth() + 5, 1),
},

View File

@ -18,8 +18,11 @@ export const getPercentageFromCounts = (
const otherSum = otherRegionArr[1] * -1 + otherRegionArr[2] * 1;
const otherVoterCount = otherRegionArr.reduce((acc, cur) => acc + cur, 0);
return (
((sameSum / sameVoterCount + otherSum / otherVoterCount + 3) / 6) * 100
return parseFloat(
(
((sameSum / sameVoterCount + otherSum / otherVoterCount + 3) / 6) *
100
).toFixed(1)
);
};