refactor(employees): added is_supervisor so the frontend can filter employees and use it in a select

This commit is contained in:
Matthieu Haineault 2025-12-04 13:57:52 -05:00
parent 9b4517a26d
commit 0c81f21f1b
3 changed files with 12 additions and 9 deletions

View File

@ -12,7 +12,7 @@ export class EmployeeDetailedDto {
@IsEmail() @IsOptional() email: string; @IsEmail() @IsOptional() email: string;
@IsString() phone_number: string; @IsString() phone_number: string;
@IsDateString() first_work_day: string; @IsDateString() first_work_day: string;
@IsDateString() @IsOptional() last_work_day?: string; @IsDateString() @IsOptional() last_work_day?: string | null;
@IsString() @IsOptional() residence?: string; @IsString() @IsOptional() residence?: string;
@IsInt() @IsPositive() @Type(() => Number) external_payroll_id: number; @IsInt() @IsPositive() @Type(() => Number) external_payroll_id: number;
@IsArray() @IsString({ each: true }) user_module_access: string[]; @IsArray() @IsString({ each: true }) user_module_access: string[];

View File

@ -6,7 +6,7 @@ import { EmailToIdResolver } from "src/common/mappers/email-id.mapper";
import { toStringFromDate } from "src/common/utils/date-utils"; import { toStringFromDate } from "src/common/utils/date-utils";
import { Result } from "src/common/errors/result-error.factory"; import { Result } from "src/common/errors/result-error.factory";
import { toStringFromCompanyCode } from "src/identity-and-account/employees/utils/employee.utils"; import { toCompanyCodeFromString, toStringFromCompanyCode } from "src/identity-and-account/employees/utils/employee.utils";
import { EmployeeDetailedDto } from "src/identity-and-account/employees/dtos/employee-detailed.dto"; import { EmployeeDetailedDto } from "src/identity-and-account/employees/dtos/employee-detailed.dto";
import { EmployeeDto } from "src/identity-and-account/employees/dtos/employee.dto"; import { EmployeeDto } from "src/identity-and-account/employees/dtos/employee.dto";
@ -37,6 +37,7 @@ export class EmployeesGetService {
}, },
}, },
}, },
is_supervisor: true,
job_title: true, job_title: true,
company_code: true, company_code: true,
external_payroll_id: true, external_payroll_id: true,
@ -50,6 +51,7 @@ export class EmployeesGetService {
job_title: r.job_title ?? '', job_title: r.job_title ?? '',
external_payroll_id: r.external_payroll_id, external_payroll_id: r.external_payroll_id,
employee_full_name: `${r.user.first_name} ${r.user.last_name}`, employee_full_name: `${r.user.first_name} ${r.user.last_name}`,
is_supervisor: r.is_supervisor,
supervisor_full_name: `${r.supervisor?.user.first_name} ${r.supervisor?.user.last_name}`, supervisor_full_name: `${r.supervisor?.user.first_name} ${r.supervisor?.user.last_name}`,
})),) })),)
return { success: true, data: employee_list } return { success: true, data: employee_list }
@ -75,6 +77,7 @@ export class EmployeesGetService {
company_code: true, company_code: true,
job_title: true, job_title: true,
external_payroll_id: true, external_payroll_id: true,
is_supervisor: true,
supervisor: { supervisor: {
select: { select: {
id: true, user: { id: true, user: {
@ -99,6 +102,7 @@ export class EmployeesGetService {
company_name: company_name, company_name: company_name,
job_title: existing_profile.job_title ?? '', job_title: existing_profile.job_title ?? '',
external_payroll_id: existing_profile.external_payroll_id, external_payroll_id: existing_profile.external_payroll_id,
is_supervisor: existing_profile.is_supervisor,
phone_number: existing_profile.user.phone_number, phone_number: existing_profile.user.phone_number,
residence: existing_profile.user.phone_number, residence: existing_profile.user.phone_number,
first_work_day: toStringFromDate(existing_profile.first_work_day), first_work_day: toStringFromDate(existing_profile.first_work_day),
@ -129,8 +133,8 @@ export class EmployeesGetService {
personal_profile: true, personal_profile: true,
timesheets: true, timesheets: true,
timesheets_approval: true, timesheets_approval: true,
} },
} },
}, },
}, },
supervisor: { supervisor: {
@ -160,10 +164,8 @@ export class EmployeesGetService {
module_access_array = toStringFromBoolean(employee.user.user_module_access); module_access_array = toStringFromBoolean(employee.user.user_module_access);
} }
let company_name = 'Solucom'; const company_name = toStringFromCompanyCode(employee.company_code);
if (employee.company_code === 271583) {
company_name = 'Targo';
}
return { return {
success: true, success: true,
data: { data: {

View File

@ -23,6 +23,7 @@ export class EmployeesUpdateService {
const company_code = toCompanyCodeFromString(dto.company_name); const company_code = toCompanyCodeFromString(dto.company_name);
const supervisor_id = await this.toIdFromFullName(dto.supervisor_full_name); const supervisor_id = await this.toIdFromFullName(dto.supervisor_full_name);
const normalized_access = await toBooleanFromString(dto.user_module_access); const normalized_access = await toBooleanFromString(dto.user_module_access);
const last_work_day = dto.last_work_day ? toDateFromString(dto.last_work_day) : null;
await this.prisma.$transaction(async (tx) => { await this.prisma.$transaction(async (tx) => {
await tx.users.update({ await tx.users.update({
@ -61,7 +62,7 @@ export class EmployeesUpdateService {
company_code: company_code, company_code: company_code,
job_title: dto.job_title, job_title: dto.job_title,
first_work_day: toDateFromString(dto.first_work_day), first_work_day: toDateFromString(dto.first_work_day),
last_work_day: dto.last_work_day, last_work_day: last_work_day,
is_supervisor: dto.is_supervisor, is_supervisor: dto.is_supervisor,
supervisor_id: supervisor_id, supervisor_id: supervisor_id,
schedule_preset_id: dto.preset_id, schedule_preset_id: dto.preset_id,