ENCOA-166: Increased the probability of this being fixed even more
This commit is contained in:
@@ -30,30 +30,10 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
participant: string;
|
participant: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (req.session?.user?.type === "mastercorporate") {
|
const adminGroups = await getGroupsForUser(admin, participant);
|
||||||
try {
|
const participants = uniq(adminGroups.flatMap((g) => g.participants));
|
||||||
const masterCorporateGroups = await getGroupsForUser(admin, participant);
|
const groups = await Promise.all(participants.map(async (c) => await getGroupsForUser(c, participant)));
|
||||||
const participants = uniq(masterCorporateGroups.flatMap((g) => g.participants));
|
return res.status(200).json([...adminGroups, ...uniqBy(groups.flat(), "id")]);
|
||||||
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.id, participant)));
|
|
||||||
return res.status(200).json([...masterCorporateGroups, ...uniqBy(groups.flat(), "id")]);
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
res.status(500).json({ok: false});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const groups = await getGroupsForUser(admin, participant);
|
|
||||||
res.status(200).json(groups);
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
res.status(500).json({ok: false});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function post(req: NextApiRequest, res: NextApiResponse) {
|
async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
|||||||
Reference in New Issue
Block a user