Solved a problem related to not showing corporates if they are not in the correct group
This commit is contained in:
@@ -7,7 +7,8 @@ import {sessionOptions} from "@/lib/session";
|
||||
import {Group} from "@/interfaces/user";
|
||||
import {v4} from "uuid";
|
||||
import {updateExpiryDateOnGroup, getGroupsForUser} from "@/utils/groups.be";
|
||||
import {uniqBy} from "lodash";
|
||||
import {uniq, uniqBy} from "lodash";
|
||||
import {getUser} from "@/utils/users.be";
|
||||
|
||||
const db = getFirestore(app);
|
||||
|
||||
@@ -32,11 +33,12 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (req.session?.user?.type === "mastercorporate") {
|
||||
try {
|
||||
const masterCorporateGroups = await getGroupsForUser(admin, participant);
|
||||
const corporatesFromMaster = masterCorporateGroups.filter((g) => g.name.trim() === "Corporate").flatMap((g) => g.participants);
|
||||
const participants = uniq(masterCorporateGroups.flatMap((g) => g.participants));
|
||||
const corporatesFromMaster = (await Promise.all(participants.map(getUser))).filter((x) => x.type === "corporate");
|
||||
|
||||
if (corporatesFromMaster.length === 0) return res.status(200).json(masterCorporateGroups);
|
||||
|
||||
const groups = await Promise.all(corporatesFromMaster.map((c) => getGroupsForUser(c, participant)));
|
||||
const groups = await Promise.all(corporatesFromMaster.map((c) => getGroupsForUser(c.id, participant)));
|
||||
return res.status(200).json([...masterCorporateGroups, ...uniqBy(groups.flat(), "id")]);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
||||
Reference in New Issue
Block a user