fix myschedule start date to be first day of the month

This commit is contained in:
Dobromir Popov
2024-03-13 13:34:13 +02:00
parent 1fb9bae130
commit aff13c631d
2 changed files with 8 additions and 3 deletions

View File

@ -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) {

View File

@ -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);