Implement getAllEvents

This commit is contained in:
Aditya Thakral 2021-09-20 14:45:59 -04:00
parent 5ca822a3e4
commit 6cdab0fd28
1 changed files with 41 additions and 0 deletions

View File

@ -111,6 +111,47 @@ export async function getUpcomingEvents(): Promise<Event[]> {
});
}
export async function getAllEvents() {
/* Promise.all implementation
const slugs = (
await Promise.all(
(
await getEventYears()
).map(
async (year) =>
await Promise.all(
(
await getEventTermsByYear(year)
).map(async (term) => {
return (await getEventsByTerm(year, term)).map((slug) => ({
slug,
term,
year,
}));
})
)
)
)
).flat(2);
return await Promise.all(
slugs.map(({ year, term, slug }) => getEventBySlug(year, term, slug))
);
*/
const events: Event[] = [];
for (const year of await getEventYears()) {
for (const term of await getEventTermsByYear(year)) {
for (const slug of await getEventsByTerm(year, term)) {
events.push(await getEventBySlug(year, term, slug));
}
}
}
return events;
}
export async function getEventsPageProps({
year,
term,