Skip to content

Commit

Permalink
Merge pull request #54 from Gather307/53-add-a-get-groupsid-request
Browse files Browse the repository at this point in the history
added group get id
  • Loading branch information
zmattes04 authored May 21, 2024
2 parents 50ffca7 + 609e0db commit a51ebdd
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions backend/routes/groupRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ router.get("/", async (req: Request, res: Response) => {
}
});

router.get("/:groupid", async (req: Request, res: Response) => {
// Ensure the database connection
connectDB();

try {
console.log("Here");

// Use findById correctly with the id parameter from the request
const group = await Group.findById(req.params.groupid);

// Check if group is null or undefined
if (!group) {
return res.status(404).send("No groups found"); // Use return to exit the function after sending the response
}

// Send the found user
res.send(group);
console.log("Sent Group")
} catch (error) {
console.error("Error fetching group:", error); // Log the error for debugging
res.status(500).send("Internal Server Error");
}
});

router.post("/", async (req: Request, res: Response) => {
connectDB();
try {
Expand Down

0 comments on commit a51ebdd

Please sign in to comment.