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

View File

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