diff --git a/assignment-db-service/app.js b/assignment-db-service/app.js index 16699b8..053f556 100644 --- a/assignment-db-service/app.js +++ b/assignment-db-service/app.js @@ -125,14 +125,18 @@ app.get("/assignments/instructor/:instructorId", async (req, res) => { // Read Assignment app.get("/assignments/:qrNumber", async (req, res) => { try { - const assignment = await prisma.assignments.findUnique({ + console.log("Fetching assignment with QR Code Number:", req.params.qrNumber); + + const assignment = await prisma.assignments.findMany({ where: { qrcodenumber: parseInt(req.params.qrNumber) }, }); if (!assignment) { + console.log("No assignment found for QR Code Number:", req.params.qrNumber); return res.status(404).json({ message: "Assignment not found" }); } + console.log("Assignment found:", assignment); res.json(assignment); } catch (err) { console.error("Error fetching assignment:", err.message); diff --git a/assignment-service/routes/InstructorRouter.js b/assignment-service/routes/InstructorRouter.js index 51d9394..c897d86 100644 --- a/assignment-service/routes/InstructorRouter.js +++ b/assignment-service/routes/InstructorRouter.js @@ -143,4 +143,45 @@ intructorRouter.delete( } ); +//get assignment by appname +intructorRouter.get( + "/checkAssignmentByAppName/:appName", + // passport.authenticate("jwt", { session: false }), + async (req, res) => { + try { + const appName = req.params.appName; + console.log("Fetching assignment for appName:", appName); + const response = await axios.get( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/appname/${appName}` + ); + console.log("exists:", response.data.length > 0); + res.status(response.status).json({"exists": response.data.length > 0}); + } catch (error) { + console.error("Error fetching assignment by app name:", error.message); + res.status(error.response?.status || 500).json({ error: error.message }); + } + } +); + +//get assignment by qrcode number +intructorRouter.get( + "/checkAssignmentByQRCode/:qrcode", + // passport.authenticate("jwt", { session: false }), + async (req, res) => { + try { + const qrcode = req.params.qrcode; + console.log("Fetching assignment for qrcode:", qrcode); + const response = await axios.get( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrcode}` + ); + console.log("response:", response.data); + console.log("exists:", response.data.length > 0); + res.status(response.status).json({"exists": response.data.length > 0}); + } catch (error) { + console.error("Error fetching assignment by QR code:", error.message); + res.status(error.response?.status || 500).json({ error: error.message }); + } + } +); + module.exports = intructorRouter;