Пришлось изменить версию SignInResDtoV1 на SignInResDtoV2 из-за непродуманного кода приложения.

This commit is contained in:
2024-10-13 18:02:52 +04:00
parent c594039ca2
commit ad730e0943
2 changed files with 10 additions and 9 deletions

View File

@@ -27,7 +27,7 @@ import {
UpdateTokenReqDto,
UpdateTokenResDto,
SignInResDtoV0,
SignInResDtoV1,
SignInResDtoV2,
} from "../dto/auth.dto";
import { ResultDto } from "../utility/validation/class-validator.interceptor";
import { ScheduleService } from "../schedule/schedule.service";
@@ -43,7 +43,7 @@ export class AuthController {
@ApiExtraModels(SignInReqDto)
@ApiExtraModels(SignInResDtoV0)
@ApiExtraModels(SignInResDtoV1)
@ApiExtraModels(SignInResDtoV2)
@ApiOperation({ summary: "Авторизация по логину и паролю", tags: ["auth"] })
@ApiBody({ schema: refs(SignInReqDto)[0] })
@ApiOkResponse({
@@ -52,18 +52,18 @@ export class AuthController {
})
@ApiOkResponse({
description: "Авторизация прошла успешно",
schema: refs(SignInResDtoV1)[0],
schema: refs(SignInResDtoV2)[0],
})
@ApiUnauthorizedResponse({
description: "Некорректное имя пользователя или пароль",
})
@ResultDto([SignInResDtoV0, SignInResDtoV1])
@ResultDto([SignInResDtoV0, SignInResDtoV2])
@HttpCode(HttpStatus.OK)
@Post("sign-in")
async signIn(
@Body() signInDto: SignInReqDto,
@ResponseVersion() responseVersion: number,
): Promise<SignInResDtoV1 | SignInResDtoV0> {
): Promise<SignInResDtoV2 | SignInResDtoV0> {
const data = await this.authService.signIn(signInDto);
return SignInResDto.stripVersion(data, responseVersion);
}

View File

@@ -36,7 +36,7 @@ export class SignInResDtoV0 {
accessToken: string;
}
export class SignInResDtoV1 extends SignInResDtoV0 {
export class SignInResDtoV2 extends SignInResDtoV0 {
@ApiProperty({
example: "ИС-214/23",
description: "Группа",
@@ -46,15 +46,16 @@ export class SignInResDtoV1 extends SignInResDtoV0 {
group: string;
}
export class SignInResDto extends SignInResDtoV1 {
export class SignInResDto extends SignInResDtoV2 {
public static stripVersion(
instance: SignInResDto,
version: number,
): SignInResDtoV0 | SignInResDtoV1 {
): SignInResDtoV0 | SignInResDtoV2 {
switch (version) {
default:
return instance;
case 0: {
case 0:
case 1: {
return plainToClass(SignInResDtoV0, instanceToPlain(instance), {
excludeExtraneousValues: true,
});