Improved some of the querying for the assignments
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import {app} from "@/firebase";
|
||||
import {Assignment} from "@/interfaces/results";
|
||||
import {CorporateUser, Group, MasterCorporateUser, StudentUser, TeacherUser, User} from "@/interfaces/user";
|
||||
import client from "@/lib/mongodb";
|
||||
import moment from "moment";
|
||||
import {getUser} from "./users.be";
|
||||
import {getLinkedUsers, getUser} from "./users.be";
|
||||
import {getSpecificUsers} from "./users.be";
|
||||
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
@@ -71,17 +72,10 @@ export const getUsersGroups = async (ids: string[]) => {
|
||||
};
|
||||
|
||||
export const getAllAssignersByCorporate = async (corporateID: string): Promise<string[]> => {
|
||||
const groups = await getUserGroups(corporateID);
|
||||
const groupUsers = (await Promise.all(groups.map(async (g) => await Promise.all(g.participants.map(getUser)))))
|
||||
.flat()
|
||||
.filter((x) => !!x) as User[];
|
||||
const teacherPromises = await Promise.all(
|
||||
groupUsers.map(async (u) =>
|
||||
u.type === "teacher" ? u.id : u.type === "corporate" ? [...(await getAllAssignersByCorporate(u.id)), u.id] : undefined,
|
||||
),
|
||||
);
|
||||
const linkedTeachers = await getLinkedUsers(corporateID, "mastercorporate", "teacher");
|
||||
const linkedCorporates = await getLinkedUsers(corporateID, "mastercorporate", "corporate");
|
||||
|
||||
return teacherPromises.filter((x) => !!x).flat() as string[];
|
||||
return [...linkedTeachers.users.map((x) => x.id), ...linkedCorporates.users.map((x) => x.id)];
|
||||
};
|
||||
|
||||
export const getGroupsForUser = async (admin?: string, participant?: string) => {
|
||||
|
||||
Reference in New Issue
Block a user