pos-be/src/modules/configuration/otp-verification/infrastructure/otp-verification-data.contr...

43 lines
1.3 KiB
TypeScript

import {
Body,
Controller,
Get,
Param,
Post,
Req,
UseGuards,
} from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Public } from 'src/core/guards';
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { OtpVerificationService } from '../data/services/otp-verification.service';
import { OtpRequestDto, OtpVerifyDto } from './dto/otp-verification.dto';
import { OtpAuthGuard } from './guards/otp-auth-guard';
//TODO implementation auth
@ApiTags(`${MODULE_NAME.OTP_VERIFICATIONS.split('-').join(' ')} - data`)
@Controller(`v1/${MODULE_NAME.OTP_VERIFICATIONS}`)
@Public()
export class OtpVerificationController {
constructor(
private readonly otpVerificationService: OtpVerificationService,
) {}
@Post('request')
@UseGuards(OtpAuthGuard)
async request(@Body() body: OtpRequestDto, @Req() req) {
return await this.otpVerificationService.requestOTP(body, req);
}
@Post('verify')
@UseGuards(OtpAuthGuard)
async verify(@Body() body: OtpVerifyDto, @Req() req) {
return await this.otpVerificationService.verifyOTP(body, req);
}
@Get(':ref_or_target_id')
async getByPhoneNumber(@Param('ref_or_target_id') ref_or_target_id: string) {
return this.otpVerificationService.getActiveOtp(ref_or_target_id);
}
}