From aff13c631d269cd9e1393fb5512755dc09b6ceed Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Wed, 13 Mar 2024 13:34:13 +0200 Subject: [PATCH] fix myschedule start date to be first day of the month --- pages/cart/publishers/myschedule.tsx | 10 +++++++--- src/helpers/common.js | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pages/cart/publishers/myschedule.tsx b/pages/cart/publishers/myschedule.tsx index 54fb87a..273dc56 100644 --- a/pages/cart/publishers/myschedule.tsx +++ b/pages/cart/publishers/myschedule.tsx @@ -165,14 +165,18 @@ export const getServerSideProps = async (context) => { } const prisma = common.getPrismaClient(); - const publisher = await prisma.publisher.findMany({ + const monthInfo = common.getMonthInfo(new Date()); + //minus 1 day from the firstMonday to get the last Sunday + const lastSunday = new Date(monthInfo.firstMonday); + lastSunday.setDate(lastSunday.getDate() - 1); + const publisher = await prisma.publisher.findUnique({ where: { id: session.user.id, assignments: { some: { shift: { startTime: { - gte: new Date(), + gte: lastSunday, }, }, }, @@ -201,7 +205,7 @@ export const getServerSideProps = async (context) => { }, }); - const assignments = publisher[0]?.assignments || []; + const assignments = publisher?.assignments || []; const transformedAssignments = assignments?.map(assignment => { if (assignment.shift && assignment.shift.startTime) { diff --git a/src/helpers/common.js b/src/helpers/common.js index c1508e1..4cc84e7 100644 --- a/src/helpers/common.js +++ b/src/helpers/common.js @@ -288,6 +288,7 @@ exports.getMonthDatesInfo = function (date) { nrOfWeeks: Math.ceil((lastMonday.getDate() - firstMonday.getDate()) / 7) }; }; +exports.getMonthInfo = exports.getMonthDatesInfo; exports.getMonthlyScheduleRange = function (date) { let info = exports.getMonthDatesInfo(date);