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:
parent
91b718237d
commit
242e3179f4
|
|
@ -9,6 +9,8 @@ import { Roles as RoleEnum } from '.prisma/client';
|
||||||
import { Req } from '@nestjs/common';
|
import { Req } from '@nestjs/common';
|
||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
import { PayPeriodsCommandService } from "../services/pay-periods-command.service";
|
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')
|
@ApiTags('pay-periods')
|
||||||
@Controller('pay-periods')
|
@Controller('pay-periods')
|
||||||
|
|
@ -100,4 +102,17 @@ export class PayPeriodsController {
|
||||||
return this.queryService.getCrewOverview(year, periodNumber, userId, includeSubtree);
|
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 };
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
src/modules/pay-periods/dtos/bundle-pay-periods.dto.ts
Normal file
11
src/modules/pay-periods/dtos/bundle-pay-periods.dto.ts
Normal 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[];
|
||||||
|
}
|
||||||
|
|
@ -44,4 +44,9 @@ export class PayPeriodsService {
|
||||||
if (!row) throw new NotFoundException(`No period found for this date: ${date}`);
|
if (!row) throw new NotFoundException(`No period found for this date: ${date}`);
|
||||||
return mapPayPeriodToDto(row);
|
return mapPayPeriodToDto(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findCurrent(date?: string): Promise<PayPeriodDto> {
|
||||||
|
const isoDay = date ?? new Date().toISOString().slice(0,10);
|
||||||
|
return this.findByDate(isoDay);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user