refactor(expenses): added start_date to find the right timesheet using expense.date
This commit is contained in:
parent
e5484da39a
commit
6c746aa3c2
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
import { CreateExpenseResult, UpdateExpensePayload, UpdateExpenseResult, DeleteExpenseResult, NormalizedExpense } from "src/time-and-attendance/utils/type.utils";
|
import { CreateExpenseResult, UpdateExpensePayload, UpdateExpenseResult, DeleteExpenseResult, NormalizedExpense } from "src/time-and-attendance/utils/type.utils";
|
||||||
import { toDateFromString, toStringFromDate } from "src/time-and-attendance/utils/date-time.utils";
|
import { toDateFromString, toStringFromDate, weekStartSunday } from "src/time-and-attendance/utils/date-time.utils";
|
||||||
import { Injectable, NotFoundException, Req } from "@nestjs/common";
|
import { Injectable, NotFoundException, Req } from "@nestjs/common";
|
||||||
import { expense_select } from "src/time-and-attendance/utils/selects.utils";
|
import { expense_select } from "src/time-and-attendance/utils/selects.utils";
|
||||||
import { PrismaService } from "src/prisma/prisma.service";
|
import { PrismaService } from "src/prisma/prisma.service";
|
||||||
|
|
@ -27,13 +27,16 @@ export class ExpenseUpsertService {
|
||||||
//normalize strings and dates
|
//normalize strings and dates
|
||||||
const normed_expense = this.normalizeExpenseDto(dto);
|
const normed_expense = this.normalizeExpenseDto(dto);
|
||||||
|
|
||||||
|
//finds the timesheet using expense.date
|
||||||
|
const start_date = weekStartSunday(normed_expense.date);
|
||||||
|
|
||||||
//parse numbers
|
//parse numbers
|
||||||
const parsed_amount = this.parseOptionalNumber(dto.amount, "amount");
|
const parsed_amount = this.parseOptionalNumber(dto.amount, "amount");
|
||||||
const parsed_mileage = this.parseOptionalNumber(dto.mileage, "mileage");
|
const parsed_mileage = this.parseOptionalNumber(dto.mileage, "mileage");
|
||||||
const parsed_attachment = this.parseOptionalNumber(dto.attachment, "attachment");
|
const parsed_attachment = this.parseOptionalNumber(dto.attachment, "attachment");
|
||||||
|
|
||||||
const timesheet = await this.prisma.timesheets.findFirst({
|
const timesheet = await this.prisma.timesheets.findFirst({
|
||||||
where: { id: dto.timesheet_id, employee_id: employee_id },
|
where: { start_date, employee_id },
|
||||||
select: { id: true, employee_id: true },
|
select: { id: true, employee_id: true },
|
||||||
});
|
});
|
||||||
if(!timesheet) throw new NotFoundException(`Timesheet with id ${dto.timesheet_id} not found`);
|
if(!timesheet) throw new NotFoundException(`Timesheet with id ${dto.timesheet_id} not found`);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user