fix(supervisor): added is_supervisor column to employees, archives and mock seeds
This commit is contained in:
parent
4d2ed4714f
commit
fe87c36884
|
|
@ -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;
|
||||
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,8 @@ model Employees {
|
|||
company_code Int
|
||||
first_work_day DateTime @db.Date
|
||||
last_work_day DateTime? @db.Date
|
||||
job_title String?
|
||||
job_title String?
|
||||
is_supervisor Boolean @default(false)
|
||||
|
||||
supervisor Employees? @relation("EmployeeSupervisor", fields: [supervisor_id], references: [id])
|
||||
supervisor_id Int?
|
||||
|
|
@ -60,12 +61,12 @@ model EmployeesArchive {
|
|||
employee_id Int
|
||||
archived_at DateTime @default(now())
|
||||
|
||||
user_id String @db.Uuid
|
||||
user Users @relation("UsersToEmployeesToArchive", fields: [user_id], references: [id])
|
||||
first_name String
|
||||
last_name String
|
||||
job_title String?
|
||||
|
||||
user_id String @db.Uuid
|
||||
user Users @relation("UsersToEmployeesToArchive", fields: [user_id], references: [id])
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
@ -252,11 +257,12 @@ async patchEmployee(id: number, dto: UpdateEmployeeDto): Promise<Employees | Emp
|
|||
await tx.users.update({
|
||||
where: { id: existing.user_id },
|
||||
data: {
|
||||
...(first_name !== undefined ? { first_name } : {}),
|
||||
...(last_name !== undefined ? { last_name } : {}),
|
||||
...(email !== undefined ? { email } : {}),
|
||||
...(phone_number !== undefined ? { phone_number } : {}),
|
||||
...(residence !== undefined ? { residence } : {}),
|
||||
...(first_name !== undefined ? { first_name } : {}),
|
||||
...(last_name !== undefined ? { last_name } : {}),
|
||||
...(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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user