1
0
forked from Yara724/api

Added fileMaker and fileReviewer for new flow

This commit is contained in:
SepehrYahyaee
2026-06-30 13:54:21 +03:30
parent f3686575ca
commit 65e7476642
16 changed files with 1232 additions and 2 deletions

View File

@@ -0,0 +1,63 @@
import { Injectable } from "@nestjs/common";
import { InjectModel } from "@nestjs/mongoose";
import { FilterQuery, Model, Types } from "mongoose";
import { FileMakerModel } from "../schema/file-maker.schema";
@Injectable()
export class FileMakerDbService {
constructor(
@InjectModel(FileMakerModel.name)
private readonly fileMakerModel: Model<FileMakerModel>,
) {}
async create(
user: Partial<FileMakerModel> & { password: string },
): Promise<FileMakerModel> {
return await this.fileMakerModel.create(user);
}
async findOne(
filter: FilterQuery<FileMakerModel>,
): Promise<FileMakerModel | null> {
return await this.fileMakerModel.findOne(filter);
}
async findByLoginIdentifier(
identifier: string,
): Promise<FileMakerModel | null> {
const id = identifier.trim();
const or: FilterQuery<FileMakerModel>[] = [
{ email: id },
{ username: id },
];
if (/^\d{10}$/.test(id)) {
or.push({ nationalCode: id });
}
return await this.fileMakerModel.findOne({ $or: or });
}
async findById(userId: string): Promise<FileMakerModel | null> {
return await this.fileMakerModel.findOne({
_id: new Types.ObjectId(userId),
});
}
async findOneAndUpdate(
filter: FilterQuery<FileMakerModel>,
update: FilterQuery<FileMakerModel>,
) {
return await this.fileMakerModel.findOneAndUpdate(filter, update, {
new: true,
});
}
async findAll(
filter: FilterQuery<FileMakerModel>,
): Promise<(FileMakerModel & { _id: Types.ObjectId })[]> {
return await this.fileMakerModel.find(filter).lean();
}
async updateOne(filter: FilterQuery<FileMakerModel>, update: any) {
return this.fileMakerModel.updateOne(filter, update);
}
}

View File

@@ -0,0 +1,63 @@
import { Injectable } from "@nestjs/common";
import { InjectModel } from "@nestjs/mongoose";
import { FilterQuery, Model, Types } from "mongoose";
import { FileReviewerModel } from "../schema/file-reviewer.schema";
@Injectable()
export class FileReviewerDbService {
constructor(
@InjectModel(FileReviewerModel.name)
private readonly fileReviewerModel: Model<FileReviewerModel>,
) {}
async create(
user: Partial<FileReviewerModel> & { password: string },
): Promise<FileReviewerModel> {
return await this.fileReviewerModel.create(user);
}
async findOne(
filter: FilterQuery<FileReviewerModel>,
): Promise<FileReviewerModel | null> {
return await this.fileReviewerModel.findOne(filter);
}
async findByLoginIdentifier(
identifier: string,
): Promise<FileReviewerModel | null> {
const id = identifier.trim();
const or: FilterQuery<FileReviewerModel>[] = [
{ email: id },
{ username: id },
];
if (/^\d{10}$/.test(id)) {
or.push({ nationalCode: id });
}
return await this.fileReviewerModel.findOne({ $or: or });
}
async findById(userId: string): Promise<FileReviewerModel | null> {
return await this.fileReviewerModel.findOne({
_id: new Types.ObjectId(userId),
});
}
async findOneAndUpdate(
filter: FilterQuery<FileReviewerModel>,
update: FilterQuery<FileReviewerModel>,
) {
return await this.fileReviewerModel.findOneAndUpdate(filter, update, {
new: true,
});
}
async findAll(
filter: FilterQuery<FileReviewerModel>,
): Promise<(FileReviewerModel & { _id: Types.ObjectId })[]> {
return await this.fileReviewerModel.find(filter).lean();
}
async updateOne(filter: FilterQuery<FileReviewerModel>, update: any) {
return this.fileReviewerModel.updateOne(filter, update);
}
}

View File

@@ -0,0 +1,67 @@
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { Types } from "mongoose";
import { RoleEnum } from "src/Types&Enums/role.enum";
@Schema({
collection: "file-maker",
versionKey: false,
timestamps: true,
})
export class FileMakerModel {
_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.FILE_MAKER })
role: RoleEnum;
@Prop({ type: "string", default: "" })
otp: string;
@Prop({ type: "string", required: false })
expertCode?: string;
createdAt: Date;
}
export const FileMakerDbSchema = SchemaFactory.createForClass(FileMakerModel);
FileMakerDbSchema.index(
{ clientKey: 1, nationalCode: 1 },
{ unique: true, sparse: true },
);
FileMakerDbSchema.pre("save", function (next) {
if (!this.username) {
this.username = (this as any).email || (this as any).nationalCode;
}
next();
});

View File

@@ -0,0 +1,68 @@
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { Types } from "mongoose";
import { RoleEnum } from "src/Types&Enums/role.enum";
@Schema({
collection: "file-reviewer",
versionKey: false,
timestamps: true,
})
export class FileReviewerModel {
_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.FILE_REVIEWER })
role: RoleEnum;
@Prop({ type: "string", default: "" })
otp: string;
@Prop({ type: "string", required: false })
expertCode?: string;
createdAt: Date;
}
export const FileReviewerDbSchema =
SchemaFactory.createForClass(FileReviewerModel);
FileReviewerDbSchema.index(
{ clientKey: 1, nationalCode: 1 },
{ unique: true, sparse: true },
);
FileReviewerDbSchema.pre("save", function (next) {
if (!this.username) {
this.username = (this as any).email || (this as any).nationalCode;
}
next();
});