added region to login

This commit is contained in:
yousef-alkhrissat
2024-08-09 19:27:51 +03:00
parent 3a5c518d11
commit 458fa1f66e
4 changed files with 36 additions and 4 deletions

View File

@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
import { IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { IsPasswordStrong } from 'src/validators/password.validator';
export class UserSignUpDto {
@ -38,4 +38,8 @@ export class UserSignUpDto {
@IsString()
@IsNotEmpty()
public lastName: string;
@IsString()
@IsOptional()
public regionUuid: string;
}

View File

@ -11,4 +11,9 @@ export class UserLoginDto {
@IsString()
@IsOptional()
password: string;
@ApiProperty()
@IsString()
@IsOptional()
regionUuid?: string;
}

View File

@ -44,9 +44,17 @@ export class UserAuthService {
);
try {
const { regionUuid, ...rest } = userSignUpDto;
const user = await this.userRepository.save({
...userSignUpDto,
...rest,
password: hashedPassword,
region: regionUuid
? {
uuid: regionUuid,
}
: {
regionName: 'United Arab Emirates',
},
});
return user;
@ -80,7 +88,11 @@ export class UserAuthService {
}
async userLogin(data: UserLoginDto) {
const user = await this.authService.validateUser(data.email, data.password);
const user = await this.authService.validateUser(
data.email,
data.password,
data.regionUuid,
);
if (!user) {
throw new UnauthorizedException('Invalid login credentials.');