26 lines
936 B
TypeScript
26 lines
936 B
TypeScript
import { Body, Controller, Post } from '@nestjs/common';
|
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
import { AuthService } from './auth.service';
|
|
import { WxLoginRequestDto, WxLoginResponseDto } from './dto/wx-login.dto';
|
|
import { ApiResponseDto } from '../../common/dto/api-response.dto';
|
|
|
|
@ApiTags('认证')
|
|
@Controller('v1/auth')
|
|
export class AuthController {
|
|
constructor(private readonly authService: AuthService) {}
|
|
|
|
@Post('wx-login')
|
|
@ApiOperation({
|
|
summary: '微信登录',
|
|
description: '使用微信 wx.login 返回的 code 换取 JWT 令牌',
|
|
})
|
|
@ApiResponse({ status: 200, description: '登录成功' })
|
|
@ApiResponse({ status: 401, description: '微信登录失败' })
|
|
async wxLogin(
|
|
@Body() dto: WxLoginRequestDto,
|
|
): Promise<ApiResponseDto<WxLoginResponseDto>> {
|
|
const data = await this.authService.wxLogin(dto.code);
|
|
return ApiResponseDto.success(data);
|
|
}
|
|
}
|