feat(pay-period): added email to Param of getCrewOverview
This commit is contained in:
parent
a23a6299dd
commit
ae6ce4bf97
|
|
@ -2073,7 +2073,7 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"/pay-periods/{year}/{periodNumber}/approval": {
|
||||
"/pay-periods/approval/{year}/{periodNumber}": {
|
||||
"patch": {
|
||||
"operationId": "PayPeriodsController_approve",
|
||||
"parameters": [
|
||||
|
|
@ -2108,7 +2108,7 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"/pay-periods/{year}/{periodNumber}/crew-overview": {
|
||||
"/pay-periods/{year}/{periodNumber}/{email}": {
|
||||
"get": {
|
||||
"operationId": "PayPeriodsController_getCrewOverview",
|
||||
"parameters": [
|
||||
|
|
@ -2131,6 +2131,14 @@
|
|||
"type": "number"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "email",
|
||||
"required": true,
|
||||
"in": "path",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "includeSubtree",
|
||||
"required": false,
|
||||
|
|
@ -2163,7 +2171,7 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"/pay-periods/{year}/{periodNumber}/overview": {
|
||||
"/pay-periods/overview/{year}/{periodNumber}": {
|
||||
"get": {
|
||||
"operationId": "PayPeriodsController_getOverviewByYear",
|
||||
"parameters": [
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ export class PayPeriodsController {
|
|||
return this.queryService.findOneByYearPeriod(year, periodNumber);
|
||||
}
|
||||
|
||||
@Patch(":year/:periodNumber/approval")
|
||||
@Patch("approval/:year/:periodNumber")
|
||||
//@RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
|
||||
@ApiOperation({ summary: "Approve all timesheets with activity in the period" })
|
||||
@ApiParam({ name: "year", type: Number, example: 2024 })
|
||||
|
|
@ -73,7 +73,7 @@ export class PayPeriodsController {
|
|||
return { message: `Pay-period ${year}-${periodNumber} approved` };
|
||||
}
|
||||
|
||||
@Get(':year/:periodNumber/crew-overview')
|
||||
@Get(':year/:periodNumber/:email')
|
||||
//@RolesAllowed(RoleEnum.SUPERVISOR)
|
||||
@ApiOperation({ summary: 'Supervisor crew overview for a given pay period' })
|
||||
@ApiParam({ name: 'year', type: Number, example: 2024 })
|
||||
|
|
@ -84,20 +84,14 @@ export class PayPeriodsController {
|
|||
async getCrewOverview(
|
||||
@Param('year', ParseIntPipe) year: number,
|
||||
@Param('periodNumber', ParseIntPipe) periodNumber: number,
|
||||
@Param('email') email: string,
|
||||
@Query('includeSubtree', new ParseBoolPipe({ optional: true })) includeSubtree = false,
|
||||
@Req() req: Request,
|
||||
): Promise<PayPeriodOverviewDto> {
|
||||
const rawUser = (req as any).user ?? {};
|
||||
const userId: string | undefined = rawUser.id ?? rawUser.sub ?? rawUser.userId; //needs ajusting according to passport logic
|
||||
|
||||
if (!userId) {
|
||||
throw new ForbiddenException('Authenticated user not found on request');
|
||||
return this.queryService.getCrewOverview(year, periodNumber, email, includeSubtree);
|
||||
}
|
||||
|
||||
return this.queryService.getCrewOverview(year, periodNumber, userId, includeSubtree);
|
||||
}
|
||||
|
||||
@Get(':year/:periodNumber/overview')
|
||||
@Get('overview/:year/:periodNumber')
|
||||
@ApiOperation({ summary: 'Detailed view of a pay period by year + number' })
|
||||
@ApiParam({ name: 'year', type: Number, example: 2024 })
|
||||
@ApiParam({ name: 'periodNumber', type: Number, example: 1, description: '1..26' })
|
||||
|
|
@ -107,6 +101,6 @@ export class PayPeriodsController {
|
|||
@Param('year', ParseIntPipe) year: number,
|
||||
@Param('periodNumber', ParseIntPipe) periodNumber: number,
|
||||
): Promise<PayPeriodOverviewDto> {
|
||||
return this.queryService.getOverviewByYearPeriod(year, periodNumber);
|
||||
return this.queryService.getOverviewByYearPeriod(year, periodNumber);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,17 +181,22 @@ export class PayPeriodsQueryService {
|
|||
}
|
||||
|
||||
|
||||
async getCrewOverview(year: number, periodNumber: number, userId: string, includeSubtree: boolean): Promise<PayPeriodOverviewDto> {
|
||||
async getCrewOverview(year: number, periodNumber: number, email: string, includeSubtree: boolean): Promise<PayPeriodOverviewDto> {
|
||||
// 1) Search for the period
|
||||
const period = await this.prisma.payPeriods.findFirst({ where: { year, period_number: periodNumber } });
|
||||
if (!period) throw new NotFoundException(`Pay period ${year}-${periodNumber} not found`);
|
||||
|
||||
// 2) fetch supervisor
|
||||
const supervisor = await this.prisma.employees.findUnique({
|
||||
where: { user_id: userId },
|
||||
select: { id: true },
|
||||
const supervisor = await this.prisma.employees.findFirst({
|
||||
where: { user: {email: email }},
|
||||
select: {
|
||||
id: true,
|
||||
is_supervisor: true,
|
||||
},
|
||||
});
|
||||
if (!supervisor) throw new ForbiddenException('No employee record linked to current user');
|
||||
|
||||
if (!supervisor) throw new NotFoundException('No employee record linked to current user');
|
||||
if (!supervisor.is_supervisor) throw new ForbiddenException('Employee is not a supervisor');
|
||||
|
||||
// 3)fetchs crew members
|
||||
const crew = await this.resolveCrew(supervisor.id, includeSubtree); // [{ id, first_name, last_name }]
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user