Пред-деплой

This commit is contained in:
2024-09-12 21:40:57 +04:00
parent 8fb9214246
commit 6d77476a57
12 changed files with 152 additions and 53 deletions

View File

@@ -23,11 +23,13 @@ import {
SignInResDto,
SignUpReqDto,
SignUpResDto,
UpdateTokenDto,
UpdateTokenResultDto,
ChangePasswordReqDto,
UpdateTokenReqDto,
UpdateTokenResDto,
} from "../dto/auth.dto";
import { ResultDto } from "../utility/validation/class-validator.interceptor";
import { ScheduleService } from "../schedule/schedule.service";
import { UserToken } from "./auth.decorator";
@Controller("api/v1/auth")
export class AuthController {
@@ -82,26 +84,52 @@ export class AuthController {
return this.authService.signUp(signUpDto);
}
@ApiExtraModels(UpdateTokenDto)
@ApiExtraModels(UpdateTokenResultDto)
@ApiExtraModels(UpdateTokenReqDto)
@ApiExtraModels(UpdateTokenResDto)
@ApiOperation({
summary: "Обновление просроченного токена",
tags: ["auth"],
tags: ["auth", "accessToken"],
})
@ApiBody({ schema: refs(UpdateTokenDto)[0] })
@ApiBody({ schema: refs(UpdateTokenReqDto)[0] })
@ApiOkResponse({
description: "Токен обновлён успешно",
schema: refs(UpdateTokenResultDto)[0],
schema: refs(UpdateTokenResDto)[0],
})
@ApiNotFoundResponse({
description: "Передан несуществующий или недействительный токен",
})
@ResultDto(UpdateTokenResultDto)
@ResultDto(UpdateTokenResDto)
@HttpCode(HttpStatus.OK)
@Post("updateToken")
updateToken(
@Body() updateTokenDto: UpdateTokenDto,
): Promise<UpdateTokenResultDto> {
@Body() updateTokenDto: UpdateTokenReqDto,
): Promise<UpdateTokenResDto> {
return this.authService.updateToken(updateTokenDto);
}
@ApiExtraModels(ChangePasswordReqDto)
@ApiOperation({
summary: "Обновление пароля",
tags: ["auth", "password"],
})
@ApiBody({ schema: refs(ChangePasswordReqDto)[0] })
@ApiOkResponse({ description: "Пароль обновлён успешно" })
@ApiConflictResponse({ description: "Пароли идентичны" })
@ApiUnauthorizedResponse({
description:
"Передан неверный текущий пароль или запрос был послан без токена",
})
@ResultDto(null)
@HttpCode(HttpStatus.OK)
@Post("changePassword")
async changePassword(
@Body() changePasswordReqDto: ChangePasswordReqDto,
@UserToken() userToken: string,
): Promise<void> {
await this.authService
.decodeUserToken(userToken)
.then((user) =>
this.authService.changePassword(user, changePasswordReqDto),
);
}
}