Fixed registrar and field expert

This commit is contained in:
SepehrYahyaee
2026-06-17 16:39:30 +03:30
parent a4eb98258b
commit bc5be99b59
19 changed files with 942 additions and 161 deletions

View File

@@ -16,17 +16,26 @@ export class FieldExpertModel {
@Prop({ required: true })
lastName: string;
@Prop({ type: "string", unique: true })
email: string;
@Prop({ type: String, unique: true, sparse: true, required: false })
email?: string;
@Prop({ type: "string" })
username: string;
@Prop({ type: String })
username?: string;
@Prop({ type: String, index: true, sparse: true })
nationalCode?: string;
@Prop({ type: Types.ObjectId, index: true })
clientKey?: Types.ObjectId;
@Prop({ type: Types.ObjectId, index: true })
branchId?: Types.ObjectId;
@Prop({ required: true })
password: string;
@Prop({ required: true })
mobile: string;
@Prop({ required: false })
mobile?: string;
@Prop({ required: false })
phone?: string;
@@ -41,4 +50,16 @@ export class FieldExpertModel {
}
export const FieldExpertDbSchema =
SchemaFactory.createForClass(FieldExpertModel);
SchemaFactory.createForClass(FieldExpertModel);
FieldExpertDbSchema.index(
{ clientKey: 1, nationalCode: 1 },
{ unique: true, sparse: true },
);
FieldExpertDbSchema.pre("save", function (next) {
if (!this.username) {
this.username = this.email || this.nationalCode;
}
next();
});