Fix mobile validation, cascade delete for businesses/categories, and DB error handling.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -12,6 +12,10 @@ import { JwtService } from '@nestjs/jwt';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { createHash, randomInt } from 'crypto';
|
||||
import { IsNull, MoreThan, Repository } from 'typeorm';
|
||||
import {
|
||||
isValidIranMobile,
|
||||
normalizeIranMobile,
|
||||
} from '../../common/utils/iran-mobile.util';
|
||||
import { AuthOtpEntity } from '../../entities/auth-otp.entity';
|
||||
import { UserEntity, UserRole } from '../../entities/user.entity';
|
||||
import { JwtPayload } from './auth.types';
|
||||
@@ -200,8 +204,8 @@ export class AuthService {
|
||||
}
|
||||
|
||||
private normalizeMobile(mobile: string): string {
|
||||
const normalized = String(mobile ?? '').trim();
|
||||
if (!/^(\+?\d{10,15}|09\d{9})$/.test(normalized)) {
|
||||
const normalized = normalizeIranMobile(mobile);
|
||||
if (!isValidIranMobile(normalized)) {
|
||||
throw new BadRequestException('Invalid mobile number');
|
||||
}
|
||||
return normalized;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsString, Matches } from 'class-validator';
|
||||
import { IsString } from 'class-validator';
|
||||
import { IsIranMobile } from '../../../common/decorators/is-iran-mobile.decorator';
|
||||
|
||||
export class RequestOtpDto {
|
||||
@ApiProperty({ example: '09122222222' })
|
||||
@IsString()
|
||||
@Matches(/^(\+?\d{10,15}|09\d{9})$/, {
|
||||
message: 'mobile must be a valid mobile number',
|
||||
})
|
||||
@IsIranMobile()
|
||||
mobile!: string;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsString, Matches } from 'class-validator';
|
||||
import { IsIranMobile } from '../../../common/decorators/is-iran-mobile.decorator';
|
||||
|
||||
export class VerifyOtpDto {
|
||||
@ApiProperty({ example: '09122222222' })
|
||||
@IsString()
|
||||
@Matches(/^(\+?\d{10,15}|09\d{9})$/, {
|
||||
message: 'mobile must be a valid mobile number',
|
||||
})
|
||||
@IsIranMobile()
|
||||
mobile!: string;
|
||||
|
||||
@ApiProperty({ example: '123456' })
|
||||
|
||||
Reference in New Issue
Block a user