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, };