forked from Yara724/api
Initial commit after migration to gitea
This commit is contained in:
103
src/expert-blame/dto/all-request.dto.ts
Normal file
103
src/expert-blame/dto/all-request.dto.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user