forked from Yara724/api
Added fileMaker and fileReviewer for new flow
This commit is contained in:
@@ -81,3 +81,19 @@ export class CreateClaimExpertByInsurerDto extends CreateInsurerExpertDto {
|
||||
})
|
||||
role?: RoleEnum.DAMAGE_EXPERT;
|
||||
}
|
||||
|
||||
export class CreateFileMakerByInsurerDto extends CreateInsurerExpertDto {
|
||||
@ApiPropertyOptional({
|
||||
enum: [RoleEnum.FILE_MAKER],
|
||||
default: RoleEnum.FILE_MAKER,
|
||||
})
|
||||
role?: RoleEnum.FILE_MAKER;
|
||||
}
|
||||
|
||||
export class CreateFileReviewerByInsurerDto extends CreateInsurerExpertDto {
|
||||
@ApiPropertyOptional({
|
||||
enum: [RoleEnum.FILE_REVIEWER],
|
||||
default: RoleEnum.FILE_REVIEWER,
|
||||
})
|
||||
role?: RoleEnum.FILE_REVIEWER;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ import { CreateBranchDto } from "src/client/dto/create-branch.dto";
|
||||
import {
|
||||
CreateBlameExpertByInsurerDto,
|
||||
CreateClaimExpertByInsurerDto,
|
||||
CreateFileMakerByInsurerDto,
|
||||
CreateFileReviewerByInsurerDto,
|
||||
} from "./dto/create-insurer-expert.dto";
|
||||
|
||||
@Controller("expert-insurer")
|
||||
@@ -142,6 +144,32 @@ export class ExpertInsurerController {
|
||||
return this.expertInsurerService.addClaimExpert(insurer.clientKey, body);
|
||||
}
|
||||
|
||||
@Post("experts/file-maker")
|
||||
@ApiBody({ type: CreateFileMakerByInsurerDto })
|
||||
@ApiOperation({ summary: "Create a FileMaker account under this insurer" })
|
||||
async addFileMaker(
|
||||
@CurrentUser() insurer,
|
||||
@Body() body: CreateFileMakerByInsurerDto,
|
||||
) {
|
||||
if (!insurer) {
|
||||
throw new UnauthorizedException("Could not identify the current user.");
|
||||
}
|
||||
return this.expertInsurerService.addFileMaker(insurer.clientKey, body);
|
||||
}
|
||||
|
||||
@Post("experts/file-reviewer")
|
||||
@ApiBody({ type: CreateFileReviewerByInsurerDto })
|
||||
@ApiOperation({ summary: "Create a FileReviewer account under this insurer" })
|
||||
async addFileReviewer(
|
||||
@CurrentUser() insurer,
|
||||
@Body() body: CreateFileReviewerByInsurerDto,
|
||||
) {
|
||||
if (!insurer) {
|
||||
throw new UnauthorizedException("Could not identify the current user.");
|
||||
}
|
||||
return this.expertInsurerService.addFileReviewer(insurer.clientKey, body);
|
||||
}
|
||||
|
||||
@ApiQuery({ name: "page", type: Number })
|
||||
@ApiQuery({ name: "response_count", type: Number })
|
||||
@Get("experts/list")
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user