update swagger
This commit is contained in:
parent
a56e4be200
commit
907719f582
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ export class Token {
|
||||
refreshToken: string
|
||||
}
|
||||
|
||||
export class RefreshToken {
|
||||
export class TokenRefreshPayload {
|
||||
@IsString()
|
||||
refreshToken: string
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user