Updated the Grading System
This commit is contained in:
@@ -46,11 +46,7 @@ async function patch(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.collection("discounts").updateOne(
|
await db.collection("discounts").updateOne({id: id}, {$set: {id: id, ...req.body}}, {upsert: true});
|
||||||
{ id: id },
|
|
||||||
{ $set: { id: id, ...req.body},
|
|
||||||
{ upsert: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
res.status(200).json({ok: true});
|
res.status(200).json({ok: true});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -4,20 +4,21 @@ import { CEFR_STEPS } from "@/resources/grading";
|
|||||||
import {getUserCorporate} from "@/utils/groups.be";
|
import {getUserCorporate} from "@/utils/groups.be";
|
||||||
import {User} from "@/interfaces/user";
|
import {User} from "@/interfaces/user";
|
||||||
import {Grading} from "@/interfaces";
|
import {Grading} from "@/interfaces";
|
||||||
const db = getFirestore(app);
|
import client from "@/lib/mongodb";
|
||||||
|
|
||||||
|
const db = client.db(process.env.MONGODB_DB);
|
||||||
|
|
||||||
export const getGradingSystem = async (user: User): Promise<Grading> => {
|
export const getGradingSystem = async (user: User): Promise<Grading> => {
|
||||||
const snapshot = await getDoc(doc(db, "grading", user.id));
|
const grading = await db.collection("grading").findOne<Grading>({id: user.id});
|
||||||
if (snapshot.exists()) return snapshot.data() as Grading;
|
if (!!grading) return grading;
|
||||||
|
|
||||||
if (user.type !== "teacher" && user.type !== "student")
|
if (user.type !== "teacher" && user.type !== "student") return {steps: CEFR_STEPS, user: user.id};
|
||||||
return { steps: CEFR_STEPS, user: user.id };
|
|
||||||
|
|
||||||
const corporate = await getUserCorporate(user.id);
|
const corporate = await getUserCorporate(user.id);
|
||||||
if (!corporate) return {steps: CEFR_STEPS, user: user.id};
|
if (!corporate) return {steps: CEFR_STEPS, user: user.id};
|
||||||
|
|
||||||
const corporateSnapshot = await getDoc(doc(db, "grading", corporate.id));
|
const corporateSnapshot = await db.collection("grading").findOne<Grading>({id: corporate.id});
|
||||||
if (corporateSnapshot.exists()) return corporateSnapshot.data() as Grading;
|
if (!!corporateSnapshot) return corporateSnapshot;
|
||||||
|
|
||||||
return {steps: CEFR_STEPS, user: user.id};
|
return {steps: CEFR_STEPS, user: user.id};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user