-
Notifications
You must be signed in to change notification settings - Fork 55
Backend update, registration events #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| const dashboardController = require("../controllers/dashboardController"); | ||
| const express = require("express"); | ||
| const router = express.Router(); | ||
| const { Event, User, OrganizationalUnit } = require("../models/schema"); | ||
|
|
@@ -255,14 +256,12 @@ router.post( | |
| event: updatedEvent, | ||
| }); | ||
| } catch (error) { | ||
| if (error?.name === "CastError") { | ||
| return res.status(400).json({ message: "Invalid event ID format." }); | ||
| } | ||
| console.error("Event registration error:", error); | ||
| return res | ||
| .status(500) | ||
| .json({ message: "Server error during registration." }); | ||
| } | ||
| if (error?.name === "CastError") { | ||
| return res.status(400).json({ message: "Invalid event ID format." }); | ||
| } | ||
| console.error("Event registration error:", error); | ||
| return res.status(500).json({ message: "Internal server error." }); | ||
| } | ||
|
Comment on lines
+259
to
+264
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent indentation in catch block. The catch block content is not properly indented relative to the function body. This appears to be a formatting error. 🧹 Proposed fix: correct indentation } catch (error) {
- if (error?.name === "CastError") {
- return res.status(400).json({ message: "Invalid event ID format." });
- }
- console.error("Event registration error:", error);
- return res.status(500).json({ message: "Internal server error." });
-}
+ if (error?.name === "CastError") {
+ return res.status(400).json({ message: "Invalid event ID format." });
+ }
+ console.error("Event registration error:", error);
+ return res.status(500).json({ message: "Internal server error." });
+ }🤖 Prompt for AI Agents |
||
| }, | ||
| ); | ||
|
|
||
|
|
@@ -474,7 +473,6 @@ router.put("/:eventId", isAuthenticated, isEventContact, async (req, res) => { | |
| .json({ message: "Server error", error: err.message }); | ||
| } | ||
| }); | ||
|
|
||
| // Delete an event (only unit contact) | ||
| router.delete( | ||
| "/:eventId", | ||
|
|
@@ -484,13 +482,24 @@ router.delete( | |
| try { | ||
| const { eventId } = req.params; | ||
| const deleted = await Event.findByIdAndDelete(eventId); | ||
| if (!deleted) return res.status(404).json({ message: "Event not found" }); | ||
|
|
||
| if (!deleted) { | ||
| return res.status(404).json({ message: "Event not found" }); | ||
| } | ||
|
|
||
| return res.json({ message: "Event deleted" }); | ||
| } catch (err) { | ||
| console.error("delete event error:", err); | ||
| return res.status(500).json({ message: "Server error" }); | ||
| } | ||
| }, | ||
| } | ||
| ); | ||
|
|
||
| // Get registered events | ||
| router.get( | ||
| "/registered-events", | ||
| isAuthenticated, | ||
| dashboardController.getRegisteredEvents | ||
| ); | ||
|
Comment on lines
+498
to
503
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Route will never be reached due to ordering. The Move this route before all parameterized routes ( 🐛 Proposed fix: move route before parameterized routesMove the route definition to appear before line 151 (before router.get("/latest", eventsController.getLatestEvents);
+// Get registered events for authenticated user
+router.get(
+ "/registered-events",
+ isAuthenticated,
+ dashboardController.getRegisteredEvents
+);
+
// Create a new event (new events can be created by admins only)
router.post(
"/create",And remove lines 498-503 from the end of the file. 🤖 Prompt for AI Agents |
||
|
|
||
| module.exports = router; | ||
| module.exports = router; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dead code: this function is never used.
According to the route definition in
backend/routes/events.js(lines 499-503), the/registered-eventsendpoint is wired todashboardController.getRegisteredEvents, not this export. This implementation is identical to the one indashboardController.jsand is never called.Remove this dead code to avoid confusion and maintenance burden.
🗑️ Proposed fix: remove unused function
📝 Committable suggestion
🤖 Prompt for AI Agents