forked from Yara724/api
Added vin inquiry for v6, fixed new damaged part for v4
This commit is contained in:
@@ -20,7 +20,10 @@ 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 { RunCallCenterInquiryV6Dto } from "./dto/run-call-center-inquiry-v6.dto";
|
||||
import {
|
||||
RunCallCenterInquiryV6Dto,
|
||||
RunCallCenterInquiryVinV6Dto,
|
||||
} from "./dto/run-call-center-inquiry-v6.dto";
|
||||
|
||||
/**
|
||||
* V6 call-center blame API.
|
||||
@@ -105,6 +108,27 @@ export class CallCenterBlameV6Controller {
|
||||
return this.requestManagementService.runCallCenterInquiryV6(agent, requestId, dto);
|
||||
}
|
||||
|
||||
@Post("run-inquiry-vin/:requestId")
|
||||
@ApiOperation({
|
||||
summary: "[V6] Run VIN/chassis inquiry for the guilty party",
|
||||
description:
|
||||
"VIN alternative to `run-inquiry`. " +
|
||||
"The agent supplies the chassis number and personal data collected from the caller. " +
|
||||
"ESG chassis lookup (`policyByChassis`) is executed and the result is stored on the " +
|
||||
"blame document under `vehicle.vin` (plateId is left empty). " +
|
||||
"Identical eligibility guards and insurer-company validation as the plate variant. " +
|
||||
"After this call, proceed to `send-link` exactly as in the plate flow.",
|
||||
})
|
||||
@ApiParam({ name: "requestId", description: "Blame request ID from `create`" })
|
||||
@ApiBody({ type: RunCallCenterInquiryVinV6Dto })
|
||||
runInquiryVin(
|
||||
@CurrentUser() agent: any,
|
||||
@Param("requestId") requestId: string,
|
||||
@Body() dto: RunCallCenterInquiryVinV6Dto,
|
||||
) {
|
||||
return this.requestManagementService.runCallCenterInquiryVinV6(agent, requestId, dto);
|
||||
}
|
||||
|
||||
@Post("send-link/:requestId")
|
||||
@ApiOperation({
|
||||
summary: "[V6] Send blame link to the guilty party via SMS",
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
MaxLength,
|
||||
ValidateNested,
|
||||
} from "class-validator";
|
||||
import { Type } from "class-transformer";
|
||||
@@ -83,3 +84,60 @@ export class RunCallCenterInquiryV6Dto {
|
||||
@IsString()
|
||||
insurerLicense?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* VIN / chassis variant of the V6 call-center inquiry.
|
||||
* Identical to `RunCallCenterInquiryV6Dto` but replaces `plate` with `vin`.
|
||||
* Sheba (IBAN) is intentionally absent — the user provides it themselves via the link.
|
||||
*/
|
||||
export class RunCallCenterInquiryVinV6Dto {
|
||||
@ApiProperty({
|
||||
example: "NAAM01E15HK123456",
|
||||
description: "17-character VIN / chassis number (شماره شاسی)",
|
||||
maxLength: 17,
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MaxLength(17)
|
||||
vin: string;
|
||||
|
||||
@ApiProperty({ example: "1234567890", description: "National code of the policyholder (insurer)" })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
nationalCodeOfInsurer: string;
|
||||
|
||||
@ApiProperty({ example: "1234567890", description: "National code of the driver" })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
nationalCodeOfDriver: string;
|
||||
|
||||
@ApiProperty({ example: true, description: "Whether the driver is the same person as the insurer" })
|
||||
@IsBoolean()
|
||||
driverIsInsurer: boolean;
|
||||
|
||||
@ApiProperty({ example: 13780624, description: "Insurer birth date (Jalali)" })
|
||||
insurerBirthday: number | string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
example: 13780624,
|
||||
description: "Driver birth date (Jalali). Required when driverIsInsurer is false.",
|
||||
})
|
||||
@IsOptional()
|
||||
driverBirthday?: number | string | null;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
example: "123456789",
|
||||
description: "Driver license (required when driverIsInsurer is false).",
|
||||
})
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
driverLicense?: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
example: "123456789",
|
||||
description: "Insurer license (required when driverIsInsurer is true).",
|
||||
})
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
insurerLicense?: string;
|
||||
}
|
||||
|
||||
@@ -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