feat: removeUsersAsAdmin mutation added

This commit is contained in:
mirarifhasan
2024-01-29 19:39:56 +06:00
committed by Andrew Bastin
parent da606f5a96
commit 2bde3f8b02
3 changed files with 54 additions and 0 deletions

View File

@@ -454,6 +454,26 @@ export class AdminService {
return E.right(true);
}
/**
* Remove users as admin
* @param userUIDs User UIDs
* @returns an Either of boolean or error
*/
async removeUsersAsAdmin(userUIDs: string[]) {
const adminUsers = await this.userService.fetchAdminUsers();
const adminsNotInArray = adminUsers.filter(
(adminUser) => !userUIDs.includes(adminUser.uid),
);
if (adminsNotInArray.length < 1) {
return E.left(ONLY_ONE_ADMIN_ACCOUNT);
}
const isUpdated = await this.userService.removeUsersAsAdmin(userUIDs);
if (E.isLeft(isUpdated)) return E.left(isUpdated.left);
return E.right(true);
}
/**
* Fetch list of all the Users in org
* @returns number of users in the org