forked from Yara724/api
128 lines
3.7 KiB
TypeScript
128 lines
3.7 KiB
TypeScript
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;
|
|
blameStatus: string;
|
|
partiesInitialForms: { firstParty: string; secondParty: string };
|
|
}
|
|
|
|
export class AllRequestDtoRsV2 {
|
|
data: AllRequestDtoV2[];
|
|
constructor(items: AllRequestDtoV2[]) {
|
|
this.data = items;
|
|
}
|
|
}
|