import {GetServerSideProps} from "next"; import {getGroup, setGroups} from "./database/groups"; import {Dict, Group} from "./types"; export interface PropsGroupProvider { id: string groups: Dict ignored: string[] base: string[] } export const getServerSidePropsGroupProvider: GetServerSideProps = async ({query}) => { const id = Array.isArray(query?.id) ? query.id[0] : query?.id const data = id && await getGroup(id) if (data) { return { props: { id: data._id.toString(), groups: data.groups, ignored: data.ignored, base: data.base } } } else if (!id) { const newId = await setGroups({groups: {}, base: [], ignored: []}) return { redirect: { destination: `?id=${newId}`, permanent: false, } } } else { console.log(data) return { notFound: true } } }