import { Body, Controller, HttpException, HttpStatus, Post, Req, UseGuards, } from "@nestjs/common"; import { ApiAcceptedResponse, ApiBody, ApiTags } from "@nestjs/swagger"; import { UserAuthService } from "src/auth/auth-services/user.auth.service"; import { UserLoginDto } from "src/auth/dto/user/login.dto"; import { UserVerifyOtp } from "src/auth/dto/user/verify.dto"; import { LocalUserAuthGuard } from "src/auth/guards/user-local.guard"; import { CurrentUser } from "src/decorators/user.decorator"; @Controller("user") @ApiTags("user") export class UserAuthController { constructor(private readonly userAuthService: UserAuthService) {} @Post("/send-otp") @ApiBody({ type: UserLoginDto, description: "user login api -- call this api and send otp", }) @ApiAcceptedResponse() async sendOtpRq(@Body() body: UserLoginDto) { const res = await this.userAuthService.sendOtpRequest(body.mobile, { linkToken: body.linkToken, linkContext: body.linkContext, }); if (res) { throw new HttpException(res, HttpStatus.ACCEPTED); } } @Post("/login") @UseGuards(LocalUserAuthGuard) @ApiBody({ type: UserVerifyOtp, description: "user verify otp -- call this api and get a tokens", }) @ApiAcceptedResponse() async login(@Body() body, @Req() req, @CurrentUser() user) { return await this.userAuthService.login(req.user); } }