I am trying to do a server side validation of a signup input I am using nestjs with prisma and postgresql i receive the request body as two filds for example
import { IsEmail, IsNotEmpty, IsString, IsMobilePhone} from "class-validator";
export class EmailSigninDto {
@IsNotEmpty()
@IsEmail()
email: string;
@IsNotEmpty()
@IsString()
@isMobilePhone()
phoneNumber: string;
}
after validating the request body i try to add the new user the probleme is: in my postgresql database these to fields must be unique and i cant find a way to validate two field at once
what i tried to do is the following i try to create a new record with the requested email and phoneNunber and if the two already exists prisma throws an error which i can catch using nestjs exception filter BUT Pisma throws and error containin only the first field which violate the unique constraint so i have to tell the client the email is already in use and the client might send an other request containing a different email but with the same phoneNumber which also violated the unique constraint
i thought about making two queries where i check if there is a user with PhoneNumber and email but i think there might be a better solution
PS: i am new to backend developement and this is my first time using a database