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