diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml deleted file mode 100644 index d1ccb54..0000000 --- a/.github/workflows/e2e.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: e2e -on: - push: - branches: [main] - pull_request: - -jobs: - e2e: - runs-on: ubuntu-latest - services: - postgres: - image: postgres:16 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: dev # ou test - ports: ["5432:5432"] - options: >- - --health-cmd="pg_isready -U postgres -d dev" - --health-interval=5s - --health-timeout=5s - --health-retries=20 - env: - DATABASE_URL: postgresql://postgres:postgres@localhost:5432/dev?schema=public - TZ: UTC - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: { node-version: '18' } - - run: npm ci - - run: npx prisma migrate deploy - - run: npm run seed:all - - run: npm run test:e2e:ci diff --git a/src/identity-and-account/authentication/controllers/auth.controller.ts b/src/identity-and-account/authentication/controllers/auth.controller.ts index 31e5f81..7abcba6 100644 --- a/src/identity-and-account/authentication/controllers/auth.controller.ts +++ b/src/identity-and-account/authentication/controllers/auth.controller.ts @@ -43,6 +43,8 @@ export class AuthController { response.clearCookie('connect.sid', { path: '/', }); + + response.sendStatus(200); }) } } diff --git a/src/time-and-attendance/domains/services/sick-leave.service.ts b/src/time-and-attendance/domains/services/sick-leave.service.ts index 35e422b..19684b7 100644 --- a/src/time-and-attendance/domains/services/sick-leave.service.ts +++ b/src/time-and-attendance/domains/services/sick-leave.service.ts @@ -122,7 +122,7 @@ export class SickLeaveService { id: true, paid_time_off: { select: { - banked_hours: true + sick_hours: true }, }, }, @@ -134,7 +134,7 @@ export class SickLeaveService { if (!employee.paid_time_off) { return { success: false, error: 'SICK_HOURS_BANK_NOT_FOUND' } as Result; } - const sick_bank = (employee.paid_time_off.banked_hours).toNumber(); + const sick_bank = (employee.paid_time_off.sick_hours).toNumber(); if (sick_bank <= 0) return { success: false, error: 'EMPTY_SICK_HOURS_BANK' } as Result; if (asked_hours > sick_bank) { @@ -143,11 +143,11 @@ export class SickLeaveService { await tx.paidTimeOff.update({ where: { employee_id: employee.id }, data: { - banked_hours: { decrement: asked_hours }, + sick_hours: { decrement: asked_hours }, last_updated: new Date(), }, - select: { banked_hours: true }, }); + return { success: true, data: asked_hours } as Result; } }); diff --git a/src/time-and-attendance/paid-time-off/REST.test.http b/src/time-and-attendance/paid-time-off/REST.test.http new file mode 100644 index 0000000..ecd228c --- /dev/null +++ b/src/time-and-attendance/paid-time-off/REST.test.http @@ -0,0 +1 @@ +GET http://localhost:3000/paid-time-off/totals \ No newline at end of file diff --git a/src/time-and-attendance/paid-time-off/paid-time-off.controller.ts b/src/time-and-attendance/paid-time-off/paid-time-off.controller.ts new file mode 100644 index 0000000..977ad77 --- /dev/null +++ b/src/time-and-attendance/paid-time-off/paid-time-off.controller.ts @@ -0,0 +1,22 @@ +import { Controller, Get, Query } from "@nestjs/common"; +import { Prisma } from "@prisma/client"; +import { Access } from "src/common/decorators/module-access.decorators"; +import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators"; +import { Result } from "src/common/errors/result-error.factory"; +import { PaidTimeOffBankHoursService } from "src/time-and-attendance/paid-time-off/paid-time-off.service"; + +@Controller('paid-time-off') +export class PaidTimeOffController { + constructor( + private readonly paidTimeOffService: PaidTimeOffBankHoursService, + ) { } + + @Get('totals') + @ModuleAccessAllowed('timesheets', 'timesheets_approval', 'employee_management') + async getPaidTimeOffTotalsForOneEmployee( + @Access('email') email: string, + @Query('email') employee_email?: string, + ) { + return this.paidTimeOffService.getPaidTimeOffTotalsWithEmployeeEmail(employee_email ?? email); + } +} \ No newline at end of file diff --git a/src/time-and-attendance/paid-time-off/paid-time-off.module.ts b/src/time-and-attendance/paid-time-off/paid-time-off.module.ts index eb4cd93..704f2b9 100644 --- a/src/time-and-attendance/paid-time-off/paid-time-off.module.ts +++ b/src/time-and-attendance/paid-time-off/paid-time-off.module.ts @@ -4,18 +4,20 @@ import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service"; import { BankedHoursService } from "src/time-and-attendance/domains/services/banking-hours.service"; import { SickLeaveService } from "src/time-and-attendance/domains/services/sick-leave.service"; import { VacationService } from "src/time-and-attendance/domains/services/vacation.service"; -import { PaidTimeOFfBankHoursService } from "src/time-and-attendance/paid-time-off/paid-time-off.service"; +import { PaidTimeOffController } from "src/time-and-attendance/paid-time-off/paid-time-off.controller"; +import { PaidTimeOffBankHoursService } from "src/time-and-attendance/paid-time-off/paid-time-off.service"; @Module({ + controllers: [PaidTimeOffController], providers: [ PrismaPostgresService, EmailToIdResolver, - PaidTimeOFfBankHoursService, + PaidTimeOffBankHoursService, VacationService, SickLeaveService, BankedHoursService, ], exports: [ - PaidTimeOFfBankHoursService, + PaidTimeOffBankHoursService, ], }) export class PaidTimeOffModule { } \ No newline at end of file diff --git a/src/time-and-attendance/paid-time-off/paid-time-off.service.ts b/src/time-and-attendance/paid-time-off/paid-time-off.service.ts index 44a7375..f3ebaa2 100644 --- a/src/time-and-attendance/paid-time-off/paid-time-off.service.ts +++ b/src/time-and-attendance/paid-time-off/paid-time-off.service.ts @@ -1,21 +1,51 @@ import { Injectable } from "@nestjs/common"; import { Result } from "src/common/errors/result-error.factory"; +import { EmailToIdResolver } from "src/common/mappers/email-id.mapper"; import { computeHours } from "src/common/utils/date-utils"; import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service"; import { BankedHoursService } from "src/time-and-attendance/domains/services/banking-hours.service"; import { SickLeaveService } from "src/time-and-attendance/domains/services/sick-leave.service"; import { VacationService } from "src/time-and-attendance/domains/services/vacation.service"; -import { paid_time_off_mapping, paid_time_off_types } from "src/time-and-attendance/paid-time-off/paid-time-off.dto"; +import { paid_time_off_mapping, paid_time_off_types, PaidTimeOffDto } from "src/time-and-attendance/paid-time-off/paid-time-off.dto"; @Injectable() -export class PaidTimeOFfBankHoursService { +export class PaidTimeOffBankHoursService { constructor( private readonly prisma: PrismaPostgresService, private readonly bankingService: BankedHoursService, private readonly vacationService: VacationService, private readonly sickLeaveService: SickLeaveService, + private readonly emailResolver: EmailToIdResolver, ) { } + getPaidTimeOffTotalsWithEmployeeEmail = async (email: string): Promise, string>> => { + const employee_info = await this.emailResolver.findIdByEmail(email); + + + if (!employee_info.success) + return { success: false, error: 'USER_NOT_FOUND' } + + const pto = await this.prisma.paidTimeOff.findUnique({ + where: { employee_id: employee_info.data }, + select: { + vacation_hours: true, + sick_hours: true, + banked_hours: true, + } + }) + + if (!pto) + return { success: false, error: 'PTO_NOT_FOUND' } + + const ptoData: Partial = { + sick_hours: Number(pto.sick_hours), + vacation_hours: Number(pto.vacation_hours), + banked_hours: Number(pto.banked_hours), + } + + return { success: true, data: ptoData } + } + //called during update function of Shifts Module updatePaidTimeOffBankHoursWhenShiftUpdate = async ( start_time: Date, diff --git a/src/time-and-attendance/shifts/services/shifts-create.service.ts b/src/time-and-attendance/shifts/services/shifts-create.service.ts index b35a460..519712d 100644 --- a/src/time-and-attendance/shifts/services/shifts-create.service.ts +++ b/src/time-and-attendance/shifts/services/shifts-create.service.ts @@ -143,7 +143,8 @@ export class ShiftsCreateService { } if (!result.success) return { success: false, error: result.error }; - const valid_hours = result.data / 1.5; + + const valid_hours = result.data; adjusted_end_time = new Date(normed_shift.data.start_time); adjusted_end_time.setHours(adjusted_end_time.getHours() + valid_hours); } diff --git a/src/time-and-attendance/shifts/services/shifts-delete.service.ts b/src/time-and-attendance/shifts/services/shifts-delete.service.ts index bd2c568..b1a03db 100644 --- a/src/time-and-attendance/shifts/services/shifts-delete.service.ts +++ b/src/time-and-attendance/shifts/services/shifts-delete.service.ts @@ -2,14 +2,14 @@ import { Injectable } from "@nestjs/common"; import { Result } from "src/common/errors/result-error.factory"; import { EmailToIdResolver } from "src/common/mappers/email-id.mapper"; import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service"; -import { PaidTimeOFfBankHoursService } from "src/time-and-attendance/paid-time-off/paid-time-off.service"; +import { PaidTimeOffBankHoursService } from "src/time-and-attendance/paid-time-off/paid-time-off.service"; import { PayPeriodEventService } from "src/time-and-attendance/pay-period/services/pay-period-event.service"; @Injectable() export class ShiftsDeleteService { constructor( private readonly prisma: PrismaPostgresService, - private readonly paidTimeOffService: PaidTimeOFfBankHoursService, + private readonly paidTimeOffService: PaidTimeOffBankHoursService, private readonly emailResolver: EmailToIdResolver, private readonly payPeriodEventService: PayPeriodEventService, ) { } diff --git a/src/time-and-attendance/shifts/services/shifts-update.service.ts b/src/time-and-attendance/shifts/services/shifts-update.service.ts index c6c52fb..2044a0e 100644 --- a/src/time-and-attendance/shifts/services/shifts-update.service.ts +++ b/src/time-and-attendance/shifts/services/shifts-update.service.ts @@ -10,7 +10,7 @@ import { shift_select } from "src/time-and-attendance/utils/selects.utils"; import { Normalized } from "src/time-and-attendance/utils/type.utils"; import { ShiftDto } from "src/time-and-attendance/shifts/shift.dto"; import { EmailToIdResolver } from "src/common/mappers/email-id.mapper"; -import { PaidTimeOFfBankHoursService } from "src/time-and-attendance/paid-time-off/paid-time-off.service"; +import { PaidTimeOffBankHoursService } from "src/time-and-attendance/paid-time-off/paid-time-off.service"; import { paid_time_off_types } from "src/time-and-attendance/paid-time-off/paid-time-off.dto"; import { PayPeriodEventService } from "src/time-and-attendance/pay-period/services/pay-period-event.service"; @@ -21,7 +21,7 @@ export class ShiftsUpdateService { private readonly typeResolver: BankCodesResolver, private readonly timesheetResolver: EmployeeTimesheetResolver, private readonly emailResolver: EmailToIdResolver, - private readonly paidTimeOffService: PaidTimeOFfBankHoursService, + private readonly paidTimeOffService: PaidTimeOffBankHoursService, private readonly payPeriodEventService: PayPeriodEventService, ) { } diff --git a/src/time-and-attendance/shifts/shifts.module.ts b/src/time-and-attendance/shifts/shifts.module.ts index 5d979e0..2374c38 100644 --- a/src/time-and-attendance/shifts/shifts.module.ts +++ b/src/time-and-attendance/shifts/shifts.module.ts @@ -8,7 +8,7 @@ import { ShiftsUpdateService } from 'src/time-and-attendance/shifts/services/shi import { VacationService } from 'src/time-and-attendance/domains/services/vacation.service'; import { BankedHoursService } from 'src/time-and-attendance/domains/services/banking-hours.service'; import { PaidTimeOffModule } from 'src/time-and-attendance/paid-time-off/paid-time-off.module'; -import { PaidTimeOFfBankHoursService } from 'src/time-and-attendance/paid-time-off/paid-time-off.service'; +import { PaidTimeOffBankHoursService } from 'src/time-and-attendance/paid-time-off/paid-time-off.service'; import { PayPeriodEventService } from 'src/time-and-attendance/pay-period/services/pay-period-event.service'; @Module({ @@ -20,7 +20,7 @@ import { PayPeriodEventService } from 'src/time-and-attendance/pay-period/servic ShiftsDeleteService, VacationService, BankedHoursService, - PaidTimeOFfBankHoursService, + PaidTimeOffBankHoursService, PayPeriodEventService, ], exports: [ diff --git a/src/time-and-attendance/time-and-attendance.module.ts b/src/time-and-attendance/time-and-attendance.module.ts index 7b7696c..1fb589d 100644 --- a/src/time-and-attendance/time-and-attendance.module.ts +++ b/src/time-and-attendance/time-and-attendance.module.ts @@ -3,7 +3,8 @@ import { BusinessLogicsModule } from "src/time-and-attendance/domains/business-l import { VacationService } from "src/time-and-attendance/domains/services/vacation.service"; import { BankedHoursService } from "src/time-and-attendance/domains/services/banking-hours.service"; import { PaidTimeOffModule } from "src/time-and-attendance/paid-time-off/paid-time-off.module"; -import { PaidTimeOFfBankHoursService } from "src/time-and-attendance/paid-time-off/paid-time-off.service"; +import { PaidTimeOffController } from "src/time-and-attendance/paid-time-off/paid-time-off.controller"; +import { PaidTimeOffBankHoursService } from "src/time-and-attendance/paid-time-off/paid-time-off.service"; import { ExpenseController } from "src/time-and-attendance/expenses/expense.controller"; import { ExpenseCreateService } from "src/time-and-attendance/expenses/services/expense-create.service"; @@ -64,7 +65,7 @@ import { PayPeriodEventService } from "./pay-period/services/pay-period-event.se ExpenseController, PayPeriodsController, CsvExportController, - + PaidTimeOffController, ], providers: [ GetTimesheetsOverviewService, @@ -90,7 +91,7 @@ import { PayPeriodEventService } from "./pay-period/services/pay-period-event.se CsvGeneratorService, VacationService, BankedHoursService, - PaidTimeOFfBankHoursService, + PaidTimeOffBankHoursService, PayPeriodEventService, ], exports: [TimesheetApprovalService],