feat(pay-period): added a wrapper function to return 2 args, 1st is current pay-period and 2nd is all pay-periods

This commit is contained in:
Matthieu Haineault 2025-08-11 09:45:10 -04:00
parent 91b718237d
commit 242e3179f4
3 changed files with 31 additions and 0 deletions

View File

@ -9,6 +9,8 @@ import { Roles as RoleEnum } from '.prisma/client';
import { Req } from '@nestjs/common';
import { Request } from 'express';
import { PayPeriodsCommandService } from "../services/pay-periods-command.service";
import { REPL_MODE_STRICT } from "repl";
import { PayPeriodBundleDto } from "../dtos/bundle-pay-periods.dto";
@ApiTags('pay-periods')
@Controller('pay-periods')
@ -100,4 +102,17 @@ export class PayPeriodsController {
return this.queryService.getCrewOverview(year, periodNumber, userId, includeSubtree);
}
@Get('bundle/current-and-all')
@ApiOperation({summary: 'Return current pay period and the full list'})
@ApiQuery({name: 'date', required:false, example: '2025-01-01', description:'Override for resolving the current period'})
@ApiResponse({status: 200, description:'Find current and all pay periods', type: PayPeriodBundleDto})
async getCurrentAndAll(@Query('date') date?: string): Promise<PayPeriodBundleDto> {
const [current, periods] = await Promise.all([
this.payPeriodsService.findCurrent(date),
this.payPeriodsService.findAll(),
]);
return { current, periods };
}
}

View File

@ -0,0 +1,11 @@
import { ApiProperty } from "@nestjs/swagger";
import { PayPeriodDto } from "./pay-period.dto";
export class PayPeriodBundleDto {
@ApiProperty({ type: PayPeriodDto, description: 'Current pay period (resolved from date)' })
current: PayPeriodDto;
@ApiProperty({ type: [PayPeriodDto], description: 'All pay periods' })
periods: PayPeriodDto[];
}

View File

@ -44,4 +44,9 @@ export class PayPeriodsService {
if (!row) throw new NotFoundException(`No period found for this date: ${date}`);
return mapPayPeriodToDto(row);
}
async findCurrent(date?: string): Promise<PayPeriodDto> {
const isoDay = date ?? new Date().toISOString().slice(0,10);
return this.findByDate(isoDay);
}
}