Solved a problem with the _id
This commit is contained in:
@@ -18,18 +18,18 @@ export const getExams = async (
|
||||
variant?: Variant,
|
||||
instructorGender?: InstructorGender,
|
||||
): Promise<Exam[]> => {
|
||||
const allExams = await db
|
||||
.collection(module)
|
||||
.find<Exam>({
|
||||
isDiagnostic: false,
|
||||
})
|
||||
.toArray();
|
||||
|
||||
const allExams = await db.collection(module).find<Exam>({
|
||||
isDiagnostic: false
|
||||
}).toArray();
|
||||
|
||||
const shuffledPublicExams = (
|
||||
shuffle(
|
||||
const shuffledPublicExams = shuffle(
|
||||
allExams.map((doc) => ({
|
||||
...doc,
|
||||
module,
|
||||
})) as Exam[],
|
||||
)
|
||||
).filter((x) => !x.private);
|
||||
|
||||
let exams: Exam[] = await filterByOwners(shuffledPublicExams, userId);
|
||||
@@ -39,9 +39,12 @@ export const getExams = async (
|
||||
exams = await filterByPreference(db, exams, module, userId);
|
||||
|
||||
if (avoidRepeated === "true") {
|
||||
const stats = await db.collection("stats").find<Stat>({
|
||||
user: userId
|
||||
}).toArray();
|
||||
const stats = await db
|
||||
.collection("stats")
|
||||
.find<Stat>({
|
||||
user: userId,
|
||||
})
|
||||
.toArray();
|
||||
|
||||
const filteredExams = exams.filter((x) => !stats.map((s) => s.exam).includes(x.id));
|
||||
|
||||
@@ -78,7 +81,7 @@ const filterByOwners = async (exams: Exam[], userID?: string) => {
|
||||
|
||||
const filterByDifficulty = async (db: Db, exams: Exam[], module: Module, userID?: string) => {
|
||||
if (!userID) return exams;
|
||||
const user = await db.collection("users").findOne<User>({ _id: new ObjectId(userID) });
|
||||
const user = await db.collection("users").findOne<User>({id: userID});
|
||||
if (!user) return exams;
|
||||
|
||||
const difficulty = user.levels[module] <= 3 ? "easy" : user.levels[module] <= 6 ? "medium" : "hard";
|
||||
@@ -92,7 +95,7 @@ const filterByPreference = async (db: Db, exams: Exam[], module: Module, userID?
|
||||
|
||||
if (!userID) return exams;
|
||||
|
||||
const user = await db.collection("users").findOne<StudentUser | DeveloperUser>({ _id: new ObjectId(userID) });
|
||||
const user = await db.collection("users").findOne<StudentUser | DeveloperUser>({id: userID});
|
||||
if (!user) return exams;
|
||||
|
||||
if (!["developer", "student"].includes(user.type)) return exams;
|
||||
|
||||
Reference in New Issue
Block a user