fix(shifts): fix minor issue with using UTC instead of local time to get timesheet id
This commit is contained in:
parent
6aa464a76e
commit
37b150d87c
|
|
@ -1,4 +1,4 @@
|
|||
import { toDateFromString, toHHmmFromString, toStringFromHHmm, toStringFromDate, overlaps } from "src/time-and-attendance/utils/date-time.utils";
|
||||
import { toDateFromString, toHHmmFromString, toStringFromHHmm, toStringFromDate, overlaps, toUTCDateFromString } from "src/time-and-attendance/utils/date-time.utils";
|
||||
import { BankCodesResolver } from "src/time-and-attendance/utils/resolve-bank-type-id.utils";
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
import { shift_select } from "src/time-and-attendance/utils/selects.utils";
|
||||
|
|
@ -62,6 +62,7 @@ export class ShiftsUpdateDeleteService {
|
|||
if (!timesheet.success) return { success: false, error: ' timesheet not found' }
|
||||
|
||||
//finds original shift
|
||||
console.log('timesheet id found: ', timesheet.data.id);
|
||||
const original = await this.prisma.shifts.findFirst({
|
||||
where: { id: dto.id, timesheet_id: timesheet.data.id },
|
||||
select: shift_select,
|
||||
|
|
@ -163,8 +164,7 @@ export class ShiftsUpdateDeleteService {
|
|||
const shift_a = shifts[i];
|
||||
const shift_b = shifts[j];
|
||||
|
||||
if (shift_a.date !== shift_b.date) continue;
|
||||
if (shift_a.id === shift_b.id) continue;
|
||||
if (shift_a.date !== shift_b.date || shift_a.id === shift_b.id) continue;
|
||||
const has_overlap = overlaps(
|
||||
{ start: toHHmmFromString(shift_a.start_time), end: toHHmmFromString(shift_a.end_time) },
|
||||
{ start: toHHmmFromString(shift_b.start_time), end: toHHmmFromString(shift_b.end_time) },
|
||||
|
|
|
|||
|
|
@ -3,11 +3,9 @@ import { ANCHOR_ISO, MS_PER_DAY, PERIODS_PER_YEAR, PERIOD_DAYS } from "src/time-
|
|||
|
||||
//ensures the week starts from sunday
|
||||
export function weekStartSunday(date_local: Date): Date {
|
||||
const start = new Date(Date.UTC(date_local.getFullYear(), date_local.getMonth(), date_local.getDate()));
|
||||
const dow = start.getDay(); // 0 = dimanche
|
||||
start.setDate(start.getDate() - dow);
|
||||
start.setHours(0, 0, 0, 0);
|
||||
return start;
|
||||
const start_date = new Date();
|
||||
start_date.setDate(date_local.getDate() - date_local.getDay());
|
||||
return start_date;
|
||||
}
|
||||
|
||||
//converts string to HHmm format
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ export class EmployeeTimesheetResolver {
|
|||
const employee_id = await this.emailResolver.findIdByEmail(email);
|
||||
if(!employee_id.success) return { success: false, error: employee_id.error}
|
||||
const start_date = weekStartSunday(date);
|
||||
console.log('start date: ', start_date);
|
||||
const timesheet = await db.timesheets.findFirst({
|
||||
where: { employee_id : employee_id.data, start_date: start_date },
|
||||
select: { id: true },
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user