bug fix for duplicate appname and qr code number

This commit is contained in:
JBB0807 2025-05-06 10:43:48 -07:00
parent 3712fb332b
commit ee04a7e8ef
4 changed files with 15 additions and 14 deletions

View file

@ -127,7 +127,7 @@ app.get("/assignments/:qrNumber", async (req, res) => {
try { try {
console.log("Fetching assignment with QR Code Number:", req.params.qrNumber); console.log("Fetching assignment with QR Code Number:", req.params.qrNumber);
const assignment = await prisma.assignments.findMany({ const assignment = await prisma.assignments.findUnique({
where: { qrcodenumber: parseInt(req.params.qrNumber) }, where: { qrcodenumber: parseInt(req.params.qrNumber) },
}); });
@ -148,17 +148,19 @@ app.get("/assignments/:qrNumber", async (req, res) => {
app.get("/assignments/appname/:appName", async (req, res) => { app.get("/assignments/appname/:appName", async (req, res) => {
try { try {
const { appName } = req.params; const { appName } = req.params;
const assignments = await prisma.assignments.findMany({ const assignment = await prisma.assignments.findUnique({
where: { appname: appName }, where: { appname: appName },
}); });
if (assignments.length === 0) { if (!assignment) {
return res.status(404).json({ message: "No assignments found" }); console.log("No assignment found for app name:", req.params.qrNumber);
return res.status(404).json({ message: "Assignment not found" });
} }
res.json(assignments); console.log("Assignment found:", assignment);
res.json(assignment);
} catch (err) { } catch (err) {
console.error("Error fetching assignments:", err.message); console.error("Error fetching assignment:", err.message);
res.status(500).json({ error: err.message }); res.status(500).json({ error: err.message });
} }
}); });

View file

@ -154,8 +154,8 @@ intructorRouter.get(
const response = await axios.get( const response = await axios.get(
`${DB_ASSIGNMENT_SERVICE_URL}/assignments/appname/${appName}` `${DB_ASSIGNMENT_SERVICE_URL}/assignments/appname/${appName}`
); );
console.log("exists:", response.data.length > 0); console.log("Response data:", response.data);
res.status(response.status).json({"exists": response.data.length > 0}); res.status(response.status).json({"exists": (response.data !== null && response.data !== undefined)});
} catch (error) { } catch (error) {
console.error("Error fetching assignment by app name:", error.message); console.error("Error fetching assignment by app name:", error.message);
res.status(error.response?.status || 500).json({ error: error.message }); res.status(error.response?.status || 500).json({ error: error.message });
@ -174,9 +174,8 @@ intructorRouter.get(
const response = await axios.get( const response = await axios.get(
`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrcode}` `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrcode}`
); );
console.log("response:", response.data); console.log("Response data:", response.data);
console.log("exists:", response.data.length > 0); res.status(response.status).json({"exists": (response.data !== null && response.data !== undefined)});
res.status(response.status).json({"exists": response.data.length > 0});
} catch (error) { } catch (error) {
console.error("Error fetching assignment by QR code:", error.message); console.error("Error fetching assignment by QR code:", error.message);
res.status(error.response?.status || 500).json({ error: error.message }); res.status(error.response?.status || 500).json({ error: error.message });

View file

@ -45,11 +45,11 @@ studentRouter.post("/verify", async (req, res) => {
console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data);
console.log("Password provided:", password); console.log("Password provided:", password);
console.log("Password hash from database:", response.data[0].passwordhash); console.log("Password hash from database:", response.data.passwordhash);
const isPasswordValid = await bcrypt.compare( const isPasswordValid = await bcrypt.compare(
password, password,
response.data[0].passwordhash response.data.passwordhash
); );
console.log("Password validation result:", isPasswordValid); console.log("Password validation result:", isPasswordValid);

View file

@ -60,7 +60,7 @@ passport.serializeUser((user, done) => {
// done(null, user); // done(null, user);
console.log("Serializing user:", user); console.log("Serializing user:", user);
done(null, { done(null, {
id: user.qrcodenumber || user.id, userId: user.qrcodenumber || user.id,
displayName: user.studentname || user.displayName, displayName: user.studentname || user.displayName,
role: user.role, role: user.role,
emails: user.emails || "none", emails: user.emails || "none",