can't vouch if kicked last month

This commit is contained in:
Kalle (Sendou)
2021-03-22 21:27:30 +02:00
parent 7721ffa5ce
commit 8a0f912c48

View File

@@ -398,12 +398,35 @@ const addVouch = async ({
input: z.infer<typeof vouchSchema>;
userId: number;
}) => {
const plusStatuses = await prisma.plusStatus.findMany({});
const [plusStatuses, summaries] = await Promise.all([
prisma.plusStatus.findMany({}),
prisma.plusVotingSummary.findMany({
where: { wasSuggested: false },
orderBy: [{ year: "desc" }, { month: "desc" }],
take: 500,
}),
]);
const suggesterPlusStatus = plusStatuses.find(
(status) => status.userId === userId
);
for (const summary of summaries) {
if (
summary.year !== summaries[0].year ||
summary.month !== summaries[0].month
) {
break;
}
if (summary.userId === input.vouchedId && summary.tier === input.tier) {
// can't vouch if they were just kicked
throw httpError.badRequest(
"can't vouch the user because they were kicked last month"
);
}
}
if ((suggesterPlusStatus?.canVouchFor ?? Infinity) > input.tier) {
throw httpError.badRequest(
"not a member of high enough tier to vouch for this tier"