ENCOA-109: Keep the same balance after deleting a user
This commit is contained in:
@@ -6,6 +6,7 @@ import {sessionOptions} from "@/lib/session";
|
||||
import {v4} from "uuid";
|
||||
import {CorporateUser, Group} from "@/interfaces/user";
|
||||
import {createUserWithEmailAndPassword, getAuth} from "firebase/auth";
|
||||
import ShortUniqueId from "short-unique-id";
|
||||
|
||||
const DEFAULT_DESIRED_LEVELS = {
|
||||
reading: 9,
|
||||
@@ -73,7 +74,22 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
subscriptionExpirationDate: expiryDate || null,
|
||||
};
|
||||
|
||||
const uid = new ShortUniqueId();
|
||||
const code = uid.randomUUID(6);
|
||||
|
||||
await setDoc(doc(db, "users", userId), user);
|
||||
await setDoc(doc(db, "codes", code), {
|
||||
code,
|
||||
creator: maker.id,
|
||||
expiryDate,
|
||||
type,
|
||||
creationDate: new Date(),
|
||||
userId,
|
||||
email: email.toLowerCase(),
|
||||
name: req.body.name,
|
||||
passport_id,
|
||||
});
|
||||
|
||||
if (type === "corporate") {
|
||||
const defaultTeachersGroup: Group = {
|
||||
admin: userId,
|
||||
@@ -110,6 +126,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
if (!corporateSnapshot.empty) {
|
||||
const corporateUser = corporateSnapshot.docs[0].data() as CorporateUser;
|
||||
await setDoc(doc(db, "codes", code), {creator: corporateUser.id}, {merge: true});
|
||||
|
||||
const q = query(
|
||||
collection(db, "groups"),
|
||||
@@ -124,7 +141,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
const participants: string[] = doc.get("participants");
|
||||
|
||||
if (!participants.includes(userId)) {
|
||||
updateDoc(doc.ref, {
|
||||
await updateDoc(doc.ref, {
|
||||
participants: [...participants, userId],
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user