Updated the groups and users

This commit is contained in:
Tiago Ribeiro
2024-09-07 15:13:13 +01:00
parent c0b814081e
commit e33fa00fa3
4 changed files with 72 additions and 137 deletions

View File

@@ -15,7 +15,7 @@ import {Grading} from "@/interfaces";
import {getGroupsForUser} from "@/utils/groups.be";
import {uniq} from "lodash";
import {getUser} from "@/utils/users.be";
import { getGradingSystem } from "@/utils/grading.be";
import {getGradingSystem} from "@/utils/grading.be";
const db = getFirestore(app);
@@ -56,7 +56,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
const participants = uniq(groups.flatMap((x) => x.participants));
const participantUsers = await Promise.all(participants.map(getUser));
const corporateUsers = participantUsers.filter((x) => x.type === "corporate") as CorporateUser[];
const corporateUsers = participantUsers.filter((x) => x?.type === "corporate") as CorporateUser[];
await Promise.all(corporateUsers.map(async (g) => await setDoc(doc(db, "grading", g.id), body)));
}

View File

@@ -9,7 +9,7 @@ import {createUserWithEmailAndPassword, getAuth} from "firebase/auth";
import ShortUniqueId from "short-unique-id";
import {getUserCorporate, getUserGroups} from "@/utils/groups.be";
import {uniq} from "lodash";
import {getUser} from "@/utils/users.be";
import {getSpecificUsers, getUser} from "@/utils/users.be";
const DEFAULT_DESIRED_LEVELS = {
reading: 9,
@@ -32,9 +32,10 @@ export default withIronSessionApiRoute(handler, sessionOptions);
const getUsersOfType = async (admin: string, type: Type) => {
const groups = await getUserGroups(admin);
const users = await Promise.all(uniq(groups.flatMap((x) => x.participants)).map(getUser));
const participants = groups.flatMap((x) => x.participants);
const users = await getSpecificUsers(participants);
return users.filter((x) => x.type === type).map((x) => x.id);
return users.filter((x) => x?.type === type).map((x) => x?.id);
};
async function handler(req: NextApiRequest, res: NextApiResponse) {