From 2509545dea9c72cec1b4e309ebf7d06d75547ed8 Mon Sep 17 00:00:00 2001 From: mirarifhasan Date: Mon, 12 Feb 2024 21:36:34 +0600 Subject: [PATCH] chore: feedback updated --- packages/hoppscotch-backend/src/admin/admin.service.ts | 6 +++--- packages/hoppscotch-backend/src/errors.ts | 3 ++- packages/hoppscotch-backend/src/user/user.service.ts | 9 +++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/hoppscotch-backend/src/admin/admin.service.ts b/packages/hoppscotch-backend/src/admin/admin.service.ts index d93cc3bdb..1ab0990f4 100644 --- a/packages/hoppscotch-backend/src/admin/admin.service.ts +++ b/packages/hoppscotch-backend/src/admin/admin.service.ts @@ -15,7 +15,7 @@ import { TEAM_INVITE_NO_INVITE_FOUND, USERS_NOT_FOUND, USER_ALREADY_INVITED, - USER_INVITATION_NOT_FOUND, + USER_INVITATION_DELETION_FAILED, USER_IS_ADMIN, USER_NOT_FOUND, } from '../errors'; @@ -164,7 +164,7 @@ export class AdminService { }); return E.right(true); } catch (error) { - return E.left(USER_INVITATION_NOT_FOUND); + return E.left(USER_INVITATION_DELETION_FAILED); } } @@ -543,7 +543,7 @@ export class AdminService { const isUpdated = await this.userService.removeUsersAsAdmin(userUIDs); if (E.isLeft(isUpdated)) return E.left(isUpdated.left); - return E.right(true); + return E.right(isUpdated.right); } /** diff --git a/packages/hoppscotch-backend/src/errors.ts b/packages/hoppscotch-backend/src/errors.ts index 28a99b07c..a8db17fef 100644 --- a/packages/hoppscotch-backend/src/errors.ts +++ b/packages/hoppscotch-backend/src/errors.ts @@ -111,7 +111,8 @@ export const USER_IS_ADMIN = 'user/is_admin' as const; * User invite deletion failure error due to invitation not found * (AdminService) */ -export const USER_INVITATION_NOT_FOUND = 'user/invitation_not_found' as const; +export const USER_INVITATION_DELETION_FAILED = + 'user/invitation_deletion_failed' as const; /** * Teams not found diff --git a/packages/hoppscotch-backend/src/user/user.service.ts b/packages/hoppscotch-backend/src/user/user.service.ts index 6d77f32b8..871e19e82 100644 --- a/packages/hoppscotch-backend/src/user/user.service.ts +++ b/packages/hoppscotch-backend/src/user/user.service.ts @@ -8,7 +8,7 @@ import * as T from 'fp-ts/Task'; import * as A from 'fp-ts/Array'; import { pipe, constVoid } from 'fp-ts/function'; import { AuthUser } from 'src/types/AuthUser'; -import { USER_NOT_FOUND } from 'src/errors'; +import { USERS_NOT_FOUND, USER_NOT_FOUND } from 'src/errors'; import { SessionType, User } from './user.model'; import { USER_UPDATE_FAILED } from 'src/errors'; import { PubSubService } from 'src/pubsub/pubsub.service'; @@ -545,10 +545,15 @@ export class UserService { * @returns a Either of true or error */ async removeUsersAsAdmin(userUIDs: string[]) { - await this.prisma.user.updateMany({ + const data = await this.prisma.user.updateMany({ where: { uid: { in: userUIDs } }, data: { isAdmin: false }, }); + + if (data.count === 0) { + return E.left(USERS_NOT_FOUND); + } + return E.right(true); } }