Added level export to excel

This commit is contained in:
Joao Ramos
2024-09-05 23:30:03 +01:00
parent a61ad2cc7e
commit e433a150a9
4 changed files with 104 additions and 43 deletions

23
src/utils/grading.be.ts Normal file
View File

@@ -0,0 +1,23 @@
import { app } from "@/firebase";
import { getFirestore, doc, getDoc } from "firebase/firestore";
import { CEFR_STEPS } from "@/resources/grading";
import { getUserCorporate } from "@/utils/groups.be";
import { User } from "@/interfaces/user";
import { Grading } from "@/interfaces";
const db = getFirestore(app);
export const getGradingSystem = async (user: User): Promise<Grading> => {
const snapshot = await getDoc(doc(db, "grading", user.id));
if (snapshot.exists()) return snapshot.data() as Grading;
if (user.type !== "teacher" && user.type !== "student")
return { steps: CEFR_STEPS, user: user.id };
const corporate = await getUserCorporate(user.id);
if (!corporate) return { steps: CEFR_STEPS, user: user.id };
const corporateSnapshot = await getDoc(doc(db, "grading", corporate.id));
if (corporateSnapshot.exists()) return corporateSnapshot.data() as Grading;
return { steps: CEFR_STEPS, user: user.id };
};