Hey i want do create a user with a unique email. I am using class-validator for additional validation. I found a lot of recommendations here to do uniqueness like that:
@Schema()
export class User {
@Prop()
firstName!: string;
@Prop()
lastName!: string;
@Prop()
email!: {
type: String,
required: true,
index: true,
unique: true
};
@Prop({ nullable: true })
password?: string;
}
But i throw me an error of:
Type 'UserDocument | null' is not assignable to type 'UserInput | null'.
...and i think overall this is not possible in NestJS.
I also found a solution by adding unique to the props:
@Prop({
unique: true,
})
email!: string;
... which works, but then i get a completely different structure of errors and i am not able to set custom errors.
Any working solution i saw on git, was testing the uniqueness in the Service and throw an Error.
Why there is no solution for NestJS automatically validating the uniqueness as expected?