From f92e27dd346441a5ffe58f0a864d58368ccfc360 Mon Sep 17 00:00:00 2001 From: N08I40K Date: Fri, 20 Dec 2024 22:41:47 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D1=80=D0=B5=D0=B3?= =?UTF-8?q?=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=B0=D0=B4=D0=B5=D0=BA=D0=B2=D0=B0=D1=82=D0=BD=D0=BE?= =?UTF-8?q?=D0=B9=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B5=D0=BF=D0=BE=D0=B4=D0=B0=D0=B2=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D0=B5=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/auth/auth.service.ts | 4 ++-- src/users/v1-users.controller.ts | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) 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); }