Solved some race conditions related to the previous commit
This commit is contained in:
@@ -19,16 +19,18 @@ export const getExams = async (
|
||||
): Promise<Exam[]> => {
|
||||
const moduleRef = collection(db, module);
|
||||
|
||||
const q = query(moduleRef, and(where("isDiagnostic", "==", false), where("private", "!=", true)));
|
||||
const q = query(moduleRef, where("isDiagnostic", "==", false));
|
||||
const snapshot = await getDocs(q);
|
||||
|
||||
const allExams = shuffle(
|
||||
snapshot.docs.map((doc) => ({
|
||||
id: doc.id,
|
||||
...doc.data(),
|
||||
module,
|
||||
})),
|
||||
) as Exam[];
|
||||
const allExams = (
|
||||
shuffle(
|
||||
snapshot.docs.map((doc) => ({
|
||||
id: doc.id,
|
||||
...doc.data(),
|
||||
module,
|
||||
})),
|
||||
) as Exam[]
|
||||
).filter((x) => !x.private);
|
||||
|
||||
let exams: Exam[] = await filterByOwners(allExams, userId);
|
||||
exams = filterByVariant(exams, variant);
|
||||
@@ -65,7 +67,7 @@ const filterByVariant = (exams: Exam[], variant?: Variant) => {
|
||||
|
||||
const filterByOwners = async (exams: Exam[], userID?: string) => {
|
||||
if (!userID) return exams.filter((x) => !x.owners || x.owners.length === 0);
|
||||
return Promise.all(
|
||||
return await Promise.all(
|
||||
exams.filter(async (x) => {
|
||||
if (!x.owners) return true;
|
||||
if (x.owners.length === 0) return true;
|
||||
|
||||
Reference in New Issue
Block a user