ENCOA-88: Create individual accounts
This commit is contained in:
@@ -37,19 +37,23 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (!maker) {
|
||||
return res.status(401).json({ok: false, reason: "You must be logged in to make user!"});
|
||||
}
|
||||
const {email, passport_id, type, groupName, expiryDate} = req.body as {
|
||||
const {email, passport_id, password, type, groupName, groupID, expiryDate} = req.body as {
|
||||
email: string;
|
||||
password?: string;
|
||||
passport_id: string;
|
||||
type: string;
|
||||
groupName: string;
|
||||
groupName?: string;
|
||||
groupID?: string;
|
||||
expiryDate: null | Date;
|
||||
};
|
||||
// cleaning data
|
||||
delete req.body.passport_id;
|
||||
delete req.body.groupName;
|
||||
delete req.body.groupID;
|
||||
delete req.body.expiryDate;
|
||||
delete req.body.password;
|
||||
|
||||
await createUserWithEmailAndPassword(auth, email.toLowerCase(), passport_id)
|
||||
await createUserWithEmailAndPassword(auth, email.toLowerCase(), !!password ? password : passport_id)
|
||||
.then(async (userCredentials) => {
|
||||
const userId = userCredentials.user.uid;
|
||||
|
||||
@@ -66,6 +70,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
registrationDate: new Date(),
|
||||
subscriptionExpirationDate: expiryDate || null,
|
||||
};
|
||||
|
||||
await setDoc(doc(db, "users", userId), user);
|
||||
if (type === "corporate") {
|
||||
const defaultTeachersGroup: Group = {
|
||||
@@ -123,6 +128,11 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!!groupID) {
|
||||
const groupSnapshot = await getDoc(doc(db, "groups", groupID));
|
||||
await setDoc(groupSnapshot.ref, {participants: [...groupSnapshot.data()!.participants, userId]}, {merge: true});
|
||||
}
|
||||
|
||||
console.log(`Returning - ${email}`);
|
||||
return res.status(200).json({ok: true});
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user