diff --git a/backend/src/middleware/validScenarioId.js b/backend/src/middleware/validScenarioId.js
new file mode 100644
index 00000000..d210d68a
--- /dev/null
+++ b/backend/src/middleware/validScenarioId.js
@@ -0,0 +1,18 @@
+import mongoose from "mongoose";
+
+const HTTP_BAD_REQUEST = 400;
+
+/**
+ * Checks if the scenarioId is valid
+ */
+export default async function validScenarioId(req, res, next) {
+ if (
+ req.params?.scenarioId &&
+ !mongoose.isValidObjectId(req.params.scenarioId)
+ ) {
+ res.status(HTTP_BAD_REQUEST).json({ error: "Invalid scenario ID." });
+ return;
+ }
+
+ next();
+}
diff --git a/backend/src/routes/api/group.js b/backend/src/routes/api/group.js
index fc828fc5..80fd0d80 100644
--- a/backend/src/routes/api/group.js
+++ b/backend/src/routes/api/group.js
@@ -1,21 +1,23 @@
import { Router } from "express";
-
import {
+ createGroup,
getCurrentScene,
getGroup,
- createGroup,
getGroupByScenarioId,
} from "../../db/daos/groupDao.js";
import { retrieveRoleList, updateRoleList } from "../../db/daos/scenarioDao.js";
import Group from "../../db/models/group.js";
+import validScenarioId from "../../middleware/validScenarioId.js";
+
const router = Router();
const HTTP_OK = 200;
const HTTP_CONFLICT = 409;
const HTTP_NO_CONTENT = 204;
const HTTP_NOT_FOUND = 404;
+const HTTP_BAD_REQUEST = 400;
// get the groups assigned to a scenario
router.get("/scenario/:scenarioId", async (req, res) => {
@@ -39,6 +41,19 @@ router.get("/path/:groupId", async (req, res) => {
}
});
+// get a group by its id
+router.get("/retrieve/:groupId", async (req, res) => {
+ const { groupId } = req.params;
+ const group = await getGroup(groupId);
+ if (!group) {
+ return res.status(HTTP_NOT_FOUND).json({ error: "Group not found" });
+ }
+ return res.status(HTTP_OK).json(group);
+});
+
+export default router;
+
+router.use("/:scenarioId", validScenarioId);
// create a new group
router.post("/:scenarioId", async (req, res) => {
const { groupList, roleList } = req.body;
@@ -98,20 +113,7 @@ router.post("/:scenarioId", async (req, res) => {
router.get("/:scenarioId/roleList", async (req, res) => {
const { scenarioId } = req.params;
-
const roleList = await retrieveRoleList(scenarioId);
res.status(HTTP_OK).json(roleList);
});
-
-// get a group by its id
-router.get("/retrieve/:groupId", async (req, res) => {
- const { groupId } = req.params;
- const group = await getGroup(groupId);
- if (!group) {
- return res.status(HTTP_NOT_FOUND).json({ error: "Group not found" });
- }
- return res.status(HTTP_OK).json(group);
-});
-
-export default router;
diff --git a/backend/src/routes/api/scenario.js b/backend/src/routes/api/scenario.js
index 0bc6ee6a..4186559e 100644
--- a/backend/src/routes/api/scenario.js
+++ b/backend/src/routes/api/scenario.js
@@ -1,13 +1,15 @@
import { Router } from "express";
import auth from "../../middleware/firebaseAuth.js";
import scenarioAuth from "../../middleware/scenarioAuth.js";
+import validScenarioId from "../../middleware/validScenarioId.js";
import {
createScenario,
- retrieveScenarioList,
- updateScenario,
deleteScenario,
+ retrieveScenario,
+ retrieveScenarioList,
updateDurations,
+ updateScenario,
} from "../../db/daos/scenarioDao.js";
import { retrieveAssignedScenarioList } from "../../db/daos/userDao.js";
@@ -48,8 +50,15 @@ router.post("/", async (req, res) => {
});
// Apply scenario auth middleware
+router.use("/:scenarioId", validScenarioId);
router.use("/:scenarioId", scenarioAuth);
+// Get a scenario by id.
+router.get("/:scenarioId", async (req, res) => {
+ const scenario = await retrieveScenario(req.params.scenarioId);
+ res.status(HTTP_OK).json(scenario);
+});
+
// Update a scenario by a user
router.put("/:scenarioId", async (req, res) => {
const { name, duration } = req.body;
diff --git a/backend/src/routes/api/scene.js b/backend/src/routes/api/scene.js
index 85e5f0f1..02bed3ed 100644
--- a/backend/src/routes/api/scene.js
+++ b/backend/src/routes/api/scene.js
@@ -2,15 +2,16 @@ import { Router } from "express";
import {
createScene,
- retrieveSceneList,
- retrieveScene,
- updateScene,
deleteScene,
duplicateScene,
incrementVisisted,
+ retrieveScene,
+ retrieveSceneList,
+ updateScene,
} from "../../db/daos/sceneDao.js";
import auth from "../../middleware/firebaseAuth.js";
import scenarioAuth from "../../middleware/scenarioAuth.js";
+import validScenarioId from "../../middleware/validScenarioId.js";
const router = Router({ mergeParams: true });
@@ -20,6 +21,7 @@ const HTTP_NOT_FOUND = 404;
// Apply auth middleware to all routes below this point
router.use(auth);
// Apply scenario auth middleware
+router.use(validScenarioId);
router.use(scenarioAuth);
// Get scene infromation
diff --git a/frontend/index.html b/frontend/index.html
index b9e3f512..74ac41ea 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -1,10 +1,18 @@
-
-
+
+
+
+
Virtual Patient System - UoA
diff --git a/frontend/src/components/DashedCard.jsx b/frontend/src/components/DashedCard.jsx
index fdce33d9..1d8148ce 100644
--- a/frontend/src/components/DashedCard.jsx
+++ b/frontend/src/components/DashedCard.jsx
@@ -1,5 +1,6 @@
import { Box } from "@material-ui/core";
-import styles from "./ListContainer/ListContainer.module.scss";
+
+import AddRoundedIcon from "@mui/icons-material/AddRounded";
/**
* Component used to represent a card with a dashed border, used to indicate that a new card can be created.
@@ -16,27 +17,27 @@ import styles from "./ListContainer/ListContainer.module.scss";
*/
export default function DashedCard({ onClick }) {
return (
-