diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index a86cae2..56347b9 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -61,7 +61,7 @@ export class AuthService { */ async signUp(signUp: SignUpDto): Promise { const group = signUp.group.replaceAll(" ", ""); - const username = signUp.username.replaceAll(" ", ""); + const username = signUp.username.trim(); if (![UserRole.STUDENT, UserRole.TEACHER].includes(signUp.role)) throw new NotAcceptableException("Передана неизвестная роль"); @@ -100,7 +100,7 @@ export class AuthService { */ async signIn(signIn: SignInDto): Promise { const user = await this.usersService.findUnique({ - username: signIn.username.replaceAll(" ", ""), + username: signIn.username, }); if ( diff --git a/src/users/v1-users.controller.ts b/src/users/v1-users.controller.ts index 3f3fe38..1df748c 100644 --- a/src/users/v1-users.controller.ts +++ b/src/users/v1-users.controller.ts @@ -22,6 +22,7 @@ import { import { ChangeUsernameDto } from "./dto/change-username.dto"; import { ChangeGroupDto } from "./dto/change-group.dto"; import { V1ClientUserDto } from "./dto/v1/v1-client-user.dto"; +import { UserRole } from "./user-role.enum"; @ApiTags("v1/users") @ApiBearerAuth() @@ -67,6 +68,11 @@ export class V1UsersController { ): Promise { const user = await this.authService.decodeUserToken(token); + reqDto.username = + user.role == UserRole.ADMIN + ? reqDto.username + : reqDto.username.replace(/\s/g, ""); + return await this.usersService.changeUsername(user, reqDto); }