From b269062816714c9516592a8acebdd5c3408c5b7a Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Wed, 4 Feb 2026 14:13:06 -0500 Subject: [PATCH] fix(Prisma): Fix prisma queries around the whole app to match new structure of many instance of clients/services files. added scripts to manage more than one schema at a time --- prisma/mariadb/mariadb.client.ts | 3 + prisma/mariadb/prisma-mariadb.module.ts | 2 +- prisma/mariadb/prisma-mariadb.service.ts | 13 +- prisma/mariadb/schema.prisma | 2 +- prisma/postgres/READMEprisma.md | 6 + prisma/postgres/postgres.client.ts | 11 + prisma/postgres/prisma-postgres.service.ts | 15 +- prisma/postgres/schema.prisma | 2 +- prisma/prisma-legacy/legacy.client.ts | 11 + prisma/prisma-legacy/prisma-legacy.module.ts | 2 +- prisma/prisma-legacy/prisma-legacy.service.ts | 14 +- prisma/prisma-legacy/schema.prisma | 2 +- src/app.module.ts | 6 +- src/common/shared/base-approval.service.ts | 4 +- .../accounts/test-account.service.ts | 2 +- .../strategies/authentik.strategy.ts | 1 - .../employees/employees.controller.ts | 2 +- .../services/employees-create.service.ts | 4 +- .../services/employees-get.service.ts | 6 +- .../services/employees-update.service.ts | 6 +- .../help/help-page.controller.ts | 2 +- .../help/help-page.service.ts | 2 +- .../preferences/preferences.controller.ts | 2 +- .../preferences/preferences.service.ts | 4 +- .../services/module-access-get.service.ts | 2 +- .../services/module-access-update.service.ts | 8 +- .../services/abstract-user.service.ts | 2 +- src/main.ts | 6 +- src/prisma-legacy/prisma.module.ts | 9 - src/prisma-legacy/prisma.service.ts | 18 - .../services/attachment-archival.service.ts | 2 +- .../services/attachment-delete.service.ts | 2 +- .../services/attachment-get.service.ts | 10 +- .../services/attachment-upload.service.ts | 2 +- .../services/garbage-collector.service.ts | 4 +- .../bank-codes/bank-codes.service.ts | 8 +- .../domains/services/banking-hours.service.ts | 4 +- .../domains/services/holiday.service.ts | 2 +- .../domains/services/mileage.service.ts | 2 +- .../domains/services/overtime.service.ts | 4 +- .../domains/services/sick-leave.service.ts | 18 +- .../domains/services/vacation.service.ts | 4 +- .../services/expense-create.service.ts | 4 +- .../services/expense-delete.service.ts | 4 +- .../services/expense-update.service.ts | 6 +- .../exports/csv-exports.controller.ts | 2 +- .../exports/services/csv-exports.service.ts | 14 +- .../leave-requests/leave-request.dto.ts | 70 ++-- .../leave-requests-archive.mapper.ts | 43 ++- .../leave-requests.controller.ts | 44 +-- .../services/leave-request.service.ts | 320 +++++++++--------- .../utils/leave-request.util.ts | 178 +++++----- .../utils/leave-requests-archive.select.ts | 28 +- .../paid-time-off/paid-time-off.service.ts | 4 +- .../pay-periods-build-overview.service.ts | 2 +- .../services/pay-periods-command.service.ts | 6 +- .../services/pay-periods-query.service.ts | 4 +- .../schedule-presets-apply.service.ts | 8 +- .../schedule-presets-create.service.ts | 4 +- .../schedule-presets-delete.service.ts | 6 +- .../services/schedule-presets-get.service.ts | 2 +- .../schedule-presets-update.service.ts | 4 +- .../shifts/services/shifts-create.service.ts | 6 +- .../shifts/services/shifts-delete.service.ts | 4 +- .../shifts/services/shifts-update.service.ts | 4 +- .../services/timesheet-approval.service.ts | 14 +- .../timesheet-employee-overview.service.ts | 12 +- .../timesheets/timesheet.mapper.ts | 3 +- .../utils/selects.utils.ts | 3 +- src/time-and-attendance/utils/type.utils.ts | 3 +- 70 files changed, 523 insertions(+), 510 deletions(-) create mode 100644 prisma/mariadb/mariadb.client.ts create mode 100644 prisma/postgres/postgres.client.ts create mode 100644 prisma/prisma-legacy/legacy.client.ts delete mode 100644 src/prisma-legacy/prisma.module.ts delete mode 100644 src/prisma-legacy/prisma.service.ts diff --git a/prisma/mariadb/mariadb.client.ts b/prisma/mariadb/mariadb.client.ts new file mode 100644 index 0000000..fb2d81d --- /dev/null +++ b/prisma/mariadb/mariadb.client.ts @@ -0,0 +1,3 @@ +import { PrismaClient } from '@prisma/client'; + +export const mariadbClient = new PrismaClient(); \ No newline at end of file diff --git a/prisma/mariadb/prisma-mariadb.module.ts b/prisma/mariadb/prisma-mariadb.module.ts index 756ae56..cdce2d5 100644 --- a/prisma/mariadb/prisma-mariadb.module.ts +++ b/prisma/mariadb/prisma-mariadb.module.ts @@ -7,4 +7,4 @@ import { PrismaMariaDbService } from 'prisma/mariadb/prisma-mariadb.service'; providers: [PrismaMariaDbService], exports: [PrismaMariaDbService], }) -export class PrismaPostgresModule {} +export class PrismaMariadbModule {} diff --git a/prisma/mariadb/prisma-mariadb.service.ts b/prisma/mariadb/prisma-mariadb.service.ts index 94cb24e..c28ce2c 100644 --- a/prisma/mariadb/prisma-mariadb.service.ts +++ b/prisma/mariadb/prisma-mariadb.service.ts @@ -3,17 +3,20 @@ import { adapterMariaDb } from 'prisma.config.mariadb'; import { PrismaClient } from 'prisma/generated/mariadb/client'; @Injectable() -export class PrismaMariaDbService extends PrismaClient - implements OnModuleInit, OnModuleDestroy { +export class PrismaMariaDbService extends PrismaClient implements OnModuleInit, OnModuleDestroy { + + readonly client: PrismaClient; + constructor() { - super({ adapter: adapterMariaDb }) + super({ adapter: adapterMariaDb }), + this.client = new PrismaClient({ adapter: adapterMariaDb }); } async onModuleInit() { - await this.$connect(); + await this.client.$connect(); } async onModuleDestroy() { - await this.$disconnect(); + await this.client.$disconnect(); } } diff --git a/prisma/mariadb/schema.prisma b/prisma/mariadb/schema.prisma index f083ff0..22c7226 100644 --- a/prisma/mariadb/schema.prisma +++ b/prisma/mariadb/schema.prisma @@ -1,6 +1,6 @@ generator client { provider = "prisma-client" - output = "../generated/mariadb" + output = "../node_modules/@prisma/client/mariadb" } datasource db { diff --git a/prisma/postgres/READMEprisma.md b/prisma/postgres/READMEprisma.md index 6ec62e0..b18b333 100644 --- a/prisma/postgres/READMEprisma.md +++ b/prisma/postgres/READMEprisma.md @@ -1,5 +1,11 @@ # TARGO-BACKEND prisma +# ******************************************************************************************************* +# MAJOR PRISMA UPDATE 2026-02-04 => from 6.13 to 7.3. A lot has changed and this read me needs updating.| +# added functionnalities to manage many schema files with many instance of clients and services | +# added scripts to generate, migrate and manage one or many database at once | +# ******************************************************************************************************* + Ce document court présente la configuration de Prisma et les conventions à respecter dans `prisma/schema.prisma`. http://prisma.io/docs/orm/prisma-schema diff --git a/prisma/postgres/postgres.client.ts b/prisma/postgres/postgres.client.ts new file mode 100644 index 0000000..c02a709 --- /dev/null +++ b/prisma/postgres/postgres.client.ts @@ -0,0 +1,11 @@ +import { PrismaClient } from '@prisma/client'; +import { PrismaPg } from '@prisma/adapter-pg'; +import { Pool } from 'pg'; + +const pool = new Pool({ + connectionString: process.env.DATABASE_URL_STAGING, +}); + +export const postgresClient = new PrismaClient({ + adapter: new PrismaPg(pool), +}); \ No newline at end of file diff --git a/prisma/postgres/prisma-postgres.service.ts b/prisma/postgres/prisma-postgres.service.ts index cd68ca5..43ca008 100644 --- a/prisma/postgres/prisma-postgres.service.ts +++ b/prisma/postgres/prisma-postgres.service.ts @@ -1,19 +1,22 @@ import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common'; +import { PrismaClient } from '@prisma/client'; import { adapterPostgres } from 'prisma.config.postgres'; -import { PrismaClient } from 'prisma/generated/postgres/client'; @Injectable() -export class PrismaPostgresService extends PrismaClient - implements OnModuleInit, OnModuleDestroy { +export class PrismaPostgresService extends PrismaClient implements OnModuleInit, OnModuleDestroy { + + readonly client: PrismaClient; + constructor() { - super({ adapter: adapterPostgres }) + super({ adapter: adapterPostgres }), + this.client = new PrismaClient({ adapter: adapterPostgres }); } async onModuleInit() { - await this.$connect(); + await this.client.$connect(); } async onModuleDestroy() { - await this.$disconnect(); + await this.client.$disconnect(); } } diff --git a/prisma/postgres/schema.prisma b/prisma/postgres/schema.prisma index 46d6491..46790d1 100644 --- a/prisma/postgres/schema.prisma +++ b/prisma/postgres/schema.prisma @@ -1,6 +1,6 @@ generator client { provider = "prisma-client" - output = "../generated/postgres" + output = "../node_modules/@prisma/client/postgres" previewFeatures = ["views"] } diff --git a/prisma/prisma-legacy/legacy.client.ts b/prisma/prisma-legacy/legacy.client.ts new file mode 100644 index 0000000..6af3c51 --- /dev/null +++ b/prisma/prisma-legacy/legacy.client.ts @@ -0,0 +1,11 @@ +import { PrismaClient } from '@prisma/client'; +import { PrismaPg } from '@prisma/adapter-pg'; +import { Pool } from 'pg'; + +const pool = new Pool({ + connectionString: process.env.DATABASE_URL_MARIADB, +}); + +export const legacyClient = new PrismaClient({ + adapter: new PrismaPg(pool), +}); \ No newline at end of file diff --git a/prisma/prisma-legacy/prisma-legacy.module.ts b/prisma/prisma-legacy/prisma-legacy.module.ts index f4522cd..981b368 100644 --- a/prisma/prisma-legacy/prisma-legacy.module.ts +++ b/prisma/prisma-legacy/prisma-legacy.module.ts @@ -7,4 +7,4 @@ import { PrismaLegacyService } from 'prisma/prisma-legacy/prisma-legacy.service' providers: [PrismaLegacyService], exports: [PrismaLegacyService], }) -export class PrismaPostgresModule {} +export class PrismaLegacyModule {} diff --git a/prisma/prisma-legacy/prisma-legacy.service.ts b/prisma/prisma-legacy/prisma-legacy.service.ts index f354e63..0b7a755 100644 --- a/prisma/prisma-legacy/prisma-legacy.service.ts +++ b/prisma/prisma-legacy/prisma-legacy.service.ts @@ -1,19 +1,21 @@ import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common'; +import { PrismaClient } from '@prisma/client'; import { adapterLegacy } from 'prisma.config.legacy'; -import { PrismaClient } from 'prisma/generated/legacy/client'; @Injectable() -export class PrismaLegacyService extends PrismaClient - implements OnModuleInit, OnModuleDestroy { +export class PrismaLegacyService implements OnModuleInit, OnModuleDestroy { + + readonly client: PrismaClient; + constructor() { - super({ adapter: adapterLegacy }) + this.client = new PrismaClient({adapter: adapterLegacy }) } async onModuleInit() { - await this.$connect(); + await this.client.$connect(); } async onModuleDestroy() { - await this.$disconnect(); + await this.client.$disconnect(); } } diff --git a/prisma/prisma-legacy/schema.prisma b/prisma/prisma-legacy/schema.prisma index 9adcc70..ab56ac6 100644 --- a/prisma/prisma-legacy/schema.prisma +++ b/prisma/prisma-legacy/schema.prisma @@ -1,6 +1,6 @@ generator client { provider = "prisma-client" - output = "../generated/legacy" + output = "../node_modules/@prisma/client/legacy" } datasource db { diff --git a/src/app.module.ts b/src/app.module.ts index 2e096a6..4f9ba68 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -11,9 +11,9 @@ import { ValidationError } from 'class-validator'; import { TimeAndAttendanceModule } from 'src/time-and-attendance/time-and-attendance.module'; import { AuthenticationModule } from 'src/identity-and-account/authentication/auth.module'; import { IdentityAndAccountModule } from 'src/identity-and-account/identity-and-account.module'; -import { PrismaLegacyModule } from 'src/prisma-legacy/prisma.module'; import { ChatbotModule } from 'src/chatbot/chatbot.module'; -import { PrismaMariaDbService } from 'prisma/mariadb/prisma-mariadb.service'; +import { PrismaMariadbModule } from 'prisma/mariadb/prisma-mariadb.module'; +import { PrismaLegacyModule } from 'prisma/prisma-legacy/prisma-legacy.module'; @Module({ imports: [ @@ -22,7 +22,7 @@ import { PrismaMariaDbService } from 'prisma/mariadb/prisma-mariadb.service'; ScheduleModule.forRoot(), //cronjobs NotificationsModule, PrismaPostgresModule, - PrismaMariaDbService, + PrismaMariadbModule, PrismaLegacyModule, TimeAndAttendanceModule, IdentityAndAccountModule, diff --git a/src/common/shared/base-approval.service.ts b/src/common/shared/base-approval.service.ts index 6f8ccc3..4c5b7f7 100644 --- a/src/common/shared/base-approval.service.ts +++ b/src/common/shared/base-approval.service.ts @@ -1,5 +1,5 @@ import { NotFoundException } from "@nestjs/common"; -import { Prisma } from "@prisma/client"; +import { Prisma, PrismaClient } from "@prisma/client"; import { PrismaClientKnownRequestError } from "@prisma/client/runtime/client"; import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service"; @@ -18,7 +18,7 @@ export abstract class BaseApprovalService { //returns the corresponding Prisma delegate protected abstract get delegate(): UpdatableDelegate; - protected abstract delegateFor(tx: Prisma.TransactionClient): UpdatableDelegate; + protected abstract delegateFor(tx: Prisma.TransactionClient | PrismaClient): UpdatableDelegate; //standard update Aproval async updateApproval(id: number, is_approved: boolean): Promise { diff --git a/src/customer-support/accounts/test-account.service.ts b/src/customer-support/accounts/test-account.service.ts index 2efc754..5c41eae 100644 --- a/src/customer-support/accounts/test-account.service.ts +++ b/src/customer-support/accounts/test-account.service.ts @@ -1,6 +1,6 @@ #!/usr/bin/env ts-node -import { adapterMariaDb } from 'prisma.config.mariadb'; +import { adapterMariaDb } from '../../../prisma.config.mariadb'; import { PrismaClient as MariaDbPrismaClient } from 'prisma/generated/mariadb/client'; import { AccountService } from 'src/customer-support/accounts/account.service'; diff --git a/src/identity-and-account/authentication/strategies/authentik.strategy.ts b/src/identity-and-account/authentication/strategies/authentik.strategy.ts index 5d1c029..6f9c5b0 100644 --- a/src/identity-and-account/authentication/strategies/authentik.strategy.ts +++ b/src/identity-and-account/authentication/strategies/authentik.strategy.ts @@ -3,7 +3,6 @@ import { Strategy as OIDCStrategy, Profile, VerifyCallback } from 'passport-open import { PassportStrategy } from '@nestjs/passport'; import { Injectable } from '@nestjs/common'; import { AuthentikAuthService } from '../services/authentik-auth.service'; -import { ValidationError } from 'class-validator'; export interface AuthentikPayload { iss: string; // Issuer diff --git a/src/identity-and-account/employees/employees.controller.ts b/src/identity-and-account/employees/employees.controller.ts index 5771a06..ad44785 100644 --- a/src/identity-and-account/employees/employees.controller.ts +++ b/src/identity-and-account/employees/employees.controller.ts @@ -1,5 +1,5 @@ import { Controller, Get, Query, Body, Post, Patch } from "@nestjs/common"; -import { Modules as ModulesEnum } from ".prisma/client"; +import { Modules as ModulesEnum } from "@prisma/client"; import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators"; import { Access } from "src/common/decorators/module-access.decorators"; import { Result } from "src/common/errors/result-error.factory"; diff --git a/src/identity-and-account/employees/services/employees-create.service.ts b/src/identity-and-account/employees/services/employees-create.service.ts index 8bbd715..1654eb6 100644 --- a/src/identity-and-account/employees/services/employees-create.service.ts +++ b/src/identity-and-account/employees/services/employees-create.service.ts @@ -17,7 +17,7 @@ export class EmployeesCreateService { const company_code = toCompanyCodeFromString(dto.company_name); const first_work_day = toDateFromString(dto.first_work_day); - await this.prisma.$transaction(async (tx) => { + await this.prisma.client.$transaction(async (tx) => { const user: Users = await tx.users.create({ data: { first_name: dto.first_name, @@ -56,7 +56,7 @@ export class EmployeesCreateService { private toIdFromFullName = async (full_name: string) => { const [first_name, last_name] = full_name.split(' ', 2); - let supervisor = await this.prisma.users.findFirst({ + let supervisor = await this.prisma.client.users.findFirst({ where: { first_name, last_name }, select: { employee: { select: { id: true } } } }); diff --git a/src/identity-and-account/employees/services/employees-get.service.ts b/src/identity-and-account/employees/services/employees-get.service.ts index 1a29a4f..f7abe25 100644 --- a/src/identity-and-account/employees/services/employees-get.service.ts +++ b/src/identity-and-account/employees/services/employees-get.service.ts @@ -18,7 +18,7 @@ export class EmployeesGetService { ) { } async findListEmployees(): Promise[], string>> { - const employee_list = await this.prisma.employees.findMany({ + const employee_list = await this.prisma.client.employees.findMany({ select: { user: { select: { @@ -71,7 +71,7 @@ export class EmployeesGetService { const user_id = await this.emailResolver.resolveUserIdWithEmail(email); if (!user_id.success) return { success: false, error: 'INVALID_USER' }; - const existing_profile = await this.prisma.employees.findUnique({ + const existing_profile = await this.prisma.client.employees.findUnique({ where: { user_id: user_id.data }, select: { user: { @@ -136,7 +136,7 @@ export class EmployeesGetService { const user_id = await this.emailResolver.resolveUserIdWithEmail(account_email); if (!user_id.success) return { success: false, error: 'INVALID_USER' }; - const employee = await this.prisma.employees.findUnique({ + const employee = await this.prisma.client.employees.findUnique({ where: { user_id: user_id.data }, select: { user: { diff --git a/src/identity-and-account/employees/services/employees-update.service.ts b/src/identity-and-account/employees/services/employees-update.service.ts index a351d83..ce9e52d 100644 --- a/src/identity-and-account/employees/services/employees-update.service.ts +++ b/src/identity-and-account/employees/services/employees-update.service.ts @@ -20,7 +20,7 @@ export class EmployeesUpdateService { const user_id = await this.emailResolver.resolveUserIdWithEmail(dto.email); if (!user_id.success) return { success: false, error: 'EMPLOYEE_NOT_FOUND'} - const employee = await this.prisma.employees.findFirst({ + const employee = await this.prisma.client.employees.findFirst({ where: { user_id: user_id.data }, select: { id: true }, }) @@ -32,7 +32,7 @@ export class EmployeesUpdateService { const normalized_access = toBooleanFromString(dto.user_module_access); const last_work_day = dto.last_work_day ? toDateFromString(dto.last_work_day) : null; - await this.prisma.$transaction(async (tx) => { + await this.prisma.client.$transaction(async (tx) => { await tx.users.update({ where: { id: user_id.data }, data: { @@ -109,7 +109,7 @@ export class EmployeesUpdateService { private toIdFromFullName = async (full_name: string) => { const [first_name, last_name] = full_name.split(' ', 2); - let supervisor = await this.prisma.users.findFirst({ + let supervisor = await this.prisma.client.users.findFirst({ where: { first_name, last_name }, select: { employee: { select: { id: true } } } }); diff --git a/src/identity-and-account/help/help-page.controller.ts b/src/identity-and-account/help/help-page.controller.ts index f3287b9..5c1c2a4 100644 --- a/src/identity-and-account/help/help-page.controller.ts +++ b/src/identity-and-account/help/help-page.controller.ts @@ -1,7 +1,7 @@ import { Controller, Get } from "@nestjs/common"; import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators"; import { HomePageService } from "src/identity-and-account/help/help-page.service"; -import { Modules as ModulesEnum } from ".prisma/client"; +import { Modules as ModulesEnum } from "@prisma/client"; import { Access } from "src/common/decorators/module-access.decorators"; @Controller() diff --git a/src/identity-and-account/help/help-page.service.ts b/src/identity-and-account/help/help-page.service.ts index 085c16d..0434e67 100644 --- a/src/identity-and-account/help/help-page.service.ts +++ b/src/identity-and-account/help/help-page.service.ts @@ -14,7 +14,7 @@ export class HomePageService { const user_id = await this.emailresolver.resolveUserIdWithEmail(email); if (!user_id.success) return { success: false, error: 'INVALID_EMAIL' }; - const module_access = await this.prisma.userModuleAccess.findUnique({ + const module_access = await this.prisma.client.userModuleAccess.findUnique({ where: { user_id: user_id.data }, select: { dashboard: true, diff --git a/src/identity-and-account/preferences/preferences.controller.ts b/src/identity-and-account/preferences/preferences.controller.ts index ad5423a..8a94ebf 100644 --- a/src/identity-and-account/preferences/preferences.controller.ts +++ b/src/identity-and-account/preferences/preferences.controller.ts @@ -4,7 +4,7 @@ import { PreferencesDto } from "./preferences.dto"; import { Result } from "src/common/errors/result-error.factory"; import { Access } from "src/common/decorators/module-access.decorators"; import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators"; -import { Modules as ModulesEnum } from ".prisma/client"; +import { Modules as ModulesEnum } from "@prisma/client"; @Controller('preferences') export class PreferencesController { diff --git a/src/identity-and-account/preferences/preferences.service.ts b/src/identity-and-account/preferences/preferences.service.ts index ab188df..a8190c0 100644 --- a/src/identity-and-account/preferences/preferences.service.ts +++ b/src/identity-and-account/preferences/preferences.service.ts @@ -16,7 +16,7 @@ export class PreferencesService { const user_id = await this.emailResolver.resolveUserIdWithEmail(account_email); if (!user_id.success) return { success: false, error: 'EMPLOYEE_NOT_FOUND' }; - const user_preferences = await this.prisma.preferences.findUnique({ + const user_preferences = await this.prisma.client.preferences.findUnique({ where: { user_id: user_id.data }, select: { id: true, @@ -46,7 +46,7 @@ export class PreferencesService { const user_id = await this.emailResolver.resolveUserIdWithEmail(email); if (!user_id.success) return { success: false, error: user_id.error } - const updated_preferences: PreferencesDto = await this.prisma.preferences.update({ + const updated_preferences: PreferencesDto = await this.prisma.client.preferences.update({ where: { user_id: user_id.data }, data: { notifications: dto.notifications, diff --git a/src/identity-and-account/user-module-access/services/module-access-get.service.ts b/src/identity-and-account/user-module-access/services/module-access-get.service.ts index b7dcdf9..5749060 100644 --- a/src/identity-and-account/user-module-access/services/module-access-get.service.ts +++ b/src/identity-and-account/user-module-access/services/module-access-get.service.ts @@ -17,7 +17,7 @@ export class AccessGetService { const user_id = await this.emailResolver.resolveUserIdWithEmail(account_email); if (!user_id.success) return { success: false, error: 'EMPLOYEE_NOT_FOUND' }; - const access = await this.prisma.userModuleAccess.findUnique({ + const access = await this.prisma.client.userModuleAccess.findUnique({ where: { user_id: user_id.data }, select: { timesheets: true, diff --git a/src/identity-and-account/user-module-access/services/module-access-update.service.ts b/src/identity-and-account/user-module-access/services/module-access-update.service.ts index 9219623..f540d17 100644 --- a/src/identity-and-account/user-module-access/services/module-access-update.service.ts +++ b/src/identity-and-account/user-module-access/services/module-access-update.service.ts @@ -16,7 +16,7 @@ export class AccessUpdateService { const user_id = await this.emailResolver.resolveUserIdWithEmail(account_email); if (!user_id.success) return { success: false, error: 'EMPLOYEE_NOT_FOUND' }; - const orignal_access = await this.prisma.userModuleAccess.findUnique({ + const orignal_access = await this.prisma.client.userModuleAccess.findUnique({ where: { user_id: user_id.data }, select: { id: true, @@ -30,7 +30,7 @@ export class AccessUpdateService { }); if (!orignal_access) return { success: false, error: 'MODULE_ACCESS_NOT_FOUND' }; - const updated_access:ModuleAccess = await this.prisma.userModuleAccess.update({ + const updated_access:ModuleAccess = await this.prisma.client.userModuleAccess.update({ where: { id: orignal_access.id }, data: { timesheets: dto.timesheets, @@ -57,13 +57,13 @@ export class AccessUpdateService { const user_id = await this.emailResolver.resolveUserIdWithEmail(account_email); if (!user_id.success) return { success: false, error: 'EMPLOYEE_NOT_FOUND' }; - const access = await this.prisma.userModuleAccess.findUnique({ + const access = await this.prisma.client.userModuleAccess.findUnique({ where: { user_id: user_id.data }, select: { id: true }, }); if (!access) return { success: false, error: 'MODULE_ACCESS_NOT_FOUND' }; - const revoked_access: ModuleAccess = await this.prisma.userModuleAccess.update({ + const revoked_access: ModuleAccess = await this.prisma.client.userModuleAccess.update({ where: { id: access.id }, data: { timesheets: false, diff --git a/src/identity-and-account/users-management/services/abstract-user.service.ts b/src/identity-and-account/users-management/services/abstract-user.service.ts index d0c2126..b021ab6 100644 --- a/src/identity-and-account/users-management/services/abstract-user.service.ts +++ b/src/identity-and-account/users-management/services/abstract-user.service.ts @@ -8,7 +8,7 @@ export abstract class AbstractUserService { constructor(protected readonly prisma: PrismaPostgresService) { } async findOneByEmail(email: string): Promise> { - const user = await this.prisma.users.findUnique({ + const user = await this.prisma.client.users.findUnique({ where: { email }, include: { user_module_access: { diff --git a/src/main.ts b/src/main.ts index 0a47df2..fee8f74 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,8 +12,8 @@ import { ModulesGuard } from './common/guards/modules.guard'; // import { writeFileSync } from 'fs'; import * as session from 'express-session'; import * as passport from 'passport'; -import { PrismaPostgresService } from 'prisma/postgres/prisma-postgres.service'; import { PrismaSessionStore } from '@quixo3/prisma-session-store'; +import { PrismaPostgresService } from 'prisma/postgres/prisma-postgres.service'; // import { initSupervisor } from 'scripts/init-supervisor'; // import { initializePaidTimeOff } from 'scripts/init-paid-time-off'; // import { initializePreferences } from 'scripts/init-preferences-access'; @@ -25,7 +25,7 @@ const SESSION_TOKEN_DURATION_MINUTES = 180 async function bootstrap() { const app = await NestFactory.create(AppModule); - const prisma_service = app.get(PrismaPostgresService); + const prisma = app.get(PrismaPostgresService); const reflector = app.get(Reflector); @@ -44,7 +44,7 @@ async function bootstrap() { maxAge: SESSION_TOKEN_DURATION_MINUTES * 60 * 1000, // property maxAge requires milliseconds httpOnly: true, }, - store: new PrismaSessionStore(prisma_service, { + store: new PrismaSessionStore(prisma, { sessionModelName: 'sessions', checkPeriod: SESSION_TOKEN_DURATION_MINUTES * 60 * 1000, //ms dbRecordIdIsSessionId: true, diff --git a/src/prisma-legacy/prisma.module.ts b/src/prisma-legacy/prisma.module.ts deleted file mode 100644 index add3840..0000000 --- a/src/prisma-legacy/prisma.module.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Global, Module } from '@nestjs/common'; -import { PrismaLegacyService } from './prisma.service'; - -@Global() -@Module({ - providers: [PrismaLegacyService], - exports: [PrismaLegacyService], -}) -export class PrismaLegacyModule {} diff --git a/src/prisma-legacy/prisma.service.ts b/src/prisma-legacy/prisma.service.ts deleted file mode 100644 index 2e8fe8e..0000000 --- a/src/prisma-legacy/prisma.service.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common'; -import { PrismaClient as PrismaLegacyClient } from '@prisma/client'; - -//Gestion des connections à la DB - -@Injectable() -export class PrismaLegacyService - extends PrismaLegacyClient - implements OnModuleInit, OnModuleDestroy -{ - async onModuleInit() { - await this.$connect(); - } - - async onModuleDestroy() { - await this.$disconnect(); - } -} diff --git a/src/time-and-attendance/attachments/services/attachment-archival.service.ts b/src/time-and-attendance/attachments/services/attachment-archival.service.ts index 1adac91..63b6ca5 100644 --- a/src/time-and-attendance/attachments/services/attachment-archival.service.ts +++ b/src/time-and-attendance/attachments/services/attachment-archival.service.ts @@ -35,7 +35,7 @@ export class AttachmentArchivalService { //only moves table content to archive and not blobs. private async archiveBatch(cutoff: Date, batch_size: number): Promise { - const moved = await this.prisma.$executeRaw ` + const moved = await this.prisma.client.$executeRaw ` WITH moved AS ( DELETE FROM "attachments" WHERE id IN ( diff --git a/src/time-and-attendance/attachments/services/attachment-delete.service.ts b/src/time-and-attendance/attachments/services/attachment-delete.service.ts index 5ce6793..77844bd 100644 --- a/src/time-and-attendance/attachments/services/attachment-delete.service.ts +++ b/src/time-and-attendance/attachments/services/attachment-delete.service.ts @@ -7,7 +7,7 @@ export class AttachmentDeleteService { constructor(private readonly prisma: PrismaPostgresService) { } async deleteAttachment(id: string): Promise> { - await this.prisma.$transaction(async (tx) => { + await this.prisma.client.$transaction(async (tx) => { const attachment = await tx.attachments.findUnique({ where: { id: Number(id) } }); if (!attachment) return { success: false, error: 'ATTACHMENT_NOT_FOUND' }; diff --git a/src/time-and-attendance/attachments/services/attachment-get.service.ts b/src/time-and-attendance/attachments/services/attachment-get.service.ts index bace544..4da9118 100644 --- a/src/time-and-attendance/attachments/services/attachment-get.service.ts +++ b/src/time-and-attendance/attachments/services/attachment-get.service.ts @@ -19,7 +19,7 @@ export class AttachmentGetService { async getListVariants(id: string): Promise> { const num_id = Number(id); if (!Number.isFinite(num_id)) return { success: false, error: 'INVALID_ATTACHMENTS' }; - const variants = await this.prisma.attachmentVariants.findMany({ + const variants = await this.prisma.client.attachmentVariants.findMany({ where: { attachment_id: num_id }, orderBy: { variant: 'asc' }, select: { variant: true, bytes: true, width: true, height: true, path: true, created_at: true }, @@ -43,8 +43,8 @@ export class AttachmentGetService { const skip = (page - 1) * page_size; const take = page_size; - const [items, total] = await this.prisma.$transaction([ - this.prisma.attachments.findMany({ + const [items, total] = await this.prisma.client.$transaction([ + this.prisma.client.attachments.findMany({ where, orderBy: { created_at: 'desc' }, skip, take, @@ -54,7 +54,7 @@ export class AttachmentGetService { }, }, }), - this.prisma.attachments.count({ where }), + this.prisma.client.attachments.count({ where }), ]); return { success: true, data: { page, page_size: take, total, items } }; @@ -65,7 +65,7 @@ export class AttachmentGetService { const num_id = Number(id); if (!Number.isFinite(num_id)) return { success: false, error: 'INVALID_ATTACHMENTS' }; - const attachment = await this.prisma.attachments.findUnique({ + const attachment = await this.prisma.client.attachments.findUnique({ where: { id: num_id }, include: { blob: true }, }); diff --git a/src/time-and-attendance/attachments/services/attachment-upload.service.ts b/src/time-and-attendance/attachments/services/attachment-upload.service.ts index 4dd8ae3..cb3648c 100644 --- a/src/time-and-attendance/attachments/services/attachment-upload.service.ts +++ b/src/time-and-attendance/attachments/services/attachment-upload.service.ts @@ -33,7 +33,7 @@ export class AttachmentUploadService { const { sha256, storage_path, size } = await this.disk.saveStreamAndHash(stream); const now = new Date(); - const attachment = await this.prisma.$transaction(async (tx) => { + const attachment = await this.prisma.client.$transaction(async (tx) => { //upsert blob: +1 ref await tx.blobs.upsert({ where: { sha256 }, diff --git a/src/time-and-attendance/attachments/services/garbage-collector.service.ts b/src/time-and-attendance/attachments/services/garbage-collector.service.ts index 2c35806..c1792be 100644 --- a/src/time-and-attendance/attachments/services/garbage-collector.service.ts +++ b/src/time-and-attendance/attachments/services/garbage-collector.service.ts @@ -41,7 +41,7 @@ export class GarbargeCollectorService { //Manage a single lot of orphan blobs private async collectBatch(): Promise { - const blobs = await this.prisma.blobs.findMany({ + const blobs = await this.prisma.client.blobs.findMany({ where: { refcount: { lte: 0 } }, select: { sha256: true, storage_path: true }, take: this.batch_size, @@ -67,7 +67,7 @@ export class GarbargeCollectorService { ); //deletes blobs lignes if file is deleted const hashes = blobs.map(blob => blob.sha256); - await this.prisma.blobs.deleteMany({ where: { sha256: { in: hashes } } }); + await this.prisma.client.blobs.deleteMany({ where: { sha256: { in: hashes } } }); return blobs.length; } diff --git a/src/time-and-attendance/bank-codes/bank-codes.service.ts b/src/time-and-attendance/bank-codes/bank-codes.service.ts index 18f7120..ca224dd 100644 --- a/src/time-and-attendance/bank-codes/bank-codes.service.ts +++ b/src/time-and-attendance/bank-codes/bank-codes.service.ts @@ -9,7 +9,7 @@ export class BankCodesService { async create(dto: Prisma.BankCodesCreateInput): Promise> { try { - await this.prisma.bankCodes.create({ + await this.prisma.client.bankCodes.create({ data: { type: dto.type, categorie: dto.categorie, @@ -24,12 +24,12 @@ export class BankCodesService { } findAll() { - return this.prisma.bankCodes.findMany(); + return this.prisma.client.bankCodes.findMany(); } async update(id: number, dto: Prisma.BankCodesUpdateInput): Promise> { try { - await this.prisma.bankCodes.update({ + await this.prisma.client.bankCodes.update({ where: { id }, data: { type: dto.type, @@ -46,7 +46,7 @@ export class BankCodesService { async delete(id: number): Promise> { try { - await this.prisma.bankCodes.delete({ + await this.prisma.client.bankCodes.delete({ where: { id }, }); return { success: true, data: true }; diff --git a/src/time-and-attendance/domains/services/banking-hours.service.ts b/src/time-and-attendance/domains/services/banking-hours.service.ts index e7f360d..0e39c66 100644 --- a/src/time-and-attendance/domains/services/banking-hours.service.ts +++ b/src/time-and-attendance/domains/services/banking-hours.service.ts @@ -12,8 +12,8 @@ export class BankedHoursService { if (asked_hours <= 0) return { success: false, error: 'INVALID_BANKING_HOURS' }; try { - const result = await this.prisma.$transaction(async (tx) => { - const employee = await this.prisma.employees.findUnique({ + const result = await this.prisma.client.$transaction(async (tx) => { + const employee = await this.prisma.client.employees.findUnique({ where: { id: employee_id }, select: { id: true, diff --git a/src/time-and-attendance/domains/services/holiday.service.ts b/src/time-and-attendance/domains/services/holiday.service.ts index 4bcb213..ca303ac 100644 --- a/src/time-and-attendance/domains/services/holiday.service.ts +++ b/src/time-and-attendance/domains/services/holiday.service.ts @@ -31,7 +31,7 @@ export class HolidayService { const window_end = new Date(holiday_week_start.getTime() - 1); const valid_codes = ['G1', 'G43', 'G56', 'G104', 'G105', 'G305', 'G700', 'G720']; - const shifts = await this.prisma.shifts.findMany({ + const shifts = await this.prisma.client.shifts.findMany({ where: { timesheet: { employee_id: employee_id }, date: { gte: window_start, lte: window_end }, diff --git a/src/time-and-attendance/domains/services/mileage.service.ts b/src/time-and-attendance/domains/services/mileage.service.ts index b946695..596a376 100644 --- a/src/time-and-attendance/domains/services/mileage.service.ts +++ b/src/time-and-attendance/domains/services/mileage.service.ts @@ -11,7 +11,7 @@ export class MileageService { if (amount < 0) return { success: false, error: 'The amount must be higher than 0' }; //fetch modifier - const bank_code = await this.prisma.bankCodes.findUnique({ + const bank_code = await this.prisma.client.bankCodes.findUnique({ where: { id: bank_code_id }, select: { modifier: true, type: true }, }); diff --git a/src/time-and-attendance/domains/services/overtime.service.ts b/src/time-and-attendance/domains/services/overtime.service.ts index d1fc68a..f97dffb 100644 --- a/src/time-and-attendance/domains/services/overtime.service.ts +++ b/src/time-and-attendance/domains/services/overtime.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@nestjs/common'; -import { Prisma, PrismaClient } from 'prisma/generated/postgres/client'; +import { Prisma, PrismaClient } from '@prisma/client'; import { getWeekStart, getWeekEnd, computeHours } from 'src/common/utils/date-utils'; import { PrismaPostgresService } from 'prisma/postgres/prisma-postgres.service'; import { DAILY_LIMIT_HOURS, WEEKLY_LIMIT_HOURS } from 'src/common/utils/constants.utils'; @@ -32,7 +32,7 @@ export class OvertimeService { constructor(private prisma: PrismaPostgresService) { } async getWeekOvertimeSummary(timesheet_id: number, date: Date, tx?: Tx): Promise> { - const db = (tx ?? this.prisma) as PrismaClient; + const db = (tx ?? this.prisma.client) as PrismaClient; const week_start = getWeekStart(date); const week_end = getWeekEnd(week_start); 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 6fda8de..8a07ce1 100644 --- a/src/time-and-attendance/domains/services/sick-leave.service.ts +++ b/src/time-and-attendance/domains/services/sick-leave.service.ts @@ -13,7 +13,7 @@ export class SickLeaveService { const today = new Date(); // get employee info - const employee = await this.prisma.employees.findUnique({ + const employee = await this.prisma.client.employees.findUnique({ where: { id: employee_id }, select: { first_work_day: true, @@ -32,9 +32,9 @@ export class SickLeaveService { } // get employee's PTO info, or create new details if not yet existing - let pto_details: Prisma.Result; + let pto_details: Prisma.Result; - pto_details = await this.prisma.paidTimeOff.findUnique({ + pto_details = await this.prisma.client.paidTimeOff.findUnique({ where: { employee_id: employee.id }, }) @@ -68,9 +68,9 @@ export class SickLeaveService { } // create a new PTO row - async createNewPTORow(employee_id: number, today: Date): Promise, string>> { + async createNewPTORow(employee_id: number, today: Date): Promise, string>> { try { - const new_pto_entry = await this.prisma.paidTimeOff.create({ + const new_pto_entry = await this.prisma.client.paidTimeOff.create({ data: { employee_id: employee_id, last_updated: today, @@ -94,7 +94,7 @@ export class SickLeaveService { // add n number of sick PTO hours to employee PTO async addHoursToPTO(sick_hours: number, employee_id: number, last_updated: Date) { try { - const update_pto = await this.prisma.paidTimeOff.update({ + const update_pto = await this.prisma.client.paidTimeOff.update({ where: { employee_id, }, @@ -114,8 +114,8 @@ export class SickLeaveService { if (asked_hours <= 0) return { success: false, error: 'INVALID_BANKING_HOURS' }; try { - const result = await this.prisma.$transaction(async (tx) => { - const employee = await this.prisma.employees.findUnique({ + const result = await this.prisma.client.$transaction(async (tx) => { + const employee = await this.prisma.client.employees.findUnique({ where: { id: employee_id }, select: { id: true, @@ -176,7 +176,7 @@ export class SickLeaveService { // const period_end = reference_date; // //fetches all shifts of a selected employee - // const shifts = await this.prisma.shifts.findMany({ + // const shifts = await this.prisma.client.shifts.findMany({ // where: { // timesheet: { employee_id: employee_id }, // date: { gte: period_start, lte: period_end }, diff --git a/src/time-and-attendance/domains/services/vacation.service.ts b/src/time-and-attendance/domains/services/vacation.service.ts index bf87b7c..584c448 100644 --- a/src/time-and-attendance/domains/services/vacation.service.ts +++ b/src/time-and-attendance/domains/services/vacation.service.ts @@ -16,7 +16,7 @@ export class VacationService { if (!employee_id.success) return { success: false, error: employee_id.error } //fetch hiring date - const employee = await this.prisma.employees.findUnique({ + const employee = await this.prisma.client.employees.findUnique({ where: { id: employee_id.data }, select: { first_work_day: true }, }); @@ -77,7 +77,7 @@ export class VacationService { if (asked_hours <= 0) return { success: false, error: 'INVALID_VACATION_SHIFT' }; try { - const result = await this.prisma.$transaction(async (tx) => { + const result = await this.prisma.client.$transaction(async (tx) => { //checks for remaining hours in vacation bank const employee = await tx.employees.findUnique({ where: { id: employee_id }, diff --git a/src/time-and-attendance/expenses/services/expense-create.service.ts b/src/time-and-attendance/expenses/services/expense-create.service.ts index a7d89ca..a74b2c9 100644 --- a/src/time-and-attendance/expenses/services/expense-create.service.ts +++ b/src/time-and-attendance/expenses/services/expense-create.service.ts @@ -37,14 +37,14 @@ export class ExpenseCreateService { //finds the timesheet using expense.date by finding the sunday const start_date = weekStartSunday(normed_expense.data.date); - const timesheet = await this.prisma.timesheets.findFirst({ + const timesheet = await this.prisma.client.timesheets.findFirst({ where: { start_date, employee_id: employee_id.data }, select: { id: true, employee_id: true }, }); if (!timesheet) return { success: false, error: `TIMESHEET_NOT_FOUND` }; //create a new expense - const expense = await this.prisma.expenses.create({ + const expense = await this.prisma.client.expenses.create({ data: { ...normed_expense.data, bank_code_id: type.data, diff --git a/src/time-and-attendance/expenses/services/expense-delete.service.ts b/src/time-and-attendance/expenses/services/expense-delete.service.ts index 9662243..d572bb1 100644 --- a/src/time-and-attendance/expenses/services/expense-delete.service.ts +++ b/src/time-and-attendance/expenses/services/expense-delete.service.ts @@ -22,7 +22,7 @@ export class ExpenseDeleteService { if (!employee.success) return employee; // confirm ownership of expense to employee who made request - const expense = await this.prisma.expenses.findUnique({ + const expense = await this.prisma.client.expenses.findUnique({ where: { id: expense_id}, select: { timesheet: { @@ -36,7 +36,7 @@ export class ExpenseDeleteService { if (!expense || expense.timesheet.employee_id !== employee.data) return { success: false, error: 'EXPENSE_NOT_FOUND'}; try { - await this.prisma.$transaction(async (tx) => { + await this.prisma.client.$transaction(async (tx) => { const expense = await tx.expenses.findUnique({ where: { id: expense_id }, select: { id: true }, diff --git a/src/time-and-attendance/expenses/services/expense-update.service.ts b/src/time-and-attendance/expenses/services/expense-update.service.ts index 727d0e3..2ae2f30 100644 --- a/src/time-and-attendance/expenses/services/expense-update.service.ts +++ b/src/time-and-attendance/expenses/services/expense-update.service.ts @@ -35,7 +35,7 @@ export class ExpenseUpdateService { //added timesheet_id modification check according to the new date const new_timesheet_start_date = weekStartSunday(toDateFromString(dto.date)); - const timesheet = await this.prisma.timesheets.findFirst({ + const timesheet = await this.prisma.client.timesheets.findFirst({ where: { start_date: new_timesheet_start_date, employee_id: employee_id.data }, select: timesheet_select, }); @@ -44,13 +44,13 @@ export class ExpenseUpdateService { //checks for modifications const data = { ...normed_expense.data, - bank_code: { connect: { id: type.data } }, + bank_code_id: type.data, is_approved: dto.is_approved, }; if (!data) return { success: false, error: `INVALID_EXPENSE` } //push updates and get updated datas - const expense = await this.prisma.expenses.update({ + const expense = await this.prisma.client.expenses.update({ where: { id: dto.id, timesheet_id: timesheet.id }, data, select: expense_select, diff --git a/src/time-and-attendance/exports/csv-exports.controller.ts b/src/time-and-attendance/exports/csv-exports.controller.ts index b8eb151..ee139a8 100644 --- a/src/time-and-attendance/exports/csv-exports.controller.ts +++ b/src/time-and-attendance/exports/csv-exports.controller.ts @@ -1,7 +1,7 @@ import { Controller, Get, Param, Query, Res } from "@nestjs/common"; import { CsvExportService } from "./services/csv-exports.service"; import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators"; -import { Modules as ModulesEnum } from "prisma/generated/postgres/client"; +import { Modules as ModulesEnum } from "@prisma/client"; import { Response } from "express"; import { CsvGeneratorService } from "src/time-and-attendance/exports/services/csv-builder.service"; diff --git a/src/time-and-attendance/exports/services/csv-exports.service.ts b/src/time-and-attendance/exports/services/csv-exports.service.ts index 449dc84..4fec781 100644 --- a/src/time-and-attendance/exports/services/csv-exports.service.ts +++ b/src/time-and-attendance/exports/services/csv-exports.service.ts @@ -21,7 +21,7 @@ export class CsvExportService { // approved: boolean = true ): Promise { //fetch period - const period = await this.prisma.payPeriods.findFirst({ + const period = await this.prisma.client.payPeriods.findFirst({ where: { pay_year: year, pay_period_no: period_no }, select: { period_start: true, period_end: true }, }); @@ -50,7 +50,7 @@ export class CsvExportService { const promises: Array> = []; if (want_shifts) { - promises.push(this.prisma.shifts.findMany({ + promises.push(this.prisma.client.shifts.findMany({ where: { date: { gte: start, lte: end }, ...approved_filter, @@ -81,7 +81,7 @@ export class CsvExportService { } if (want_holiday) { - promises.push(this.prisma.shifts.findMany({ + promises.push(this.prisma.client.shifts.findMany({ where: { date: { gte: start, lte: end }, ...approved_filter, @@ -112,7 +112,7 @@ export class CsvExportService { } if (want_vacation) { - promises.push(this.prisma.shifts.findMany({ + promises.push(this.prisma.client.shifts.findMany({ where: { date: { gte: start, lte: end }, ...approved_filter, @@ -143,7 +143,7 @@ export class CsvExportService { } if (want_expense) { - promises.push(this.prisma.expenses.findMany({ + promises.push(this.prisma.client.expenses.findMany({ where: { date: { gte: start, lte: end }, ...approved_filter, @@ -244,7 +244,7 @@ export class CsvExportService { } resolveHolidayTypeCode = async (holiday: string): Promise => { - const holiday_code = await this.prisma.bankCodes.findFirst({ + const holiday_code = await this.prisma.client.bankCodes.findFirst({ where: { type: holiday }, select: { bank_code: true, @@ -261,7 +261,7 @@ export class CsvExportService { } resolveVacationTypeCode = async (vacation: string): Promise => { - const vacation_code = await this.prisma.bankCodes.findFirst({ + const vacation_code = await this.prisma.client.bankCodes.findFirst({ where: { type: vacation }, select: { bank_code: true, diff --git a/src/time-and-attendance/leave-requests/leave-request.dto.ts b/src/time-and-attendance/leave-requests/leave-request.dto.ts index 2ae4e8d..b3cfc1c 100644 --- a/src/time-and-attendance/leave-requests/leave-request.dto.ts +++ b/src/time-and-attendance/leave-requests/leave-request.dto.ts @@ -1,43 +1,43 @@ -import { IsEmail, IsArray, IsOptional, IsString, IsNumber, IsEnum, IsDateString } from "class-validator"; -import { LeaveApprovalStatus, LeaveTypes } from "prisma/generated/postgres/client"; -import { Type } from "class-transformer"; +// import { IsEmail, IsArray, IsOptional, IsString, IsNumber, IsEnum, IsDateString } from "class-validator"; +// import { LeaveApprovalStatus, LeaveTypes } from "prisma/generated/postgres/client"; +// import { Type } from "class-transformer"; -//sets wich types to use -export const REQUEST_TYPES = Object.values(LeaveTypes) as readonly LeaveTypes[]; -export type RequestTypes = (typeof REQUEST_TYPES)[number]; +// //sets wich types to use +// export const REQUEST_TYPES = Object.values(LeaveTypes) as readonly LeaveTypes[]; +// export type RequestTypes = (typeof REQUEST_TYPES)[number]; -export class LeaveRequestDto { - @IsEmail() @IsString() - email!: string; +// export class LeaveRequestDto { +// @IsEmail() @IsString() +// email!: string; - @IsArray() - @IsDateString() - dates!: string[]; +// @IsArray() +// @IsDateString() +// dates!: string[]; - @IsEnum(LeaveTypes) - type!: string; +// @IsEnum(LeaveTypes) +// type!: string; - @IsString() - comment!: string; +// @IsString() +// comment!: string; - @IsOptional() - @Type(() => Number) - @IsNumber({ maxDecimalPlaces: 2 }) - requested_hours?: number; +// @IsOptional() +// @Type(() => Number) +// @IsNumber({ maxDecimalPlaces: 2 }) +// requested_hours?: number; - @IsEnum(LeaveApprovalStatus) - approval_status?: LeaveApprovalStatus -} +// @IsEnum(LeaveApprovalStatus) +// approval_status?: LeaveApprovalStatus +// } -export class LeaveRequestViewDto { - id: number; - leave_type!: LeaveTypes; - date!: string; - comment!: string; - approval_status: LeaveApprovalStatus; - email!: string; - employee_full_name!: string; - payable_hours?: number; - requested_hours?: number; - action?: 'create' | 'update' | 'delete'; -} \ No newline at end of file +// export class LeaveRequestViewDto { +// id: number; +// leave_type!: LeaveTypes; +// date!: string; +// comment!: string; +// approval_status: LeaveApprovalStatus; +// email!: string; +// employee_full_name!: string; +// payable_hours?: number; +// requested_hours?: number; +// action?: 'create' | 'update' | 'delete'; +// } \ No newline at end of file diff --git a/src/time-and-attendance/leave-requests/leave-requests-archive.mapper.ts b/src/time-and-attendance/leave-requests/leave-requests-archive.mapper.ts index fb19218..be3d1d3 100644 --- a/src/time-and-attendance/leave-requests/leave-requests-archive.mapper.ts +++ b/src/time-and-attendance/leave-requests/leave-requests-archive.mapper.ts @@ -1,24 +1,23 @@ +// import { Prisma } from "@prisma/client"; +// import { LeaveRequestViewDto } from "src/time-and-attendance/leave-requests/leave-request.dto"; +// import { LeaveRequestArchiveRow } from "src/time-and-attendance/leave-requests/utils/leave-requests-archive.select"; -import { Prisma } from "prisma/generated/postgres/client"; -import { LeaveRequestViewDto } from "src/time-and-attendance/leave-requests/leave-request.dto"; -import { LeaveRequestArchiveRow } from "src/time-and-attendance/leave-requests/utils/leave-requests-archive.select"; +// const toNum = (value?: Prisma.Decimal | null) => value ? Number(value) : undefined; -const toNum = (value?: Prisma.Decimal | null) => value ? Number(value) : undefined; - -export function mapArchiveRowToView(row: LeaveRequestArchiveRow, email: string, employee_full_name:string): LeaveRequestViewDto { - const isoDate = row.date?.toISOString().slice(0, 10); - if (!isoDate) { - throw new Error(`Leave request #${row.id} has no date set.`); - } - return { - id: row.id, - leave_type: row.leave_type, - date: isoDate, - payable_hours: toNum(row.payable_hours), - requested_hours: toNum(row.requested_hours), - comment: row.comment, - approval_status: row.approval_status, - email, - employee_full_name, - } -} \ No newline at end of file +// export function mapArchiveRowToView(row: LeaveRequestArchiveRow, email: string, employee_full_name:string): LeaveRequestViewDto { +// const isoDate = row.date?.toISOString().slice(0, 10); +// if (!isoDate) { +// throw new Error(`Leave request #${row.id} has no date set.`); +// } +// return { +// id: row.id, +// leave_type: row.leave_type, +// date: isoDate, +// payable_hours: toNum(row.payable_hours), +// requested_hours: toNum(row.requested_hours), +// comment: row.comment, +// approval_status: row.approval_status, +// email, +// employee_full_name, +// } +// } \ No newline at end of file diff --git a/src/time-and-attendance/leave-requests/leave-requests.controller.ts b/src/time-and-attendance/leave-requests/leave-requests.controller.ts index 2f58611..869b81a 100644 --- a/src/time-and-attendance/leave-requests/leave-requests.controller.ts +++ b/src/time-and-attendance/leave-requests/leave-requests.controller.ts @@ -1,28 +1,28 @@ -import { Body, Controller, Delete, Patch, Post, Req } from "@nestjs/common"; -// import { LeaveRequestDto } from "../dtos/leave-request.dto"; -import { LeaveRequestsService } from "src/time-and-attendance/leave-requests/services/leave-request.service"; +// import { Body, Controller, Delete, Patch, Post, Req } from "@nestjs/common"; +// // import { LeaveRequestDto } from "../dtos/leave-request.dto"; +// import { LeaveRequestsService } from "src/time-and-attendance/leave-requests/services/leave-request.service"; -@Controller('leave-requests') -export class LeaveRequestController { - constructor(private readonly leave_service: LeaveRequestsService) { } +// @Controller('leave-requests') +// export class LeaveRequestController { +// constructor(private readonly leave_service: LeaveRequestsService) { } - // @Post('create') - // async create(@Req() req, @Body() dto: LeaveRequestDto) { - // const email = req.user?.email; - // return await this.leave_service.create(email, dto); - // } +// // @Post('create') +// // async create(@Req() req, @Body() dto: LeaveRequestDto) { +// // const email = req.user?.email; +// // return await this.leave_service.create(email, dto); +// // } - // @Delete('delete') - // async delete(@Req() req, @Body() leave_request_id: number) { - // const email = req.user?.email; - // return await this.leave_service.delete(email, leave_request_id); - // } +// // @Delete('delete') +// // async delete(@Req() req, @Body() leave_request_id: number) { +// // const email = req.user?.email; +// // return await this.leave_service.delete(email, leave_request_id); +// // } - // @Patch('update') - // async update(@Req() req, @Body() request_id: number, approval_status: string) { - // const email = req.user?.email; - // return await this.leave_service.update(email, request_id, approval_status); - // } +// // @Patch('update') +// // async update(@Req() req, @Body() request_id: number, approval_status: string) { +// // const email = req.user?.email; +// // return await this.leave_service.update(email, request_id, approval_status); +// // } -} +// } diff --git a/src/time-and-attendance/leave-requests/services/leave-request.service.ts b/src/time-and-attendance/leave-requests/services/leave-request.service.ts index 6eba499..0e84d40 100644 --- a/src/time-and-attendance/leave-requests/services/leave-request.service.ts +++ b/src/time-and-attendance/leave-requests/services/leave-request.service.ts @@ -1,186 +1,186 @@ -import { EmployeeTimesheetResolver } from "src/common/mappers/timesheet.mapper"; -import { EmailToIdResolver } from "src/common/mappers/email-id.mapper"; -import { BankCodesResolver } from "src/common/mappers/bank-type-id.mapper"; -import { LeaveApprovalStatus, LeaveRequests, LeaveTypes, Prisma, Shifts } from "@prisma/client"; -import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service"; -import { Result } from "src/common/errors/result-error.factory"; -import { Injectable } from "@nestjs/common"; -import { LeaveRequestDto } from "src/time-and-attendance/leave-requests/leave-request.dto"; -import { leave_requests_select } from "src/time-and-attendance/utils/selects.utils"; -import { toDateFromString, toStringFromDate } from "src/common/utils/date-utils"; -import { NormalizedLeaveRequest } from "src/time-and-attendance/utils/type.utils"; +// import { EmployeeTimesheetResolver } from "src/common/mappers/timesheet.mapper"; +// import { EmailToIdResolver } from "src/common/mappers/email-id.mapper"; +// import { BankCodesResolver } from "src/common/mappers/bank-type-id.mapper"; +// import { LeaveApprovalStatus, LeaveRequests, LeaveTypes, Prisma, Shifts } from "@prisma/client"; +// import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service"; +// import { Result } from "src/common/errors/result-error.factory"; +// import { Injectable } from "@nestjs/common"; +// import { LeaveRequestDto } from "src/time-and-attendance/leave-requests/leave-request.dto"; +// import { leave_requests_select } from "src/time-and-attendance/utils/selects.utils"; +// import { toDateFromString, toStringFromDate } from "src/common/utils/date-utils"; +// import { NormalizedLeaveRequest } from "src/time-and-attendance/utils/type.utils"; -@Injectable() -export class LeaveRequestsService { -// constructor( -// private readonly prisma: PrismaPostgresService, -// private readonly timesheetResolver: EmployeeTimesheetResolver, -// private readonly emailResolver: EmailToIdResolver, -// private readonly typeResolver: BankCodesResolver, -// ) { } +// @Injectable() +// export class LeaveRequestsService { +// // constructor( +// // private readonly prisma: PrismaPostgresService, +// // private readonly timesheetResolver: EmployeeTimesheetResolver, +// // private readonly emailResolver: EmailToIdResolver, +// // private readonly typeResolver: BankCodesResolver, +// // ) { } -// async create(email: string, dto: LeaveRequestDto): Promise> { -// try { -// //verify if array is empty or not -// if (!Array.isArray(dto.dates) || dto.dates.length === 0) return { success: false, error: 'no data received' }; -// //verify if email is valid or not -// const employee = await this.emailResolver.findIdByEmail(email); -// if (!employee.success) return { success: false, error: employee.error } -// //normalized dto datas to match DB's -// const normed_request = await this.normalizeRequest(dto); -// if (!normed_request.success) return { success: false, error: normed_request.error } +// // async create(email: string, dto: LeaveRequestDto): Promise> { +// // try { +// // //verify if array is empty or not +// // if (!Array.isArray(dto.dates) || dto.dates.length === 0) return { success: false, error: 'no data received' }; +// // //verify if email is valid or not +// // const employee = await this.emailResolver.findIdByEmail(email); +// // if (!employee.success) return { success: false, error: employee.error } +// // //normalized dto datas to match DB's +// // const normed_request = await this.normalizeRequest(dto); +// // if (!normed_request.success) return { success: false, error: normed_request.error } -// //creates the requests -// const request_day = await this.prisma.leaveRequests.create({ -// data: { -// employee_id: employee.data, -// bank_code_id: normed_request.data.bank_code_id, -// comment: normed_request.data.comment, -// dates: normed_request.data.dates, -// approval_status: dto.approval_status, -// requested_hours: dto.requested_hours, -// leave_type: normed_request.data.leave_type, -// }, -// select: leave_requests_select, -// }); -// if (!request_day) return { success: false, error: 'An error occured during creation. Leave-Request is invalid' } +// // //creates the requests +// // const request_day = await this.prisma.leaveRequests.create({ +// // data: { +// // employee_id: employee.data, +// // bank_code_id: normed_request.data.bank_code_id, +// // comment: normed_request.data.comment, +// // dates: normed_request.data.dates, +// // approval_status: dto.approval_status, +// // requested_hours: dto.requested_hours, +// // leave_type: normed_request.data.leave_type, +// // }, +// // select: leave_requests_select, +// // }); +// // if (!request_day) return { success: false, error: 'An error occured during creation. Leave-Request is invalid' } -// const created_request: LeaveRequestDto = { -// email: dto.email, -// type: request_day.leave_type.toString(), -// dates: dto.dates, -// comment: normed_request.data.comment, -// approval_status: 'PENDING', -// requested_hours: dto.requested_hours, -// }; +// // const created_request: LeaveRequestDto = { +// // email: dto.email, +// // type: request_day.leave_type.toString(), +// // dates: dto.dates, +// // comment: normed_request.data.comment, +// // approval_status: 'PENDING', +// // requested_hours: dto.requested_hours, +// // }; -// return { success: true, data: created_request }; -// } catch (error) { -// return { success: false, error: `An error occured during creation, invalid data` } -// } -// } +// // return { success: true, data: created_request }; +// // } catch (error) { +// // return { success: false, error: `An error occured during creation, invalid data` } +// // } +// // } -// async update(email: string, request_id: number, dto: LeaveRequestDto): Promise> { -// try { -// const employee = await this.emailResolver.findIdByEmail(email); -// if (!employee.success) return { success: false, error: employee.error } +// // async update(email: string, request_id: number, dto: LeaveRequestDto): Promise> { +// // try { +// // const employee = await this.emailResolver.findIdByEmail(email); +// // if (!employee.success) return { success: false, error: employee.error } -// switch (dto.approval_status) { -// case 'APPROVED': //creation of shifts and returns void -// break; -// case 'DENIED': //simple update and returns void -// break; -// case 'CANCELLED': //CANCELLED, simple update and returns void -// break; -// case 'PENDING': this.updatePendingRequest(dto) -// break; -// default: return { success: false, error: `invalid approval_status` }; -// } +// // switch (dto.approval_status) { +// // case 'APPROVED': //creation of shifts and returns void +// // break; +// // case 'DENIED': //simple update and returns void +// // break; +// // case 'CANCELLED': //CANCELLED, simple update and returns void +// // break; +// // case 'PENDING': this.updatePendingRequest(dto) +// // break; +// // default: return { success: false, error: `invalid approval_status` }; +// // } -// // const updated_request: LeaveRequestDto = { -// // email: dto.email, -// // type: request_day.leave_type.toString(), -// // dates: dto.dates, -// // comment: normed_request.data.comment, -// // approval_status: dto.approval_status, -// // requested_hours: dto.requested_hours, -// // } +// // // const updated_request: LeaveRequestDto = { +// // // email: dto.email, +// // // type: request_day.leave_type.toString(), +// // // dates: dto.dates, +// // // comment: normed_request.data.comment, +// // // approval_status: dto.approval_status, +// // // requested_hours: dto.requested_hours, +// // // } -// } catch (error) { -// return { success: false, error: ' An error occured during update, Invalid Leave-Request data' } -// } -// return { success: true, data: updated_request }; -// } +// // } catch (error) { +// // return { success: false, error: ' An error occured during update, Invalid Leave-Request data' } +// // } +// // return { success: true, data: updated_request }; +// // } -// async delete(email: string, request_id: number): Promise> { -// try { -// const employee = await this.emailResolver.findIdByEmail(email); -// if (!employee.success) return { success: false, error: employee.error } +// // async delete(email: string, request_id: number): Promise> { +// // try { +// // const employee = await this.emailResolver.findIdByEmail(email); +// // if (!employee.success) return { success: false, error: employee.error } -// const deleted = await this.prisma.leaveRequests.findUnique({ -// where: { id: request_id, employee_id: employee.data }, -// select: { id: true, dates: true }, -// }); -// if (!deleted) return { success: false, error: `Leave Request with id ${request_id} not found ` }; -// return { success: true, data: deleted.id }; +// // const deleted = await this.prisma.leaveRequests.findUnique({ +// // where: { id: request_id, employee_id: employee.data }, +// // select: { id: true, dates: true }, +// // }); +// // if (!deleted) return { success: false, error: `Leave Request with id ${request_id} not found ` }; +// // return { success: true, data: deleted.id }; -// } catch (error) { -// return { success: false, error: `INVALID_REQUEST, leave-request with id ${request_id} not found` } -// } -// } +// // } catch (error) { +// // return { success: false, error: `INVALID_REQUEST, leave-request with id ${request_id} not found` } +// // } +// // } -// private normalizeRequest = async (dto: LeaveRequestDto): Promise> => { -// const bank_code = await this.typeResolver.findBankCodeIDByType(dto.type); -// if (!bank_code.success) return { success: false, error: bank_code.error }; -// const comment = this.truncate280(dto.comment); -// //maps enum, check if dto.type is include in the list and return a valid type -// const leave_type_list = Object.values(LeaveTypes); -// const leave_type = leave_type_list.includes(dto.type.toUpperCase() as LeaveTypes); -// if (!leave_type) return { success: false, error: `Leave Request of type ${dto.type} is invalid` } -// const valid_leave_type = dto.type.toUpperCase() as LeaveTypes; +// // private normalizeRequest = async (dto: LeaveRequestDto): Promise> => { +// // const bank_code = await this.typeResolver.findBankCodeIDByType(dto.type); +// // if (!bank_code.success) return { success: false, error: bank_code.error }; +// // const comment = this.truncate280(dto.comment); +// // //maps enum, check if dto.type is include in the list and return a valid type +// // const leave_type_list = Object.values(LeaveTypes); +// // const leave_type = leave_type_list.includes(dto.type.toUpperCase() as LeaveTypes); +// // if (!leave_type) return { success: false, error: `Leave Request of type ${dto.type} is invalid` } +// // const valid_leave_type = dto.type.toUpperCase() as LeaveTypes; -// //map of all dates in string format -// const dates = dto.dates.map(toDateFromString); -// if (!dates) return { success: false, error: 'Bad date' } +// // //map of all dates in string format +// // const dates = dto.dates.map(toDateFromString); +// // if (!dates) return { success: false, error: 'Bad date' } -// return { success: true, data: { comment, dates, leave_type: valid_leave_type, bank_code_id: bank_code.data } }; -// } +// // return { success: true, data: { comment, dates, leave_type: valid_leave_type, bank_code_id: bank_code.data } }; +// // } -// //makes sure that a string cannot exceed 280 chars -// private truncate280 = (input: string): string => { -// return input.length > 280 ? input.slice(0, 280) : input; -// } +// // //makes sure that a string cannot exceed 280 chars +// // private truncate280 = (input: string): string => { +// // return input.length > 280 ? input.slice(0, 280) : input; +// // } -// private updatePendingRequest = async (request_id: number, dto: LeaveRequestDto): Promise> => { -// const normed_dto = await this.normalizeRequest(dto); -// if (!normed_dto.success) return { success: false, error: normed_dto.error } +// // private updatePendingRequest = async (request_id: number, dto: LeaveRequestDto): Promise> => { +// // const normed_dto = await this.normalizeRequest(dto); +// // if (!normed_dto.success) return { success: false, error: normed_dto.error } -// const leave_request = await this.prisma.leaveRequests.findUnique({ -// where: { id: request_id }, -// select: leave_requests_select, -// }); -// if (!leave_request) return { success: false, error: `Leave Request with id: ${request_id} not found` } +// // const leave_request = await this.prisma.leaveRequests.findUnique({ +// // where: { id: request_id }, +// // select: leave_requests_select, +// // }); +// // if (!leave_request) return { success: false, error: `Leave Request with id: ${request_id} not found` } -// const update = await this.prisma.leaveRequests.update({ -// where: { id: request_id }, -// data: { -// bank_code_id: normed_dto.data.bank_code_id, -// leave_type: normed_dto.data.leave_type, -// comment: normed_dto.data.comment, -// dates: normed_dto.data.dates, -// requested_hours: dto.requested_hours ?? 0, -// } -// }) -// // (alias) class LeaveRequestDto { -// // email: string; -// // dates: string[]; -// // type: string; -// // comment: string; -// // requested_hours?: number | undefined; -// // approval_status?: $Enums.LeaveApprovalStatus | undefined; -// // } -// // const dates_string = update.dates.map(toStringFromDate); -// // const updated_request: LeaveRequestDto = { -// // email: leave_request, -// // type: update.leave_type, +// // const update = await this.prisma.leaveRequests.update({ +// // where: { id: request_id }, +// // data: { +// // bank_code_id: normed_dto.data.bank_code_id, +// // leave_type: normed_dto.data.leave_type, +// // comment: normed_dto.data.comment, +// // dates: normed_dto.data.dates, +// // requested_hours: dto.requested_hours ?? 0, +// // } +// // }) +// // // (alias) class LeaveRequestDto { +// // // email: string; +// // // dates: string[]; +// // // type: string; +// // // comment: string; +// // // requested_hours?: number | undefined; +// // // approval_status?: $Enums.LeaveApprovalStatus | undefined; +// // // } +// // // const dates_string = update.dates.map(toStringFromDate); +// // // const updated_request: LeaveRequestDto = { +// // // email: leave_request, +// // // type: update.leave_type, -// // } +// // // } -// return { success: true, data: updated_request } -// } -} +// // return { success: true, data: updated_request } +// // } +// } -type leaveRequests = { - id: number; - bank_code_id: number; - comment: string; - dates: Date[]; - payable_hours: Prisma.Decimal | null; - requested_hours: Prisma.Decimal | null; - approval_status: LeaveApprovalStatus; - leave_type: LeaveTypes; -} +// type leaveRequests = { +// id: number; +// bank_code_id: number; +// comment: string; +// dates: Date[]; +// payable_hours: Prisma.Decimal | null; +// requested_hours: Prisma.Decimal | null; +// approval_status: LeaveApprovalStatus; +// leave_type: LeaveTypes; +// } diff --git a/src/time-and-attendance/leave-requests/utils/leave-request.util.ts b/src/time-and-attendance/leave-requests/utils/leave-request.util.ts index 86edeeb..a67b561 100644 --- a/src/time-and-attendance/leave-requests/utils/leave-request.util.ts +++ b/src/time-and-attendance/leave-requests/utils/leave-request.util.ts @@ -1,102 +1,102 @@ -import { BadRequestException, Injectable } from "@nestjs/common"; -import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service"; -import { LeaveTypes } from "prisma/generated/postgres/client"; -import { toDateFromString, toStringFromDate } from "src/common/utils/date-utils"; -@Injectable() -export class LeaveRequestsUtils { - constructor( - private readonly prisma: PrismaPostgresService, - ) { } +// import { BadRequestException, Injectable } from "@nestjs/common"; +// import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service"; +// import { LeaveTypes } from "prisma/generated/postgres/client"; +// import { toDateFromString, toStringFromDate } from "src/common/utils/date-utils"; +// @Injectable() +// export class LeaveRequestsUtils { +// constructor( +// private readonly prisma: PrismaPostgresService, +// ) { } - async syncShift( - email: string, - employee_id: number, - date: string, - hours: number, - type: LeaveTypes, - comment?: string, - ) { - if (hours <= 0) return; +// async syncShift( +// email: string, +// employee_id: number, +// date: string, +// hours: number, +// type: LeaveTypes, +// comment?: string, +// ) { +// if (hours <= 0) return; - const duration_minutes = Math.round(hours * 60); - if (duration_minutes > 8 * 60) { - throw new BadRequestException("Amount of hours cannot exceed 8 hours per day."); - } - const date_only = toDateFromString(date); - const yyyy_mm_dd = toStringFromDate(date_only); +// const duration_minutes = Math.round(hours * 60); +// if (duration_minutes > 8 * 60) { +// throw new BadRequestException("Amount of hours cannot exceed 8 hours per day."); +// } +// const date_only = toDateFromString(date); +// const yyyy_mm_dd = toStringFromDate(date_only); - const start_minutes = 8 * 60; - const end_minutes = start_minutes + duration_minutes; - const toHHmm = (total: number) => - `${String(Math.floor(total / 60)).padStart(2, "0")}:${String(total % 60).padStart(2, "0")}`; +// const start_minutes = 8 * 60; +// const end_minutes = start_minutes + duration_minutes; +// const toHHmm = (total: number) => +// `${String(Math.floor(total / 60)).padStart(2, "0")}:${String(total % 60).padStart(2, "0")}`; - const existing = await this.prisma.shifts.findFirst({ - where: { - date: date_only, - bank_code: { type }, - timesheet: { employee_id: employee_id }, - }, - include: { bank_code: true }, - }); +// const existing = await this.prisma.shifts.findFirst({ +// where: { +// date: date_only, +// bank_code: { type }, +// timesheet: { employee_id: employee_id }, +// }, +// include: { bank_code: true }, +// }); - // await this.shiftsService.upsertShifts(email, action, { - // old_shift: existing - // ? { - // date: yyyy_mm_dd, - // start_time: existing.start_time.toISOString().slice(11, 16), - // end_time: existing.end_time.toISOString().slice(11, 16), - // type: existing.bank_code?.type ?? type, - // is_remote: existing.is_remote, - // is_approved:existing.is_approved, - // comment: existing.comment ?? undefined, - // } - // : undefined, - // new_shift: { - // date: yyyy_mm_dd, - // start_time: toHHmm(start_minutes), - // end_time: toHHmm(end_minutes), - // is_remote: existing?.is_remote ?? false, - // is_approved:existing?.is_approved ?? false, - // comment: comment ?? existing?.comment ?? "", - // type: type, - // }, - // }); - } +// // await this.shiftsService.upsertShifts(email, action, { +// // old_shift: existing +// // ? { +// // date: yyyy_mm_dd, +// // start_time: existing.start_time.toISOString().slice(11, 16), +// // end_time: existing.end_time.toISOString().slice(11, 16), +// // type: existing.bank_code?.type ?? type, +// // is_remote: existing.is_remote, +// // is_approved:existing.is_approved, +// // comment: existing.comment ?? undefined, +// // } +// // : undefined, +// // new_shift: { +// // date: yyyy_mm_dd, +// // start_time: toHHmm(start_minutes), +// // end_time: toHHmm(end_minutes), +// // is_remote: existing?.is_remote ?? false, +// // is_approved:existing?.is_approved ?? false, +// // comment: comment ?? existing?.comment ?? "", +// // type: type, +// // }, +// // }); +// } - async removeShift( - email: string, - employee_id: number, - iso_date: string, - type: LeaveTypes, - ) { - const date_only = toDateFromString(iso_date); - const yyyy_mm_dd = toStringFromDate(date_only); - const existing = await this.prisma.shifts.findFirst({ - where: { - date: date_only, - bank_code: { type }, - timesheet: { employee_id: employee_id }, - }, - include: { bank_code: true }, - }); - if (!existing) return; +// async removeShift( +// email: string, +// employee_id: number, +// iso_date: string, +// type: LeaveTypes, +// ) { +// const date_only = toDateFromString(iso_date); +// const yyyy_mm_dd = toStringFromDate(date_only); +// const existing = await this.prisma.shifts.findFirst({ +// where: { +// date: date_only, +// bank_code: { type }, +// timesheet: { employee_id: employee_id }, +// }, +// include: { bank_code: true }, +// }); +// if (!existing) return; - // await this.shiftsService.upsertShifts(email, 'delete', { - // old_shift: { - // date: yyyy_mm_dd, - // start_time: hhmmFromLocal(existing.start_time), - // end_time: hhmmFromLocal(existing.end_time), - // type: existing.bank_code?.type ?? type, - // is_remote: existing.is_remote, - // is_approved:existing.is_approved, - // comment: existing.comment ?? undefined, - // }, - // }); - } +// // await this.shiftsService.upsertShifts(email, 'delete', { +// // old_shift: { +// // date: yyyy_mm_dd, +// // start_time: hhmmFromLocal(existing.start_time), +// // end_time: hhmmFromLocal(existing.end_time), +// // type: existing.bank_code?.type ?? type, +// // is_remote: existing.is_remote, +// // is_approved:existing.is_approved, +// // comment: existing.comment ?? undefined, +// // }, +// // }); +// } -} +// } diff --git a/src/time-and-attendance/leave-requests/utils/leave-requests-archive.select.ts b/src/time-and-attendance/leave-requests/utils/leave-requests-archive.select.ts index 43d045e..5b456db 100644 --- a/src/time-and-attendance/leave-requests/utils/leave-requests-archive.select.ts +++ b/src/time-and-attendance/leave-requests/utils/leave-requests-archive.select.ts @@ -1,16 +1,16 @@ -import { Prisma } from "prisma/generated/postgres/client"; +// import { Prisma } from "prisma/generated/postgres/client"; -export const leaveRequestsArchiveSelect = { - id: true, - leave_request_id: true, - archived_at: true, - employee_id: true, - leave_type: true, - date: true, - payable_hours: true, - requested_hours: true, - comment: true, - approval_status: true, -} satisfies Prisma.LeaveRequestsArchiveSelect; +// export const leaveRequestsArchiveSelect = { +// id: true, +// leave_request_id: true, +// archived_at: true, +// employee_id: true, +// leave_type: true, +// date: true, +// payable_hours: true, +// requested_hours: true, +// comment: true, +// approval_status: true, +// } satisfies Prisma.LeaveRequestsArchiveSelect; -export type LeaveRequestArchiveRow = Prisma.LeaveRequestsArchiveGetPayload<{ select: typeof leaveRequestsArchiveSelect}>; \ No newline at end of file +// export type LeaveRequestArchiveRow = Prisma.LeaveRequestsArchiveGetPayload<{ select: typeof leaveRequestsArchiveSelect}>; \ 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..5e8b9df 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 @@ -73,7 +73,7 @@ export class PaidTimeOFfBankHoursService { if (!config) return { success: false, error: 'INVALID_PAID_TIME_OFF_TYPE' } const operation = config.invert_logic ? 'decrement' : 'increment'; - await this.prisma.paidTimeOff.update({ + await this.prisma.client.paidTimeOff.update({ where: { employee_id }, data: { [config.field]: { [operation]: hours }, @@ -100,7 +100,7 @@ export class PaidTimeOFfBankHoursService { const last_updated = new Date(); - await this.prisma.paidTimeOff.update({ + await this.prisma.client.paidTimeOff.update({ where: { employee_id }, data: { [config.field]: { [config.operation]: ajusted_hours }, diff --git a/src/time-and-attendance/pay-period/services/pay-periods-build-overview.service.ts b/src/time-and-attendance/pay-period/services/pay-periods-build-overview.service.ts index dfd7f18..c5ca511 100644 --- a/src/time-and-attendance/pay-period/services/pay-periods-build-overview.service.ts +++ b/src/time-and-attendance/pay-period/services/pay-periods-build-overview.service.ts @@ -27,7 +27,7 @@ export class GetOverviewService { } async buildOverview(overview: Overview): Promise> { - const employee_overviews = await this.prisma.employees.findMany({ + const employee_overviews = await this.prisma.client.employees.findMany({ where: { OR: [ { last_work_day: { gte: toDateFromString(overview.period_start) } }, diff --git a/src/time-and-attendance/pay-period/services/pay-periods-command.service.ts b/src/time-and-attendance/pay-period/services/pay-periods-command.service.ts index a849de6..9d11dfa 100644 --- a/src/time-and-attendance/pay-period/services/pay-periods-command.service.ts +++ b/src/time-and-attendance/pay-period/services/pay-periods-command.service.ts @@ -23,7 +23,7 @@ export class PayPeriodsCommandService { if (!employee_id.success) return { success: false, error: employee_id.error } try { - shifts = await this.prisma.shifts.updateMany({ + shifts = await this.prisma.client.shifts.updateMany({ where: { timesheet: { id: { in: timesheet_ids }, @@ -35,7 +35,7 @@ export class PayPeriodsCommandService { } }); - expenses = await this.prisma.expenses.updateMany({ + expenses = await this.prisma.client.expenses.updateMany({ where: { timesheet: { id: { in: timesheet_ids }, @@ -47,7 +47,7 @@ export class PayPeriodsCommandService { } }); - await this.prisma.timesheets.updateMany({ + await this.prisma.client.timesheets.updateMany({ where: { id: { in: timesheet_ids}, employee_id: employee_id.data, diff --git a/src/time-and-attendance/pay-period/services/pay-periods-query.service.ts b/src/time-and-attendance/pay-period/services/pay-periods-query.service.ts index 27dfc8b..3fd6684 100644 --- a/src/time-and-attendance/pay-period/services/pay-periods-query.service.ts +++ b/src/time-and-attendance/pay-period/services/pay-periods-query.service.ts @@ -11,7 +11,7 @@ export class PayPeriodsQueryService { private readonly prisma: PrismaPostgresService) { } async findOneByYearPeriod(pay_year: number, period_no: number): Promise> { - const row = await this.prisma.payPeriods.findFirst({ + const row = await this.prisma.client.payPeriods.findFirst({ where: { pay_year, pay_period_no: period_no }, }); if (row) return { success: true, data: mapPayPeriodToDto(row) }; @@ -34,7 +34,7 @@ export class PayPeriodsQueryService { //function to cherry pick a Date to find a period async findByDate(date: string): Promise> { const dt = new Date(date); - const row = await this.prisma.payPeriods.findFirst({ + const row = await this.prisma.client.payPeriods.findFirst({ where: { period_start: { lte: dt }, period_end: { gte: dt } }, }); if (row) return { success: true, data: mapPayPeriodToDto(row) }; diff --git a/src/time-and-attendance/schedule-presets/services/schedule-presets-apply.service.ts b/src/time-and-attendance/schedule-presets/services/schedule-presets-apply.service.ts index 0beacbb..c528596 100644 --- a/src/time-and-attendance/schedule-presets/services/schedule-presets-apply.service.ts +++ b/src/time-and-attendance/schedule-presets/services/schedule-presets-apply.service.ts @@ -29,7 +29,7 @@ export class SchedulePresetsApplyService { const employee_id = await this.emailResolver.findIdByEmail(user_email); if (!employee_id.success) return { success: false, error: 'EMPLOYEE_NOT_FOUND' }; - const employee_default_schedule_preset = await this.prisma.employees.findFirst({ + const employee_default_schedule_preset = await this.prisma.client.employees.findFirst({ where: { id: employee_id.data }, select: { schedule_preset: { @@ -43,7 +43,7 @@ export class SchedulePresetsApplyService { if (!employee_default_schedule_preset) return { success: false, error: 'EMPLOYEE_NOT_FOUND' }; if (!employee_default_schedule_preset.schedule_preset) return { success: false, error: 'SCHEDULE_PRESET_NOT_FOUND' }; - const default_preset_shifts = await this.prisma.schedulePresetShifts.findMany({ + const default_preset_shifts = await this.prisma.client.schedulePresetShifts.findMany({ where: { preset_id: employee_default_schedule_preset.schedule_preset.id }, select: { bank_code_id: true, @@ -55,7 +55,7 @@ export class SchedulePresetsApplyService { }); if (default_preset_shifts.length <= 0) return { success: false, error: 'INVALID_SCHEDULE_PRESET' }; - const timesheet = await this.prisma.timesheets.findUnique({ + const timesheet = await this.prisma.client.timesheets.findUnique({ where: { id: timesheet_id }, select: timesheet_select, }); @@ -101,7 +101,7 @@ export class SchedulePresetsApplyService { if (!employee_id.success) return { success: false, error: 'EMPLOYEE_NOT_FOUND' }; const week_day = Object.keys(WEEKDAY_MAP)[week_day_index]; - const preset_shift = await this.prisma.employees.findFirst({ + const preset_shift = await this.prisma.client.employees.findFirst({ where: { id: employee_id.data, }, select: { schedule_preset: { diff --git a/src/time-and-attendance/schedule-presets/services/schedule-presets-create.service.ts b/src/time-and-attendance/schedule-presets/services/schedule-presets-create.service.ts index 4daf523..e0dcbe8 100644 --- a/src/time-and-attendance/schedule-presets/services/schedule-presets-create.service.ts +++ b/src/time-and-attendance/schedule-presets/services/schedule-presets-create.service.ts @@ -20,7 +20,7 @@ export class SchedulePresetsCreateService { async createPreset(dto: SchedulePresetsDto): Promise> { try { //validate new unique name - const existing = await this.prisma.schedulePresets.findFirst({ + const existing = await this.prisma.client.schedulePresets.findFirst({ where: { name: dto.name }, select: { name: true }, }); @@ -54,7 +54,7 @@ export class SchedulePresetsCreateService { if (!result.success) return { success: false, error: 'INVALID_SCHEDULE_PRESET' } } - await this.prisma.$transaction(async (tx) => { + await this.prisma.client.$transaction(async (tx) => { await tx.schedulePresets.create({ data: { name: dto.name, diff --git a/src/time-and-attendance/schedule-presets/services/schedule-presets-delete.service.ts b/src/time-and-attendance/schedule-presets/services/schedule-presets-delete.service.ts index c39dfac..c89bf06 100644 --- a/src/time-and-attendance/schedule-presets/services/schedule-presets-delete.service.ts +++ b/src/time-and-attendance/schedule-presets/services/schedule-presets-delete.service.ts @@ -11,20 +11,20 @@ export class SchedulePresetDeleteService { //_________________________________________________________________ async deletePreset(preset_id: number): Promise> { - const preset = await this.prisma.schedulePresets.findUnique({ + const preset = await this.prisma.client.schedulePresets.findUnique({ where: { id: preset_id }, select: { id: true }, }); if (!preset) return { success: false, error: `SCHEDULE_PRESET_NOT_FOUND` }; - const updated_employees = await this.prisma.employees.updateMany({ + const updated_employees = await this.prisma.client.employees.updateMany({ where: { schedule_preset_id: preset_id }, data: { schedule_preset_id: 0, }, }); - await this.prisma.$transaction(async (tx) => { + await this.prisma.client.$transaction(async (tx) => { await tx.schedulePresetShifts.deleteMany({ where: { preset_id: preset_id } }); await tx.schedulePresets.delete({ where: { id: preset_id } }); }); diff --git a/src/time-and-attendance/schedule-presets/services/schedule-presets-get.service.ts b/src/time-and-attendance/schedule-presets/services/schedule-presets-get.service.ts index 81fce2b..f9d695a 100644 --- a/src/time-and-attendance/schedule-presets/services/schedule-presets-get.service.ts +++ b/src/time-and-attendance/schedule-presets/services/schedule-presets-get.service.ts @@ -14,7 +14,7 @@ export class SchedulePresetsGetService { async getSchedulePresets(): Promise> { try { - const presets = await this.prisma.schedulePresets.findMany({ + const presets = await this.prisma.client.schedulePresets.findMany({ orderBy: [{ name: 'asc' }], include: { shifts: { diff --git a/src/time-and-attendance/schedule-presets/services/schedule-presets-update.service.ts b/src/time-and-attendance/schedule-presets/services/schedule-presets-update.service.ts index fa08906..9a3eac2 100644 --- a/src/time-and-attendance/schedule-presets/services/schedule-presets-update.service.ts +++ b/src/time-and-attendance/schedule-presets/services/schedule-presets-update.service.ts @@ -18,7 +18,7 @@ export class SchedulePresetUpdateService { // UPDATE //_________________________________________________________________ async updatePreset(dto: SchedulePresetsDto): Promise> { - const existing = await this.prisma.schedulePresets.findFirst({ + const existing = await this.prisma.client.schedulePresets.findFirst({ where: { id: dto.id }, select: { id: true, @@ -50,7 +50,7 @@ export class SchedulePresetUpdateService { if (!result.success) return { success: false, error: 'INVALID_SCHEDULE_PRESET' } } - await this.prisma.$transaction(async (tx) => { + await this.prisma.client.$transaction(async (tx) => { await tx.schedulePresetShifts.deleteMany({ where: { preset_id: existing.id } }); await tx.schedulePresets.update({ 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..e92a9f8 100644 --- a/src/time-and-attendance/shifts/services/shifts-create.service.ts +++ b/src/time-and-attendance/shifts/services/shifts-create.service.ts @@ -84,7 +84,7 @@ export class ShiftsCreateService { if (!normed_shift.success) return { success: false, error: normed_shift.error }; if (normed_shift.data.end_time <= normed_shift.data.start_time) return { success: false, error: `INVALID_SHIFT_TIME` }; //fetch the right timesheet - const timesheet = await this.prisma.timesheets.findUnique({ + const timesheet = await this.prisma.client.timesheets.findUnique({ where: { id: dto.timesheet_id, employee_id }, select: timesheet_select, }); @@ -94,7 +94,7 @@ export class ShiftsCreateService { if (!bank_code_id.success) return { success: false, error: bank_code_id.error }; //fetchs existing shifts from DB to check for overlaps - const existing_shifts = await this.prisma.shifts.findMany({ + const existing_shifts = await this.prisma.client.shifts.findMany({ where: { timesheet_id: timesheet.id, date: normed_shift.data.date }, select: { id: true, date: true, start_time: true, end_time: true }, }); @@ -149,7 +149,7 @@ export class ShiftsCreateService { } //sends data for creation of a shift in db - const created_shift = await this.prisma.shifts.create({ + const created_shift = await this.prisma.client.shifts.create({ data: { timesheet_id: timesheet.id, bank_code_id: bank_code_id.data, 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..bfec467 100644 --- a/src/time-and-attendance/shifts/services/shifts-delete.service.ts +++ b/src/time-and-attendance/shifts/services/shifts-delete.service.ts @@ -27,7 +27,7 @@ export class ShiftsDeleteService { if (!employee_id.success) return { success: false, error: employee_id.error }; // check if shift actually belongs to employee - const shift = await this.prisma.shifts.findUnique({ + const shift = await this.prisma.client.shifts.findUnique({ where: { id: shift_id }, select: { timesheet: { @@ -42,7 +42,7 @@ export class ShiftsDeleteService { return { success: false, error: 'SHIFT_NOT_FOUND'} // return deletion result - return await this.prisma.$transaction(async (tx) => { + return await this.prisma.client.$transaction(async (tx) => { const shift = await tx.shifts.findUnique({ where: { id: shift_id }, select: { 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..210098a 100644 --- a/src/time-and-attendance/shifts/services/shifts-update.service.ts +++ b/src/time-and-attendance/shifts/services/shifts-update.service.ts @@ -81,7 +81,7 @@ export class ShiftsUpdateService { const employee = await this.emailResolver.findIdByEmail(email); if (!employee.success) return { success: false, error: employee.error }; //finds original shift - const original = await this.prisma.shifts.findFirst({ + const original = await this.prisma.client.shifts.findFirst({ where: { id: dto.id, timesheet_id: timesheet.data.id }, select: shift_select, }); @@ -134,7 +134,7 @@ export class ShiftsUpdateService { } //updates sent to DB - const updated = await this.prisma.shifts.update({ + const updated = await this.prisma.client.shifts.update({ where: { id: original.id }, data: { date: normed_shift.data.date, diff --git a/src/time-and-attendance/timesheets/services/timesheet-approval.service.ts b/src/time-and-attendance/timesheets/services/timesheet-approval.service.ts index cd8b8cd..a4a9af2 100644 --- a/src/time-and-attendance/timesheets/services/timesheet-approval.service.ts +++ b/src/time-and-attendance/timesheets/services/timesheet-approval.service.ts @@ -1,8 +1,8 @@ -import { BaseApprovalService } from "src/common/shared/base-approval.service"; -import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service"; import { Injectable, NotFoundException } from "@nestjs/common"; +import { Prisma, PrismaClient, Timesheets } from "@prisma/client"; +import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service"; +import { BaseApprovalService } from "src/common/shared/base-approval.service"; import { timesheet_select } from "src/time-and-attendance/utils/selects.utils"; -import { Prisma, Timesheets } from "prisma/generated/postgres/client"; @Injectable() export class TimesheetApprovalService extends BaseApprovalService{ @@ -14,15 +14,15 @@ import { Prisma, Timesheets } from "prisma/generated/postgres/client"; // APPROVAL AND DELEGATE METHODS //_____________________________________________________________________________________________ protected get delegate() { - return this.prisma.timesheets; + return this.prisma.client.timesheets; } - protected delegateFor(tx: Prisma.TransactionClient) { + protected delegateFor(tx: Prisma.TransactionClient | PrismaClient) { return tx.timesheets; } async updateApproval(id: number, is_approved: boolean): Promise { - return this.prisma.$transaction((tx) => + return this.prisma.client.$transaction((tx) => this.updateApprovalWithTransaction(tx, id, is_approved), ); } @@ -41,7 +41,7 @@ import { Prisma, Timesheets } from "prisma/generated/postgres/client"; } async approveTimesheetById( timesheet_id: number, is_approved: boolean){ - return this.prisma.$transaction(async (tx) => { + return this.prisma.client.$transaction(async (tx) => { const timesheet = await tx.timesheets.findUnique({ where: { id: timesheet_id }, select: { id: true }, diff --git a/src/time-and-attendance/timesheets/services/timesheet-employee-overview.service.ts b/src/time-and-attendance/timesheets/services/timesheet-employee-overview.service.ts index 8d958ac..222f1d3 100644 --- a/src/time-and-attendance/timesheets/services/timesheet-employee-overview.service.ts +++ b/src/time-and-attendance/timesheets/services/timesheet-employee-overview.service.ts @@ -23,7 +23,7 @@ export class GetTimesheetsOverviewService { const account_email = employee_email ?? email; //find period using year and period_no - const period = await this.prisma.payPeriods.findFirst({ where: { pay_year, pay_period_no } }); + const period = await this.prisma.client.payPeriods.findFirst({ where: { pay_year, pay_period_no } }); if (!period) return { success: false, error: `PAY_PERIOD_NOT_FOUND` }; //fetch the employee_id using the email @@ -52,7 +52,7 @@ export class GetTimesheetsOverviewService { rows = await this.loadTimesheets(employee_id.data, period.period_start, period.period_end); //find user infos using the employee_id - const employee = await this.prisma.employees.findUnique({ + const employee = await this.prisma.client.employees.findUnique({ where: { id: employee_id.data }, include: { schedule_preset: true, user: true }, }); @@ -79,7 +79,7 @@ export class GetTimesheetsOverviewService { //----------------------------------------------------------------------------------- //fetch timesheet's infos private async loadTimesheets(employee_id: number, period_start: Date, period_end: Date) { - return this.prisma.timesheets.findMany({ + return this.prisma.client.timesheets.findMany({ where: { employee_id, start_date: { gte: period_start, lte: period_end } }, include: { employee: { include: { user: true } }, @@ -93,7 +93,7 @@ export class GetTimesheetsOverviewService { private ensureTimesheet = async (employee_id: number, start_date: Date | string) => { const start = toDateFromString(start_date); - let row = await this.prisma.timesheets.findFirst({ + let row = await this.prisma.client.timesheets.findFirst({ where: { employee_id, start_date: start }, include: { employee: { include: { user: true } }, @@ -103,7 +103,7 @@ export class GetTimesheetsOverviewService { }); if (row) return row; - await this.prisma.timesheets.create({ + await this.prisma.client.timesheets.create({ data: { employee_id, start_date: start, @@ -111,7 +111,7 @@ export class GetTimesheetsOverviewService { }, }); - row = await this.prisma.timesheets.findFirst({ + row = await this.prisma.client.timesheets.findFirst({ where: { employee_id, start_date: start }, include: { employee: { include: { user: true } }, diff --git a/src/time-and-attendance/timesheets/timesheet.mapper.ts b/src/time-and-attendance/timesheets/timesheet.mapper.ts index b2463e3..1bcfd67 100644 --- a/src/time-and-attendance/timesheets/timesheet.mapper.ts +++ b/src/time-and-attendance/timesheets/timesheet.mapper.ts @@ -1,4 +1,5 @@ -import { Prisma } from "prisma/generated/postgres/client"; + +import { Prisma } from "@prisma/client"; import { toDateFromString, sevenDaysFrom, toStringFromDate, toHHmmFromDate } from "src/common/utils/date-utils"; import { Timesheet } from "src/time-and-attendance/timesheets/timesheet.dto"; diff --git a/src/time-and-attendance/utils/selects.utils.ts b/src/time-and-attendance/utils/selects.utils.ts index 054204f..5aee293 100644 --- a/src/time-and-attendance/utils/selects.utils.ts +++ b/src/time-and-attendance/utils/selects.utils.ts @@ -1,4 +1,5 @@ -import { Prisma } from "prisma/generated/postgres/client"; +import { Prisma } from "@prisma/client"; + export const expense_select = { id: true, diff --git a/src/time-and-attendance/utils/type.utils.ts b/src/time-and-attendance/utils/type.utils.ts index 32fad32..78c0661 100644 --- a/src/time-and-attendance/utils/type.utils.ts +++ b/src/time-and-attendance/utils/type.utils.ts @@ -1,4 +1,5 @@ -import { LeaveTypes, Prisma } from "prisma/generated/postgres/client"; +import { LeaveTypes, Prisma } from "@prisma/client"; + export type Normalized = { date: Date;