Enforce claim beneficiary access and retire unused legacy APIs

This commit is contained in:
SepehrYahyaee
2026-10-05 14:39:51 +03:30
parent 0735333467
commit a3f9aab8fb
104 changed files with 6864 additions and 13223 deletions
@@ -1,19 +0,0 @@
import { ApiProperty } from "@nestjs/swagger";
/**
* Computed on GET blame v2 for the current viewer — no DB field on BlameRequest.
*/
export class ClaimCreationHintDto {
@ApiProperty({
description:
"True if a v2 claim case already exists for this blame (by blameRequestId).",
})
hasClaim: boolean;
@ApiProperty({
description:
"True when this viewer is the damaged party, blame is COMPLETED, no claim exists yet, " +
"and for THIRD_PARTY all parties have signed and accepted the expert decision.",
})
shouldGuideToCreateClaim: boolean;
}
@@ -1,29 +0,0 @@
import { ApiProperty } from "@nestjs/swagger";
import { AddPlateDto } from "src/profile/dto/user/AddPlateDto";
import { DescriptionDto } from "./create-request-management.dto";
import { InitialFormDto, CarBodyFormDto } from "./create-request-management.dto";
/**
* Comprehensive form for experts to fill all information at once for IN_PERSON CAR_BODY files
*/
export class ExpertCompleteCarBodyFormDto {
// First Party Information
@ApiProperty({
description: "First party phone number",
example: "09123456789",
})
firstPartyPhoneNumber: string;
@ApiProperty({ type: InitialFormDto })
firstPartyInitialForm: InitialFormDto;
@ApiProperty({ type: CarBodyFormDto })
carBodyForm: CarBodyFormDto;
@ApiProperty({ type: AddPlateDto })
firstPartyPlate: AddPlateDto;
@ApiProperty({ type: DescriptionDto })
firstPartyDescription: DescriptionDto;
}
@@ -1,11 +0,0 @@
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { LocationDto } from "./create-request-management.dto";
export class ExpertCompleteLocationsDto {
@ApiProperty({ type: LocationDto })
firstPartyLocation: LocationDto;
@ApiPropertyOptional({ type: LocationDto })
secondPartyLocation?: LocationDto;
}
@@ -1,57 +0,0 @@
import { ApiProperty } from "@nestjs/swagger";
import { AddPlateDto } from "src/profile/dto/user/AddPlateDto";
import { DescriptionDto } from "./create-request-management.dto";
import { InitialFormDto } from "./create-request-management.dto";
/**
* Second party information for expert-completed THIRD_PARTY forms
*/
export class ExpertSecondPartyInfoDto {
@ApiProperty({
description: "Second party phone number",
example: "09123456789",
})
phoneNumber: string;
@ApiProperty({ type: InitialFormDto })
initialForm: InitialFormDto;
@ApiProperty({ type: AddPlateDto })
plate: AddPlateDto;
@ApiProperty({ type: DescriptionDto })
description: DescriptionDto;
}
/**
* Comprehensive form for experts to fill all information at once for IN_PERSON THIRD_PARTY files
*/
export class ExpertCompleteThirdPartyFormDto {
// First Party Information
@ApiProperty({
description: "First party phone number",
example: "09123456789",
})
firstPartyPhoneNumber: string;
@ApiProperty({ type: InitialFormDto })
firstPartyInitialForm: InitialFormDto;
@ApiProperty({ type: AddPlateDto })
firstPartyPlate: AddPlateDto;
@ApiProperty({ type: DescriptionDto })
firstPartyDescription: DescriptionDto;
// Second Party Information
@ApiProperty({ type: ExpertSecondPartyInfoDto })
secondParty: ExpertSecondPartyInfoDto;
// Guilty Party
@ApiProperty({
description: "Phone number of the guilty party. Must match either first or second party phone number.",
example: "09123456789",
})
guiltyPartyPhoneNumber: string;
}
@@ -1,52 +0,0 @@
import { ApiProperty } from "@nestjs/swagger";
import { RequestManagementModel } from "../entities/schema/request-management.schema";
export class UserReplyDto {
public _id: string;
@ApiProperty({ required: true })
isAccept: boolean;
@ApiProperty({ required: true })
signId: string;
constructor(requestId: string) {
this._id = requestId;
}
}
export class DetailsReplyDtoRs {
public fields: Object;
public actorFullName: string;
public description: string;
public dateOfReply: string;
public timeOfReply: string;
public isGuiltyUser: boolean;
public firstPartyAccept: boolean;
public secondPartyAccept: boolean;
public status: string;
public expertResendReply: any;
public expertSubmitReply: any;
public expertSubmitReplyFinal: any;
public theParties: any;
public type: string;
constructor(request: RequestManagementModel, details: any) {
const finalReply = request.expertSubmitReply;
this.fields = finalReply.fields;
this.description = finalReply.description;
this.firstPartyAccept = finalReply?.firstPartyComment?.isAccept;
this.secondPartyAccept = finalReply?.secondPartyComment?.isAccept;
this.actorFullName = details.actorDetail.CheckedRequest.fullName;
this.dateOfReply = details.actorDetail.Date.toLocaleDateString("fa-IR");
this.timeOfReply = details.actorDetail.Date.toLocaleTimeString("fa-IR");
this.isGuiltyUser = details.isGuilty;
this.status = request.blameStatus;
this.expertResendReply = request.expertResendReply;
this.expertSubmitReply = request.expertSubmitReply;
this.expertSubmitReplyFinal = request.expertSubmitReplyFinal;
this.theParties = details.theParties;
this.type = request.type || "THIRD_PARTY"; // Include type field
}
}
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { FilterQuery, Model, UpdateQuery } from 'mongoose';
import { BlameDocumentModel } from '../schema/blame-document.schema';
import { Injectable } from "@nestjs/common";
import { InjectModel } from "@nestjs/mongoose";
import { Model } from "mongoose";
import { BlameDocumentModel } from "../schema/blame-document.schema";
@Injectable()
export class BlameDocumentDbService {
@@ -10,27 +10,14 @@ export class BlameDocumentDbService {
private readonly blameDocumentModel: Model<BlameDocumentModel>,
) {}
async create(createDto: Partial<BlameDocumentModel>): Promise<BlameDocumentModel> {
async create(
createDto: Partial<BlameDocumentModel>,
): Promise<BlameDocumentModel> {
const newDocument = new this.blameDocumentModel(createDto);
return newDocument.save();
}
async findOne(filter: FilterQuery<BlameDocumentModel>): Promise<BlameDocumentModel | null> {
return this.blameDocumentModel.findOne(filter).lean();
}
async findAll(filter: FilterQuery<BlameDocumentModel>): Promise<BlameDocumentModel[]> {
return this.blameDocumentModel.find(filter).lean();
}
async findById(id: string): Promise<BlameDocumentModel | null> {
return this.blameDocumentModel.findById(id).lean();
}
async findByIdAndUpdate(
id: string,
updateDto: UpdateQuery<BlameDocumentModel>,
): Promise<BlameDocumentModel | null> {
return this.blameDocumentModel.findByIdAndUpdate(id, updateDto, { new: true }).lean();
}
}
}
@@ -17,12 +17,6 @@ export class BlameRequestDbService {
return this.blameRequestModel.create(payload);
}
async findOne(
filter: FilterQuery<BlameRequest>,
): Promise<BlameRequestDocument | null> {
return this.blameRequestModel.findOne(filter);
}
async findById(
id: string | Types.ObjectId,
): Promise<BlameRequestDocument | null> {
@@ -16,10 +16,6 @@ export class BlameVideoDbService {
return await this.blameVideoModel.findOne(new Types.ObjectId(id));
}
async findOneByRequestId(id: string): Promise<BlameVideosModel> {
return await this.blameVideoModel.findById(id);
}
async findById(id: string): Promise<BlameVideosModel | null> {
return this.blameVideoModel.findById(id).lean();
}
@@ -8,12 +8,6 @@ export class RequestManagementDbService {
private readonly requestModel: Model<RequestManagementModel>,
) {}
async create(
request: RequestManagementModel,
): Promise<RequestManagementModel> {
return await this.requestModel.create(request);
}
async findOne(id: string) {
return await this.requestModel.findOne(new Types.ObjectId(id));
}
@@ -22,21 +16,6 @@ export class RequestManagementDbService {
return await this.requestModel.find({ ...filter });
}
async findAllAndPagination(query, currentPage, resPerPage?) {
const responsePerPage = resPerPage | 1;
const skipPge = responsePerPage * (Number(currentPage) - 1);
return await this.requestModel
.find(query)
.limit(responsePerPage)
.skip(skipPge);
}
async countByFilter(
filter: FilterQuery<RequestManagementModel>,
): Promise<number> {
return await this.requestModel.countDocuments(filter);
}
async findAndUpdate(
filter: FilterQuery<RequestManagementModel>,
update: UpdateQuery<RequestManagementModel>,
@@ -83,12 +62,4 @@ export class RequestManagementDbService {
update,
);
}
async aggregate(filter?) {
return await this.requestModel.aggregate(filter);
}
async updateMany(filter?, update?) {
return await this.requestModel.updateMany(filter, update);
}
}
@@ -1,5 +1,5 @@
import { InjectModel } from "@nestjs/mongoose";
import { Model, Types } from "mongoose";
import { Model } from "mongoose";
import { UserSignModel } from "../schema/sign.schema";
export class UserSignDbService {
@@ -12,10 +12,6 @@ export class UserSignDbService {
return await this.blameVoiceModel.create(sign);
}
async findOne(id: string): Promise<UserSignModel> {
return await this.blameVoiceModel.findOne(new Types.ObjectId(id));
}
async findById(id: string): Promise<UserSignModel | null> {
// Use your correct Model type
return this.blameVoiceModel.findById(id).lean();
@@ -1,44 +1,15 @@
import { extname } from "node:path";
import {
Controller,
Post,
Body,
Param,
UseGuards,
Get,
UseInterceptors,
UploadedFile,
} from "@nestjs/common";
import {
FileInterceptor,
} from "@nestjs/platform-express";
import { diskStorage } from "multer";
import {
ApiBearerAuth,
ApiBody,
ApiParam,
ApiTags,
ApiOperation,
ApiResponse,
ApiConsumes,
ApiExcludeController,
} from "@nestjs/swagger";
import { Body, Controller, Param, Post, UseGuards } from "@nestjs/common";
import { ApiBearerAuth, ApiExcludeController } from "@nestjs/swagger";
import { LocalActorAuthGuard } from "src/auth/guards/actor-local.guard";
import { RolesGuard } from "src/auth/guards/role.guard";
import { CurrentUser } from "src/decorators/user.decorator";
import { Roles } from "src/decorators/roles.decorator";
import { CurrentUser } from "src/decorators/user.decorator";
import { RoleEnum } from "src/Types&Enums/role.enum";
import { DEFAULT_MEDIA_MAX_BYTES } from "src/client/client.service";
import { RequestManagementService } from "./request-management.service";
import { CreateExpertInitiatedFileDto } from "./dto/expert-initiated.dto";
import { ExpertCompleteThirdPartyFormDto } from "./dto/expert-complete-third-party-form.dto";
import { ExpertCompleteCarBodyFormDto } from "./dto/expert-complete-car-body-form.dto";
import { ExpertAccidentFieldsDto } from "./dto/expert-accident-fields.dto";
import { ExpertCompleteClaimDataDto } from "./dto/expert-complete-claim-data.dto";
import { ClaimRequestManagementService } from "src/claim-request-management/claim-request-management.service";
import { RequestManagementService } from "./request-management.service";
@ApiExcludeController()
// @ApiTags("expert-initiated-blame")
@Controller("expert-initiated-blame")
@ApiBearerAuth()
@UseGuards(LocalActorAuthGuard, RolesGuard)
@@ -46,239 +17,9 @@ import { ClaimRequestManagementService } from "src/claim-request-management/clai
export class ExpertInitiatedController {
constructor(
private readonly requestManagementService: RequestManagementService,
private readonly claimRequestManagementService: ClaimRequestManagementService,
) {}
// @ApiOperation({ deprecated: true })
@Get("my-files")
// @ApiOperation({
// summary: "List my expert-initiated files",
// description:
// "Returns all blame files created by the current field expert (their panel).",
// })
// @ApiResponse({ status: 200, description: "List of expert-initiated files" })
async getMyFiles(@CurrentUser() expert: any) {
return await this.requestManagementService.getMyExpertInitiatedFiles(expert);
}
// @ApiOperation({ deprecated: true })
@Post("complete-blame-data/:requestId")
// @ApiParam({ name: "requestId", description: "ID of the expert-initiated file" })
// @ApiBody({
// description:
// "Send ExpertCompleteThirdPartyFormDto for THIRD_PARTY files or ExpertCompleteCarBodyFormDto for CAR_BODY files (according to file type).",
// })
// @ApiResponse({ status: 200, description: "Blame form completed successfully" })
async completeBlameData(
@CurrentUser() expert: any,
@Param("requestId") requestId: string,
@Body() formData: any,
) {
return await this.requestManagementService.completeBlameData(
expert,
requestId,
formData,
);
}
// @ApiOperation({ deprecated: true })
@Post("complete-claim-data/:claimRequestId")
// @ApiOperation({
// summary: "Submit claim-needed data",
// description:
// "Field expert fills claim data for expert-initiated IN_PERSON files (car part damage, sheba, national code, other parts). " +
// "Only the initiating expert can call this.",
// })
// @ApiParam({
// name: "claimRequestId",
// description: "ID of the claim file (created from the expert-initiated blame file)",
// })
// @ApiBody({ type: ExpertCompleteClaimDataDto })
// @ApiResponse({ status: 200, description: "Claim data updated successfully" })
async completeClaimData(
@CurrentUser() expert: any,
@Param("claimRequestId") claimRequestId: string,
@Body() dto: ExpertCompleteClaimDataDto,
) {
return await this.claimRequestManagementService.expertCompleteClaimData(
claimRequestId,
expert,
dto,
);
}
// @ApiOperation({ deprecated: true })
// @Post("create")
// @ApiOperation({
// summary: "Create expert-initiated blame file",
// description:
// "Expert creates an initial incomplete blame file. Can be IN_PERSON (expert fills all info) or LINK (expert sends link to users).",
// })
// @ApiBody({ type: CreateExpertInitiatedFileDto })
// @ApiResponse({
// status: 201,
// description: "File created successfully",
// schema: {
// type: "object",
// properties: {
// requestId: { type: "string" },
// },
// },
// })
// async createExpertInitiatedFile(
// @CurrentUser() expert: any,
// @Body() dto: CreateExpertInitiatedFileDto,
// ) {
// return await this.requestManagementService.createExpertInitiatedFile(
// expert,
// dto,
// );
// }
// @ApiOperation({ deprecated: true })
@Post("complete-form-third-party/:requestId")
// @ApiParam({ name: "requestId" })
// @ApiBody({ type: ExpertCompleteThirdPartyFormDto })
// @ApiResponse({ status: 200, description: "Form completed successfully. File is now ready for user signatures." })
async completeThirdPartyForm(
@CurrentUser() expert: any,
@Param("requestId") requestId: string,
@Body() formData: ExpertCompleteThirdPartyFormDto,
) {
return await this.requestManagementService.expertCompleteThirdPartyForm(
expert,
requestId,
formData,
);
}
// @ApiOperation({ deprecated: true })
@Post("complete-form-car-body/:requestId")
// @ApiOperation({
// summary: "Expert completes all information for IN_PERSON CAR_BODY file",
// description:
// "Expert fills all information at once for IN_PERSON CAR_BODY files. " +
// "Includes first party data and carBodyForm. " +
// "Video and voice uploads are handled separately.",
// })
async completeCarBodyForm(
@CurrentUser() expert: any,
@Param("requestId") requestId: string,
@Body() formData: ExpertCompleteCarBodyFormDto,
) {
return await this.requestManagementService.expertCompleteCarBodyForm(
expert,
requestId,
formData,
);
}
// @ApiOperation({ deprecated: true })
@Post("upload-video/:requestId")
// @ApiParam({ name: "requestId" })
// @ApiConsumes("multipart/form-data")
// @ApiBody({
// schema: {
// type: "object",
// properties: { file: { type: "string", format: "binary" } },
// },
// })
@UseInterceptors(
FileInterceptor("file", {
limits: {
fileSize: DEFAULT_MEDIA_MAX_BYTES,
},
storage: diskStorage({
destination: "./files/video",
filename: (req, file, callback) => {
const unique = Date.now();
const ex = extname(file.originalname);
const filename = `expert-${file.originalname}-${unique}${ex}`;
callback(null, filename);
},
}),
}),
)
// @ApiResponse({
// status: 200,
// description: "Video uploaded successfully",
// })
async uploadVideo(
@CurrentUser() expert: any,
@Param("requestId") requestId: string,
@UploadedFile() file?: Express.Multer.File,
) {
return await this.requestManagementService.expertUploadVideo(
expert,
requestId,
file,
);
}
// @ApiOperation({ deprecated: true })
@Post("upload-voice/:requestId")
// @ApiOperation({
// summary: "Expert uploads voice for expert-initiated file",
// description:
// "Expert uploads a single voice file for the entire blame file. " +
// "Only one voice is needed per file (not per party). " +
// "Only works for expert-initiated files.",
// })
// @ApiParam({ name: "requestId" })
// @ApiConsumes("multipart/form-data")
// @ApiBody({
// schema: {
// type: "object",
// properties: {
// voice: {
// type: "string",
// format: "binary",
// },
// },
// },
// })
@UseInterceptors(
FileInterceptor("voice", {
limits: {
fileSize: DEFAULT_MEDIA_MAX_BYTES,
},
storage: diskStorage({
destination: "./files/voice",
filename: (req, file, callback) => {
const unique = Date.now();
const ex = extname(file.originalname);
const flname = file.originalname.split(".")[0];
const filename = `expert-${flname}-${unique}${ex}`;
callback(null, filename);
},
}),
}),
)
// @ApiResponse({ status: 200, description: "Voice uploaded successfully" })
async uploadVoice(
@CurrentUser() expert: any,
@Param("requestId") requestId: string,
@UploadedFile() voice?: Express.Multer.File,
) {
return await this.requestManagementService.expertUploadVoice(
expert,
requestId,
voice,
);
}
// @ApiOperation({ deprecated: true })
@Post("add-accident-fields/:requestId")
// @ApiOperation({
// summary: "Expert adds accident fields to expert-initiated file",
// description:
// "Expert adds accident way, reason, and type fields to an expert-initiated file. " +
// "Can be used for both IN_PERSON and LINK-based files. " +
// "If expertSubmitReply already exists, updates the fields. Otherwise, creates a new expertSubmitReply.",
// })
// @ApiParam({ name: "requestId" })
// @ApiBody({ type: ExpertAccidentFieldsDto })
// @ApiResponse({ status: 200, description: "Accident fields added successfully" })
async addAccidentFields(
@CurrentUser() expert: any,
@Param("requestId") requestId: string,
@@ -291,4 +32,3 @@ export class ExpertInitiatedController {
);
}
}
@@ -1,10 +1,4 @@
import {
Body,
Controller,
Param,
Post,
UseGuards,
} from "@nestjs/common";
import { Body, Controller, Param, Post, UseGuards } from "@nestjs/common";
import {
ApiBearerAuth,
ApiBody,
@@ -21,12 +15,12 @@ import { Roles } from "src/decorators/roles.decorator";
import { CurrentUser } from "src/decorators/user.decorator";
import { RoleEnum } from "src/Types&Enums/role.enum";
import { RequestManagementService } from "./request-management.service";
import { ClaimRequestManagementService } from "src/claim-request-management/claim-request-management.service";
class FileMakerRejectDto {
@ApiPropertyOptional({
description: "Reason for rejection (visible to FileReviewer)",
example: "Damage assessment is incorrect — please re-evaluate parts X and Y",
example:
"Damage assessment is incorrect — please re-evaluate parts X and Y",
})
@IsOptional()
@IsString()
@@ -57,7 +51,6 @@ class FileMakerRejectDto {
export class FileMakerClaimApprovalV5Controller {
constructor(
private readonly requestManagementService: RequestManagementService,
private readonly claimRequestManagementService: ClaimRequestManagementService,
) {}
@Post("approve/:claimRequestId")
@@ -17,23 +17,11 @@ describe("RequestManagementService V5 FileMaker approval", () => {
}),
findByIdAndUpdate: jest.fn().mockResolvedValue({}),
};
const service = new (RequestManagementService as any)(
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
claimCaseDbService,
const service = Object.assign(
Object.create(RequestManagementService.prototype),
{
claimCaseDbService,
},
) as RequestManagementService;
const result = await service.fileMakerApproveV5(
@@ -1,157 +0,0 @@
import { extname } from "node:path";
import { Body, Controller, Get, Param, Post, UploadedFile, UseGuards, UseInterceptors } from "@nestjs/common";
import { FileInterceptor } from "@nestjs/platform-express";
import { diskStorage } from "multer";
import { ApiBearerAuth, ApiBody, ApiConsumes, ApiOperation, ApiParam, ApiTags, ApiExcludeController } from "@nestjs/swagger";
import { LocalActorAuthGuard } from "src/auth/guards/actor-local.guard";
import { RolesGuard } from "src/auth/guards/role.guard";
import { CurrentUser } from "src/decorators/user.decorator";
import { Roles } from "src/decorators/roles.decorator";
import { RoleEnum } from "src/Types&Enums/role.enum";
import { DEFAULT_MEDIA_MAX_BYTES } from "src/client/client.service";
import { RequestManagementService } from "./request-management.service";
import { CreateRegistrarInitiatedFileDto } from "./dto/registrar-initiated.dto";
import { SendPartyOtpsDto } from "./dto/send-party-otps.dto";
import { VerifyPartyOtpsDto } from "./dto/verify-party-otps.dto";
import { ExpertAccidentFieldsDto } from "./dto/expert-accident-fields.dto";
import { PartyRole } from "./entities/schema/partyRole.enum";
@ApiExcludeController()
// @ApiTags("registrar-initiated-blame (v1)")
@Controller("registrar-initiated-blame")
@ApiBearerAuth()
@UseGuards(LocalActorAuthGuard, RolesGuard)
@Roles(RoleEnum.REGISTRAR)
export class RegistrarInitiatedController {
constructor(private readonly requestManagementService: RequestManagementService) {}
@Post("create")
// @ApiOperation({ summary: "Registrar creates IN_PERSON blame file" })
// @ApiBody({ type: CreateRegistrarInitiatedFileDto })
create(@CurrentUser() registrar: any, @Body() dto: CreateRegistrarInitiatedFileDto) {
return this.requestManagementService.createRegistrarInitiatedBlame(registrar, dto);
}
@Get("my-files")
myFiles(@CurrentUser() registrar: any) {
return this.requestManagementService.getMyExpertInitiatedFilesV2(registrar);
}
@Get("blame/:requestId")
getBlame(@Param("requestId") requestId: string, @CurrentUser() registrar: any) {
return this.requestManagementService.getBlameRequestV2(requestId, registrar);
}
@Post("send-party-otps/:requestId")
// @ApiParam({ name: "requestId" })
// @ApiBody({ type: SendPartyOtpsDto })
sendPartyOtps(
@CurrentUser() registrar: any,
@Param("requestId") requestId: string,
@Body() dto: SendPartyOtpsDto,
) {
return this.requestManagementService.sendPartyOtpsV2(registrar, requestId, dto);
}
@Post("verify-party-otps/:requestId")
// @ApiParam({ name: "requestId" })
// @ApiBody({ type: VerifyPartyOtpsDto })
verifyPartyOtps(
@CurrentUser() registrar: any,
@Param("requestId") requestId: string,
@Body() dto: VerifyPartyOtpsDto,
) {
return this.requestManagementService.verifyPartyOtpsV2(registrar, requestId, dto);
}
@Post("complete-blame-data/:requestId")
completeBlameData(
@CurrentUser() registrar: any,
@Param("requestId") requestId: string,
@Body() body: any,
) {
return this.requestManagementService.expertCompleteBlameDataV2(registrar, requestId, body);
}
@Post("upload-video/:requestId")
// @ApiConsumes("multipart/form-data")
@UseInterceptors(
FileInterceptor("file", {
limits: { fileSize: DEFAULT_MEDIA_MAX_BYTES },
storage: diskStorage({
destination: "./files/video",
filename: (req, file, cb) => cb(null, `registrar-${Date.now()}${extname(file.originalname)}`),
}),
}),
)
uploadVideo(
@CurrentUser() registrar: any,
@Param("requestId") requestId: string,
@UploadedFile() file?: Express.Multer.File,
) {
return this.requestManagementService.expertUploadVideoForBlameV2(registrar, requestId, file);
}
@Post("upload-voice/:requestId")
// @ApiConsumes("multipart/form-data")
@UseInterceptors(
FileInterceptor("voice", {
limits: { fileSize: DEFAULT_MEDIA_MAX_BYTES },
storage: diskStorage({
destination: "./files/voice",
filename: (req, file, cb) => cb(null, `registrar-${Date.now()}${extname(file.originalname)}`),
}),
}),
)
uploadVoice(
@CurrentUser() registrar: any,
@Param("requestId") requestId: string,
@UploadedFile() voice?: Express.Multer.File,
) {
return this.requestManagementService.expertUploadVoiceForBlameV2(registrar, requestId, voice);
}
@Post("add-accident-fields/:requestId")
// @ApiBody({ type: ExpertAccidentFieldsDto })
addAccidentFields(
@CurrentUser() registrar: any,
@Param("requestId") requestId: string,
@Body() fields: ExpertAccidentFieldsDto,
) {
return this.requestManagementService.expertAddAccidentFieldsForBlameV2(
registrar,
requestId,
fields,
);
}
@Post("upload-party-signature/:requestId")
// @ApiConsumes("multipart/form-data")
@UseInterceptors(
FileInterceptor("sign", {
limits: { fileSize: DEFAULT_MEDIA_MAX_BYTES },
storage: diskStorage({
destination: "./files/signs",
filename: (req, file, cb) => cb(null, `registrar-party-${Date.now()}${extname(file.originalname)}`),
}),
}),
)
uploadPartySignature(
@CurrentUser() registrar: any,
@Param("requestId") requestId: string,
@Body() body: { partyRole?: string; isAccept?: boolean | string },
@UploadedFile() sign?: Express.Multer.File,
) {
const role =
body.partyRole === "SECOND" ? PartyRole.SECOND : PartyRole.FIRST;
const isAccept = !(body.isAccept === false || body.isAccept === "false");
return this.requestManagementService.expertUploadPartySignatureV2(
registrar,
requestId,
role,
isAccept,
sign!,
);
}
}
@@ -1,417 +0,0 @@
import { extname } from "node:path";
import {
Controller,
Get,
Post,
Body,
Param,
UseGuards,
UseInterceptors,
UploadedFile,
Req,
Put,
UploadedFiles,
} from "@nestjs/common";
import {
FileFieldsInterceptor,
FileInterceptor,
} from "@nestjs/platform-express";
import {
ApiBearerAuth,
ApiBody,
ApiConsumes,
ApiParam,
ApiTags,
ApiOperation,
ApiExcludeController,
} from "@nestjs/swagger";
import { Request } from "express";
import { diskStorage } from "multer";
import { GlobalGuard } from "src/auth/guards/global.guard";
import { RolesGuard } from "src/auth/guards/role.guard";
import { CurrentUser } from "src/decorators/user.decorator";
import { Roles } from "src/decorators/roles.decorator";
import { AddPlateDto } from "src/profile/dto/user/AddPlateDto";
import { RoleEnum } from "src/Types&Enums/role.enum";
import { DEFAULT_MEDIA_MAX_BYTES } from "src/client/client.service";
import { BlameDocumentType } from "./entities/schema/blame-document.schema";
import {
CarBodyFormDto,
CarBodySecondForm,
DescriptionDto,
InitialFormDto,
LocationDto,
} from "./dto/create-request-management.dto";
import { RequestManagementService } from "./request-management.service";
@ApiExcludeController()
@Controller("blame-request-management")
// @ApiTags("blame-request-management")
@ApiBearerAuth()
@UseGuards(GlobalGuard, RolesGuard)
@Roles(RoleEnum.USER)
export class RequestManagementController {
constructor(
private readonly requestManagementService: RequestManagementService,
) {}
// @ApiOperation({ deprecated: true })
// @Post()
// @UseGuards(GlobalGuard)
// async createRequest(
// @CurrentUser() user,
// @Body() createRequestDto: CreateRequestDto,
// ) {
// return await this.requestManagementService.createRequest(
// user,
// createRequestDto.type,
// );
// }
@ApiOperation({ deprecated: true })
@Post("/initial-form/:requestId")
@ApiParam({ name: "requestId" })
@ApiBody({ type: InitialFormDto })
@UseGuards(GlobalGuard)
async initialFrom(
@Body()
body: InitialFormDto,
@CurrentUser() user,
@Param("requestId") requestId,
) {
return await this.requestManagementService.initialFormStep(
body,
user,
requestId,
);
}
@ApiBody({
schema: {
type: "object",
properties: {
file: {
type: "string",
format: "binary",
},
},
},
})
@ApiConsumes("multipart/form-data")
@UseInterceptors(
FileInterceptor("file", {
limits: {
fileSize: DEFAULT_MEDIA_MAX_BYTES,
},
storage: diskStorage({
destination: "./files/video",
filename: (req, file, callback) => {
const unique = Date.now();
const ex = extname(file.originalname);
const filename = `${file.originalname}-${unique}${ex}`;
callback(null, filename);
},
}),
}),
)
@UseGuards(GlobalGuard)
@ApiParam({ name: "requestId" })
@ApiOperation({ deprecated: true })
@Post("upload-video/:requestId")
@UseGuards(GlobalGuard)
async videoUploader(
@Param("requestId") requestId,
@CurrentUser() user,
@UploadedFile() file?: Express.Multer.File,
) {
return await this.requestManagementService.videoUploadStep(
file,
user,
requestId,
);
}
@ApiOperation({ deprecated: true })
@Post("/add-plate/:requestId")
@ApiParam({ name: "requestId" })
@ApiBody({ type: AddPlateDto })
@UseGuards(GlobalGuard)
async addPlate(
@Body()
body: AddPlateDto,
@CurrentUser() user,
@Param("requestId") requestId,
) {
return await this.requestManagementService.addPlateToRequest(
user,
body,
requestId,
);
}
@ApiOperation({ deprecated: true })
@Post("/carbody-form/:requestId")
@ApiParam({ name: "requestId" })
@ApiBody({ type: CarBodyFormDto })
@UseGuards(GlobalGuard)
async carBodyForm(
@Body()
body: CarBodyFormDto,
@CurrentUser() user,
@Param("requestId") requestId,
) {
return await this.requestManagementService.carBodyFormStep(
body,
user,
requestId,
);
}
@ApiOperation({ deprecated: true })
@Post("/carbody-secondform/:requestId")
@ApiParam({ name: "requestId" })
@ApiBody({ type: CarBodySecondForm })
@UseGuards(GlobalGuard)
async carBodySecondForm(
@Body()
body: CarBodySecondForm,
@CurrentUser() user,
@Param("requestId") requestId,
) {
return await this.requestManagementService.carBodySecondForm(
body,
user,
requestId,
);
}
@ApiOperation({ deprecated: true })
@Post("/add-detail-location/:requestId")
@ApiParam({ name: "requestId" })
@ApiBody({ type: LocationDto })
@UseGuards(GlobalGuard)
async addLocation(
@Body()
body: LocationDto,
@CurrentUser() user,
@Param("requestId") requestId,
) {
return await this.requestManagementService.addDetailToRequestLocation(
user.sub,
body,
requestId,
user, // Pass user object for expert verification
);
}
@ApiBody({
schema: {
type: "object",
properties: {
file: {
type: "string",
format: "binary",
},
},
},
})
@ApiConsumes("multipart/form-data")
@UseInterceptors(
FileInterceptor("file", {
limits: {
fileSize: DEFAULT_MEDIA_MAX_BYTES,
},
storage: diskStorage({
destination: "./files/voice",
filename: (req, file, callback) => {
const unique = Date.now();
const ex = extname(file.originalname);
const flname = file.originalname.split(".")[0];
const filename = `${flname}-${unique}${ex}`;
callback(null, filename);
},
}),
}),
)
@ApiParam({ name: "requestId" })
@ApiOperation({ deprecated: true })
@Post("upload-voice/:requestId")
@UseGuards(GlobalGuard)
async voiceUploader(
@Param("requestId") requestId,
@CurrentUser() user,
@UploadedFile() voice?: Express.Multer.File,
) {
return await this.requestManagementService.voiceUploadStep(
user,
voice,
requestId,
);
}
@ApiOperation({ deprecated: true })
@Post("/add-detail-description/:requestId")
@ApiParam({ name: "requestId" })
@ApiBody({ type: DescriptionDto })
@UseGuards(GlobalGuard)
async addDescription(
@Body()
body: DescriptionDto,
@Param("requestId") requestId,
@CurrentUser() user,
) {
return await this.requestManagementService.addDescriptionToRequest(
user,
body,
requestId,
);
}
@ApiOperation({ deprecated: true })
@Post("add-second-party-details/:phoneNumber/:requestId/:frontendRoutes")
@ApiParam({ name: "phoneNumber" })
@ApiParam({ name: "requestId" })
@ApiParam({ name: "frontendRoutes" })
@UseGuards(GlobalGuard)
async addSecondPartyDetailsToRequest(
@Req() req: Request,
@Param("phoneNumber") phoneNumber,
@Param("requestId") requestId,
@Param("frontendRoutes") frontendRoutes,
@CurrentUser() firstPartyUser,
) {
return await this.requestManagementService.addSecondPartyDetailsToRequest(
phoneNumber,
requestId,
firstPartyUser,
frontendRoutes,
req,
);
}
@ApiOperation({ deprecated: true })
@Get("requests")
async requests(@CurrentUser() user) {
return await this.requestManagementService.myRequests(user.username);
}
@ApiOperation({ deprecated: true })
@Get("creatable-claims")
@UseGuards(GlobalGuard)
async getCreatableClaims(@CurrentUser() user) {
return await this.requestManagementService.getCreatableClaims(user);
}
@ApiOperation({ deprecated: true })
@Get("request/:requestId")
@ApiParam({ name: "requestId" })
@Roles(RoleEnum.USER)
async checkParties(@CurrentUser() user, @Param("requestId") requestId) {
return await this.requestManagementService.requestDetails(user, requestId);
}
@ApiBody({
schema: {
type: "object",
properties: {
sign: {
type: "string",
format: "binary",
},
isAccept: {
type: "Boolean",
},
},
},
})
@ApiConsumes("multipart/form-data")
@UseInterceptors(
FileInterceptor("sign", {
limits: {
fileSize: DEFAULT_MEDIA_MAX_BYTES,
},
storage: diskStorage({
destination: "./files/signs",
filename: (req, file, callback) => {
const unique = Date.now();
const ex = extname(file.originalname);
const filename = `${file.originalname.split(/[.,\s-]/)[0]}-${unique}${ex}`;
callback(null, filename);
},
}),
}),
)
@ApiOperation({ deprecated: true })
@Put("request/reply/:requestId")
@ApiParam({ name: "requestId" })
@UseGuards(GlobalGuard)
async userReply(
@Body("isAccept") isAccept: boolean,
@Param("requestId") requestId: string,
@CurrentUser() user,
@UploadedFile() sign?: Express.Multer.File,
) {
const props = { requestId, user };
return await this.requestManagementService.userReply(
props,
Boolean(isAccept),
sign,
);
}
@ApiBody({
schema: {
type: "object",
properties: {
nationalCertificate: { type: "string", format: "binary" },
carCertificate: { type: "string", format: "binary" },
drivingLicense: { type: "string", format: "binary" },
carGreenCard: { type: "string", format: "binary" },
voice: { type: "string", format: "binary" },
description: { type: "string" },
},
},
})
@ApiConsumes("multipart/form-data")
@UseInterceptors(
FileFieldsInterceptor(
[
{ name: "nationalCertificate", maxCount: 1 },
{ name: "carCertificate", maxCount: 1 },
{ name: "drivingLicense", maxCount: 1 },
{ name: "carGreenCard", maxCount: 1 },
{ name: "voice", maxCount: 1 },
],
{
limits: { fileSize: DEFAULT_MEDIA_MAX_BYTES },
storage: diskStorage({
destination: "./files/blame-resend-docs",
filename: (req, file, callback) => {
const unique = Date.now();
const ex = extname(file.originalname);
const filename = `${file.fieldname}-${unique}${ex}`;
callback(null, filename);
},
}),
},
),
)
@UseGuards(GlobalGuard)
@ApiParam({ name: "requestId" })
@ApiOperation({ deprecated: true })
@Put("request/resend/:requestId")
userResendReply(
@Body("description") description: string,
@Param("requestId") requestId: string,
@CurrentUser() user: any,
@UploadedFiles()
files: { [key in BlameDocumentType | "voice"]?: Express.Multer.File[] },
) {
return this.requestManagementService.userResend(
files,
user,
requestId,
description,
);
}
}
@@ -39,7 +39,9 @@ describe("RequestManagementService FileReviewer inbox", () => {
find: jest.fn().mockResolvedValue([]),
};
(service as any).fanavaranLocationService = {
assertMakerReviewerBranchCompatible: jest.fn().mockResolvedValue(undefined),
assertMakerReviewerBranchCompatible: jest
.fn()
.mockResolvedValue(undefined),
};
return { service, blameRequestDbService };
}
@@ -94,10 +96,11 @@ describe("RequestManagementService FileReviewer inbox", () => {
it("does not list an open file from another branch", async () => {
const { service } = createService([sealedFile]);
(service as any).fanavaranLocationService
.assertMakerReviewerBranchCompatible.mockRejectedValue(
new Error("This file belongs to another branch."),
);
(
service as any
).fanavaranLocationService.assertMakerReviewerBranchCompatible.mockRejectedValue(
new Error("This file belongs to another branch."),
);
const result = await service.getMyFileReviewerFiles({
sub: String(reviewerId),
@@ -137,10 +140,12 @@ describe("RequestManagementService FileReviewer inbox", () => {
it("does not expose an open file's details to a reviewer from another tenant", async () => {
const { service } = createService([]);
(service as any).blameRequestDbService.findById = jest.fn().mockResolvedValue({
...sealedFile,
parties: [{ role: "FIRST", person: { clientId: otherClientId } }],
});
(service as any).blameRequestDbService.findById = jest
.fn()
.mockResolvedValue({
...sealedFile,
parties: [{ role: "FIRST", person: { clientId: otherClientId } }],
});
await expect(
service.getMyFileReviewerFileDetail(
@@ -225,16 +230,11 @@ describe("RequestManagementService FileReviewer inbox", () => {
}),
findOneAndUpdate: jest.fn(),
};
const expertClaimService = new (ExpertClaimService as any)(
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
blameRequestDbService,
const expertClaimService = Object.assign(
Object.create(ExpertClaimService.prototype),
{
blameRequestDbService,
},
) as ExpertClaimService;
await expect(
@@ -31,19 +31,23 @@ import {
BlameVoiceSchema,
BlameVoicesModel,
} from "./entities/schema/blame-voice.schema";
import { BlameDocumentModel, BlameDocumentSchema } from "./entities/schema/blame-document.schema";
import { BlameRequest, BlameRequestSchema } from "./entities/schema/blame-cases.schema";
import {
BlameDocumentModel,
BlameDocumentSchema,
} from "./entities/schema/blame-document.schema";
import {
BlameRequest,
BlameRequestSchema,
} from "./entities/schema/blame-cases.schema";
import {
RequestManagementModel,
RequestManagementSchema,
} from "./entities/schema/request-management.schema";
import { RequestManagementService } from "./request-management.service";
import { RequestManagementController } from "./request-management.controller";
import { RequestManagementV2Controller } from "./request-management.v2.controller";
import { ExpertInitiatedController } from "./expert-initiated.controller";
import { ExpertInitiatedV2Controller } from "./expert-initiated.v2.controller";
import { ExpertInitiatedBlameMirrorController } from "./expert-initiated-blame.mirror.controller";
import { RegistrarInitiatedController } from "./registrar-initiated.controller";
import { RegistrarBlameMirrorController } from "./registrar-blame.mirror.controller";
import { ExpertInitiatedBlameV3MirrorController } from "./expert-initiated-blame-v3.mirror.controller";
import { FileMakerBlameV4Controller } from "./file-maker-blame-v4.controller";
@@ -85,13 +89,11 @@ import { CallCenterBlameV6Controller } from "./call-center-blame-v6.controller";
MediaPolicyModule,
],
controllers: [
RequestManagementController,
RequestManagementV2Controller,
ExpertInitiatedController,
ExpertInitiatedV2Controller,
ExpertInitiatedBlameMirrorController,
ExpertInitiatedBlameV3MirrorController,
RegistrarInitiatedController,
RegistrarBlameMirrorController,
FileMakerBlameV4Controller,
FileReviewerBlameV4Controller,
File diff suppressed because it is too large Load Diff
@@ -141,6 +141,30 @@ describe("user blame next action and claim eligibility", () => {
expect(service.claimCaseDbService.findOne).not.toHaveBeenCalled();
});
it("shows an existing claim as actionable only to its beneficiary", async () => {
const service = subject();
for (const [viewer, nextAction] of [
[guiltyId, "VIEW_RESULT"],
[damagedId, "CONTINUE_CLAIM"],
]) {
const hint = await service.computeClaimCreationHintForViewer(
blame(),
{ sub: viewer },
{ _id: blameId },
);
expect(resolveBlameUserNextAction("COMPLETED", {}, hint)).toBe(
nextAction,
);
}
const unknown = blame({ expert: { decision: { guiltyPartyId: blameId } } });
const hint = await service.computeClaimCreationHintForViewer(
unknown,
{ sub: damagedId },
null,
);
expect(hint.shouldGuideToCreateClaim).toBe(false);
});
it("permits a completed body-insurance claim only for its own party", async () => {
const service = subject();
const body = blame({
@@ -172,15 +196,13 @@ describe("user blame next action and claim eligibility", () => {
it("keeps identity filters working but omits private/search-only fields in list responses", async () => {
const service = subject();
service.blameRequestDbService = {
find: jest
.fn()
.mockResolvedValue([
blame({
__v: 42,
inquiries: { raw: "private" },
initiatedByFieldExpertId: guiltyId,
}),
]),
find: jest.fn().mockResolvedValue([
blame({
__v: 42,
inquiries: { raw: "private" },
initiatedByFieldExpertId: guiltyId,
}),
]),
};
const response = await service.getAllBlameRequestsV2(
{ sub: damagedId, role: RoleEnum.USER },