From 8a0f912c48a2668e455d3b993d8381ba00fa35fe Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Mon, 22 Mar 2021 21:27:30 +0200 Subject: [PATCH] can't vouch if kicked last month --- app/plus/service.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/plus/service.ts b/app/plus/service.ts index e6ff8ae8c..338e3b620 100644 --- a/app/plus/service.ts +++ b/app/plus/service.ts @@ -398,12 +398,35 @@ const addVouch = async ({ input: z.infer; 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"