diff --git a/src/modules/pay-periods/controllers/pay-periods.controller.ts b/src/modules/pay-periods/controllers/pay-periods.controller.ts index e680fda..d645638 100644 --- a/src/modules/pay-periods/controllers/pay-periods.controller.ts +++ b/src/modules/pay-periods/controllers/pay-periods.controller.ts @@ -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 { + const [current, periods] = await Promise.all([ + this.payPeriodsService.findCurrent(date), + this.payPeriodsService.findAll(), + ]); + return { current, periods }; + } + } diff --git a/src/modules/pay-periods/dtos/bundle-pay-periods.dto.ts b/src/modules/pay-periods/dtos/bundle-pay-periods.dto.ts new file mode 100644 index 0000000..9c5a61f --- /dev/null +++ b/src/modules/pay-periods/dtos/bundle-pay-periods.dto.ts @@ -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[]; +} \ No newline at end of file diff --git a/src/modules/pay-periods/services/pay-periods.service.ts b/src/modules/pay-periods/services/pay-periods.service.ts index fc1440b..a6627fe 100644 --- a/src/modules/pay-periods/services/pay-periods.service.ts +++ b/src/modules/pay-periods/services/pay-periods.service.ts @@ -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 { + const isoDay = date ?? new Date().toISOString().slice(0,10); + return this.findByDate(isoDay); + } } \ No newline at end of file