| import { Request, Response } from "express";
|
| import { AuthService } from "./auth.service";
|
| import {
|
| loginRequestSchema,
|
| refreshSessionRequestSchema,
|
| registerUserRequestSchema,
|
| resendOtpRequestSchema,
|
| resetPasswordRequestSchema,
|
| verifyOtpRequestSchema
|
| } from "./auth.dto";
|
| import { Validate } from "@/api/middleware/validation.middleware";
|
| import { RequestHandler } from "@/shared/http/request-handler";
|
| import { HttpStatusCode } from "@/shared/http/status-code";
|
|
|
| export class AuthController {
|
| constructor(private readonly authService: AuthService) {}
|
|
|
| @Validate({ body: registerUserRequestSchema })
|
| public async register(req: Request, res: Response){
|
| return RequestHandler.handle(() => this.authService.register(req.body), res);
|
| }
|
|
|
| @Validate({ body: loginRequestSchema })
|
| public async login(req: Request, res: Response){
|
| return RequestHandler.handle(() => this.authService.login(req.body), res);
|
| }
|
|
|
| @Validate({ body: verifyOtpRequestSchema })
|
| public async verifyOtp(req: Request, res: Response) {
|
| return RequestHandler.handle(() => this.authService.verifyEmailOtp(req.body), res);
|
| }
|
|
|
| @Validate({ body: resendOtpRequestSchema })
|
| public async resendOtp(req: Request, res: Response) {
|
| return RequestHandler.handle(() => this.authService.resendOtp(req.body), res);
|
| }
|
|
|
| @Validate({ body: resetPasswordRequestSchema })
|
| public async resetPassword(req: Request, res: Response) {
|
| return RequestHandler.handle(() => this.authService.resetPassword(req.body), res);
|
| }
|
|
|
| @Validate({body: refreshSessionRequestSchema})
|
| public async refreshSession(req: Request, res: Response) {
|
| return RequestHandler.handle(() => this.authService.refreshSession(req.body), res);
|
| }
|
|
|
| public async forgetPassword(req: Request, res: Response) {
|
| const email = req.params.email;
|
|
|
| if (!email) {
|
| return res.error(HttpStatusCode.BAD_REQUEST, 'VALIDATION_ERROR', 'Invalid params', [
|
| { message: 'Email is required', field: 'email' }
|
| ]);
|
| }
|
|
|
| return RequestHandler.handle(() => this.authService.forgetPassword(email), res);
|
| }
|
| }
|
|
|