ENCOA-109: Keep the same balance after deleting a user
This commit is contained in:
@@ -42,7 +42,7 @@ export async function getUserBalance(user: User) {
|
||||
const groups = await getGroupsForUser(user.id);
|
||||
const participants = uniq(groups.flatMap((x) => x.participants));
|
||||
|
||||
if (user.type === "corporate") return participants.length + codes.length;
|
||||
if (user.type === "corporate") return participants.length + codes.filter((x) => !participants.includes(x.userId || "")).length;
|
||||
|
||||
const participantUsers = await Promise.all(participants.map(getUser));
|
||||
const corporateUsers = participantUsers.filter((x) => x.type === "corporate") as CorporateUser[];
|
||||
@@ -50,6 +50,6 @@ export async function getUserBalance(user: User) {
|
||||
return (
|
||||
corporateUsers.reduce((acc, curr) => acc + curr.corporateInformation?.companyInformation?.userAmount || 0, 0) +
|
||||
corporateUsers.length +
|
||||
codes.length
|
||||
codes.filter((x) => !participants.includes(x.userId || "") && !corporateUsers.map((u) => u.id).includes(x.userId || "")).length
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user