Refactor most getServerProps to fetch independent request in parallel and projected the data only to return the necessary fields and changed some functions
This commit is contained in:
@@ -32,10 +32,7 @@ import { capitalize } from "lodash";
|
||||
import { Module } from "@/interfaces";
|
||||
import ProgressBar from "@/components/Low/ProgressBar";
|
||||
import { calculateBandScore } from "@/utils/score";
|
||||
import {
|
||||
MODULE_ARRAY,
|
||||
sortByModule,
|
||||
} from "@/utils/moduleUtils";
|
||||
import { MODULE_ARRAY, sortByModule } from "@/utils/moduleUtils";
|
||||
import { Chart } from "react-chartjs-2";
|
||||
import DatePicker from "react-datepicker";
|
||||
import { shouldRedirectHome } from "@/utils/navigation.disabled";
|
||||
@@ -45,7 +42,6 @@ import { Stat, User } from "@/interfaces/user";
|
||||
import { Divider } from "primereact/divider";
|
||||
import Badge from "@/components/Low/Badge";
|
||||
import { mapBy, redirect, serialize } from "@/utils";
|
||||
import { getEntities } from "@/utils/entities.be";
|
||||
import { checkAccess } from "@/utils/permissions";
|
||||
import { EntityWithRoles } from "@/interfaces/entity";
|
||||
import Select from "@/components/Low/Select";
|
||||
@@ -69,19 +65,10 @@ const COLORS = ["#1EB3FF", "#FF790A", "#3D9F11", "#EF5DA8", "#414288"];
|
||||
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
|
||||
const user = await requestUser(req, res);
|
||||
if (!user) return redirect("/login");
|
||||
|
||||
if (shouldRedirectHome(user)) return redirect("/");
|
||||
|
||||
const entityIDs = mapBy(user.entities, "id");
|
||||
const isAdmin = checkAccess(user, ["admin", "developer"]);
|
||||
|
||||
const entities = await getEntities(isAdmin ? undefined : entityIDs, {
|
||||
id: 1,
|
||||
label: 1,
|
||||
});
|
||||
|
||||
return {
|
||||
props: serialize({ user, entities, isAdmin }),
|
||||
props: serialize({ user, isAdmin }),
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user