Continued creating the entity system
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user