forked from Yara724/api
202 lines
5.2 KiB
TypeScript
202 lines
5.2 KiB
TypeScript
import {
|
|
BadRequestException,
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
Post,
|
|
Put,
|
|
Query,
|
|
UnauthorizedException,
|
|
UseGuards,
|
|
} from "@nestjs/common";
|
|
import {
|
|
ApiBearerAuth,
|
|
ApiBody,
|
|
ApiParam,
|
|
ApiQuery,
|
|
ApiTags,
|
|
} from "@nestjs/swagger";
|
|
import { Types } from "mongoose";
|
|
import { LocalActorAuthGuard } from "src/auth/guards/actor-local.guard";
|
|
import { RolesGuard } from "src/auth/guards/role.guard";
|
|
import { Roles } from "src/decorators/roles.decorator";
|
|
import { CurrentUser } from "src/decorators/user.decorator";
|
|
import { FileRating } from "src/request-management/entities/schema/request-management.schema";
|
|
import { RoleEnum } from "src/Types&Enums/role.enum";
|
|
import { ExpertInsurerService } from "./expert-insurer.service";
|
|
import { CreateBranchDto } from "src/client/dto/create-branch.dto";
|
|
|
|
@Controller("expert-insurer")
|
|
@ApiTags("expert-insurer-panel")
|
|
@ApiBearerAuth()
|
|
@UseGuards(LocalActorAuthGuard, RolesGuard)
|
|
@Roles(RoleEnum.COMPANY)
|
|
export class ExpertInsurerController {
|
|
constructor(private readonly expertInsurerService: ExpertInsurerService) {}
|
|
|
|
@Get("files")
|
|
async getAllFiles(@CurrentUser() insurer) {
|
|
return await this.expertInsurerService.retrieveAllFilesOfClient(
|
|
insurer.clientKey,
|
|
);
|
|
}
|
|
|
|
@ApiQuery({ name: "page", type: Number })
|
|
@ApiQuery({ name: "response_count", type: Number })
|
|
@Get("list")
|
|
async getAllExperts(
|
|
@Query("page") page: number,
|
|
@Query("response_count") count: number,
|
|
@CurrentUser() actor,
|
|
) {
|
|
return await this.expertInsurerService.retrieveAllExpertsOfClient(
|
|
actor,
|
|
page,
|
|
count,
|
|
);
|
|
}
|
|
|
|
@Get("top-experts")
|
|
async getTopExperts(@CurrentUser() actor) {
|
|
return await this.expertInsurerService.getTopExpertsForClient(actor);
|
|
}
|
|
|
|
@Get("top-files")
|
|
async getTopFiles(@CurrentUser() insurer) {
|
|
return await this.expertInsurerService.getTopFilesForClient(
|
|
insurer.clientKey,
|
|
);
|
|
}
|
|
|
|
@Get("statistics")
|
|
async getExpertStatistics(@CurrentUser() actor) {
|
|
return await this.expertInsurerService.getExpertStatisticsReport(actor);
|
|
}
|
|
|
|
@ApiParam({ name: "expertId" })
|
|
@ApiQuery({ name: "role", enum: ["claim", "blame"] })
|
|
@Get("/:expertId")
|
|
async requestDetail(
|
|
@CurrentUser() insurer,
|
|
@Param("expertId") id: string,
|
|
@Query("role") role: "claim" | "blame",
|
|
) {
|
|
if (!Types.ObjectId.isValid(new Types.ObjectId(id))) {
|
|
throw new BadRequestException("Invalid expert ID");
|
|
}
|
|
|
|
if (!["claim", "blame"].includes(role)) {
|
|
throw new BadRequestException("Invalid role");
|
|
}
|
|
|
|
return await this.expertInsurerService.getAllFilesByExpertAndRole(
|
|
id,
|
|
role,
|
|
insurer.clientKey,
|
|
);
|
|
}
|
|
|
|
@ApiBody({
|
|
description: "Detailed expert rating",
|
|
schema: {
|
|
type: "object",
|
|
properties: {
|
|
collisionMethodAccuracy: {
|
|
type: "number",
|
|
minimum: 0,
|
|
maximum: 5,
|
|
example: 4,
|
|
description: "تشخیص درست نحوه برخورد",
|
|
},
|
|
evaluationTimeliness: {
|
|
type: "number",
|
|
minimum: 0,
|
|
maximum: 5,
|
|
example: 3,
|
|
description: "زمان ارزیابی",
|
|
},
|
|
accidentCauseAccuracy: {
|
|
type: "number",
|
|
minimum: 0,
|
|
maximum: 5,
|
|
example: 5,
|
|
description: "تشخیص درست علت تصادف",
|
|
},
|
|
guiltyVehicleIdentification: {
|
|
type: "number",
|
|
minimum: 0,
|
|
maximum: 5,
|
|
example: 4,
|
|
description: "تشخیص درست وسیله نقلیه مقصر",
|
|
},
|
|
botRating: {
|
|
type: "number",
|
|
minimum: 0,
|
|
maximum: 5,
|
|
example: 4,
|
|
description: "برای امتیاز دادن به بات",
|
|
},
|
|
},
|
|
required: [
|
|
"collisionMethodAccuracy",
|
|
"evaluationTimeliness",
|
|
"accidentCauseAccuracy",
|
|
"guiltyVehicleIdentification",
|
|
"botRating",
|
|
],
|
|
example: {
|
|
collisionMethodAccuracy: 4,
|
|
evaluationTimeliness: 3,
|
|
accidentCauseAccuracy: 5,
|
|
guiltyVehicleIdentification: 4,
|
|
botRating: 4,
|
|
},
|
|
},
|
|
})
|
|
@ApiParam({ name: "requestId" })
|
|
@ApiQuery({ name: "role", enum: ["claim", "blame"] })
|
|
@Put("/:requestId/rating")
|
|
async rateExperts(
|
|
@CurrentUser() insurer,
|
|
@Param("requestId") requestId: string,
|
|
@Body() rating: FileRating,
|
|
@Query("role") role: "claim" | "blame",
|
|
) {
|
|
if (!["claim", "blame"].includes(role)) {
|
|
throw new BadRequestException("Invalid role");
|
|
}
|
|
|
|
return await this.expertInsurerService.rateExpertOnFile(
|
|
requestId,
|
|
rating,
|
|
role,
|
|
insurer.clientKey,
|
|
);
|
|
}
|
|
|
|
@Get("branches/:insuranceId")
|
|
@ApiParam({ name: "insuranceId" })
|
|
async getInsuranceBranches(@Param("insuranceId") insuranceId: string) {
|
|
return await this.expertInsurerService.retrieveInsuranceBranches(
|
|
insuranceId,
|
|
);
|
|
}
|
|
|
|
@Post("branches")
|
|
@ApiBody({ type: CreateBranchDto })
|
|
async addBranch(
|
|
@CurrentUser() insurer,
|
|
@Body() createBranchDto: CreateBranchDto,
|
|
) {
|
|
if (!insurer) {
|
|
throw new UnauthorizedException("Could not identify the current user.");
|
|
}
|
|
|
|
return await this.expertInsurerService.addBranch(
|
|
insurer.clientKey,
|
|
createBranchDto,
|
|
);
|
|
}
|
|
}
|