fix statistics;
rewrite availability filters; fix availability filters; ProtectedRoute.IsInRole helper
This commit is contained in:
@ -3,6 +3,8 @@ import NewPubPage from "../new";
|
||||
export default NewPubPage;
|
||||
|
||||
import { Assignment, Shift, UserRole, AvailabilityType } from "prisma/prisma-client";
|
||||
//import ProtectedRoute from '../../../../components/protectedRoute';
|
||||
|
||||
// import { monthNamesBG } from "~/src/helpers/const"
|
||||
import { monthNamesBG } from "src/helpers/const";
|
||||
|
||||
@ -38,6 +40,7 @@ function getShiftGroups(shifts: [Shift]) {
|
||||
export const getServerSideProps = async (context) => {
|
||||
const axios = await axiosServer(context);
|
||||
|
||||
// const isAdmin = await ProtectedRoute.IsInRole(UserRole.ADMIN); does not work on server side
|
||||
context.res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate");
|
||||
if (!context.query || !context.query.id) {
|
||||
return {
|
||||
@ -50,11 +53,9 @@ export const getServerSideProps = async (context) => {
|
||||
|
||||
// item.allShifts = item.assignments.map((a: Assignment[]) => a.shift);
|
||||
|
||||
//group shifts by month, remove duplicates
|
||||
//sort availabilities by start time
|
||||
// item.availabilities = item.availabilities
|
||||
// .sort((a, b) => b.startTime - a.startTime);
|
||||
|
||||
// ============================================================
|
||||
// don't show past availabilities (if user not admin) ToDo: add admin check
|
||||
// ============================================================
|
||||
item.availabilities = item.availabilities.filter((a) => new Date(a.startTime) >= new Date() || a.type == AvailabilityType.Weekly);
|
||||
item.assignments = item.assignments
|
||||
.sort((a, b) => b.startTime - a.startTime)
|
||||
|
@ -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, true);
|
||||
let publishers = await data.filterPublishersNew('id,firstName,lastName,email,isActive,desiredShiftsPerMonth,lastLogin', dateStr, false, true, 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`);
|
||||
|
Reference in New Issue
Block a user