Skip to content

Commit

Permalink
fix: password reset request verification return type
Browse files Browse the repository at this point in the history
  • Loading branch information
Krr0ptioN committed Sep 6, 2024
1 parent e2a7c1c commit 5a87a50
Showing 1 changed file with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Controller, Body, Post, UseGuards, Req } from '@nestjs/common';
import {
Controller,
Body,
Post,
UseGuards,
Req,
Logger,
BadRequestException,
} from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { ApiDocsAuthentication } from '../swagger';
import { CommandBus } from '@nestjs/cqrs';
Expand All @@ -23,6 +31,7 @@ import {
import { Result, match } from 'oxide.ts';
import { ExceptionBase } from '@goran/common';
import { Request } from 'express';
import { PasswordResetRequestAggregate } from '../../../domain';

@ApiTags('auth', 'password-reset')
@Controller('auth/password-reset')
Expand All @@ -31,6 +40,9 @@ export class PasswordResetController {
private readonly commandBus: CommandBus,
private readonly tokenService: AuthenticationTokenService
) {}
private readonly logger = new Logger(
VerifyPasswordResetAttemptCommand.name
);

@ApiOkResponse()
@ApiOperation({
Expand Down Expand Up @@ -63,15 +75,21 @@ export class PasswordResetController {
@Body() credential: VerifyPasswordResetRequestDto
) {
const token = this.tokenService.extractTokenFromRequest(req);
const result: Result<any, ExceptionBase> =
const result: Result<PasswordResetRequestAggregate, ExceptionBase> =
await this.commandBus.execute(
new VerifyPasswordResetAttemptCommand({ ...credential, token })
new VerifyPasswordResetAttemptCommand({
token,
email: credential.email,
otpcode: credential.otpcode,
})
);

return match(result, {
Ok: () => new VerifyPasswordResetRequestResponse(),
Err: (error: Error) => {
throw error;
Ok: (agg) => {
return new VerifyPasswordResetRequestResponse();
},
Err: (error: ExceptionBase) => {
throw new BadRequestException(error);
},
});
}
Expand Down

0 comments on commit 5a87a50

Please sign in to comment.