fix(expenses): fix Prisma query select
This commit is contained in:
parent
7863a15562
commit
194a12d7ab
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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` }
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user