fix: check for admin users when removing user as admin (HBE-180) (#52)
* fix: check if admin users are there in infra when removing user as an admin * fix: corrected the logic for length check * chore: update error message * chore: add new error message
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
DUPLICATE_EMAIL,
|
DUPLICATE_EMAIL,
|
||||||
EMAIL_FAILED,
|
EMAIL_FAILED,
|
||||||
INVALID_EMAIL,
|
INVALID_EMAIL,
|
||||||
|
ONLY_ONE_ADMIN_ACCOUNT,
|
||||||
TEAM_INVITE_ALREADY_MEMBER,
|
TEAM_INVITE_ALREADY_MEMBER,
|
||||||
USER_ALREADY_INVITED,
|
USER_ALREADY_INVITED,
|
||||||
USER_IS_ADMIN,
|
USER_IS_ADMIN,
|
||||||
@@ -348,6 +349,9 @@ export class AdminService {
|
|||||||
* @returns an Either of boolean or error
|
* @returns an Either of boolean or error
|
||||||
*/
|
*/
|
||||||
async removeUserAsAdmin(userUID: string) {
|
async removeUserAsAdmin(userUID: string) {
|
||||||
|
const adminUsers = await this.userService.fetchAdminUsers();
|
||||||
|
if (adminUsers.length === 1) return E.left(ONLY_ONE_ADMIN_ACCOUNT);
|
||||||
|
|
||||||
const admin = await this.userService.removeUserAsAdmin(userUID);
|
const admin = await this.userService.removeUserAsAdmin(userUID);
|
||||||
if (E.isLeft(admin)) return E.left(admin.left);
|
if (E.isLeft(admin)) return E.left(admin.left);
|
||||||
return E.right(true);
|
return E.right(true);
|
||||||
|
|||||||
@@ -3,6 +3,13 @@ export const INVALID_EMAIL = 'invalid/email' as const;
|
|||||||
export const EMAIL_FAILED = 'email/failed' as const;
|
export const EMAIL_FAILED = 'email/failed' as const;
|
||||||
export const DUPLICATE_EMAIL = 'email/both_emails_cannot_be_same' as const;
|
export const DUPLICATE_EMAIL = 'email/both_emails_cannot_be_same' as const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only one admin account found in infra
|
||||||
|
* (AdminService)
|
||||||
|
*/
|
||||||
|
export const ONLY_ONE_ADMIN_ACCOUNT =
|
||||||
|
'admin/only_one_admin_account_found' as const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Token Authorization failed (Check 'Authorization' Header)
|
* Token Authorization failed (Check 'Authorization' Header)
|
||||||
* (GqlAuthGuard)
|
* (GqlAuthGuard)
|
||||||
|
|||||||
Reference in New Issue
Block a user