fix(supervisor): added is_supervisor column to employees, archives and mock seeds

This commit is contained in:
Matthieu Haineault 2025-08-18 12:26:52 -04:00
parent 4d2ed4714f
commit fe87c36884
8 changed files with 42 additions and 17 deletions

View File

@ -0,0 +1,11 @@
/*
Warnings:
- Added the required column `is_supervisor` to the `employees_archive` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "public"."employees" ADD COLUMN "is_supervisor" BOOLEAN NOT NULL DEFAULT false;
-- AlterTable
ALTER TABLE "public"."employees_archive" ADD COLUMN "is_supervisor" BOOLEAN NOT NULL;

View File

@ -37,6 +37,7 @@ async function main() {
// 40 employees
for (let i = 0; i < 40; i++) {
const fn = pick(firstNames);
const ln = pick(lastNames);
usersData.push({

View File

@ -53,6 +53,7 @@ async function main() {
first_work_day: randomPastDate(3),
last_work_day: null,
job_title: randomTitle(),
is_supervisor: true,
},
});
supervisorEmployeeIds.push(emp.id);

View File

@ -28,6 +28,7 @@ async function main() {
last_work_day: daysAgo(30),
supervisor_id: e.supervisor_id ?? null,
job_title: e.job_title,
is_supervisor: e.is_supervisor,
},
});
}

View File

@ -41,6 +41,7 @@ model Employees {
first_work_day DateTime @db.Date
last_work_day DateTime? @db.Date
job_title String?
is_supervisor Boolean @default(false)
supervisor Employees? @relation("EmployeeSupervisor", fields: [supervisor_id], references: [id])
supervisor_id Int?
@ -65,7 +66,7 @@ model EmployeesArchive {
first_name String
last_name String
job_title String?
is_supervisor Boolean
external_payroll_id Int
company_code Int
first_Work_Day DateTime @db.Date

View File

@ -1,6 +1,6 @@
import {
Allow,
IsDate,
IsBoolean,
IsDateString,
IsEmail,
IsInt,
@ -53,6 +53,11 @@ export class CreateEmployeeDto {
@IsOptional()
email: string;
@IsOptional()
@IsBoolean()
is_supervisor: boolean;
@ApiProperty({
example: '82538437464',
description: 'Employee`s phone number',

View File

@ -33,6 +33,7 @@ export class EmployeesService {
job_title,
first_work_day,
last_work_day,
is_supervisor,
} = dto;
return this.prisma.$transaction(async (tx) => {
@ -53,6 +54,7 @@ export class EmployeesService {
job_title,
first_work_day,
last_work_day,
is_supervisor,
},
});
});
@ -171,6 +173,7 @@ async update(
job_title,
first_work_day,
last_work_day,
is_supervisor
} = dto;
return this.prisma.$transaction(async (tx) => {
@ -193,6 +196,7 @@ async update(
...(first_work_day !== undefined && { first_work_day }),
...(last_work_day !== undefined && { last_work_day }),
...(job_title !== undefined && { job_title }),
...(is_supervisor !== undefined && { is_supervisor }),
},
});
});
@ -233,6 +237,7 @@ async patchEmployee(id: number, dto: UpdateEmployeeDto): Promise<Employees | Emp
first_work_day,
last_work_day,
supervisor_id,
is_supervisor,
} = dto;
const fw = toDateOrUndefined(first_work_day);
@ -257,6 +262,7 @@ async patchEmployee(id: number, dto: UpdateEmployeeDto): Promise<Employees | Emp
...(email !== undefined ? { email } : {}),
...(phone_number !== undefined ? { phone_number } : {}),
...(residence !== undefined ? { residence } : {}),
...(is_supervisor !== undefined ? { is_supervisor }: {}),
},
});
}
@ -268,9 +274,7 @@ async patchEmployee(id: number, dto: UpdateEmployeeDto): Promise<Employees | Emp
...(company_code !== undefined ? { company_code } : {}),
...(job_title !== undefined ? { job_title } : {}),
...(fw !== undefined ? { first_work_day: fw } : {}),
...(lw !== undefined
? { last_work_day: lw }
: {}),
...(lw !== undefined ? { last_work_day: lw } : {}),
...(supervisor_id !== undefined ? { supervisor_id } : {}),
},
});
@ -313,6 +317,7 @@ async patchEmployee(id: number, dto: UpdateEmployeeDto): Promise<Employees | Emp
first_Work_Day: existing.first_Work_Day,
last_work_day: existing.last_work_day,
supervisor_id: existing.supervisor_id ?? null,
is_supervisor: existing.is_supervisor,
},
});
//delete from employees table

View File

@ -192,7 +192,7 @@ export class PayPeriodsQueryService {
});
if (!supervisor) throw new ForbiddenException('No employee record linked to current user');
// 3)fetchs crew memebrs
// 3)fetchs crew members
const crew = await this.resolveCrew(supervisor.id, includeSubtree); // [{ id, first_name, last_name }]
const crewIds = crew.map(c => c.id);
// seed names map for employee without data