Skip to content

Commit

Permalink
Merge pull request #243 from agiledev-students-fall2023/sprint/3/spik…
Browse files Browse the repository at this point in the history
…e/237/routing-bug

Fixed GET routing bug for student issue details
  • Loading branch information
hasiburratul authored Nov 16, 2023
2 parents 1a16199 + 2d882a3 commit 1d21ebe
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions back-end/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
44 changes: 24 additions & 20 deletions back-end/src/controllers/studentIssueUpdateHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down
2 changes: 1 addition & 1 deletion back-end/src/controllers/studentIssueViewDetailsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions back-end/src/routes/studentIssues.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 1d21ebe

Please sign in to comment.