Skip to content

Commit

Permalink
added tsconfig backend
Browse files Browse the repository at this point in the history
  • Loading branch information
palldas committed Jun 2, 2024
1 parent 154671a commit 6a8aeac
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 201 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main_gather-app-307.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
- name: npm install, build, and test
run: |
npm install --workspaces=false --legacy-peer-deps
npm run build -w . build --if-present
npm run test -w . test --if-present
npm run build -w backend build --if-present
npm run test -w backend test --if-present
working-directory: backend

- name: Zip artifact for deployment
Expand Down
72 changes: 0 additions & 72 deletions .github/workflows/main_gather-app-inv.yml

This file was deleted.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "",
"main": "index.ts",

"scripts": {
"test": "echo \"Error: no test specified\" && exit 0",
"dev": "nodemon index.ts",
Expand Down
58 changes: 31 additions & 27 deletions backend/routes/basketRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,41 @@ router.get("/", authenticateUser, async (req: Request, res: Response) => {
}
});

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

try {
// Use findById correctly with the id parameter from the request
const basketById = await Basket.findById(req.params.basketid);

// Check if basket is null or undefined
if (!basketById) {
// If not found by ObjectId, try to find by basketName
const basketsByName = await Basket.find({
basketName: req.params.basketid,
});

if (!basketsByName.length) {
return res.status(404).send("No baskets found"); // Use return to exit the function after sending the response
try {
// Use findById correctly with the id parameter from the request
const basketById = await Basket.findById(req.params.basketid);

// Check if basket is null or undefined
if (!basketById) {
// If not found by ObjectId, try to find by basketName
const basketsByName = await Basket.find({
basketName: req.params.basketid,
});

if (!basketsByName.length) {
return res.status(404).send("No baskets found"); // Use return to exit the function after sending the response
}

// Send the found baskets
return res.send(basketsByName);
}

// Send the found baskets
return res.send(basketsByName);
// Send the found basket by ObjectId
res.send(basketById);
console.log("Sent Basket:", basketById);
} catch (error) {
console.error("Error fetching basket:", error); // Log the error for debugging
res.status(500).send("Internal Server Error");
}

// Send the found basket by ObjectId
res.send(basketById);
console.log("Sent Basket:", basketById);
} catch (error) {
console.error("Error fetching basket:", error); // Log the error for debugging
res.status(500).send("Internal Server Error");
}
});
},
);

router.post("/", authenticateUser, async (req: Request, res: Response) => {
connectDB();
Expand Down
60 changes: 33 additions & 27 deletions backend/routes/groupRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,46 @@ router.get("/", authenticateUser, async (req: Request, res: Response) => {
}
});

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

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

// Check if group is null or undefined
if (!groupById) {
return res.status(404).send("No group found"); // Use return to exit the function after sending the response
}
router.get(
"/:groupid",
authenticateUser,
async (req: Request, res: Response) => {
// Ensure the database connection
connectDB();

// Send the found user
res.send(groupById);
console.log("Sent Group:", groupById);
} catch (error) {
console.log("Now trying to find by GroupName");
try {
const groupsByName = await Group.find({ groupName: req.params.groupid });
console.log(groupsByName);
if (!groupsByName) {
return res.status(404).send("No groups found"); // Use return to exit the function after sending the response
// Use findById correctly with the id parameter from the request
const groupById = await Group.findById(req.params.groupid);

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

// Send the found user
res.send(groupsByName);
console.log("Sent Groups", groupsByName);
res.send(groupById);
console.log("Sent Group:", groupById);
} catch (error) {
console.error("Error fetching group:", error); // Log the error for debugging
res.status(500).send("Internal Server Error");
console.log("Now trying to find by GroupName");
try {
const groupsByName = await Group.find({
groupName: req.params.groupid,
});
console.log(groupsByName);
if (!groupsByName) {
return res.status(404).send("No groups found"); // Use return to exit the function after sending the response
}

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

router.post("/", authenticateUser, async (req: Request, res: Response) => {
connectDB();
Expand Down
60 changes: 32 additions & 28 deletions backend/routes/itemRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,45 @@ router.get("/", authenticateUser, async (req: Request, res: Response) => {
}
});

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

try {
console.log("Here");
try {
console.log("Here");

// Use findById correctly with the id parameter from the request
const itemById = await Item.findById(req.params.itemid);
// Use findById correctly with the id parameter from the request
const itemById = await Item.findById(req.params.itemid);

// Check if group is null or undefined
if (!itemById) {
return res.status(404).send("No item found"); // Use return to exit the function after sending the response
}
// Send the found user
res.send(itemById);
console.log("Sent item");
} catch (error) {
console.log("Now trying to find by Name");
try {
const itemsByName = await Item.find({ name: req.params.itemid });
console.log(itemsByName);
if (!itemsByName) {
return res.status(404).send("No items found"); // Use return to exit the function after sending the response
// Check if group is null or undefined
if (!itemById) {
return res.status(404).send("No item found"); // Use return to exit the function after sending the response
}

// Send the found user
res.send(itemsByName);
console.log("Sent items");
res.send(itemById);
console.log("Sent item");
} catch (error) {
console.error("Error fetching group:", error); // Log the error for debugging
res.status(500).send("Internal Server Error");
console.log("Now trying to find by Name");
try {
const itemsByName = await Item.find({ name: req.params.itemid });
console.log(itemsByName);
if (!itemsByName) {
return res.status(404).send("No items found"); // Use return to exit the function after sending the response
}

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

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

0 comments on commit 6a8aeac

Please sign in to comment.