forked from Yara724/api
YARA-1094, YARA-1095, YARA-1096
This commit is contained in:
63
src/users/entities/db-service/financial-expert.db.service.ts
Normal file
63
src/users/entities/db-service/financial-expert.db.service.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
69
src/users/entities/schema/financial-expert.schema.ts
Normal file
69
src/users/entities/schema/financial-expert.schema.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
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();
|
||||
});
|
||||
@@ -11,6 +11,7 @@ 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,
|
||||
@@ -41,6 +42,10 @@ import {
|
||||
FileReviewerDbSchema,
|
||||
FileReviewerModel,
|
||||
} from "./entities/schema/file-reviewer.schema";
|
||||
import {
|
||||
FinancialExpertDbSchema,
|
||||
FinancialExpertModel,
|
||||
} from "./entities/schema/financial-expert.schema";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -54,6 +59,7 @@ import {
|
||||
{ name: ExpertFileActivity.name, schema: ExpertFileActivitySchema },
|
||||
{ name: FileMakerModel.name, schema: FileMakerDbSchema },
|
||||
{ name: FileReviewerModel.name, schema: FileReviewerDbSchema },
|
||||
{ name: FinancialExpertModel.name, schema: FinancialExpertDbSchema },
|
||||
]),
|
||||
HashModule,
|
||||
],
|
||||
@@ -68,6 +74,7 @@ import {
|
||||
ExpertFileActivityDbService,
|
||||
FileMakerDbService,
|
||||
FileReviewerDbService,
|
||||
FinancialExpertDbService,
|
||||
],
|
||||
exports: [
|
||||
UserDbService,
|
||||
@@ -79,6 +86,7 @@ import {
|
||||
ExpertFileActivityDbService,
|
||||
FileMakerDbService,
|
||||
FileReviewerDbService,
|
||||
FinancialExpertDbService,
|
||||
],
|
||||
})
|
||||
export class UsersModule {}
|
||||
|
||||
Reference in New Issue
Block a user