mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-07-16 08:27:05 -05:00
can't vouch or suggest if voting has started
This commit is contained in:
parent
85408d30cd
commit
d38f707d17
26
lib/plus.ts
26
lib/plus.ts
|
|
@ -22,3 +22,29 @@ export const getPercentageFromCounts = (
|
|||
((sameSum / sameVoterCount + otherSum / otherVoterCount + 3) / 6) * 100
|
||||
);
|
||||
};
|
||||
|
||||
export const getVotingRange = () => {
|
||||
const startDate = new Date();
|
||||
|
||||
startDate.setUTCHours(10, 0, 0, 0);
|
||||
|
||||
startDate.setDate(1);
|
||||
|
||||
// Get the first Friday in the month
|
||||
while (startDate.getDay() !== 5) {
|
||||
startDate.setDate(startDate.getDate() + 1);
|
||||
}
|
||||
|
||||
// Get the second Friday
|
||||
startDate.setDate(startDate.getDate() + 7);
|
||||
|
||||
// Get the ending time on Monday
|
||||
const endDate = new Date(startDate);
|
||||
endDate.setDate(endDate.getDate() + 3);
|
||||
|
||||
const isHappening =
|
||||
new Date().getTime() > startDate.getTime() &&
|
||||
new Date().getTime() < endDate.getTime();
|
||||
|
||||
return { startDate, endDate, isHappening };
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Prisma } from "@prisma/client";
|
||||
import { UserError } from "lib/errors";
|
||||
import { getPercentageFromCounts } from "lib/plus";
|
||||
import { getPercentageFromCounts, getVotingRange } from "lib/plus";
|
||||
import { userBasicSelection } from "lib/prisma";
|
||||
import { suggestionFullSchema } from "lib/validators/suggestion";
|
||||
import { vouchSchema } from "lib/validators/vouch";
|
||||
|
|
@ -211,7 +211,9 @@ const addSuggestion = async ({
|
|||
throw new UserError("suggested user already has access");
|
||||
}
|
||||
|
||||
// TODO voting has started
|
||||
if (getVotingRange().isHappening) {
|
||||
throw new UserError("voting has already started");
|
||||
}
|
||||
|
||||
return prisma.$transaction([
|
||||
prisma.plusSuggestion.create({
|
||||
|
|
@ -260,7 +262,9 @@ const addVouch = async ({
|
|||
throw new UserError("vouched user already has access");
|
||||
}
|
||||
|
||||
// TODO voting has started
|
||||
if (getVotingRange().isHappening) {
|
||||
throw new UserError("voting has already started");
|
||||
}
|
||||
|
||||
return prisma.$transaction([
|
||||
prisma.plusStatus.upsert({
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user