37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
import { Body, Controller, Get, Param, ParseBoolPipe, ParseIntPipe, Patch, Req, UnauthorizedException } from "@nestjs/common";
|
|
import { RolesAllowed } from "src/common/decorators/roles.decorators";
|
|
import { GetTimesheetsOverviewService } from "src/time-and-attendance/time-tracker/timesheets/services/timesheet-get-overview.service";
|
|
import { TimesheetApprovalService } from "src/time-and-attendance/time-tracker/timesheets/services/timesheet-approval.service";
|
|
import { GLOBAL_CONTROLLER_ROLES, MANAGER_ROLES } from "src/common/shared/role-groupes";
|
|
|
|
|
|
@Controller('timesheets')
|
|
@RolesAllowed(...GLOBAL_CONTROLLER_ROLES)
|
|
export class TimesheetController {
|
|
constructor(
|
|
private readonly timesheetOverview: GetTimesheetsOverviewService,
|
|
private readonly approvalService: TimesheetApprovalService,
|
|
) { }
|
|
|
|
@Get(':year/:period_number')
|
|
getTimesheetByPayPeriod(
|
|
@Req() req,
|
|
@Param('year', ParseIntPipe) year: number,
|
|
@Param('period_number', ParseIntPipe) period_number: number
|
|
) {
|
|
const email = req.user?.email;
|
|
if (!email) throw new UnauthorizedException('Unauthorized User');
|
|
return this.timesheetOverview.getTimesheetsForEmployeeByPeriod(email, year, period_number);
|
|
}
|
|
|
|
@Patch('timesheet-approval')
|
|
@RolesAllowed(...MANAGER_ROLES)
|
|
approveTimesheet(
|
|
@Body('timesheet_id', ParseIntPipe) timesheet_id: number,
|
|
@Body('is_approved', ParseBoolPipe) is_approved: boolean,
|
|
) {
|
|
return this.approvalService.approveTimesheetById(timesheet_id, is_approved);
|
|
}
|
|
}
|
|
|