forked from Yara724/api
fix(workflows): resolve QA blockers and protect case evidence
Fix registrar signing, reviewer re-entry, replacement evidence freshness, owner decision and rating races, multipart objections, vehicle serialization and product reporting. Validate uploaded media with FFmpeg, serve evidence through expiring signed links, and add targeted regressions plus a dry-run repair for prematurely completed visit cases.
This commit is contained in:
@@ -234,9 +234,9 @@ describe("V6 call-center workflow", () => {
|
||||
Object.assign(body, {
|
||||
accidentDate: "1405/08/18",
|
||||
accidentTime: "12:00",
|
||||
weatherCondition: 1,
|
||||
roadCondition: 1,
|
||||
lightCondition: 1,
|
||||
weatherCondition: "صاف",
|
||||
roadCondition: "خشک",
|
||||
lightCondition: "روز",
|
||||
});
|
||||
await service.addDescriptionV2(id, body, first);
|
||||
if (type === Kind.THIRD_PARTY) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { extname } from "node:path";
|
||||
import {
|
||||
BadRequestException,
|
||||
@@ -382,7 +383,7 @@ export class FileReviewerBlameV4Controller {
|
||||
storage: diskStorage({
|
||||
destination: "./files/claim-sign",
|
||||
filename: (req, file, callback) => {
|
||||
const unique = Date.now();
|
||||
const unique = randomUUID();
|
||||
const ex = extname(file.originalname);
|
||||
const base = file.originalname.split(/[.,\s-]/)[0] || "sign";
|
||||
callback(null, `${base}-${unique}${ex}`);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { extname } from "node:path";
|
||||
import {
|
||||
Body,
|
||||
@@ -380,7 +381,7 @@ export class FileReviewerBlameV5Controller {
|
||||
storage: diskStorage({
|
||||
destination: "./files/claim-sign",
|
||||
filename: (req, file, callback) => {
|
||||
const unique = Date.now();
|
||||
const unique = randomUUID();
|
||||
const ex = extname(file.originalname);
|
||||
const base = file.originalname.split(/[.,\s-]/)[0] || "sign";
|
||||
callback(null, `${base}-${unique}${ex}`);
|
||||
|
||||
@@ -393,18 +393,6 @@ export class RegistrarBlameMirrorController {
|
||||
@CurrentUser() registrar: any,
|
||||
@UploadedFile() sign: Express.Multer.File,
|
||||
) {
|
||||
// Guard: accident fields must be filled before signing to prevent the
|
||||
// double-sign bug where add-accident-fields re-enters WAITING_FOR_SIGNATURES.
|
||||
const requestData = await this.requestManagementService.getBlameRequestV2(
|
||||
requestId,
|
||||
registrar,
|
||||
);
|
||||
if (!(requestData?.expert?.decision as any)?.fields?.accidentWay) {
|
||||
throw new BadRequestException(
|
||||
"Accident fields (accidentWay, accidentReason, accidentType) must be submitted via add-accident-fields before signing.",
|
||||
);
|
||||
}
|
||||
|
||||
await this.mediaPolicyService.assertForBlame(sign, requestId, "image");
|
||||
const partyRole =
|
||||
body?.partyRole === "SECOND" ? PartyRole.SECOND : PartyRole.FIRST;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { WeatherCondition, RoadCondition, LightCondition } from "src/Types&Enums/blame-request-management/accident-conditions.enum";
|
||||
import { UserClaimBranchService, userClaimBranchContext, usesUserClaimBranch } from "src/client/user-claim-branch.service";
|
||||
import { normalizeAccidentLocation } from "./accident-location";
|
||||
import {
|
||||
@@ -215,6 +216,13 @@ export class RequestManagementService {
|
||||
}
|
||||
|
||||
/** Keep eligibility rejections distinct from an unavailable CAR_BODY provider. */
|
||||
private assertAccidentConditions(body: {weatherCondition?: unknown; roadCondition?: unknown; lightCondition?: unknown}): void {
|
||||
for (const [value, choices] of [[body.weatherCondition, WeatherCondition], [body.roadCondition, RoadCondition], [body.lightCondition, LightCondition]] as const) {
|
||||
if (value != null && !Object.values(choices).includes(value as never))
|
||||
throw new BadRequestException("شرایط آبوهوا، راه یا روشنایی حادثه معتبر نیست. گزینههای فرم را دوباره انتخاب کنید.");
|
||||
}
|
||||
}
|
||||
|
||||
private assertCarBodyDescriptionMinimum(
|
||||
requestType: BlameRequestType | string | undefined,
|
||||
description: unknown,
|
||||
@@ -2910,6 +2918,7 @@ export class RequestManagementService {
|
||||
);
|
||||
|
||||
this.assertCarBodyDescriptionMinimum(req.type, body.desc);
|
||||
this.assertAccidentConditions(body as DescriptionDto);
|
||||
|
||||
// Set userId for party if not already set (important for second party)
|
||||
if (!party.person) party.person = {} as any;
|
||||
@@ -5075,6 +5084,7 @@ export class RequestManagementService {
|
||||
formData?.expertDescription?.desc,
|
||||
);
|
||||
|
||||
this.assertAccidentConditions(formData?.expertDescription ?? {});
|
||||
const firstPartyUserId = await this.getOrCreateUserByPhoneNumber(
|
||||
formData.firstPartyPhoneNumber,
|
||||
);
|
||||
@@ -5399,6 +5409,7 @@ export class RequestManagementService {
|
||||
throw new BadRequestException("expertDescription.desc is required.");
|
||||
}
|
||||
|
||||
this.assertAccidentConditions(formData?.expertDescription ?? {});
|
||||
const firstPartyUserId = await this.getOrCreateUserByPhoneNumber(
|
||||
formData.firstPartyPhoneNumber,
|
||||
);
|
||||
@@ -5846,7 +5857,7 @@ export class RequestManagementService {
|
||||
const req = await this.blameRequestDbService.findById(requestId);
|
||||
if (!req) throw new NotFoundException("Request not found");
|
||||
if (
|
||||
!req.expertInitiated ||
|
||||
(!req.expertInitiated && !req.registrarInitiated) ||
|
||||
req.creationMethod !== CreationMethod.IN_PERSON
|
||||
) {
|
||||
throw new BadRequestException(
|
||||
@@ -5889,7 +5900,7 @@ export class RequestManagementService {
|
||||
const signatureData = {
|
||||
fileId: String((signDoc as any)._id),
|
||||
fileName: signFile.filename,
|
||||
fileUrl: signFile.path,
|
||||
fileUrl: buildFileLink(signFile.path),
|
||||
};
|
||||
const updatePayload: any = {
|
||||
$set: {
|
||||
@@ -6578,7 +6589,7 @@ export class RequestManagementService {
|
||||
const signatureData = {
|
||||
fileId: String((signDoc as any)._id),
|
||||
fileName: signFile.filename,
|
||||
fileUrl: signFile.path,
|
||||
fileUrl: buildFileLink(signFile.path),
|
||||
};
|
||||
|
||||
const confirmationPayload = {
|
||||
@@ -8203,7 +8214,7 @@ export class RequestManagementService {
|
||||
const signatureData = {
|
||||
fileId: String((signDoc as any)._id),
|
||||
fileName: signFile.filename,
|
||||
fileUrl: signFile.path,
|
||||
fileUrl: buildFileLink(signFile.path),
|
||||
};
|
||||
|
||||
await this.blameRequestDbService.findByIdAndUpdate(requestId, {
|
||||
@@ -8700,6 +8711,7 @@ export class RequestManagementService {
|
||||
const role = this.resolvePartyRoleV3(req, partyRole);
|
||||
this.assertBlameV3PartyDetailPhase(req, role);
|
||||
this.assertCarBodyDescriptionMinimum(req.type, body.desc);
|
||||
this.assertAccidentConditions(body as DescriptionDto);
|
||||
|
||||
// accidentDate and accidentTime are only required for the first (guilty)
|
||||
// party — the second (damaged) party can skip them.
|
||||
@@ -8724,8 +8736,6 @@ export class RequestManagementService {
|
||||
const idx = this.getPartyIndex(req, role);
|
||||
if (idx === -1) throw new BadRequestException(`${role} party not found`);
|
||||
|
||||
this.assertCarBodyDescriptionMinimum(req.type, body.desc);
|
||||
|
||||
const party = req.parties[idx];
|
||||
if (req.type === BlameRequestType.CAR_BODY && role === PartyRole.FIRST) {
|
||||
await this.validateCarBodyAccidentCoverage(party, body.accidentDate);
|
||||
|
||||
Reference in New Issue
Block a user