56 lines
2.5 KiB
TypeScript
56 lines
2.5 KiB
TypeScript
import { Body, Controller, Get, Param, ParseIntPipe, Patch } from "@nestjs/common";
|
|
import { PayPeriodOverviewDto } from "./dtos/overview-pay-period.dto";
|
|
import { PayPeriodsQueryService } from "./services/pay-periods-query.service";
|
|
import { PayPeriodsCommandService } from "./services/pay-periods-command.service";
|
|
import { Result } from "src/common/errors/result-error.factory";
|
|
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
|
import { Modules as ModulesEnum } from ".prisma/client";
|
|
import { GetOverviewService } from "src/time-and-attendance/pay-period/services/pay-periods-build-overview.service";
|
|
|
|
@Controller('pay-periods')
|
|
export class PayPeriodsController {
|
|
|
|
constructor(
|
|
private readonly queryService: PayPeriodsQueryService,
|
|
private readonly getOverviewService: GetOverviewService,
|
|
private readonly commandService: PayPeriodsCommandService,
|
|
) { }
|
|
|
|
@Get("date/:date")
|
|
@ModuleAccessAllowed(ModulesEnum.timesheets)
|
|
async findByDate(@Param("date") date: string) {
|
|
return this.queryService.findByDate(date);
|
|
}
|
|
|
|
@Get(":year/:periodNumber")
|
|
@ModuleAccessAllowed(ModulesEnum.timesheets)
|
|
async findOneByYear(
|
|
@Param("year", ParseIntPipe) year: number,
|
|
@Param("periodNumber", ParseIntPipe) period_no: number,
|
|
) {
|
|
return this.queryService.findOneByYearPeriod(year, period_no);
|
|
}
|
|
|
|
@Patch("pay-period-approval")
|
|
@ModuleAccessAllowed(ModulesEnum.timesheets_approval)
|
|
async bulkApproval(
|
|
@Body('email') email: string,
|
|
@Body('timesheet_ids') timesheet_ids: number[],
|
|
@Body('is_approved') is_approved: boolean,
|
|
): Promise<Result<{ shifts: number, expenses: number }, string>> {
|
|
if (!email) return { success: false, error: 'EMAIL_REQUIRED' };
|
|
if (!timesheet_ids || timesheet_ids.length < 1) return { success: false, error: 'TIMESHEET_ID_REQUIRED' };
|
|
if (!is_approved) return { success: false, error: 'APPROVAL_STATUS_REQUIRED' }
|
|
return this.commandService.bulkApproveEmployee(email, timesheet_ids, is_approved);
|
|
}
|
|
|
|
@Get('overview/:year/:periodNumber')
|
|
@ModuleAccessAllowed(ModulesEnum.timesheets_approval)
|
|
async getOverviewByYear(
|
|
@Param('year', ParseIntPipe) year: number,
|
|
@Param('periodNumber', ParseIntPipe) period_no: number,
|
|
): Promise<Result<PayPeriodOverviewDto, string>> {
|
|
return this.getOverviewService.getOverviewByYearPeriod(year, period_no);
|
|
}
|
|
}
|