From af9fc6af9787079198da913b0e72fb8c8ac62720 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Thu, 25 Apr 2024 20:22:36 +0300 Subject: [PATCH] update LastLogin on login, show it. remove end date for filter pubs for month; fix stats end date --- pages/api/auth/[...nextauth].ts | 2 +- pages/cart/publishers/stats.tsx | 6 ++++-- src/helpers/data.js | 8 ++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index 382eef5..2db98e9 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -146,7 +146,7 @@ export const authOptions: NextAuthOptions = { //user.permissions = dbUser.permissions; const session = { ...user }; - prisma.publisher.update({ + await prisma.publisher.update({ where: { id: dbUser.id }, data: { lastLogin: new Date() } }); diff --git a/pages/cart/publishers/stats.tsx b/pages/cart/publishers/stats.tsx index b377092..3486a3f 100644 --- a/pages/cart/publishers/stats.tsx +++ b/pages/cart/publishers/stats.tsx @@ -68,7 +68,7 @@ function ContactsPage({ publishers, allPublishers }) { - {pub.lastLogin ? common.getDateFormated(pub.lastLogin) : ""} + {pub.lastLogin ? new Date(pub.lastLogin).toLocaleString("bg") : ""} ) : ( <> @@ -127,7 +127,7 @@ export const getServerSideProps = async (context) => { const prisma = common.getPrismaClient(); const dateStr = new Date().toISOString().split('T')[0]; - let publishers = await data.filterPublishersNew('id,firstName,lastName,email,isActive,desiredShiftsPerMonth,lastLogin', dateStr, false, true, true); + let publishers = await data.filterPublishersNew('id,firstName,lastName,email,isActive,desiredShiftsPerMonth,lastLogin', dateStr, false, true, true, true); // const axios = await axiosServer(context); // const { data: publishers } = await axios.get(`api/?action=filterPublishers&assignments=true&availabilities=true&date=${dateStr}&select=id,firstName,lastName,isActive,desiredShiftsPerMonth`); @@ -160,6 +160,7 @@ export const getServerSideProps = async (context) => { } } }); + publisher.lastLogin = publisher.lastLogin ? publisher.lastLogin.toISOString() : null; //remove availabilities that isFromPreviousAssignment publisher.availabilities = publisher.availabilities.filter(availability => !availability.isFromPreviousAssignment); @@ -214,6 +215,7 @@ export const getServerSideProps = async (context) => { publisher.currentMonthAssignments = countAssignments(publisher.assignments, currentMonthStart, currentMonthEnd); publisher.previousMonthAssignments = countAssignments(publisher.assignments, previousMonthStart, previousMonthEnd); + publisher.lastLogin = publisher.lastLogin ? publisher.lastLogin.toISOString() : null; // Convert date formats within the same iteration convertShiftDates(publisher.assignments); }); diff --git a/src/helpers/data.js b/src/helpers/data.js index 0bdb57f..972ddb1 100644 --- a/src/helpers/data.js +++ b/src/helpers/data.js @@ -228,7 +228,7 @@ async function getAvailabilities(userId) { } -async function filterPublishersNew(selectFields, filterDate, isExactTime = false, isForTheMonth = false, isWithStats = true, includeOldAvailabilities = false) { +async function filterPublishersNew(selectFields, filterDate, isExactTime = false, isForTheMonth = false, isNoEndDateFilter = false, isWithStats = true, includeOldAvailabilities = false) { filterDate = new Date(filterDate); // Convert to date object if not already @@ -341,7 +341,7 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false { dayOfMonth: { not: null }, startTime: { gte: monthInfo.firstMonday }, - endTime: { lte: monthInfo.lastSunday } + // endTime: { lte: monthInfo.lastSunday } }, // Check if dayOfMonth is null and match by day of week using the enum (Assigments every week) { @@ -358,6 +358,10 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false ] } }; + + if (!isNoEndDateFilter) { // Check if we need to apply the endTime filter + whereClause["availabilities"].some.OR[0].endTime = { lte: monthInfo.lastSunday }; + } } console.log(`getting publishers for date: ${filterDate}, isExactTime: ${isExactTime}, isForTheMonth: ${isForTheMonth}`);