diff --git a/src/customer-support/accounts/account.controller.ts b/src/customer-support/accounts/account.controller.ts index dde850e..d85b8be 100644 --- a/src/customer-support/accounts/account.controller.ts +++ b/src/customer-support/accounts/account.controller.ts @@ -1,4 +1,4 @@ -import { Controller } from "@nestjs/common"; +import { Controller, Get, Param } from "@nestjs/common"; import { AccountService } from "src/customer-support/accounts/account.service"; @@ -6,14 +6,14 @@ import { AccountService } from "src/customer-support/accounts/account.service"; export class AccountController { constructor(private readonly accountService: AccountService) { } - findAllAccounts = async() => { - return await this.accountService.findAllAccounts(); + @Get() + findAllAccounts(){ + return this.accountService.findAllAccounts(); } - findMemosByAccountId = async( - accountId:number, - ) => { - return await this.accountService.findMemosByAccountId(accountId); + @Get() + findMemosByAccountId(@Param('accountId') accountId: number) { + return this.accountService.findMemosByAccountId(accountId); } - + } \ No newline at end of file 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 f647027..3a8968a 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.client.$transaction(async (tx) => { + await this.prisma.$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.client.users.findFirst({ + let supervisor = await this.prisma.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 a4d2e1e..e9fa53d 100644 --- a/src/identity-and-account/employees/services/employees-get.service.ts +++ b/src/identity-and-account/employees/services/employees-get.service.ts @@ -17,7 +17,7 @@ export class EmployeesGetService { ) { } async findListEmployees(): Promise[], string>> { - const employee_list = await this.prisma.client.employees.findMany({ + const employee_list = await this.prisma.employees.findMany({ select: { user: { select: { @@ -70,7 +70,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.client.employees.findUnique({ + const existing_profile = await this.prisma.employees.findUnique({ where: { user_id: user_id.data }, select: { user: { @@ -135,7 +135,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.client.employees.findUnique({ + const employee = await this.prisma.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 b3c04f2..6af11ed 100644 --- a/src/identity-and-account/employees/services/employees-update.service.ts +++ b/src/identity-and-account/employees/services/employees-update.service.ts @@ -22,7 +22,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.client.employees.findFirst({ + const employee = await this.prisma.employees.findFirst({ where: { user_id: user_id.data }, select: { id: true }, }) @@ -34,7 +34,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.client.$transaction(async (tx) => { + await this.prisma.$transaction(async (tx) => { await tx.users.update({ where: { id: user_id.data }, data: { @@ -111,7 +111,7 @@ export class EmployeesUpdateService { private toIdFromFullName = async (full_name: string) => { const [first_name, last_name] = full_name.split(' ', 2); - let supervisor = await this.prisma.client.users.findFirst({ + let supervisor = await this.prisma.users.findFirst({ where: { first_name, last_name }, select: { employee: { select: { id: true } } } }); diff --git a/src/identity-and-account/help/help-page.service.ts b/src/identity-and-account/help/help-page.service.ts index 0434e67..085c16d 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.client.userModuleAccess.findUnique({ + const module_access = await this.prisma.userModuleAccess.findUnique({ where: { user_id: user_id.data }, select: { dashboard: true, diff --git a/src/identity-and-account/preferences/preferences.service.ts b/src/identity-and-account/preferences/preferences.service.ts index a8190c0..ab188df 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.client.preferences.findUnique({ + const user_preferences = await this.prisma.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.client.preferences.update({ + const updated_preferences: PreferencesDto = await this.prisma.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 5749060..b7dcdf9 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.client.userModuleAccess.findUnique({ + const access = await this.prisma.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 f540d17..9219623 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.client.userModuleAccess.findUnique({ + const orignal_access = await this.prisma.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.client.userModuleAccess.update({ + const updated_access:ModuleAccess = await this.prisma.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.client.userModuleAccess.findUnique({ + const access = await this.prisma.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.client.userModuleAccess.update({ + const revoked_access: ModuleAccess = await this.prisma.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 56bd7b9..565490f 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.client.users.findUnique({ + const user = await this.prisma.users.findUnique({ where: { email }, include: { user_module_access: { diff --git a/src/main.ts b/src/main.ts index fee8f74..f73a72d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -25,7 +25,7 @@ const SESSION_TOKEN_DURATION_MINUTES = 180 async function bootstrap() { const app = await NestFactory.create(AppModule); - const prisma = app.get(PrismaPostgresService); + const prisma_postgres = 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, { + store: new PrismaSessionStore(prisma_postgres, { sessionModelName: 'sessions', checkPeriod: SESSION_TOKEN_DURATION_MINUTES * 60 * 1000, //ms dbRecordIdIsSessionId: true, 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 9ab465a..65f6e5d 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.client.bankCodes.create({ + await this.prisma.bankCodes.create({ data: { type: dto.type, categorie: dto.categorie, @@ -24,12 +24,12 @@ export class BankCodesService { } findAll() { - return this.prisma.client.bankCodes.findMany(); + return this.prisma.bankCodes.findMany(); } async update(id: number, dto: Prisma.BankCodesUpdateInput): Promise> { try { - await this.prisma.client.bankCodes.update({ + await this.prisma.bankCodes.update({ where: { id }, data: { type: dto.type, @@ -46,7 +46,7 @@ export class BankCodesService { async delete(id: number): Promise> { try { - await this.prisma.client.bankCodes.delete({ + await this.prisma.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 0e39c66..e7f360d 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.client.$transaction(async (tx) => { - const employee = await this.prisma.client.employees.findUnique({ + const result = await this.prisma.$transaction(async (tx) => { + const employee = await this.prisma.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 ca303ac..4bcb213 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.client.shifts.findMany({ + const shifts = await this.prisma.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 596a376..b946695 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.client.bankCodes.findUnique({ + const bank_code = await this.prisma.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 ab0397c..d4d9cb6 100644 --- a/src/time-and-attendance/domains/services/overtime.service.ts +++ b/src/time-and-attendance/domains/services/overtime.service.ts @@ -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.client) as PrismaClient; + const db = (tx ?? this.prisma) 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 9bdaf59..35e422b 100644 --- a/src/time-and-attendance/domains/services/sick-leave.service.ts +++ b/src/time-and-attendance/domains/services/sick-leave.service.ts @@ -14,7 +14,7 @@ export class SickLeaveService { const today = new Date(); // get employee info - const employee = await this.prisma.client.employees.findUnique({ + const employee = await this.prisma.employees.findUnique({ where: { id: employee_id }, select: { first_work_day: true, @@ -33,9 +33,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.client.paidTimeOff.findUnique({ + pto_details = await this.prisma.paidTimeOff.findUnique({ where: { employee_id: employee.id }, }) @@ -69,9 +69,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.client.paidTimeOff.create({ + const new_pto_entry = await this.prisma.paidTimeOff.create({ data: { employee_id: employee_id, last_updated: today, @@ -95,7 +95,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.client.paidTimeOff.update({ + const update_pto = await this.prisma.paidTimeOff.update({ where: { employee_id, }, @@ -115,8 +115,8 @@ export class SickLeaveService { if (asked_hours <= 0) return { success: false, error: 'INVALID_BANKING_HOURS' }; try { - const result = await this.prisma.client.$transaction(async (tx) => { - const employee = await this.prisma.client.employees.findUnique({ + const result = await this.prisma.$transaction(async (tx) => { + const employee = await this.prisma.employees.findUnique({ where: { id: employee_id }, select: { id: true, @@ -177,7 +177,7 @@ export class SickLeaveService { // const period_end = reference_date; // //fetches all shifts of a selected employee - // const shifts = await this.prisma.client.shifts.findMany({ + // const shifts = await this.prisma.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 584c448..bf87b7c 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.client.employees.findUnique({ + const employee = await this.prisma.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.client.$transaction(async (tx) => { + const result = await this.prisma.$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 a74b2c9..a7d89ca 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.client.timesheets.findFirst({ + const timesheet = await this.prisma.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.client.expenses.create({ + const expense = await this.prisma.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 d572bb1..9662243 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.client.expenses.findUnique({ + const expense = await this.prisma.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.client.$transaction(async (tx) => { + await this.prisma.$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 2ae2f30..8d313c4 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.client.timesheets.findFirst({ + const timesheet = await this.prisma.timesheets.findFirst({ where: { start_date: new_timesheet_start_date, employee_id: employee_id.data }, select: timesheet_select, }); @@ -50,7 +50,7 @@ export class ExpenseUpdateService { if (!data) return { success: false, error: `INVALID_EXPENSE` } //push updates and get updated datas - const expense = await this.prisma.client.expenses.update({ + const expense = await this.prisma.expenses.update({ where: { id: dto.id, timesheet_id: timesheet.id }, data, select: expense_select, 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 4fec781..449dc84 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.client.payPeriods.findFirst({ + const period = await this.prisma.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.client.shifts.findMany({ + promises.push(this.prisma.shifts.findMany({ where: { date: { gte: start, lte: end }, ...approved_filter, @@ -81,7 +81,7 @@ export class CsvExportService { } if (want_holiday) { - promises.push(this.prisma.client.shifts.findMany({ + promises.push(this.prisma.shifts.findMany({ where: { date: { gte: start, lte: end }, ...approved_filter, @@ -112,7 +112,7 @@ export class CsvExportService { } if (want_vacation) { - promises.push(this.prisma.client.shifts.findMany({ + promises.push(this.prisma.shifts.findMany({ where: { date: { gte: start, lte: end }, ...approved_filter, @@ -143,7 +143,7 @@ export class CsvExportService { } if (want_expense) { - promises.push(this.prisma.client.expenses.findMany({ + promises.push(this.prisma.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.client.bankCodes.findFirst({ + const holiday_code = await this.prisma.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.client.bankCodes.findFirst({ + const vacation_code = await this.prisma.bankCodes.findFirst({ where: { type: vacation }, select: { bank_code: true, 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 5e8b9df..44a7375 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.client.paidTimeOff.update({ + await this.prisma.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.client.paidTimeOff.update({ + await this.prisma.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 c5ca511..dfd7f18 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.client.employees.findMany({ + const employee_overviews = await this.prisma.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 d3c875d..4e992a6 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.client.shifts.updateMany({ + shifts = await this.prisma.shifts.updateMany({ where: { timesheet: { id: { in: timesheet_ids }, @@ -35,7 +35,7 @@ export class PayPeriodsCommandService { } }); - expenses = await this.prisma.client.expenses.updateMany({ + expenses = await this.prisma.expenses.updateMany({ where: { timesheet: { id: { in: timesheet_ids }, @@ -47,7 +47,7 @@ export class PayPeriodsCommandService { } }); - await this.prisma.client.timesheets.updateMany({ + await this.prisma.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 3fd6684..27dfc8b 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.client.payPeriods.findFirst({ + const row = await this.prisma.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.client.payPeriods.findFirst({ + const row = await this.prisma.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 65b3906..bba15e6 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.client.employees.findFirst({ + const employee_default_schedule_preset = await this.prisma.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.client.schedulePresetShifts.findMany({ + const default_preset_shifts = await this.prisma.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.client.timesheets.findUnique({ + const timesheet = await this.prisma.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.client.employees.findFirst({ + const preset_shift = await this.prisma.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 e0dcbe8..4daf523 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.client.schedulePresets.findFirst({ + const existing = await this.prisma.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.client.$transaction(async (tx) => { + await this.prisma.$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 c89bf06..c39dfac 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.client.schedulePresets.findUnique({ + const preset = await this.prisma.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.client.employees.updateMany({ + const updated_employees = await this.prisma.employees.updateMany({ where: { schedule_preset_id: preset_id }, data: { schedule_preset_id: 0, }, }); - await this.prisma.client.$transaction(async (tx) => { + await this.prisma.$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 f9d695a..81fce2b 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.client.schedulePresets.findMany({ + const presets = await this.prisma.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 9a3eac2..fa08906 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.client.schedulePresets.findFirst({ + const existing = await this.prisma.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.client.$transaction(async (tx) => { + await this.prisma.$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 e92a9f8..b35a460 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.client.timesheets.findUnique({ + const timesheet = await this.prisma.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.client.shifts.findMany({ + const existing_shifts = await this.prisma.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.client.shifts.create({ + const created_shift = await this.prisma.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 bfec467..bd2c568 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.client.shifts.findUnique({ + const shift = await this.prisma.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.client.$transaction(async (tx) => { + return await this.prisma.$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 210098a..c6c52fb 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.client.shifts.findFirst({ + const original = await this.prisma.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.client.shifts.update({ + const updated = await this.prisma.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 53ee497..392a616 100644 --- a/src/time-and-attendance/timesheets/services/timesheet-approval.service.ts +++ b/src/time-and-attendance/timesheets/services/timesheet-approval.service.ts @@ -17,7 +17,7 @@ import { timesheet_select } from "src/time-and-attendance/utils/selects.utils"; // APPROVAL AND DELEGATE METHODS //_____________________________________________________________________________________________ protected get delegate() { - return this.prisma.client.timesheets; + return this.prisma.timesheets; } protected delegateFor(tx: TransactionClient) { @@ -25,7 +25,7 @@ import { timesheet_select } from "src/time-and-attendance/utils/selects.utils"; } async updateApproval(id: number, is_approved: boolean): Promise { - return this.prisma.client.$transaction((tx) => + return this.prisma.$transaction((tx) => this.updateApprovalWithTransaction(tx, id, is_approved), ); } @@ -44,7 +44,7 @@ import { timesheet_select } from "src/time-and-attendance/utils/selects.utils"; } async approveTimesheetById( timesheet_id: number, is_approved: boolean){ - return this.prisma.client.$transaction(async (tx) => { + return this.prisma.$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 222f1d3..8d958ac 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.client.payPeriods.findFirst({ where: { pay_year, pay_period_no } }); + const period = await this.prisma.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.client.employees.findUnique({ + const employee = await this.prisma.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.client.timesheets.findMany({ + return this.prisma.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.client.timesheets.findFirst({ + let row = await this.prisma.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.client.timesheets.create({ + await this.prisma.timesheets.create({ data: { employee_id, start_date: start, @@ -111,7 +111,7 @@ export class GetTimesheetsOverviewService { }, }); - row = await this.prisma.client.timesheets.findFirst({ + row = await this.prisma.timesheets.findFirst({ where: { employee_id, start_date: start }, include: { employee: { include: { user: true } },