Browse Source

Refactoring

pull/5914/head
Thomas Kaul 2 months ago
parent
commit
531bb269db
  1. 4
      apps/api/src/app/user/user.controller.ts
  2. 17
      apps/api/src/app/user/user.service.ts

4
apps/api/src/app/user/user.controller.ts

@ -126,9 +126,7 @@ export class UserController {
); );
} }
const { accessToken, id, role } = await this.userService.createUser({ const { accessToken, id, role } = await this.userService.createUser();
data: {}
});
return { return {
accessToken, accessToken,

17
apps/api/src/app/user/user.service.ts

@ -526,19 +526,20 @@ export class UserService {
}); });
} }
public async createUser({ public async createUser(
data {
}: { data
data: Prisma.UserCreateInput; }: {
}): Promise<User> { data: Prisma.UserCreateInput;
if (!data?.provider) { } = { data: {} }
): Promise<User> {
if (!data.provider) {
data.provider = 'ANONYMOUS'; data.provider = 'ANONYMOUS';
} }
// Check if there's already an admin user
// If not, assign ADMIN role to the first user
if (!data.role) { if (!data.role) {
const hasAdmin = await this.hasAdmin(); const hasAdmin = await this.hasAdmin();
data.role = hasAdmin ? 'USER' : 'ADMIN'; data.role = hasAdmin ? 'USER' : 'ADMIN';
} }

Loading…
Cancel
Save