From 907719f582f18b8dd370e3879d4cbb0cdfd7502d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E7=A7=8B=E6=97=AD?= Date: Mon, 20 Feb 2023 16:25:46 +0800 Subject: [PATCH] update swagger --- src/auth/auth.controller.ts | 14 +++++++++----- src/auth/dto/token.dto.ts | 2 +- src/users/users.controller.ts | 7 ++++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 8814626..ff82041 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -1,27 +1,31 @@ -import { Body, Controller, Post } from '@nestjs/common' +import { Body, Controller, Post, Put } from '@nestjs/common' import { AuthService } from './auth.service' import { CreateUserDto } from 'src/users/dto/create-user.dto' -import { ApiTags } from '@nestjs/swagger' +import { ApiTags, ApiOperation, ApiUnauthorizedResponse } from '@nestjs/swagger' import { LoginInputDto } from './dto/login-input.dto' -import { RefreshToken } from './dto/token.dto' +import { TokenRefreshPayload } from './dto/token.dto' @ApiTags('Auth') @Controller('api/auth') export class AuthController { constructor(private readonly authService: AuthService) {} + @ApiOperation({ summary: '注册用户,返回token' }) @Post('register') async register(@Body() userData: CreateUserDto) { return this.authService.register(userData) } + @ApiOperation({ summary: '登录用户,返回token' }) @Post('login') async login(@Body() user: LoginInputDto) { return this.authService.login(user.email, user.password) } - @Post('token') - async refreshToken(@Body() payload: RefreshToken) { + @ApiOperation({ summary: '刷新token' }) + @ApiUnauthorizedResponse({ description: 'Unauthorized' }) + @Put('token') + async refreshToken(@Body() payload: TokenRefreshPayload) { return this.authService.refreshToken(payload.refreshToken) } } diff --git a/src/auth/dto/token.dto.ts b/src/auth/dto/token.dto.ts index c122cdc..7204272 100644 --- a/src/auth/dto/token.dto.ts +++ b/src/auth/dto/token.dto.ts @@ -9,7 +9,7 @@ export class Token { refreshToken: string } -export class RefreshToken { +export class TokenRefreshPayload { @IsString() refreshToken: string } diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index 251b7a8..d5e96c7 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -1,18 +1,19 @@ import { Controller, Get, UseInterceptors } from '@nestjs/common' import { UsersService } from './users.service' -import { ApiTags } from '@nestjs/swagger' +import { ApiOperation, ApiTags } from '@nestjs/swagger' import { User } from 'src/common/decorators/user.decorator' import { NeedAuth } from 'src/common/decorators/need-auth.decorator' import { PasswordInterceptor } from 'src/common/interceptors/password.interceptor' @ApiTags('User') -@Controller('api/user') +@Controller('api/users') export class UsersController { constructor(private readonly userService: UsersService) {} + @ApiOperation({ summary: '获取用户信息' }) @UseInterceptors(PasswordInterceptor) @NeedAuth() - @Get('profile') + @Get('me') async getUserInfo(@User('userId') userId: string) { const user = await this.userService.findUser({ id: userId }) return user