forked from Yara724/api
Added vin inquiry for v6, fixed new damaged part for v4
This commit is contained in:
@@ -10953,6 +10953,97 @@ export class RequestManagementService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* V6 VIN variant: Run VIN/chassis inquiry for the guilty party on behalf of the caller.
|
||||
* Identical to `runCallCenterInquiryV6` but calls `runPartyInquiriesVinV3Internal`
|
||||
* (ESG chassis lookup) instead of the plate-based path.
|
||||
* Returns `vehicle.vin` in the guiltyParty payload instead of `vehicle.plateId`.
|
||||
*/
|
||||
async runCallCenterInquiryVinV6(
|
||||
agent: any,
|
||||
requestId: string,
|
||||
dto: Omit<RunInquiriesVinV3Dto, "sheba">,
|
||||
): Promise<Record<string, unknown>> {
|
||||
if (agent?.role !== RoleEnum.CALL_CENTER) {
|
||||
throw new ForbiddenException("Only call-center agents can use this endpoint.");
|
||||
}
|
||||
const req = await this.blameRequestDbService.findById(requestId);
|
||||
if (!req) throw new NotFoundException("Blame request not found");
|
||||
if (!req.callCenterInitiated || String(req.initiatedByCallCenterId) !== String(agent.sub)) {
|
||||
throw new ForbiddenException("You can only access files that you have initiated.");
|
||||
}
|
||||
|
||||
const firstIdx = this.getPartyIndex(req, PartyRole.FIRST);
|
||||
if (firstIdx === -1) throw new BadRequestException("First party not found");
|
||||
const firstParty = req.parties[firstIdx];
|
||||
|
||||
await this.runPartyInquiriesVinV3Internal(req, dto as RunInquiriesVinV3Dto, PartyRole.FIRST, firstParty);
|
||||
|
||||
// Same insurer-company guard as the plate variant.
|
||||
const resolvedClientId = req.parties[firstIdx]?.person?.clientId;
|
||||
if (resolvedClientId && process.env.CLIENT_ID) {
|
||||
const resolvedClient = await this.clientService.findOne({
|
||||
_id: new Types.ObjectId(String(resolvedClientId)),
|
||||
});
|
||||
if (
|
||||
resolvedClient &&
|
||||
String(resolvedClient.clientCode) !== String(process.env.CLIENT_ID)
|
||||
) {
|
||||
throw new ForbiddenException(
|
||||
"بیمهنامه طرف مقصر متعلق به شرکت بیمه این سامانه نیست. لینک تقصیر فقط برای بیمهگذاران همین شرکت قابل ارسال است.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Array.isArray((req as any).history)) (req as any).history = [];
|
||||
(req as any).history.push({
|
||||
type: "CALL_CENTER_INQUIRY_COMPLETED",
|
||||
actor: {
|
||||
actorId: new Types.ObjectId(agent.sub),
|
||||
actorName: `${agent.firstName || ""} ${agent.lastName || ""}`.trim(),
|
||||
actorType: RoleEnum.CALL_CENTER,
|
||||
},
|
||||
metadata: { partyRole: PartyRole.FIRST, inquiryType: "VIN" },
|
||||
});
|
||||
await (req as any).save();
|
||||
|
||||
const firstPartyAfter = req.parties[firstIdx];
|
||||
return {
|
||||
blameRequestId: requestId,
|
||||
publicId: (req as any).publicId,
|
||||
type: (req as any).type,
|
||||
status: (req as any).status,
|
||||
message: "استعلام VIN طرف مقصر با موفقیت انجام شد. اکنون میتوانید لینک تقصیر را برای کاربر ارسال کنید.",
|
||||
guiltyParty: {
|
||||
vehicle: firstPartyAfter?.vehicle
|
||||
? {
|
||||
vin: firstPartyAfter.vehicle.vin,
|
||||
name: firstPartyAfter.vehicle.name,
|
||||
type: firstPartyAfter.vehicle.type,
|
||||
}
|
||||
: undefined,
|
||||
insurance: firstPartyAfter?.insurance
|
||||
? {
|
||||
company: firstPartyAfter.insurance.company,
|
||||
policyNumber: firstPartyAfter.insurance.policyNumber,
|
||||
startDate: firstPartyAfter.insurance.startDate,
|
||||
endDate: firstPartyAfter.insurance.endDate,
|
||||
financialCeiling: (firstPartyAfter.insurance as any).financialCeiling,
|
||||
}
|
||||
: undefined,
|
||||
person: firstPartyAfter?.person
|
||||
? {
|
||||
nationalCodeOfInsurer: firstPartyAfter.person.nationalCodeOfInsurer,
|
||||
nationalCodeOfDriver: firstPartyAfter.person.nationalCodeOfDriver,
|
||||
driverIsInsurer: firstPartyAfter.person.driverIsInsurer,
|
||||
insurerBirthday: formatJalaliCompact(firstPartyAfter.person.insurerBirthday),
|
||||
driverBirthday: formatJalaliCompact(firstPartyAfter.person.driverBirthday),
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* V6: Send the blame link to the guilty party's phone number.
|
||||
* Registers/looks up the user by phone and stores them as the first party, then
|
||||
@@ -11134,6 +11225,7 @@ export class RequestManagementService {
|
||||
vehicle: p.vehicle
|
||||
? {
|
||||
plateId: p.vehicle.plateId,
|
||||
vin: p.vehicle.vin,
|
||||
name: p.vehicle.name,
|
||||
type: p.vehicle.type,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user