wip stats
This commit is contained in:
@ -355,7 +355,8 @@ export default async function handler(req, res) {
|
||||
res.status(200).json(data);
|
||||
break;
|
||||
case "getAllPublishersWithStatistics":
|
||||
res.status(200).json(await dataHelper.getAllPublishersWithStatistics(day));
|
||||
let noEndDate = common.parseBool(req.query.noEndDate);
|
||||
res.status(200).json(await dataHelper.getAllPublishersWithStatistics(day, noEndDate));
|
||||
|
||||
default:
|
||||
res.status(200).json({
|
||||
|
@ -67,6 +67,7 @@ function ContactsPage({ allPublishers }) {
|
||||
});
|
||||
}
|
||||
setFilteredPublishers(filtered);
|
||||
setPubWithAssignmentsCount(filtered.filter(publisher => publisher.currentMonthAvailabilityHoursCount && publisher.currentMonthAvailabilityHoursCount > 0).length);
|
||||
}, [searchQuery, publisherType, sortField, sortOrder, allPublishers]);
|
||||
|
||||
useEffect(() => {
|
||||
@ -75,7 +76,7 @@ function ContactsPage({ allPublishers }) {
|
||||
const month = parseInt(selectedMonth);
|
||||
const filterDate = new Date(new Date().getFullYear(), month - 1, 15);
|
||||
try {
|
||||
const response = await axiosInstance.get(`/api/?action=getAllPublishersWithStatistics&date=${filterDate.toISOString()}`);
|
||||
const response = await axiosInstance.get(`/api/?action=getAllPublishersWithStatistics&date=${filterDate.toISOString()}&noEndDate=false`);
|
||||
setPublishers(response.data);
|
||||
setFilteredPublishers(response.data);
|
||||
|
||||
@ -101,7 +102,7 @@ function ContactsPage({ allPublishers }) {
|
||||
<ProtectedRoute allowedRoles={[UserRole.ADMIN, UserRole.POWERUSER, UserRole.USER]}>
|
||||
<div className="container mx-auto p-4">
|
||||
<h1 className="text-xl font-semibold mb-4">Статистика </h1>
|
||||
<h5 className="text-lg font-semibold mb-4">{pubWithAssignmentsCount} участника с предпочитания за месеца (от {allPublishers.length} )</h5>
|
||||
<h5 className="text-lg font-semibold mb-4">{pubWithAssignmentsCount} участника с предпочитания за месеца (от {filteredPublishers.length} )</h5>
|
||||
<div className="mb-4 flex justify-between items-center">
|
||||
<input
|
||||
type="text"
|
||||
|
@ -472,13 +472,13 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
}
|
||||
|
||||
//ToDo: refactor this function
|
||||
async function getAllPublishersWithStatistics(filterDate) {
|
||||
async function getAllPublishersWithStatistics(filterDate, noEndDateFilter = false) {
|
||||
|
||||
const prisma = common.getPrismaClient();
|
||||
const monthInfo = common.getMonthDatesInfo(new Date(filterDate));
|
||||
const dateStr = new Date(monthInfo.firstMonday).toISOString().split('T')[0];
|
||||
|
||||
let publishers = await filterPublishersNew('id,firstName,lastName,email,isActive,desiredShiftsPerMonth,lastLogin,type', dateStr, false, true, true, true, true);
|
||||
let publishers = await filterPublishersNew('id,firstName,lastName,email,isActive,desiredShiftsPerMonth,lastLogin,type', dateStr, false, true, noEndDateFilter, 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`);
|
||||
|
Reference in New Issue
Block a user