mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-07-30 23:56:50 -05:00
plus voting history initial
This commit is contained in:
parent
08303cc8a4
commit
463ebeee39
44
pages/plus/history/[slug].tsx
Normal file
44
pages/plus/history/[slug].tsx
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { GetStaticPaths, GetStaticProps } from "next";
|
||||
import PlusVotingHistoryPage, {
|
||||
PlusVotingHistoryPageProps,
|
||||
} from "scenes/plus/PlusVotingHistoryPage";
|
||||
import plusService from "scenes/plus/plusService";
|
||||
|
||||
export const getStaticPaths: GetStaticPaths = async () => {
|
||||
return {
|
||||
paths: [],
|
||||
fallback: "blocking",
|
||||
};
|
||||
};
|
||||
|
||||
export const getStaticProps: GetStaticProps<PlusVotingHistoryPageProps> = async ({
|
||||
params,
|
||||
}) => {
|
||||
const getSlug = async () => {
|
||||
const slug = Array.isArray(params!.slug) ? params!.slug : [];
|
||||
if (slug.length === 3) {
|
||||
return slug;
|
||||
}
|
||||
|
||||
const mostRecent = await plusService.getMostRecentVotingWithResultsMonth();
|
||||
|
||||
return ["1", mostRecent.year, mostRecent.month];
|
||||
};
|
||||
|
||||
const [tier, year, month] = (await getSlug()).map((param) => Number(param));
|
||||
const summaries = await plusService.getVotingSummariesByMonthAndTier({
|
||||
tier: tier as any,
|
||||
year,
|
||||
month,
|
||||
});
|
||||
|
||||
console.log({ summaries });
|
||||
|
||||
if (!summaries.length) return { notFound: true };
|
||||
|
||||
return {
|
||||
props: { summaries },
|
||||
};
|
||||
};
|
||||
|
||||
export default PlusVotingHistoryPage;
|
||||
14
scenes/plus/PlusVotingHistoryPage.tsx
Normal file
14
scenes/plus/PlusVotingHistoryPage.tsx
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { GetVotingSummariesByMonthAndTierData } from "./plusService";
|
||||
|
||||
export interface PlusVotingHistoryPageProps {
|
||||
summaries: GetVotingSummariesByMonthAndTierData;
|
||||
}
|
||||
|
||||
const PlusVotingHistoryPage: React.FC<PlusVotingHistoryPageProps> = ({
|
||||
summaries,
|
||||
}) => {
|
||||
console.log({ summaries });
|
||||
return <>hello</>;
|
||||
};
|
||||
|
||||
export default PlusVotingHistoryPage;
|
||||
47
scenes/plus/plusService.ts
Normal file
47
scenes/plus/plusService.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
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,
|
||||
};
|
||||
6
utils/prisma.ts
Normal file
6
utils/prisma.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export const userBasicSelection = {
|
||||
username: true,
|
||||
discordAvatar: true,
|
||||
discriminator: true,
|
||||
discordId: true,
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user