update LastLogin on login, show it.
remove end date for filter pubs for month; fix stats end date
This commit is contained in:
@ -146,7 +146,7 @@ export const authOptions: NextAuthOptions = {
|
|||||||
//user.permissions = dbUser.permissions;
|
//user.permissions = dbUser.permissions;
|
||||||
const session = { ...user };
|
const session = { ...user };
|
||||||
|
|
||||||
prisma.publisher.update({
|
await prisma.publisher.update({
|
||||||
where: { id: dbUser.id },
|
where: { id: dbUser.id },
|
||||||
data: { lastLogin: new Date() }
|
data: { lastLogin: new Date() }
|
||||||
});
|
});
|
||||||
|
@ -68,7 +68,7 @@ function ContactsPage({ publishers, allPublishers }) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td className="border-b p-4">{pub.lastLogin ? common.getDateFormated(pub.lastLogin) : ""}</td>
|
<td className="border-b p-4">{pub.lastLogin ? new Date(pub.lastLogin).toLocaleString("bg") : ""}</td>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
@ -127,7 +127,7 @@ export const getServerSideProps = async (context) => {
|
|||||||
const prisma = common.getPrismaClient();
|
const prisma = common.getPrismaClient();
|
||||||
const dateStr = new Date().toISOString().split('T')[0];
|
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 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`);
|
// 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
|
//remove availabilities that isFromPreviousAssignment
|
||||||
publisher.availabilities = publisher.availabilities.filter(availability => !availability.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.currentMonthAssignments = countAssignments(publisher.assignments, currentMonthStart, currentMonthEnd);
|
||||||
publisher.previousMonthAssignments = countAssignments(publisher.assignments, previousMonthStart, previousMonthEnd);
|
publisher.previousMonthAssignments = countAssignments(publisher.assignments, previousMonthStart, previousMonthEnd);
|
||||||
|
|
||||||
|
publisher.lastLogin = publisher.lastLogin ? publisher.lastLogin.toISOString() : null;
|
||||||
// Convert date formats within the same iteration
|
// Convert date formats within the same iteration
|
||||||
convertShiftDates(publisher.assignments);
|
convertShiftDates(publisher.assignments);
|
||||||
});
|
});
|
||||||
|
@ -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
|
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 },
|
dayOfMonth: { not: null },
|
||||||
startTime: { gte: monthInfo.firstMonday },
|
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)
|
// 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}`);
|
console.log(`getting publishers for date: ${filterDate}, isExactTime: ${isExactTime}, isForTheMonth: ${isForTheMonth}`);
|
||||||
|
Reference in New Issue
Block a user