import { PayPeriods } from "@prisma/client"; import { PayPeriodDto } from "../dtos/pay-period.dto"; import { payYearOfDate } from "../utils/pay-year.util"; const toDateString = (d: Date) => d.toISOString().slice(0, 10); // "YYYY-MM-DD" export function mapPayPeriodToDto(row: PayPeriods): PayPeriodDto { const s = toDateString(row.start_date); const e = toDateString(row.end_date); return { period_number: row.period_number, start_date: toDateString(row.start_date), end_date: toDateString(row.end_date), year: payYearOfDate(s), label: `${s} => ${e}`, }; } export function mapMany(rows: PayPeriods[]): PayPeriodDto[] { return rows.map(mapPayPeriodToDto); }