Resolved another bug related to master corporate groups
This commit is contained in:
@@ -7,6 +7,7 @@ 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";
|
||||
|
||||
const db = getFirestore(app);
|
||||
|
||||
@@ -31,15 +32,13 @@ 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 === "Corporate").flatMap((g) => g.participants);
|
||||
const corporatesFromMaster = masterCorporateGroups.filter((g) => g.name.trim() === "Corporate").flatMap((g) => g.participants);
|
||||
|
||||
if (corporatesFromMaster.length === 0) return res.status(200).json(masterCorporateGroups);
|
||||
|
||||
if (corporatesFromMaster.length === 0) {
|
||||
res.status(200).json(masterCorporateGroups);
|
||||
return;
|
||||
}
|
||||
Promise.all(corporatesFromMaster.map((c) => getGroupsForUser(c, participant)))
|
||||
.then((groups) => {
|
||||
res.status(200).json([...masterCorporateGroups, ...groups.flat()]);
|
||||
res.status(200).json([...masterCorporateGroups, ...uniqBy(groups.flat(), "id")]);
|
||||
return;
|
||||
})
|
||||
.catch((e) => {
|
||||
|
||||
Reference in New Issue
Block a user