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
|
// 40 employees
|
||||||
for (let i = 0; i < 40; i++) {
|
for (let i = 0; i < 40; i++) {
|
||||||
|
|
||||||
const fn = pick(firstNames);
|
const fn = pick(firstNames);
|
||||||
const ln = pick(lastNames);
|
const ln = pick(lastNames);
|
||||||
usersData.push({
|
usersData.push({
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ async function main() {
|
||||||
first_work_day: randomPastDate(3),
|
first_work_day: randomPastDate(3),
|
||||||
last_work_day: null,
|
last_work_day: null,
|
||||||
job_title: randomTitle(),
|
job_title: randomTitle(),
|
||||||
|
is_supervisor: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
supervisorEmployeeIds.push(emp.id);
|
supervisorEmployeeIds.push(emp.id);
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ async function main() {
|
||||||
last_work_day: daysAgo(30),
|
last_work_day: daysAgo(30),
|
||||||
supervisor_id: e.supervisor_id ?? null,
|
supervisor_id: e.supervisor_id ?? null,
|
||||||
job_title: e.job_title,
|
job_title: e.job_title,
|
||||||
|
is_supervisor: e.is_supervisor,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ model Employees {
|
||||||
first_work_day DateTime @db.Date
|
first_work_day DateTime @db.Date
|
||||||
last_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 Employees? @relation("EmployeeSupervisor", fields: [supervisor_id], references: [id])
|
||||||
supervisor_id Int?
|
supervisor_id Int?
|
||||||
|
|
@ -65,7 +66,7 @@ model EmployeesArchive {
|
||||||
first_name String
|
first_name String
|
||||||
last_name String
|
last_name String
|
||||||
job_title String?
|
job_title String?
|
||||||
|
is_supervisor Boolean
|
||||||
external_payroll_id Int
|
external_payroll_id Int
|
||||||
company_code Int
|
company_code Int
|
||||||
first_Work_Day DateTime @db.Date
|
first_Work_Day DateTime @db.Date
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import {
|
import {
|
||||||
Allow,
|
Allow,
|
||||||
IsDate,
|
IsBoolean,
|
||||||
IsDateString,
|
IsDateString,
|
||||||
IsEmail,
|
IsEmail,
|
||||||
IsInt,
|
IsInt,
|
||||||
|
|
@ -53,6 +53,11 @@ export class CreateEmployeeDto {
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
email: string;
|
email: string;
|
||||||
|
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsBoolean()
|
||||||
|
is_supervisor: boolean;
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
example: '82538437464',
|
example: '82538437464',
|
||||||
description: 'Employee`s phone number',
|
description: 'Employee`s phone number',
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ export class EmployeesService {
|
||||||
job_title,
|
job_title,
|
||||||
first_work_day,
|
first_work_day,
|
||||||
last_work_day,
|
last_work_day,
|
||||||
|
is_supervisor,
|
||||||
} = dto;
|
} = dto;
|
||||||
|
|
||||||
return this.prisma.$transaction(async (tx) => {
|
return this.prisma.$transaction(async (tx) => {
|
||||||
|
|
@ -53,6 +54,7 @@ export class EmployeesService {
|
||||||
job_title,
|
job_title,
|
||||||
first_work_day,
|
first_work_day,
|
||||||
last_work_day,
|
last_work_day,
|
||||||
|
is_supervisor,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -171,6 +173,7 @@ async update(
|
||||||
job_title,
|
job_title,
|
||||||
first_work_day,
|
first_work_day,
|
||||||
last_work_day,
|
last_work_day,
|
||||||
|
is_supervisor
|
||||||
} = dto;
|
} = dto;
|
||||||
|
|
||||||
return this.prisma.$transaction(async (tx) => {
|
return this.prisma.$transaction(async (tx) => {
|
||||||
|
|
@ -193,6 +196,7 @@ async update(
|
||||||
...(first_work_day !== undefined && { first_work_day }),
|
...(first_work_day !== undefined && { first_work_day }),
|
||||||
...(last_work_day !== undefined && { last_work_day }),
|
...(last_work_day !== undefined && { last_work_day }),
|
||||||
...(job_title !== undefined && { job_title }),
|
...(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,
|
first_work_day,
|
||||||
last_work_day,
|
last_work_day,
|
||||||
supervisor_id,
|
supervisor_id,
|
||||||
|
is_supervisor,
|
||||||
} = dto;
|
} = dto;
|
||||||
|
|
||||||
const fw = toDateOrUndefined(first_work_day);
|
const fw = toDateOrUndefined(first_work_day);
|
||||||
|
|
@ -257,6 +262,7 @@ async patchEmployee(id: number, dto: UpdateEmployeeDto): Promise<Employees | Emp
|
||||||
...(email !== undefined ? { email } : {}),
|
...(email !== undefined ? { email } : {}),
|
||||||
...(phone_number !== undefined ? { phone_number } : {}),
|
...(phone_number !== undefined ? { phone_number } : {}),
|
||||||
...(residence !== undefined ? { residence } : {}),
|
...(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 } : {}),
|
...(company_code !== undefined ? { company_code } : {}),
|
||||||
...(job_title !== undefined ? { job_title } : {}),
|
...(job_title !== undefined ? { job_title } : {}),
|
||||||
...(fw !== undefined ? { first_work_day: fw } : {}),
|
...(fw !== undefined ? { first_work_day: fw } : {}),
|
||||||
...(lw !== undefined
|
...(lw !== undefined ? { last_work_day: lw } : {}),
|
||||||
? { last_work_day: lw }
|
|
||||||
: {}),
|
|
||||||
...(supervisor_id !== undefined ? { supervisor_id } : {}),
|
...(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,
|
first_Work_Day: existing.first_Work_Day,
|
||||||
last_work_day: existing.last_work_day,
|
last_work_day: existing.last_work_day,
|
||||||
supervisor_id: existing.supervisor_id ?? null,
|
supervisor_id: existing.supervisor_id ?? null,
|
||||||
|
is_supervisor: existing.is_supervisor,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
//delete from employees table
|
//delete from employees table
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ export class PayPeriodsQueryService {
|
||||||
});
|
});
|
||||||
if (!supervisor) throw new ForbiddenException('No employee record linked to current user');
|
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 crew = await this.resolveCrew(supervisor.id, includeSubtree); // [{ id, first_name, last_name }]
|
||||||
const crewIds = crew.map(c => c.id);
|
const crewIds = crew.map(c => c.id);
|
||||||
// seed names map for employee without data
|
// seed names map for employee without data
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user