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 { AuthService } from './auth.service'
|
||||||
import { CreateUserDto } from 'src/users/dto/create-user.dto'
|
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 { LoginInputDto } from './dto/login-input.dto'
|
||||||
import { RefreshToken } from './dto/token.dto'
|
import { TokenRefreshPayload } from './dto/token.dto'
|
||||||
|
|
||||||
@ApiTags('Auth')
|
@ApiTags('Auth')
|
||||||
@Controller('api/auth')
|
@Controller('api/auth')
|
||||||
export class AuthController {
|
export class AuthController {
|
||||||
constructor(private readonly authService: AuthService) {}
|
constructor(private readonly authService: AuthService) {}
|
||||||
|
|
||||||
|
@ApiOperation({ summary: '注册用户,返回token' })
|
||||||
@Post('register')
|
@Post('register')
|
||||||
async register(@Body() userData: CreateUserDto) {
|
async register(@Body() userData: CreateUserDto) {
|
||||||
return this.authService.register(userData)
|
return this.authService.register(userData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation({ summary: '登录用户,返回token' })
|
||||||
@Post('login')
|
@Post('login')
|
||||||
async login(@Body() user: LoginInputDto) {
|
async login(@Body() user: LoginInputDto) {
|
||||||
return this.authService.login(user.email, user.password)
|
return this.authService.login(user.email, user.password)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('token')
|
@ApiOperation({ summary: '刷新token' })
|
||||||
async refreshToken(@Body() payload: RefreshToken) {
|
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
|
||||||
|
@Put('token')
|
||||||
|
async refreshToken(@Body() payload: TokenRefreshPayload) {
|
||||||
return this.authService.refreshToken(payload.refreshToken)
|
return this.authService.refreshToken(payload.refreshToken)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ export class Token {
|
|||||||
refreshToken: string
|
refreshToken: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RefreshToken {
|
export class TokenRefreshPayload {
|
||||||
@IsString()
|
@IsString()
|
||||||
refreshToken: string
|
refreshToken: string
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
import { Controller, Get, UseInterceptors } from '@nestjs/common'
|
import { Controller, Get, UseInterceptors } from '@nestjs/common'
|
||||||
import { UsersService } from './users.service'
|
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 { User } from 'src/common/decorators/user.decorator'
|
||||||
import { NeedAuth } from 'src/common/decorators/need-auth.decorator'
|
import { NeedAuth } from 'src/common/decorators/need-auth.decorator'
|
||||||
import { PasswordInterceptor } from 'src/common/interceptors/password.interceptor'
|
import { PasswordInterceptor } from 'src/common/interceptors/password.interceptor'
|
||||||
|
|
||||||
@ApiTags('User')
|
@ApiTags('User')
|
||||||
@Controller('api/user')
|
@Controller('api/users')
|
||||||
export class UsersController {
|
export class UsersController {
|
||||||
constructor(private readonly userService: UsersService) {}
|
constructor(private readonly userService: UsersService) {}
|
||||||
|
|
||||||
|
@ApiOperation({ summary: '获取用户信息' })
|
||||||
@UseInterceptors(PasswordInterceptor)
|
@UseInterceptors(PasswordInterceptor)
|
||||||
@NeedAuth()
|
@NeedAuth()
|
||||||
@Get('profile')
|
@Get('me')
|
||||||
async getUserInfo(@User('userId') userId: string) {
|
async getUserInfo(@User('userId') userId: string) {
|
||||||
const user = await this.userService.findUser({ id: userId })
|
const user = await this.userService.findUser({ id: userId })
|
||||||
return user
|
return user
|
||||||
|
Loading…
Reference in New Issue
Block a user