Files
yara724-api/src/expert-blame/dto/all-request.dto.ts
2026-08-19 12:30:53 +03:30

163 lines
4.7 KiB
TypeScript

import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { RequestManagementModel } from "src/request-management/entities/schema/request-management.schema";
export class AllRequestDto {
// TODO fix interface for class
firstPartyPlate: object;
secondPartyPlate: object;
secondPartyCar: string | undefined;
firstPartyCar: string | undefined;
requestId: string;
submitTime: string;
requestCode: string;
date: Date | string;
time: Date | string;
firstPartyDetail: Object | undefined;
secondPartyDetail: Object | undefined;
requestStatus: string;
lockFile: boolean | undefined;
lockTime: any;
userComment: boolean | null;
status: string;
partiesInitialForms: Object;
type: string;
constructor(request: RequestManagementModel) {
// TODO FIX THIS OBJECT AND CLASS FOR CLEAN CODE
this.requestId = request["_id"];
this.status = request.blameStatus;
this.userComment = this.userCommentVoid(request);
this.requestCode = request.requestNumber;
// Format date and time with Iran timezone (Asia/Tehran)
if (request.createdAt) {
const dateFormatOptions: Intl.DateTimeFormatOptions = {
timeZone: "Asia/Tehran",
year: "numeric",
month: "2-digit",
day: "2-digit",
};
const timeFormatOptions: Intl.DateTimeFormatOptions = {
timeZone: "Asia/Tehran",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
};
this.date = `${new Date(request.createdAt).toLocaleDateString("fa-IR", dateFormatOptions)} `;
this.time = new Date(request.createdAt).toLocaleTimeString("fa-IR", timeFormatOptions);
} else {
this.date = "";
this.time = "";
}
this.lockFile = request.lockFile;
this.lockTime = request.lockTime;
this.type = request.type || "THIRD_PARTY"; // Include type field, default to THIRD_PARTY for backward compatibility
this.partiesInitialForms = {
firstParty: Object.entries(
request.firstPartyDetails.firstPartyInitialForm,
)
.filter(([key, value]) => value)
.flat()[0],
secondParty: Object.entries(
request.secondPartyDetails.secondPartyInitialForm,
)
.filter(([key, value]) => (value ? key : null))
.flat()[0],
};
this.firstPartyCar =
request.firstPartyDetails?.firstPartyCarDetail?.carName;
this.secondPartyCar =
request.secondPartyDetails?.secondPartyCarDetail?.carName;
}
userCommentVoid(request: RequestManagementModel): boolean | null {
if (
request?.expertSubmitReply?.firstPartyComment &&
request?.expertSubmitReply?.secondPartyComment
) {
if (
request.expertSubmitReply.firstPartyComment.isAccept ||
request.expertSubmitReply.secondPartyComment.isAccept
) {
return true;
} else {
return false;
}
} else {
return null;
}
}
getFirstValidKey(obj: Record<string, boolean>) {
return (
Object.entries(obj).find(([_, value]) => value === true)?.[0] ?? null
);
}
}
export class AllRequestDtoRs {
public data;
constructor(requests: RequestManagementModel[]) {
this.data = requests.map((r) => new AllRequestDto(r));
}
}
/** V2: list item from blameCases (BlameRequest) for expert panel */
export class AllRequestDtoV2 {
requestId: string;
status: string;
userComment: null;
requestCode: string;
date: string;
time: string;
updatedAtDate: string;
updatedAtTime: string;
lockFile: boolean;
lockTime: string | null;
type: string;
/** IN_PERSON or LINK — how the blame file was created */
creationMethod?: string;
blameStatus: string;
/** Calculated blame + linked claim lifecycle status */
unifiedFileStatus?: string;
partiesInitialForms: { firstParty: string; secondParty: string };
partiesVehicles: { firstPartyVehicle: string; secondPartyVehicle: string };
/**
* True when the file is in WAITING_FOR_FILE_REVIEWER status — the FileReviewer
* must complete accident fields, capture, and upload-video via v4 endpoints
* before the file enters the normal expert-blame review queue.
*/
needsFileReviewerCompletion?: boolean;
}
export class AllRequestDtoRsV2 {
data: AllRequestDtoV2[];
@ApiProperty({ description: "Total rows after search filter" })
total: number;
@ApiPropertyOptional()
page?: number;
@ApiPropertyOptional()
limit?: number;
@ApiPropertyOptional()
totalPages?: number;
constructor(payload: {
data: AllRequestDtoV2[];
total: number;
page?: number;
limit?: number;
totalPages?: number;
}) {
this.data = payload.data;
this.total = payload.total;
this.page = payload.page;
this.limit = payload.limit;
this.totalPages = payload.totalPages;
}
}