From 531bb269db6c34fcb741cb309f40ed6d4cd02cd7 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Wed, 5 Nov 2025 20:16:07 +0100 Subject: [PATCH] Refactoring --- apps/api/src/app/user/user.controller.ts | 4 +--- apps/api/src/app/user/user.service.ts | 17 +++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/apps/api/src/app/user/user.controller.ts b/apps/api/src/app/user/user.controller.ts index 00f4586bc..8704662f7 100644 --- a/apps/api/src/app/user/user.controller.ts +++ b/apps/api/src/app/user/user.controller.ts @@ -126,9 +126,7 @@ export class UserController { ); } - const { accessToken, id, role } = await this.userService.createUser({ - data: {} - }); + const { accessToken, id, role } = await this.userService.createUser(); return { accessToken, diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts index 23c3d868f..65ce92cb2 100644 --- a/apps/api/src/app/user/user.service.ts +++ b/apps/api/src/app/user/user.service.ts @@ -526,19 +526,20 @@ export class UserService { }); } - public async createUser({ - data - }: { - data: Prisma.UserCreateInput; - }): Promise { - if (!data?.provider) { + public async createUser( + { + data + }: { + data: Prisma.UserCreateInput; + } = { data: {} } + ): Promise { + if (!data.provider) { data.provider = 'ANONYMOUS'; } - // Check if there's already an admin user - // If not, assign ADMIN role to the first user if (!data.role) { const hasAdmin = await this.hasAdmin(); + data.role = hasAdmin ? 'USER' : 'ADMIN'; }