Skip to content

Commit

Permalink
fix(user-controller): use consistent returns (closes #1918)
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Jun 9, 2024
1 parent 26859df commit e703a3d
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions apps/api/src/controllers/admin/manage/manage-users-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,30 @@ export class ManageUsersController {
async getUserById(
@PathParams("id") id: string,
@QueryParams("select-citizens") selectCitizens: boolean,
): Promise<APITypes.GetManageUserByIdData> {
@QueryParams("steamId", String) steamId?: string,
@QueryParams("discordId", String) discordId?: string,
): Promise<APITypes.GetManageUserByIdData | APITypes.GetManageUserByIdData[]> {
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),
});

Expand Down

0 comments on commit e703a3d

Please sign in to comment.