forked from Yara724/api
Fixed type fixes and errors
This commit is contained in:
@@ -38,8 +38,8 @@ export class Person {
|
||||
@Prop({ type: Boolean })
|
||||
userNoCertificate?: boolean;
|
||||
|
||||
@Prop({ type: Number })
|
||||
insurerBirthday?: number;
|
||||
@Prop({ type: String })
|
||||
insurerBirthday?: string;
|
||||
|
||||
@Prop({ type: String })
|
||||
driverBirthday?: string | null;
|
||||
@@ -90,7 +90,7 @@ export class Vehicle {
|
||||
@Prop() name?: string;
|
||||
@Prop() model?: string;
|
||||
@Prop() type?: string;
|
||||
@Prop() isNew?: boolean;
|
||||
@Prop({ type: Boolean }) isNewCar?: boolean;
|
||||
@Prop({ enum: ["CURRENT", "RECENTLY_TRANSFERRED"] })
|
||||
registrationState?: "CURRENT" | "RECENTLY_TRANSFERRED";
|
||||
@Prop() previousPlateId?: string;
|
||||
|
||||
118
src/request-management/inquiry-participant-persistence.spec.ts
Normal file
118
src/request-management/inquiry-participant-persistence.spec.ts
Normal file
@@ -0,0 +1,118 @@
|
||||
import { model, Types } from "mongoose";
|
||||
import { BlameRequestType } from "src/Types&Enums/blame-request-management/blameRequestType.enum";
|
||||
import {
|
||||
BlameRequest,
|
||||
BlameRequestSchema,
|
||||
} from "./entities/schema/blame-cases.schema";
|
||||
import { PartyRole } from "./entities/schema/partyRole.enum";
|
||||
import { normalizeInquirySubmission } from "./inquiry-participant-resolver";
|
||||
|
||||
describe("inquiry participant persistence", () => {
|
||||
it("accepts slash-formatted Jalali birthdays from the structured payload", () => {
|
||||
const submission = normalizeInquirySubmission(
|
||||
BlameRequestType.THIRD_PARTY,
|
||||
{
|
||||
driver: {
|
||||
nationalCode: "0022324224",
|
||||
birthday: "1378/04/26",
|
||||
hasDrivingLicense: true,
|
||||
licenseNumber: "1001011111",
|
||||
licenseType: "10",
|
||||
},
|
||||
vehicleOwner: {
|
||||
nationalCode: "5560568341",
|
||||
birthday: "1378/06/27",
|
||||
},
|
||||
thirdPartyPolicyholder: { sameAs: "VEHICLE_OWNER" },
|
||||
vehicle: {
|
||||
registrationState: "CURRENT",
|
||||
currentPlate: {
|
||||
leftDigits: "59",
|
||||
centerAlphabet: "ی",
|
||||
centerDigits: "419",
|
||||
ir: "78",
|
||||
},
|
||||
isNewCar: false,
|
||||
},
|
||||
},
|
||||
);
|
||||
const BlameRequestModel = model<BlameRequest>(
|
||||
"InquiryParticipantBirthdayPersistenceTest",
|
||||
BlameRequestSchema,
|
||||
);
|
||||
const request = new BlameRequestModel({
|
||||
requestNo: "BL-PARTICIPANT-BIRTHDAY",
|
||||
publicId: "PARTICIPANT-BIRTHDAY",
|
||||
type: BlameRequestType.THIRD_PARTY,
|
||||
parties: [
|
||||
{
|
||||
role: PartyRole.FIRST,
|
||||
person: {
|
||||
insurerBirthday: submission.dto.insurerBirthday,
|
||||
driverBirthday: submission.dto.driverBirthday,
|
||||
},
|
||||
participants: submission.participants.participants,
|
||||
participantRoles: submission.participants.roles,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(request.validateSync()).toBeUndefined();
|
||||
expect(request.parties[0].person.insurerBirthday).toBe("1378/06/27");
|
||||
expect(request.parties[0].person.driverBirthday).toBe("1378/04/26");
|
||||
});
|
||||
|
||||
it("recasts populated party subdocuments during an inquiry-audit update", () => {
|
||||
const BlameRequestModel = model<BlameRequest>(
|
||||
"InquiryParticipantAuditPersistenceTest",
|
||||
BlameRequestSchema,
|
||||
);
|
||||
const request = new BlameRequestModel({
|
||||
requestNo: "BL-PARTICIPANT-AUDIT",
|
||||
publicId: "PARTICIPANT-AUDIT",
|
||||
type: BlameRequestType.THIRD_PARTY,
|
||||
parties: [
|
||||
{
|
||||
role: PartyRole.FIRST,
|
||||
person: {
|
||||
userId: new Types.ObjectId(),
|
||||
phoneNumber: "09120723528",
|
||||
},
|
||||
statement: {
|
||||
acceptsExpertOpinion: false,
|
||||
claimsDamage: false,
|
||||
admitsGuilt: true,
|
||||
},
|
||||
participants: [
|
||||
{
|
||||
participantId: "DRIVER",
|
||||
nationalCode: "0022324224",
|
||||
birthday: "1378/04/26",
|
||||
hasDrivingLicense: true,
|
||||
licenseNumber: "1001011111",
|
||||
licenseType: "10",
|
||||
},
|
||||
],
|
||||
participantRoles: {
|
||||
driver: "DRIVER",
|
||||
vehicleOwner: "DRIVER",
|
||||
thirdPartyPolicyholder: "DRIVER",
|
||||
},
|
||||
vehicle: {
|
||||
registrationState: "CURRENT",
|
||||
plateId: "78-59-ی-419",
|
||||
},
|
||||
},
|
||||
],
|
||||
inquiries: {},
|
||||
});
|
||||
const query = BlameRequestModel.findByIdAndUpdate(request._id, {
|
||||
$set: {
|
||||
inquiries: request.inquiries,
|
||||
parties: request.parties,
|
||||
},
|
||||
});
|
||||
|
||||
expect(() => (query as any)._castUpdate(query.getUpdate())).not.toThrow();
|
||||
});
|
||||
});
|
||||
@@ -1950,7 +1950,7 @@ export class RequestManagementService {
|
||||
(body.driverIsInsurer ? String(body.insurerBirthday) : null);
|
||||
|
||||
if (!party.vehicle) party.vehicle = {} as any;
|
||||
party.vehicle.isNew = body.isNewCar;
|
||||
party.vehicle.isNewCar = body.isNewCar;
|
||||
party.vehicle.plateId =
|
||||
typeof body.plateId === "string"
|
||||
? body.plateId
|
||||
@@ -2382,7 +2382,7 @@ export class RequestManagementService {
|
||||
(body.driverIsInsurer ? String(body.insurerBirthday) : null);
|
||||
|
||||
if (!party.vehicle) party.vehicle = {} as any;
|
||||
party.vehicle.isNew = body.isNewCar;
|
||||
party.vehicle.isNewCar = body.isNewCar;
|
||||
// Derive plateId from the plate parts returned by the VIN inquiry.
|
||||
// Plk2 may be a numeric letter code (e.g. 5 → "د") or already a Persian
|
||||
// letter string — resolvePlk2Letter handles both forms.
|
||||
@@ -6633,7 +6633,7 @@ export class RequestManagementService {
|
||||
name: party.vehicle.name,
|
||||
model: party.vehicle.model,
|
||||
type: party.vehicle.type,
|
||||
isNew: party.vehicle.isNew,
|
||||
isNew: party.vehicle.isNewCar ?? (party.vehicle as any)?._doc?.isNew,
|
||||
}
|
||||
: undefined;
|
||||
const participants = Array.isArray(party.participants)
|
||||
@@ -7134,7 +7134,7 @@ export class RequestManagementService {
|
||||
name: sandHubReport?.MapTypNam || sandHubReport?.CarName,
|
||||
model: sandHubReport?.MapTypNam,
|
||||
type: `${sandHubReport?.UsageField || ""} / ${sandHubReport?.MapUsageName || "-"}`,
|
||||
isNew: firstPartyPlate.isNewCar,
|
||||
isNewCar: firstPartyPlate.isNewCar,
|
||||
registrationState: inquirySubmission.vehicle?.registrationState,
|
||||
previousPlateId: inquirySubmission.vehicle?.previousPlate
|
||||
? this.plateToPlateIdString(inquirySubmission.vehicle.previousPlate)
|
||||
@@ -7429,7 +7429,7 @@ export class RequestManagementService {
|
||||
name: sandHubReport?.MapTypNam || sandHubReport?.CarName,
|
||||
model: sandHubReport?.MapTypNam,
|
||||
type: `${sandHubReport?.UsageField || ""} / ${sandHubReport?.MapUsageName || "-"}`,
|
||||
isNew: plateDto.isNewCar,
|
||||
isNewCar: plateDto.isNewCar,
|
||||
registrationState: inquirySubmission.vehicle?.registrationState,
|
||||
previousPlateId: inquirySubmission.vehicle?.previousPlate
|
||||
? this.plateToPlateIdString(inquirySubmission.vehicle.previousPlate)
|
||||
|
||||
Reference in New Issue
Block a user