targo-backend/src/Time_And_Attendance/modules/time-tracker/timesheets/controllers/timesheet.controller.ts

27 lines
1.2 KiB
TypeScript

import { EmailToIdResolver } from "src/Time_And_Attendance/modules/shared/utils/resolve-email-id.utils";
import { GetTimesheetsOverviewService } from "../services/timesheet-get-overview.service";
import { BadRequestException, Controller, Get, Query} from "@nestjs/common";
@Controller('timesheets')
export class TimesheetController {
constructor(
private readonly timesheetOverview: GetTimesheetsOverviewService,
private readonly emailResolver: EmailToIdResolver,
){}
@Get()
async getTimesheetByIds(
@Query('employee_email') employee_email: string,
@Query('year') year: string,
@Query('period_number') period_number: string,
) {
if (!employee_email || !year || !period_number) {
throw new BadRequestException('Query params "employee_email", "year" and eriod_number" are required.');
}
const employee_id = await this.emailResolver.findIdByEmail(employee_email);
const pay_year = Number(year);
const period_num = Number(period_number);
return this.timesheetOverview.getTimesheetsForEmployeeByPeriod(employee_id, pay_year, period_num);
}
}