auth.controller.ts 984 B

12345678910111213141516171819202122232425262728293031
  1. import { PhoneLoginDto } from './dto/login.dto'
  2. import { Body, Controller, Get, Param, Post } from '@nestjs/common'
  3. import { AuthService } from './auth.service'
  4. import { ApiTags } from '@nestjs/swagger'
  5. import { Public } from './public.decorator'
  6. import { HasRoles } from './roles.decorator'
  7. import { Role } from '../model/role.enum'
  8. @ApiTags('auth')
  9. @Controller('/auth')
  10. export class AuthController {
  11. constructor(private readonly authService: AuthService) {}
  12. @Public()
  13. @Post('/phoneLogin')
  14. async phoneLogin(@Body() loginDto: PhoneLoginDto) {
  15. return await this.authService.loginByPhone(loginDto)
  16. }
  17. @Public()
  18. @Post('/admin/login')
  19. async login(@Body() { username, password }) {
  20. return await this.authService.loginAdmin(username, password)
  21. }
  22. @Get('/admin/user/:userId/token')
  23. @HasRoles(Role.Admin)
  24. async getToken(@Param('userId') userId: string) {
  25. return await this.authService.getToken(Number(userId))
  26. }
  27. }