Added more lists related to the expired accounts
This commit is contained in:
41
src/pages/api/exam/[module]/generate.tsx
Normal file
41
src/pages/api/exam/[module]/generate.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
// 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} from "firebase/firestore";
|
||||
import {withIronSessionApiRoute} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {shuffle} from "lodash";
|
||||
import {Exam} from "@/interfaces/exam";
|
||||
import {Stat} from "@/interfaces/user";
|
||||
import {Module} from "@/interfaces";
|
||||
import axios from "axios";
|
||||
|
||||
const db = getFirestore(app);
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (!req.session.user) {
|
||||
res.status(401).json({ok: false});
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.session.user.type !== "developer") {
|
||||
res.status(403).json({ok: false});
|
||||
return;
|
||||
}
|
||||
|
||||
const {module} = req.query as {module: Module};
|
||||
|
||||
switch (module) {
|
||||
case "reading":
|
||||
const result = await axios.get(
|
||||
`${process.env.BACKEND_URL}/reading_passage_1?topic=football manager video game&exercises=multipleChoice&exercises=trueFalse&exercises=fillBlanks&exercises=writeBlanks`,
|
||||
{headers: {Authorization: `Bearer ${process.env.BACKEND_JWT}`}},
|
||||
);
|
||||
res.status(200).json(result.data);
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(200).json({ok: true});
|
||||
}
|
||||
Reference in New Issue
Block a user