mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-12 13:49:22 -05:00
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import { Prisma } from "@prisma/client";
|
|
import prisma from "prisma/client";
|
|
import { userBasicSelection } from "utils/prisma";
|
|
|
|
export type GetVotingSummariesByMonthAndTierData = Prisma.PromiseReturnType<
|
|
typeof getVotingSummariesByMonthAndTier
|
|
>;
|
|
|
|
const getVotingSummariesByMonthAndTier = ({
|
|
tier,
|
|
year,
|
|
month,
|
|
}: {
|
|
tier: 1 | 2;
|
|
year: number;
|
|
month: number;
|
|
}) => {
|
|
return prisma.plusVotingSummary.findMany({
|
|
where: { tier, year, month },
|
|
select: {
|
|
countsEU: true,
|
|
wasSuggested: true,
|
|
wasVouched: true,
|
|
countsNA: true,
|
|
user: {
|
|
select: userBasicSelection,
|
|
},
|
|
},
|
|
});
|
|
};
|
|
|
|
const getMostRecentVotingWithResultsMonth = async () => {
|
|
const mostRecent = await prisma.plusVotingSummary.findFirst({
|
|
orderBy: [{ year: "desc" }, { month: "desc" }],
|
|
});
|
|
if (!mostRecent)
|
|
throw Error(
|
|
"unexpected null mostRecent in getMostRecentVotingWithResultsMonth"
|
|
);
|
|
|
|
return { year: mostRecent.year, month: mostRecent.month };
|
|
};
|
|
|
|
export default {
|
|
getVotingSummariesByMonthAndTier,
|
|
getMostRecentVotingWithResultsMonth,
|
|
};
|