23 lines
882 B
TypeScript
23 lines
882 B
TypeScript
import { Prisma } from "@prisma/client";
|
|
import { LeaveRequestViewDto } from "../dtos/leave-request-view.dto";
|
|
import { LeaveRequestArchiveRow } from "../utils/leave-requests-archive.select";
|
|
|
|
const toNum = (value?: Prisma.Decimal | null) => value ? Number(value) : undefined;
|
|
|
|
export function mapArchiveRowToView(row: LeaveRequestArchiveRow, email: string, employee_full_name:string): LeaveRequestViewDto {
|
|
const isoDate = row.date?.toISOString().slice(0, 10);
|
|
if (!isoDate) {
|
|
throw new Error(`Leave request #${row.id} has no date set.`);
|
|
}
|
|
return {
|
|
id: row.id,
|
|
leave_type: row.leave_type,
|
|
date: isoDate,
|
|
payable_hours: toNum(row.payable_hours),
|
|
requested_hours: toNum(row.requested_hours),
|
|
comment: row.comment,
|
|
approval_status: row.approval_status,
|
|
email,
|
|
employee_full_name,
|
|
}
|
|
} |