targo-backend/src/modules/pay-periods/mappers/pay-periods.mapper.ts
2025-08-21 10:07:04 -04:00

23 lines
731 B
TypeScript

import { PayPeriods } from "@prisma/client";
import { PayPeriodDto } from "../dtos/pay-period.dto";
const toDateString = (date: Date) => date.toISOString().slice(0, 10); // "YYYY-MM-DD"
export function mapPayPeriodToDto(row: PayPeriods): PayPeriodDto {
const start = toDateString(row.period_start);
const end = toDateString(row.period_end);
const pay = toDateString(row.payday);
return {
pay_period_no: row.pay_period_no,
period_start: toDateString(row.period_start),
period_end: toDateString(row.period_end),
payday:pay,
pay_year: new Date(pay).getFullYear(),
label: `${start}.${end}`,
};
}
export function mapMany(rows: PayPeriods[]): PayPeriodDto[] {
return rows.map(mapPayPeriodToDto);
}