minor changes

This commit is contained in:
Bhavnoor Singh Saroya 2025-08-25 14:23:55 -07:00
parent 909b29dfb5
commit af2e220116
30 changed files with 598 additions and 350 deletions

View file

@ -75,7 +75,7 @@ async function convertToAssignment(req) {
console.log("Converted assignment object:", assignment);
return assignment;
}
}
// Create Assignment
app.post("/assignments", async (req, res) => {
@ -86,7 +86,7 @@ app.post("/assignments", async (req, res) => {
const newAssignment = await prisma.assignments.create({
data: assignment,
});
console.log("Assignment created successfully:", newAssignment);
res.json({
@ -104,14 +104,20 @@ app.get("/assignments/instructor/:instructorId", async (req, res) => {
try {
const { instructorId } = req.params;
console.log("InstructorID:", instructorId);
// changes below
// const whereClause = { instructorid: parseInt(instructorId) };
const whereClause = {}
// changes above
const assignments = await prisma.assignments.findMany({
where: { instructorid: parseInt(instructorId) },
orderBy: { assignmentid: 'asc' },
// where: { instructorid: parseInt(instructorId) },
where: whereClause,
// orderBy: { assignmentid: 'asc' }, // commnented out to return in the chronological order
});
if (assignments.length === 0) {
return res
.status(404)
.status(204)
.json({ message: "No assignments found for this instructor" });
}
@ -122,6 +128,43 @@ app.get("/assignments/instructor/:instructorId", async (req, res) => {
}
});
// // Get Assignments by optional InstructorID (if not provided, return all assignments)
// app.get("/assignments/instructor/:instructorId?", async (req, res) => {
// try {
// // force all queries to return all assignments even if instructorId is provided
// // const { instructorId } = req.params;
// const instructorId = null;
// const whereClause = instructorId
// ? { instructorid: parseInt(instructorId) }
// : {};
// const assignments = await prisma.assignments.findMany({
// where: whereClause,
// orderBy: { assignmentid: 'asc' },
// });
// if (assignments.length === 0) {
// return res.status(204).json({
// message: instructorId
// ? "No assignments found for this instructor"
// : "No assignments found",
// });
// }
// res.json(assignments);
// } catch (err) {
// console.error("Error fetching assignments:", err.message);
// res.status(500).json({ error: err.message });
// }
// });
//Get assignment by assignmentid
app.get("/assignments/:id", async (req, res) => {
try {