From 7863a155628d61570e2a01be81f5e6cc58abe925 Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Mon, 17 Nov 2025 16:04:36 -0500 Subject: [PATCH] fix(expenses): fixes to prisma create request --- .../services/expense-upsert.service.ts | 27 +++++++------------ src/time-and-attendance/utils/type.utils.ts | 6 ++--- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/time-and-attendance/expenses/services/expense-upsert.service.ts b/src/time-and-attendance/expenses/services/expense-upsert.service.ts index 972ee8e..f666896 100644 --- a/src/time-and-attendance/expenses/services/expense-upsert.service.ts +++ b/src/time-and-attendance/expenses/services/expense-upsert.service.ts @@ -1,14 +1,13 @@ +import { weekStartSunday, toStringFromDate, toDateFromString } from "src/common/utils/date-utils"; import { EmailToIdResolver } from "src/common/mappers/email-id.mapper"; import { expense_select } from "src/time-and-attendance/utils/selects.utils"; import { PrismaService } from "src/prisma/prisma.service"; -import { ExpenseEntity } from "src/time-and-attendance/expenses/dtos/expense-entity.dto"; import { Injectable } from "@nestjs/common"; import { Result } from "src/common/errors/result-error.factory"; import { NormalizedExpense } from "src/time-and-attendance/utils/type.utils"; -import { weekStartSunday, toStringFromDate, toDateFromString } from "src/common/utils/date-utils"; import { BankCodesResolver } from "src/common/mappers/bank-type-id.mapper"; -import { EmployeeTimesheetResolver } from "src/common/mappers/timesheet.mapper"; import { ExpenseDto } from "src/time-and-attendance/expenses/dtos/expense-create.dto"; +import { Prisma } from "@prisma/client"; @Injectable() @@ -17,7 +16,6 @@ export class ExpenseUpsertService { private readonly prisma: PrismaService, private readonly emailResolver: EmailToIdResolver, private readonly typeResolver: BankCodesResolver, - private readonly timesheetResolver: EmployeeTimesheetResolver, ) { } //_________________________________________________________________ @@ -45,9 +43,6 @@ export class ExpenseUpsertService { const expense = await this.prisma.expenses.create({ data: { ...normed_expense.data, - amount: normed_expense.data.parsed_amount, - mileage: normed_expense.data.parsed_mileage, - attachment: normed_expense.data.parsed_attachment, timesheet_id: timesheet.id, is_approved: dto.is_approved, }, @@ -89,10 +84,8 @@ export class ExpenseUpsertService { if (!timesheet) return { success: false, error: `Timesheet ${dto.timesheet_id} not found` } //checks for modifications - const data: ExpenseEntity = { + const data: Prisma.ExpensesUpdateInput = { ...normed_expense.data, - id: dto.id, - timesheet_id: timesheet?.id, is_approved: dto.is_approved, }; if (!data) return { success: false, error: `An error occured during normalization. Expense with id: ${dto.id} is invalid` } @@ -103,7 +96,7 @@ export class ExpenseUpsertService { data, select: expense_select, }); - if (!expense) return { success: false, error: `An error occured during update. Expense with id: ${data.id} was not updated` } + if (!expense) return { success: false, error: `An error occured during update. Expense with id: ${dto.id} was not updated` } //build an object to return to the frontend const updated: ExpenseDto = { @@ -152,9 +145,9 @@ export class ExpenseUpsertService { //_________________________________________________________________ //makes sure that comments are the right length the date is of Date type private normalizeAndParseExpenseDto = async (dto: ExpenseDto): Promise> => { - const parsed_attachment = this.parseOptionalNumber(dto.attachment, "attachment"); - const parsed_mileage = this.parseOptionalNumber(dto.mileage, "mileage"); - const parsed_amount = this.parseOptionalNumber(dto.amount, "amount"); + const attachment = this.parseOptionalNumber(dto.attachment, "attachment"); + const mileage = this.parseOptionalNumber(dto.mileage, "mileage"); + const amount = this.parseOptionalNumber(dto.amount, "amount"); const comment = this.truncate280(dto.comment); const supervisor_comment = dto.supervisor_comment && dto.supervisor_comment.trim() @@ -170,9 +163,9 @@ export class ExpenseUpsertService { date, comment, supervisor_comment, - parsed_amount, - parsed_attachment, - parsed_mileage, + amount, + attachment, + mileage, bank_code_id: type.data, } }; diff --git a/src/time-and-attendance/utils/type.utils.ts b/src/time-and-attendance/utils/type.utils.ts index d0c25ea..543f52c 100644 --- a/src/time-and-attendance/utils/type.utils.ts +++ b/src/time-and-attendance/utils/type.utils.ts @@ -11,9 +11,9 @@ export type NormalizedExpense = { date: Date; comment: string; supervisor_comment?: string; - parsed_amount?: number | Prisma.Decimal | null; - parsed_mileage?: number | Prisma.Decimal | null; - parsed_attachment?: number; + amount?: number | Prisma.Decimal | null; + mileage?: number | Prisma.Decimal | null; + attachment?: number; bank_code_id: number; };