diff --git a/src/modules/auth/dto/request-otp.dto.ts b/src/modules/auth/dto/request-otp.dto.ts index 83984af..4e40f10 100644 --- a/src/modules/auth/dto/request-otp.dto.ts +++ b/src/modules/auth/dto/request-otp.dto.ts @@ -1,5 +1,6 @@ import { IsNotEmpty, IsString, IsMobilePhone } from 'class-validator'; import { ApiProperty } from '@nestjs/swagger'; +import { Transform } from 'class-transformer'; export class RequestOtpDto { @IsNotEmpty() @@ -10,6 +11,7 @@ export class RequestOtpDto { @IsNotEmpty() @IsString() + @Transform(({ value }) => value?.toLowerCase()) @ApiProperty({ example: 'zhivan', description: 'restaurant slug' }) slug: string; } diff --git a/src/modules/auth/dto/verify-otp.dto.ts b/src/modules/auth/dto/verify-otp.dto.ts index ec1c6f1..9836479 100644 --- a/src/modules/auth/dto/verify-otp.dto.ts +++ b/src/modules/auth/dto/verify-otp.dto.ts @@ -1,5 +1,6 @@ import { IsNotEmpty, IsString, Length, IsMobilePhone } from 'class-validator'; import { ApiProperty } from '@nestjs/swagger'; +import { Transform } from 'class-transformer'; export class VerifyOtpDto { @IsNotEmpty() @@ -16,6 +17,7 @@ export class VerifyOtpDto { @IsNotEmpty() @IsString() + @Transform(({ value }) => value?.toLowerCase()) @ApiProperty({ example: 'zhivan', description: 'restaurant slug' }) slug: string; } diff --git a/src/modules/auth/services/auth.service.ts b/src/modules/auth/services/auth.service.ts index b6844eb..fb18bfa 100644 --- a/src/modules/auth/services/auth.service.ts +++ b/src/modules/auth/services/auth.service.ts @@ -40,6 +40,13 @@ export class AuthService { async requestOtp(dto: RequestOtpDto, isAdmin: boolean) { const { phone, slug } = dto; const normalizedPhone = normalizePhone(phone); + + if (isAdmin) { + const admin = await this.adminRepository.findByPhoneAndRestaurantSlug(normalizedPhone, slug); + if (!admin) { + throw new BadRequestException(AuthMessage.ADMIN_NOT_FOUND); + } + } const code = this.generateOtpCode(); const key = isAdmin ? this.adminOtpKey(slug, normalizedPhone) : this.userOtpKey(slug, normalizedPhone); await this.cacheService.set(key, code, this.OTP_EXPIRATION_TIME);