added checking if appname and qrcode number already exist

This commit is contained in:
JBB0807 2025-05-05 23:37:54 -07:00
parent 5a79b9970b
commit f003708282
2 changed files with 46 additions and 1 deletions

View file

@ -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);

View file

@ -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;