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

@@ -12,6 +12,8 @@ import { BranchDbService } from "src/client/entities/db-service/branch.db.servic
import {
CreateBlameExpertByInsurerDto,
CreateClaimExpertByInsurerDto,
CreateFileMakerByInsurerDto,
CreateFileReviewerByInsurerDto,
CreateInsurerExpertDto,
} from "./dto/create-insurer-expert.dto";
import {
@@ -25,6 +27,8 @@ import { ClaimCaseStatus } from "src/Types&Enums/claim-request-management/claim-
import { DamageExpertDbService } from "src/users/entities/db-service/damage-expert.db.service";
import { ExpertDbService } from "src/users/entities/db-service/expert.db.service";
import { FieldExpertDbService } from "src/users/entities/db-service/field-expert.db.service";
import { FileMakerDbService } from "src/users/entities/db-service/file-maker.db.service";
import { FileReviewerDbService } from "src/users/entities/db-service/file-reviewer.db.service";
import { ExpertFileActivityDbService } from "src/users/entities/db-service/expert-file-activity.db.service";
import { ExpertFileActivityType } from "src/users/entities/schema/expert-file-activity.schema";
import { HashService } from "src/utils/hash/hash.service";
@@ -89,6 +93,8 @@ export class ExpertInsurerService {
private readonly videoCaptureDbService: VideoCaptureDbService,
private readonly clientDbService: ClientDbService,
private readonly claimSignDbService: ClaimSignDbService,
private readonly fileMakerDbService: FileMakerDbService,
private readonly fileReviewerDbService: FileReviewerDbService,
) {}
/**
@@ -1651,6 +1657,108 @@ export class ExpertInsurerService {
);
}
async addFileMaker(
insurerClientKey: string,
payload: CreateFileMakerByInsurerDto,
) {
const clientObjectId = this.getClientId(insurerClientKey);
const branch = await this.assertBranchBelongsToClient(
payload.branchId,
clientObjectId,
);
const email = payload.email.trim().toLowerCase();
const existing = await this.fileMakerDbService.findOne({ email });
if (existing) {
throw new ConflictException("A FileMaker with this email already exists.");
}
const nationalCode = payload.nationalCode.trim();
const existingByNational = await this.fileMakerDbService.findOne({
nationalCode,
});
if (existingByNational) {
throw new ConflictException(
"A FileMaker with this national code already exists.",
);
}
const hashedPassword = await this.hashService.hash(payload.password);
const created = await this.fileMakerDbService.create({
...payload,
email,
nationalCode,
password: hashedPassword,
role: RoleEnum.FILE_MAKER,
clientKey: clientObjectId,
branchId: new Types.ObjectId(payload.branchId),
});
return {
fileMaker: this.sanitizeExpertResponse(created),
branch: {
_id: (branch as any)._id,
name: branch.name,
code: branch.code,
city: branch.city,
state: branch.state,
address: branch.address,
},
};
}
async addFileReviewer(
insurerClientKey: string,
payload: CreateFileReviewerByInsurerDto,
) {
const clientObjectId = this.getClientId(insurerClientKey);
const branch = await this.assertBranchBelongsToClient(
payload.branchId,
clientObjectId,
);
const email = payload.email.trim().toLowerCase();
const existing = await this.fileReviewerDbService.findOne({ email });
if (existing) {
throw new ConflictException(
"A FileReviewer with this email already exists.",
);
}
const nationalCode = payload.nationalCode.trim();
const existingByNational = await this.fileReviewerDbService.findOne({
nationalCode,
});
if (existingByNational) {
throw new ConflictException(
"A FileReviewer with this national code already exists.",
);
}
const hashedPassword = await this.hashService.hash(payload.password);
const created = await this.fileReviewerDbService.create({
...payload,
email,
nationalCode,
password: hashedPassword,
role: RoleEnum.FILE_REVIEWER,
clientKey: clientObjectId,
branchId: new Types.ObjectId(payload.branchId),
});
return {
fileReviewer: this.sanitizeExpertResponse(created),
branch: {
_id: (branch as any)._id,
name: branch.name,
code: branch.code,
city: branch.city,
state: branch.state,
address: branch.address,
},
};
}
/**
* Get comprehensive statistics for all experts of a client
* Returns: