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 { BankCodesResolver } from "src/time-and-attendance/utils/resolve-bank-type-id.utils";
|
||||||
import { PrismaService } from "src/prisma/prisma.service";
|
import { PrismaService } from "src/prisma/prisma.service";
|
||||||
import { shift_select } from "src/time-and-attendance/utils/selects.utils";
|
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' }
|
if (!timesheet.success) return { success: false, error: ' timesheet not found' }
|
||||||
|
|
||||||
//finds original shift
|
//finds original shift
|
||||||
|
console.log('timesheet id found: ', timesheet.data.id);
|
||||||
const original = await this.prisma.shifts.findFirst({
|
const original = await this.prisma.shifts.findFirst({
|
||||||
where: { id: dto.id, timesheet_id: timesheet.data.id },
|
where: { id: dto.id, timesheet_id: timesheet.data.id },
|
||||||
select: shift_select,
|
select: shift_select,
|
||||||
|
|
@ -163,8 +164,7 @@ export class ShiftsUpdateDeleteService {
|
||||||
const shift_a = shifts[i];
|
const shift_a = shifts[i];
|
||||||
const shift_b = shifts[j];
|
const shift_b = shifts[j];
|
||||||
|
|
||||||
if (shift_a.date !== shift_b.date) continue;
|
if (shift_a.date !== shift_b.date || shift_a.id === shift_b.id) continue;
|
||||||
if (shift_a.id === shift_b.id) continue;
|
|
||||||
const has_overlap = overlaps(
|
const has_overlap = overlaps(
|
||||||
{ start: toHHmmFromString(shift_a.start_time), end: toHHmmFromString(shift_a.end_time) },
|
{ start: toHHmmFromString(shift_a.start_time), end: toHHmmFromString(shift_a.end_time) },
|
||||||
{ start: toHHmmFromString(shift_b.start_time), end: toHHmmFromString(shift_b.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
|
//ensures the week starts from sunday
|
||||||
export function weekStartSunday(date_local: Date): Date {
|
export function weekStartSunday(date_local: Date): Date {
|
||||||
const start = new Date(Date.UTC(date_local.getFullYear(), date_local.getMonth(), date_local.getDate()));
|
const start_date = new Date();
|
||||||
const dow = start.getDay(); // 0 = dimanche
|
start_date.setDate(date_local.getDate() - date_local.getDay());
|
||||||
start.setDate(start.getDate() - dow);
|
return start_date;
|
||||||
start.setHours(0, 0, 0, 0);
|
|
||||||
return start;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//converts string to HHmm format
|
//converts string to HHmm format
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ export class EmployeeTimesheetResolver {
|
||||||
const employee_id = await this.emailResolver.findIdByEmail(email);
|
const employee_id = await this.emailResolver.findIdByEmail(email);
|
||||||
if(!employee_id.success) return { success: false, error: employee_id.error}
|
if(!employee_id.success) return { success: false, error: employee_id.error}
|
||||||
const start_date = weekStartSunday(date);
|
const start_date = weekStartSunday(date);
|
||||||
|
console.log('start date: ', start_date);
|
||||||
const timesheet = await db.timesheets.findFirst({
|
const timesheet = await db.timesheets.findFirst({
|
||||||
where: { employee_id : employee_id.data, start_date: start_date },
|
where: { employee_id : employee_id.data, start_date: start_date },
|
||||||
select: { id: true },
|
select: { id: true },
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user