fix(expenses): fix Prisma query select

This commit is contained in:
Matthieu Haineault 2025-11-18 08:24:51 -05:00
parent 7863a15562
commit 194a12d7ab
2 changed files with 4 additions and 3 deletions

View File

@ -57,7 +57,7 @@ import { ANCHOR_ISO, MS_PER_DAY, PERIODS_PER_YEAR, PERIOD_DAYS } from "src/commo
//ensures the week starts from sunday
export function weekStartSunday(date_local: Date): Date {
const start_date = new Date();
start_date.setDate(date_local.getDate() - date_local.getDay());
start_date.setDate(date_local.getUTCDate() - date_local.getUTCDay());
return start_date;
}

View File

@ -1,6 +1,6 @@
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 { expense_select, timesheet_select } from "src/time-and-attendance/utils/selects.utils";
import { PrismaService } from "src/prisma/prisma.service";
import { Injectable } from "@nestjs/common";
import { Result } from "src/common/errors/result-error.factory";
@ -33,6 +33,7 @@ export class ExpenseUpsertService {
//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({
where: { start_date, employee_id: employee_id.data },
select: { id: true, employee_id: true },
@ -79,7 +80,7 @@ export class ExpenseUpsertService {
const timesheet = await this.prisma.timesheets.findUnique({
where: { id: dto.timesheet_id },
select: expense_select,
select: timesheet_select,
});
if (!timesheet) return { success: false, error: `Timesheet ${dto.timesheet_id} not found` }