Exam generation rework, batch user tables, fastapi endpoint switch

This commit is contained in:
Carlos-Mesquita
2024-11-04 23:29:14 +00:00
parent a2bc997e8f
commit 15c9c4d4bd
148 changed files with 11348 additions and 3901 deletions

20
src/utils/popout.ts Normal file
View File

@@ -0,0 +1,20 @@
import { NextRouter } from "next/router";
const openDetachedTab = (uri: string, router: NextRouter, name = 'ExamPreview', width = 1000, height = 600) => {
const left = (window.screen.width - width) / 2;
const top = (window.screen.height - height) / 2;
const features = `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes,status=yes`;
const url = router.basePath + `/${uri}`;
const newWindow = window.open(url, name, features);
if (newWindow) {
newWindow.focus();
} else {
alert('Pop-up blocker may have prevented opening the new window. Please check your browser settings.');
}
return newWindow;
}
export default openDetachedTab;

View File

@@ -0,0 +1,15 @@
import { NextApiRequest } from "next";
export default function queryToURLSearchParams(req: NextApiRequest): URLSearchParams {
const queryEntries = Object.entries(req.query);
const searchParams = new URLSearchParams();
for (const [key, value] of queryEntries) {
if (Array.isArray(value)) {
value.forEach(v => searchParams.append(key, v));
} else if (value !== undefined) {
searchParams.append(key, value as string);
}
}
return searchParams;
}

5
src/utils/type.check.ts Normal file
View File

@@ -0,0 +1,5 @@
import { FillBlanksMCOption } from "@/interfaces/exam";
export const typeCheckWordsMC = (words: any[]): words is FillBlanksMCOption[] => {
return Array.isArray(words) && words.every((word) => word && typeof word === "object" && "id" in word && "options" in word);
};