Skip to content

Commit

Permalink
organized code
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b committed May 24, 2024
1 parent 3934fe0 commit 8347a96
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { AuthGuard } from '../auth/guard/auth/auth.guard';
import { PrismaModule } from '../prisma/prisma.module';
import { MailModule } from '../mail/mail.module';
import { ProviderModule } from '../provider/provider.module';
import { CommonModule } from '../common/common.module';

@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
CommonModule,
AuthModule,
UserModule,
OauthModule,
Expand Down
5 changes: 4 additions & 1 deletion src/auth/controller/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
ApiTags,
} from '@nestjs/swagger';
import { userProperties } from '../../schemas/user.properties';
import { LowercasePipe } from 'src/common/pipes/lowercase.pipe';

@Controller('auth')
@ApiTags('Auth Controller')
Expand Down Expand Up @@ -195,7 +196,9 @@ export class AuthController {
description: 'User not found',
})
@HttpCode(HttpStatus.NO_CONTENT)
async resendEmailVerificationCode(@Param('email') email: string) {
async resendEmailVerificationCode(
@Param('email', LowercasePipe) email: string,
) {
return await this.authService.resendEmailVerificationCode(email);
}

Expand Down
2 changes: 2 additions & 0 deletions src/auth/dto/email-verification.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsEmail, Matches } from 'class-validator';

export class EmailVerificationDto {
Expand All @@ -10,6 +11,7 @@ export class EmailVerificationDto {
type: String,
example: '[email protected]',
})
@Transform(({ value }) => value.toLowerCase())
email: string;
@Matches(/^[0-9]{6}$/, {
message: 'Code must be a 6 digit number',
Expand Down
5 changes: 0 additions & 5 deletions src/auth/service/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export class AuthService {
}

async resendEmailVerificationCode(email: string) {
email = email.toLowerCase();
const user = await this.findUserByEmail(email);
if (!user) {
throw new NotFoundException('User not found');
Expand All @@ -144,8 +143,6 @@ export class AuthService {
}

async verifyEmail(email: string, code: string) {
email = email.toLowerCase();

const verificationCode = await this.prisma.verificationCode.findUnique({
where: {
email,
Expand Down Expand Up @@ -262,8 +259,6 @@ export class AuthService {
}

private async sendEmailVerificationCode(email: string) {
email = email.toLowerCase();

// Generate the code
let code: string;

Expand Down
5 changes: 5 additions & 0 deletions src/common/common.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Global, Module } from '@nestjs/common';

@Global()
@Module({})
export class CommonModule {}
8 changes: 8 additions & 0 deletions src/common/pipes/lowercase.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { PipeTransform, Injectable } from '@nestjs/common';

@Injectable()
export class LowercasePipe implements PipeTransform {
transform(value: string) {
return value.toLowerCase();
}
}

0 comments on commit 8347a96

Please sign in to comment.