Continued creating the entity system

This commit is contained in:
Tiago Ribeiro
2024-10-01 17:39:43 +01:00
parent bae02e5192
commit 564e6438cb
37 changed files with 2522 additions and 130 deletions

View File

@@ -1,5 +1,5 @@
import {collection, getDocs, query, where, setDoc, doc, Firestore, getDoc, and} from "firebase/firestore";
import {shuffle} from "lodash";
import {groupBy, shuffle} from "lodash";
import {Difficulty, Exam, InstructorGender, SpeakingExam, Variant, WritingExam} from "@/interfaces/exam";
import {DeveloperUser, Stat, StudentUser, User} from "@/interfaces/user";
import {Module} from "@/interfaces";
@@ -29,6 +29,23 @@ export async function getSpecificExams(ids: string[]) {
return exams;
}
export const getExamsByIds = async (ids: {module: Module; id: string}[]) => {
const groupedByModule = groupBy(ids, "module");
const exams: Exam[] = (
await Promise.all(
Object.keys(groupedByModule).map(
async (m) =>
await db
.collection(m)
.find<Exam>({id: {$in: groupedByModule[m]}})
.toArray(),
),
)
).flat();
return exams;
};
export const getExams = async (
db: Db,
module: Module,