1
0
forked from Yara724/api

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

View File

@@ -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);
}
}

View File

@@ -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();
});

View File

@@ -11,7 +11,6 @@ import { UserDbService } from "./entities/db-service/user.db.service";
import { ExpertFileActivityDbService } from "./entities/db-service/expert-file-activity.db.service";
import { FileMakerDbService } from "./entities/db-service/file-maker.db.service";
import { FileReviewerDbService } from "./entities/db-service/file-reviewer.db.service";
import { FinancialExpertDbService } from "./entities/db-service/financial-expert.db.service";
import {
DamageExpertDbSchema,
DamageExpertModel,
@@ -42,10 +41,6 @@ import {
FileReviewerDbSchema,
FileReviewerModel,
} from "./entities/schema/file-reviewer.schema";
import {
FinancialExpertDbSchema,
FinancialExpertModel,
} from "./entities/schema/financial-expert.schema";
@Module({
imports: [
@@ -59,7 +54,6 @@ import {
{ name: ExpertFileActivity.name, schema: ExpertFileActivitySchema },
{ name: FileMakerModel.name, schema: FileMakerDbSchema },
{ name: FileReviewerModel.name, schema: FileReviewerDbSchema },
{ name: FinancialExpertModel.name, schema: FinancialExpertDbSchema },
]),
HashModule,
],
@@ -74,7 +68,6 @@ import {
ExpertFileActivityDbService,
FileMakerDbService,
FileReviewerDbService,
FinancialExpertDbService,
],
exports: [
UserDbService,
@@ -86,7 +79,6 @@ import {
ExpertFileActivityDbService,
FileMakerDbService,
FileReviewerDbService,
FinancialExpertDbService,
],
})
export class UsersModule {}