- Initial response set to null; Frontend now generates a list of anticipated stats; - Background evaluation dynamically updates DB upon completion; - Frontend actively monitors and finalizes upon stat evaluation completion.
24 lines
852 B
TypeScript
24 lines
852 B
TypeScript
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
|
import type {NextApiRequest, NextApiResponse} from "next";
|
|
import {app} from "@/firebase";
|
|
import {getFirestore, collection, getDocs, query, where, setDoc, doc, getDoc, deleteDoc} from "firebase/firestore";
|
|
import {withIronSessionApiRoute} from "iron-session/next";
|
|
import {sessionOptions} from "@/lib/session";
|
|
import {uuidv4} from "@firebase/util";
|
|
|
|
const db = getFirestore(app);
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
if (req.method === "GET") return GET(req, res);
|
|
|
|
res.status(404).json({ok: false});
|
|
}
|
|
|
|
async function GET(req: NextApiRequest, res: NextApiResponse) {
|
|
const {id} = req.query;
|
|
|
|
const snapshot = await getDoc(doc(db, "stats", id as string));
|
|
|
|
res.status(200).json({...snapshot.data(), id: snapshot.id});
|
|
}
|