Add case identity filters and description validation

This commit is contained in:
SepehrYahyaee
2026-09-27 09:54:56 +03:30
parent 8ac185c861
commit b758346af1
15 changed files with 339 additions and 13 deletions

View File

@@ -211,6 +211,19 @@ export class RequestManagementService {
}
/** Keep eligibility rejections distinct from an unavailable CAR_BODY provider. */
private assertCarBodyDescriptionMinimum(
requestType: BlameRequestType | string | undefined,
description: unknown,
): void {
if (requestType !== BlameRequestType.CAR_BODY) return;
const length = String(description ?? "").trim().length;
if (length < 100) {
throw new BadRequestException(
"CAR_BODY description must contain at least 100 non-whitespace characters.",
);
}
}
private throwCarBodyInquiryFailure(
err: unknown,
context: "carBodyPlate" | "carBodyVin" = "carBodyPlate",
@@ -2021,6 +2034,7 @@ export class RequestManagementService {
party.person.nationalCodeOfDriver = body.nationalCodeOfDriver;
party.person.insurerLicense = body.insurerLicense;
party.person.driverLicense = body.driverLicense;
party.person.driverLicenseDate = body.driverLicenseDate;
party.person.driverIsInsurer = body.driverIsInsurer;
party.person.isNewCar = body.isNewCar;
party.person.userNoCertificate = body.userNoCertificate;
@@ -2448,6 +2462,7 @@ export class RequestManagementService {
party.person.nationalCodeOfDriver = body.nationalCodeOfDriver;
party.person.insurerLicense = body.insurerLicense;
party.person.driverLicense = body.driverLicense;
party.person.driverLicenseDate = body.driverLicenseDate;
party.person.driverIsInsurer = body.driverIsInsurer;
party.person.isNewCar = body.isNewCar;
party.person.userNoCertificate = body.userNoCertificate;
@@ -2817,6 +2832,8 @@ export class RequestManagementService {
this.isBlameOnBehalfActor(req, user),
);
this.assertCarBodyDescriptionMinimum(req.type, body.desc);
// Set userId for party if not already set (important for second party)
if (!party.person) party.person = {} as any;
if (
@@ -4120,6 +4137,8 @@ export class RequestManagementService {
throw new NotFoundException("Request not found");
}
this.assertCarBodyDescriptionMinimum(request.type, body.desc);
// --- First Party Flow ---
if (request.firstPartyDetails.firstPartyId == user.sub) {
// Build base update payload with proper MongoDB operators
@@ -6611,11 +6630,26 @@ export class RequestManagementService {
);
const obj = req.toObject();
const partyIdentities = Array.isArray(req.parties)
? req.parties.map((entry: any) => ({
phoneNumber: entry?.person?.phoneNumber,
nationalCode: entry?.person?.nationalCode,
nationalCodeOfInsurer: entry?.person?.nationalCodeOfInsurer,
nationalCodeOfDriver: entry?.person?.nationalCodeOfDriver,
inquiryParticipants: Array.isArray(entry?.inquiryParticipants)
? entry.inquiryParticipants.map((participant: any) => ({
phoneNumber: participant?.phoneNumber,
nationalCode: participant?.nationalCode,
}))
: undefined,
}))
: [];
delete obj.parties;
return {
...obj,
partyIdentities,
userSide: party?.role ?? null,
initiatedByMe: isInitiator,
unifiedFileStatus: resolveUnifiedFileStatus({
@@ -7091,9 +7125,10 @@ export class RequestManagementService {
if (!formData.carBodyForm) {
throw new BadRequestException("carBodyForm is required.");
}
if (!formData?.expertDescription?.desc) {
throw new BadRequestException("expertDescription.desc is required.");
}
this.assertCarBodyDescriptionMinimum(
req.type,
formData?.expertDescription?.desc,
);
const firstPartyUserId = await this.getOrCreateUserByPhoneNumber(
formData.firstPartyPhoneNumber,
@@ -7272,6 +7307,7 @@ export class RequestManagementService {
nationalCodeOfDriver: firstPartyPlate.nationalCodeOfDriver,
insurerLicense: firstPartyPlate.insurerLicense,
driverLicense: firstPartyPlate.driverLicense,
driverLicenseDate: firstPartyPlate.driverLicenseDate,
driverIsInsurer: firstPartyPlate.driverIsInsurer,
isNewCar: firstPartyPlate.isNewCar,
userNoCertificate: firstPartyPlate.userNoCertificate,
@@ -7560,6 +7596,7 @@ export class RequestManagementService {
nationalCodeOfDriver: plateDto.nationalCodeOfDriver,
insurerLicense: plateDto.insurerLicense,
driverLicense: plateDto.driverLicense,
driverLicenseDate: plateDto.driverLicenseDate,
driverIsInsurer: plateDto.driverIsInsurer,
isNewCar: plateDto.isNewCar,
userNoCertificate: plateDto.userNoCertificate,
@@ -8286,6 +8323,7 @@ export class RequestManagementService {
carName: sandHubReport?.MapTypNam || sandHubReport?.CarName,
insurerBirthday: firstPartyPlate.insurerBirthday,
driverBirthday: firstPartyPlate.driverBirthday,
driverLicenseDate: firstPartyPlate.driverLicenseDate,
carType: `${sandHubReport?.UsageField || ""} / ${sandHubReport?.MapUsageName || "-"}`,
isNewCar: firstPartyPlate.isNewCar,
};
@@ -8632,6 +8670,11 @@ export class RequestManagementService {
);
}
this.assertCarBodyDescriptionMinimum(
request.type,
formData.firstPartyDescription?.desc,
);
this.assertAccidentDateTimeNotInFuture({
accidentDate: formData.firstPartyDescription?.accidentDate,
accidentTime: formData.firstPartyDescription?.accidentTime,
@@ -8772,6 +8815,7 @@ export class RequestManagementService {
carName: sandHubReport?.MapTypNam || sandHubReport?.CarName,
insurerBirthday: firstPartyPlate.insurerBirthday,
driverBirthday: firstPartyPlate.driverBirthday,
driverLicenseDate: firstPartyPlate.driverLicenseDate,
carType: `${sandHubReport?.UsageField || ""} / ${sandHubReport?.MapUsageName || "-"}`,
isNewCar: firstPartyPlate.isNewCar,
};
@@ -10107,6 +10151,8 @@ export class RequestManagementService {
party.person.insurerLicense = partyData.insurerLicense;
if (partyData.driverLicense)
party.person.driverLicense = partyData.driverLicense;
if ((partyData as any).driverLicenseDate)
party.person.driverLicenseDate = (partyData as any).driverLicenseDate;
if ((partyData as any).licenseType)
(party.person as any).licenseType = (partyData as any).licenseType;
@@ -11015,6 +11061,8 @@ export class RequestManagementService {
party.person.insurerLicense = partyData.insurerLicense;
if (partyData.driverLicense)
party.person.driverLicense = partyData.driverLicense;
if ((partyData as any).driverLicenseDate)
party.person.driverLicenseDate = (partyData as any).driverLicenseDate;
if ((partyData as any).licenseType)
(party.person as any).licenseType = (partyData as any).licenseType;
@@ -11829,6 +11877,7 @@ export class RequestManagementService {
await this.verifyExpertAccessForBlameV2(req, actor);
const role = this.resolvePartyRoleV3(req, partyRole);
this.assertBlameV3PartyDetailPhase(req, role);
this.assertCarBodyDescriptionMinimum(req.type, body.desc);
// accidentDate and accidentTime are only required for the first (guilty)
// party — the second (damaged) party can skip them.
@@ -13198,6 +13247,7 @@ export class RequestManagementService {
driverBirthday: p.person?.driverBirthday,
insurerLicense: p.person?.insurerLicense,
driverLicense: p.person?.driverLicense,
driverLicenseDate: p.person?.driverLicenseDate,
userId: p.person?.userId ? String(p.person.userId) : undefined,
clientId: p.person?.clientId ? String(p.person.clientId) : undefined,
licenseType: p.person?.licenseType ?? undefined,
@@ -13440,6 +13490,7 @@ export class RequestManagementService {
driverBirthday: p.person?.driverBirthday,
insurerLicense: p.person?.insurerLicense,
driverLicense: p.person?.driverLicense,
driverLicenseDate: p.person?.driverLicenseDate,
userId: p.person?.userId ? String(p.person.userId) : undefined,
clientId: p.person?.clientId ? String(p.person.clientId) : undefined,
licenseType: p.person?.licenseType ?? undefined,