added checking if appname and qrcode number already exist
This commit is contained in:
parent
5a79b9970b
commit
f003708282
2 changed files with 46 additions and 1 deletions
|
|
@ -125,14 +125,18 @@ app.get("/assignments/instructor/:instructorId", async (req, res) => {
|
||||||
// Read Assignment
|
// Read Assignment
|
||||||
app.get("/assignments/:qrNumber", async (req, res) => {
|
app.get("/assignments/:qrNumber", async (req, res) => {
|
||||||
try {
|
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) },
|
where: { qrcodenumber: parseInt(req.params.qrNumber) },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!assignment) {
|
if (!assignment) {
|
||||||
|
console.log("No assignment found for QR Code Number:", req.params.qrNumber);
|
||||||
return res.status(404).json({ message: "Assignment not found" });
|
return res.status(404).json({ message: "Assignment not found" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Assignment found:", assignment);
|
||||||
res.json(assignment);
|
res.json(assignment);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error fetching assignment:", err.message);
|
console.error("Error fetching assignment:", err.message);
|
||||||
|
|
|
||||||
|
|
@ -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;
|
module.exports = intructorRouter;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue