forked from Yara724/api
Fixed registrar and field expert
This commit is contained in:
@@ -22,6 +22,20 @@ export class FieldExpertDbService {
|
||||
return await this.fieldExpertModel.findOne(filter);
|
||||
}
|
||||
|
||||
async findByLoginIdentifier(
|
||||
identifier: string,
|
||||
): Promise<FieldExpertModel | null> {
|
||||
const id = identifier.trim();
|
||||
const or: FilterQuery<FieldExpertModel>[] = [
|
||||
{ email: id },
|
||||
{ username: id },
|
||||
];
|
||||
if (/^\d{10}$/.test(id)) {
|
||||
or.push({ nationalCode: id });
|
||||
}
|
||||
return await this.fieldExpertModel.findOne({ $or: or });
|
||||
}
|
||||
|
||||
async findById(userId: string): Promise<FieldExpertModel | null> {
|
||||
return await this.fieldExpertModel.findOne({
|
||||
_id: new Types.ObjectId(userId),
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user