feat(timesheets): preparing for Express Session requests
This commit is contained in:
parent
06ad34a4c8
commit
a563df0943
|
|
@ -14,7 +14,7 @@ export class OvertimeService {
|
|||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
//calculate daily overtime
|
||||
async getDailyOvertimeHoursForDay(employee_id: number, date: Date): Promise<number> {
|
||||
async getDailyOvertimeHours(employee_id: number, date: Date): Promise<number> {
|
||||
const shifts = await this.prisma.shifts.findMany({
|
||||
where: { date: date, timesheet: { employee_id: employee_id } },
|
||||
select: { start_time: true, end_time: true },
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ export class ShiftsHelpersService {
|
|||
async afterWriteOvertimeAndLog(tx: Tx, employee_id: number, date_only: Date) {
|
||||
// Switch regular → weekly overtime si > 40h
|
||||
await this.overtimeService.transformRegularHoursToWeeklyOvertime(employee_id, date_only, tx);
|
||||
const daily = await this.overtimeService.getDailyOvertimeHoursForDay(employee_id, date_only);
|
||||
const daily = await this.overtimeService.getDailyOvertimeHours(employee_id, date_only);
|
||||
const weekly = await this.overtimeService.getWeeklyOvertimeHours(employee_id, date_only);
|
||||
// const [daily, weekly] = await Promise.all([
|
||||
// this.overtimeService.getDailyOvertimeHoursForDay(employee_id, date_only),
|
||||
|
|
|
|||
52
src/modules/timesheets/dtos/timesheet.dto.ts
Normal file
52
src/modules/timesheets/dtos/timesheet.dto.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
export class Timesheets {
|
||||
timesheet_id: number;
|
||||
days: TimesheetDay[];
|
||||
weekly_hours: TotalHours[];
|
||||
weekly_expenses: TotalExpenses[];
|
||||
}
|
||||
|
||||
export class TimesheetDay {
|
||||
date: string;
|
||||
shifts: Shift[];
|
||||
expenses: Expense[];
|
||||
daily_hours: TotalHours[];
|
||||
daily_expenses: TotalExpenses[];
|
||||
}
|
||||
|
||||
export class TotalHours {
|
||||
regular: number;
|
||||
evening: number;
|
||||
emergency: number;
|
||||
overtime: number;
|
||||
vacation: number;
|
||||
holiday: number;
|
||||
sick: number;
|
||||
}
|
||||
export class TotalExpenses {
|
||||
expenses: number;
|
||||
perd_diem: number;
|
||||
on_call: number;
|
||||
mileage: number;
|
||||
}
|
||||
|
||||
export class Shift {
|
||||
date: string;
|
||||
start: string;
|
||||
end: string;
|
||||
type: string;
|
||||
is_remote: boolean;
|
||||
is_approved: boolean;
|
||||
shift_id?: number | null;
|
||||
comment?: string | null;
|
||||
}
|
||||
|
||||
export class Expense {
|
||||
date: string;
|
||||
is_approved: boolean;
|
||||
comment: string;
|
||||
amount?: number;
|
||||
mileage?: number;
|
||||
attachment?: string;
|
||||
expense_id?: number | null;
|
||||
supervisor_comment?: string | null;
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import { EmailToIdResolver } from "src/modules/shared/utils/resolve-email-id.uti
|
|||
import { BankCodesResolver } from "src/modules/shared/utils/resolve-bank-type-id.utils";
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
import { TimesheetMap } from "../utils-helpers-others/timesheet.types";
|
||||
import { Shift, Expense } from "../dtos/timesheet.dto";
|
||||
|
||||
@Injectable()
|
||||
export class TimesheetsCommandService extends BaseApprovalService<Timesheets>{
|
||||
|
|
@ -50,6 +51,44 @@ export class TimesheetsCommandService extends BaseApprovalService<Timesheets>{
|
|||
return timesheet;
|
||||
}
|
||||
|
||||
/**_____________________________________________________________________________________________
|
||||
create/update/delete shifts and expenses from 1 or many timesheet(s)
|
||||
|
||||
-this function receives an email and an array of timesheets
|
||||
|
||||
-this function will find the timesheets with all shifts and expenses
|
||||
-this function will calculate total hours, total expenses, filtered by types,
|
||||
cumulate in daily and weekly.
|
||||
|
||||
-the timesheet_id will be determined using the employee email
|
||||
-with the timesheet_id, all shifts and expenses will be fetched
|
||||
|
||||
-with shift_id and expense_id, this function will compare both
|
||||
datas from the DB and from the body of the function and then:
|
||||
-it will create a shift if no shift is found in the DB
|
||||
-it will update a shift if a shift is found in the DB
|
||||
-it will delete a shift if a shift is found and no data is received from the frontend
|
||||
|
||||
This function will be used for the Timesheet Page for an employee to enter, modify or delete and entry
|
||||
This function will also be used in the modal of the timesheet validation page to
|
||||
allow a supervisor to enter, modify or delete and entry of a selected employee
|
||||
_____________________________________________________________________________________________*/
|
||||
|
||||
async findTimesheetsByEmailAndPayPeriod(email: string, year: number, period_no: number, timesheets: Timesheets[]): Promise<Timesheets[]> {
|
||||
const employee_id = await this.emailResolver.findIdByEmail(email);
|
||||
|
||||
|
||||
return timesheets;
|
||||
}
|
||||
|
||||
async upsertOrDeleteShiftsByEmailAndDate(email:string, shift_ids: Shift[]) {}
|
||||
|
||||
async upsertOrDeleteExpensesByEmailAndDate(email:string, expenses_id: Expense[]) {}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//_____________________________________________________________________________________________
|
||||
//
|
||||
//_____________________________________________________________________________________________
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user