Exporting a report from an user now allows access to the user data of the user that did the exam instead of the current session
This commit is contained in:
@@ -126,6 +126,15 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
const stats = docsSnap.docs.map((d) => d.data());
|
const stats = docsSnap.docs.map((d) => d.data());
|
||||||
// verify if the stats already have a pdf generated
|
// verify if the stats already have a pdf generated
|
||||||
const hasPDF = stats.find((s) => s.pdf);
|
const hasPDF = stats.find((s) => s.pdf);
|
||||||
|
// find the user that generated the stats
|
||||||
|
const statIndex = stats.findIndex((s) => s.user);
|
||||||
|
|
||||||
|
if(statIndex === -1) {
|
||||||
|
res.status(401).json({ok: false});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const userId = stats[statIndex].user;
|
||||||
|
|
||||||
|
|
||||||
if (hasPDF) {
|
if (hasPDF) {
|
||||||
// if it does, return the pdf url
|
// if it does, return the pdf url
|
||||||
@@ -138,7 +147,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// generate the pdf report
|
// generate the pdf report
|
||||||
const docUser = await getDoc(doc(db, "users", req.session.user.id));
|
const docUser = await getDoc(doc(db, "users", userId));
|
||||||
|
|
||||||
if (docUser.exists()) {
|
if (docUser.exists()) {
|
||||||
// we'll need the user in order to get the user data (name, email, focus, etc);
|
// we'll need the user in order to get the user data (name, email, focus, etc);
|
||||||
|
|||||||
Reference in New Issue
Block a user