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