From e703a3d8d83c22b9a0e1fd5be993a4d1b8d0d7fc Mon Sep 17 00:00:00 2001 From: casperiv0 <53900565+casperiv0@users.noreply.github.com> Date: Sun, 9 Jun 2024 17:06:19 +0200 Subject: [PATCH] fix(user-controller): use consistent returns (closes #1918) --- .../admin/manage/manage-users-controller.ts | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/apps/api/src/controllers/admin/manage/manage-users-controller.ts b/apps/api/src/controllers/admin/manage/manage-users-controller.ts index ace455883..c7a3d588e 100644 --- a/apps/api/src/controllers/admin/manage/manage-users-controller.ts +++ b/apps/api/src/controllers/admin/manage/manage-users-controller.ts @@ -194,9 +194,30 @@ export class ManageUsersController { async getUserById( @PathParams("id") id: string, @QueryParams("select-citizens") selectCitizens: boolean, - ): Promise { + @QueryParams("steamId", String) steamId?: string, + @QueryParams("discordId", String) discordId?: string, + ): Promise { + if (steamId || discordId) { + const users = await prisma.user.findMany({ + where: { OR: [{ discordId }, { steamId }] }, + select: manageUsersSelect(selectCitizens), + }); + + if (users.length <= 0) { + throw new NotFound("userNotFound"); + } + + return users.map((user) => { + const { User2FA, ...rest } = user; + return { + twoFactorEnabled: User2FA.length >= 1, + ...rest, + }; + }); + } + const user = await prisma.user.findFirst({ - where: { OR: [{ id }, { discordId: id }, { steamId: id }] }, + where: { OR: [{ id }, { discordId }, { steamId }] }, select: manageUsersSelect(selectCitizens), });