YARA-1110

This commit is contained in:
SepehrYahyaee
2026-07-13 11:53:47 +03:30
parent 72dec7a917
commit 5595083e86
21 changed files with 413 additions and 653 deletions
@@ -1,63 +0,0 @@
import { Injectable } from "@nestjs/common";
import { InjectModel } from "@nestjs/mongoose";
import { FilterQuery, Model, Types } from "mongoose";
import { FinancialExpertModel } from "../schema/financial-expert.schema";
@Injectable()
export class FinancialExpertDbService {
constructor(
@InjectModel(FinancialExpertModel.name)
private readonly financialExpertModel: Model<FinancialExpertModel>,
) {}
async create(
user: Partial<FinancialExpertModel> & { password: string },
): Promise<FinancialExpertModel> {
return await this.financialExpertModel.create(user);
}
async findOne(
filter: FilterQuery<FinancialExpertModel>,
): Promise<FinancialExpertModel | null> {
return await this.financialExpertModel.findOne(filter);
}
async findByLoginIdentifier(
identifier: string,
): Promise<FinancialExpertModel | null> {
const id = identifier.trim();
const or: FilterQuery<FinancialExpertModel>[] = [
{ email: id },
{ username: id },
];
if (/^\d{10}$/.test(id)) {
or.push({ nationalCode: id });
}
return await this.financialExpertModel.findOne({ $or: or });
}
async findById(userId: string): Promise<FinancialExpertModel | null> {
return await this.financialExpertModel.findOne({
_id: new Types.ObjectId(userId),
});
}
async findOneAndUpdate(
filter: FilterQuery<FinancialExpertModel>,
update: FilterQuery<FinancialExpertModel>,
) {
return await this.financialExpertModel.findOneAndUpdate(filter, update, {
new: true,
});
}
async findAll(
filter: FilterQuery<FinancialExpertModel>,
): Promise<(FinancialExpertModel & { _id: Types.ObjectId })[]> {
return await this.financialExpertModel.find(filter).lean();
}
async updateOne(filter: FilterQuery<FinancialExpertModel>, update: any) {
return this.financialExpertModel.updateOne(filter, update);
}
}
@@ -1,69 +0,0 @@
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { Types } from "mongoose";
import { RoleEnum } from "src/Types&Enums/role.enum";
@Schema({
collection: "financial-expert",
versionKey: false,
timestamps: true,
})
export class FinancialExpertModel {
_id?: Types.ObjectId;
@Prop({ required: true })
firstName: string;
@Prop({ required: true })
lastName: string;
@Prop({ type: String, unique: true, sparse: true, required: false })
email?: 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: false })
mobile?: string;
@Prop({ required: false })
phone?: string;
@Prop({ default: RoleEnum.FINANCIAL_EXPERT })
role: RoleEnum;
@Prop({ type: "string", default: "" })
otp: string;
@Prop({ type: "string", required: false })
expertCode?: string;
createdAt: Date;
}
export const FinancialExpertDbSchema = SchemaFactory.createForClass(
FinancialExpertModel,
);
FinancialExpertDbSchema.index(
{ clientKey: 1, nationalCode: 1 },
{ unique: true, sparse: true },
);
FinancialExpertDbSchema.pre("save", function (next) {
if (!this.username) {
this.username = (this as any).email || (this as any).nationalCode;
}
next();
});