ENCOA-126: Corporate should not be allowed to edit is own name

This commit is contained in:
Tiago Ribeiro
2024-08-29 13:18:11 +01:00
parent cd1caf0f53
commit 2b71f2467c
6 changed files with 203 additions and 245 deletions

View File

@@ -1,5 +1,5 @@
import {app} from "@/firebase";
import {CorporateUser, Group, StudentUser, TeacherUser} from "@/interfaces/user";
import {CorporateUser, Group, MasterCorporateUser, StudentUser, TeacherUser} from "@/interfaces/user";
import {collection, doc, getDoc, getDocs, getFirestore, query, setDoc, where} from "firebase/firestore";
import moment from "moment";
import {getUser} from "./users.be";
@@ -35,14 +35,14 @@ export const updateExpiryDateOnGroup = async (participantID: string, corporateID
export const getUserCorporate = async (id: string) => {
const user = await getUser(id);
if (user.type === "corporate" || user.type === "mastercorporate") return user;
if (user.type === "mastercorporate") return user;
const groups = await getParticipantGroups(id);
const admins = await Promise.all(groups.map((x) => x.admin).map(getUser));
const corporates = admins.filter((x) => x.type === "corporate");
const corporates = admins.filter((x) => x.type === "corporate" || x.type === "mastercorporate");
if (corporates.length === 0) return undefined;
return corporates.shift() as CorporateUser;
return corporates.shift() as CorporateUser | MasterCorporateUser;
};
export const getGroups = async () => {