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

@@ -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) {