refactor(employees): added functionality to take an optional employee email to retrieve profile data

This commit is contained in:
Nicolas Drolet 2025-11-27 08:40:41 -05:00
parent fc323a393b
commit 5a28630c21
2 changed files with 9 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import { Controller, Get, Patch, Param, Body, NotFoundException, Req, Post } from "@nestjs/common";
import { Controller, Get, Patch, Param, Body, NotFoundException, Req, Post, Query } from "@nestjs/common";
import { Employees } from "@prisma/client";
import { RolesAllowed } from "src/common/decorators/roles.decorators";
import { Result } from "src/common/errors/result-error.factory";
@ -19,9 +19,12 @@ export class EmployeesController {
) { }
@Get('profile')
findOneProfile(@Req() req): Promise<Result<EmployeeProfileItemDto,string>> {
findOneProfile(
@Req() req,
@Query('employee_email') employee_email?: string,
): Promise<Result<EmployeeProfileItemDto,string>> {
const email = req.user?.email;
return this.employeesService.findOneProfile(email);
return this.employeesService.findOneProfile(employee_email ?? email);
}
@Get('employee-list')

View File

@ -99,7 +99,7 @@ export class GetTimesheetsOverviewService {
where: { employee_id, start_date: { gte: period_start, lte: period_end } },
include: {
employee: { include: { user: true } },
shift: { include: { bank_code: true } },
shift: { include: { bank_code: true }, orderBy: { start_time: 'asc'} },
expense: { include: { bank_code: true, attachment_record: true } },
},
orderBy: { start_date: 'asc' },
@ -109,7 +109,7 @@ export class GetTimesheetsOverviewService {
private async mapOneTimesheet(timesheet: Prisma.TimesheetsGetPayload<{
include: {
employee: { include: { user } },
shift: { include: { bank_code } },
shift: { include: { bank_code }, orderBy: { start_time: 'asc'} },
expense: { include: { bank_code, attachment_record } },
}
}>): Promise<Timesheet> {
@ -118,7 +118,7 @@ export class GetTimesheetsOverviewService {
const day_dates = sevenDaysFrom(start);
//map of shifts by days
const shifts_by_date = new Map<string, Prisma.ShiftsGetPayload<{ include: { bank_code } }>[]>();
const shifts_by_date = new Map<string, Prisma.ShiftsGetPayload<{ include: { bank_code }, orderBy: { start_time: 'asc'} }>[]>();
for (const shift of timesheet.shift) {
const date_string = toStringFromDate(shift.date);
const arr = shifts_by_date.get(date_string) ?? [];