From 2d882a36b276870e0d98fb9996adb240782b7e3d Mon Sep 17 00:00:00 2001 From: basil-ahmed Date: Thu, 16 Nov 2023 14:56:47 -0500 Subject: [PATCH] Fixed GET routing bug for student issue details --- back-end/app.js | 4 +- .../controllers/studentIssueUpdateHandler.js | 44 ++++++++++--------- .../studentIssueViewDetailsHandler.js | 2 +- back-end/src/routes/studentIssues.js | 2 + 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/back-end/app.js b/back-end/app.js index 2cf09ea..2a6173d 100644 --- a/back-end/app.js +++ b/back-end/app.js @@ -53,10 +53,10 @@ app.use("/api/login", login); app.use("/api/issues/student", studentIssues); // Student Side Issue View Details -app.use("/api/issues/student/", studentIssueViewDetails); +// app.use("/api/issues/student/", studentIssueViewDetails); // Student Side Issue Update -app.use("/api/actions/student/", studentIssueUpdate); +app.use("/api/actions/student", studentIssueUpdate); // Admin side issue retrieval app.use("/api/issues/admin", adminIssues); diff --git a/back-end/src/controllers/studentIssueUpdateHandler.js b/back-end/src/controllers/studentIssueUpdateHandler.js index ba602be..36f42ab 100644 --- a/back-end/src/controllers/studentIssueUpdateHandler.js +++ b/back-end/src/controllers/studentIssueUpdateHandler.js @@ -16,35 +16,39 @@ export async function studentIssueUpdateHandler(req, res) { const jsonData = JSON.parse(fileContent); - const specificIssue = jsonData.filter( - (item) => String(item.index) === String(issueindex) - ); + // const specificIssue = jsonData.filter( + // (item) => String(item.index) === String(issueindex) + // ); - if (newcomment !== undefined) { - specificIssue[0].comments.unshift(newcomment); - } - if (currentStatus !== undefined) { - specificIssue[0].currentStatus = currentStatus; - } + // if (newcomment !== undefined) { + // specificIssue[0].comments.unshift(newcomment); + // } + // if (currentStatus !== undefined) { + // specificIssue[0].currentStatus = currentStatus; + // } - fs.writeFile(filePath, JSON.stringify(jsonData, null, '\t'), (err) => { - if (err) { - console.error(err); - } else { - console.log('File written successfully.'); - } - }); + // fs.writeFile(filePath, JSON.stringify(jsonData, null, '\t'), (err) => { + // if (err) { + // console.error(err); + // } else { + // console.log('File written successfully.'); + // } + // }); - const updateData = req.body; // This should contain the data you want to update + // const updateData = req.body; // This should contain the data you want to update try { // Make a POST request to the backend API to update the student issue + // const response = await axios.post( + // `${process.env.BACKEND_URL}/api/actions/student/${studentNetID}`, + // updateData + // ); + const response = await axios.post( - `${process.env.BACKEND_URL}/api/actions/student/${studentNetID}`, - updateData + `${process.env.BACKEND_URL}/json/mockapi.json`, + updateData // will be replaced with db call ); - const specificIssue = jsonData.filter( (item) => String(item.index) === String(paramName) ); diff --git a/back-end/src/controllers/studentIssueViewDetailsHandler.js b/back-end/src/controllers/studentIssueViewDetailsHandler.js index 2b94f4d..5c2e08d 100644 --- a/back-end/src/controllers/studentIssueViewDetailsHandler.js +++ b/back-end/src/controllers/studentIssueViewDetailsHandler.js @@ -16,7 +16,7 @@ export async function studentIssueViewDetailsHandler(req, res) { try { // Assuming the data you want is at the response.data property const response = await axios.get( - `${process.env.BACKEND_URL}/api/issues/student/${studentNetID}` + `${process.env.BACKEND_URL}/json/mockapi.json` // will be replaced with db call ); // Check if any data is returned for the student diff --git a/back-end/src/routes/studentIssues.js b/back-end/src/routes/studentIssues.js index 7481e96..e750e61 100644 --- a/back-end/src/routes/studentIssues.js +++ b/back-end/src/routes/studentIssues.js @@ -1,8 +1,10 @@ import express from "express"; import { issueRetrievalHandler } from "../controllers/studentIssuesHandler.js"; +import { studentIssueViewDetailsHandler } from "../controllers/studentIssueViewDetailsHandler.js"; const router = express.Router(); router.get("/:paramName", issueRetrievalHandler); +router.get("/:studentNetID/:paramName", studentIssueViewDetailsHandler); export default router;