Removed a part of the make_user

This commit is contained in:
Tiago Ribeiro
2024-09-05 11:35:53 +01:00
parent 3d3c4448ae
commit 6ce81b300a

View File

@@ -42,19 +42,17 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
const corporateCorporate = await getUserCorporate(maker.id); const corporateCorporate = await getUserCorporate(maker.id);
const {email, passport_id, password, type, groupName, groupID, expiryDate, corporate} = req.body as { const {email, passport_id, password, type, groupID, expiryDate, corporate} = req.body as {
email: string; email: string;
password?: string; password?: string;
passport_id: string; passport_id: string;
type: string; type: string;
groupName?: string;
groupID?: string; groupID?: string;
corporate?: string; corporate?: string;
expiryDate: null | Date; expiryDate: null | Date;
}; };
// cleaning data // cleaning data
delete req.body.passport_id; delete req.body.passport_id;
delete req.body.groupName;
delete req.body.groupID; delete req.body.groupID;
delete req.body.expiryDate; delete req.body.expiryDate;
delete req.body.password; delete req.body.password;
@@ -202,32 +200,6 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
} }
} }
if (typeof groupName === "string" && groupName.trim().length > 0) {
const q = query(collection(db, "groups"), where("admin", "==", maker.id), where("name", "==", groupName.trim()), limit(1));
const snapshot = await getDocs(q);
if (snapshot.empty) {
const values = {
id: v4(),
admin: maker.id,
name: groupName.trim(),
participants: [userId],
disableEditing: false,
};
await setDoc(doc(db, "groups", values.id), values);
} else {
const doc = snapshot.docs[0];
const participants: string[] = doc.get("participants");
if (!participants.includes(userId)) {
updateDoc(doc.ref, {
participants: [...participants, userId],
});
}
}
}
if (!!groupID) { if (!!groupID) {
const groupSnapshot = await getDoc(doc(db, "groups", groupID)); const groupSnapshot = await getDoc(doc(db, "groups", groupID));
await setDoc(groupSnapshot.ref, {participants: [...groupSnapshot.data()!.participants, userId]}, {merge: true}); await setDoc(groupSnapshot.ref, {participants: [...groupSnapshot.data()!.participants, userId]}, {merge: true});