| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import { PhoneLoginDto } from './dto/login.dto'
- import { Body, Controller, Get, Param, Post } from '@nestjs/common'
- import { AuthService } from './auth.service'
- import { ApiTags } from '@nestjs/swagger'
- import { Public } from './public.decorator'
- import { HasRoles } from './roles.decorator'
- import { Role } from '../model/role.enum'
- import { UserRegisterDto } from 'src/users/dto/user-register.dto'
- @ApiTags('auth')
- @Controller('/auth')
- export class AuthController {
- constructor(private readonly authService: AuthService) {}
- @Public()
- @Post('/phoneLogin')
- async phoneLogin(@Body() loginDto: PhoneLoginDto) {
- return await this.authService.loginByPhone(loginDto)
- }
- @Public()
- @Post('/login')
- async login(@Body() { username, password }) {
- return await this.authService.login(username, password)
- }
- @Public()
- @Post('/admin/login')
- async loginAdmin(@Body() { username, password }) {
- return await this.authService.loginAdmin(username, password)
- }
- @Get('/admin/user/:userId/token')
- @HasRoles(Role.Admin)
- async getToken(@Param('userId') userId: string) {
- return await this.authService.getToken(Number(userId))
- }
- @Public()
- @Post('/register')
- async register(@Body() register: UserRegisterDto) {
- return await this.authService.register(register)
- }
- }
|