Legt de bestaande wijzigingen in de hoofdworktree vast voordat de laatste worktree wordt gemerged.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
44 lines
996 B
JavaScript
44 lines
996 B
JavaScript
const router = require("express").Router();
|
|
|
|
const auth = require("../middleware/auth");
|
|
|
|
const ProductRepository = require("../repositories/ProductRepository");
|
|
const ShoppingListRepository = require("../repositories/ShoppingListRepository");
|
|
|
|
// Get all products
|
|
router.get("/products", auth, (req, res) => {
|
|
|
|
const products = ProductRepository.getAll();
|
|
|
|
res.json(products);
|
|
|
|
});
|
|
|
|
// Get shopping lists for household
|
|
router.get("/lists", auth, (req, res) => {
|
|
|
|
const lists = ShoppingListRepository.getByHousehold(
|
|
req.user.household_id
|
|
);
|
|
|
|
res.json(lists);
|
|
|
|
});
|
|
|
|
// Get shopping list items
|
|
router.get("/lists/:id/items", auth, (req, res) => {
|
|
|
|
const list = ShoppingListRepository.getById(req.params.id);
|
|
|
|
if (!list || list.household_id !== req.user.household_id) {
|
|
return res.status(403).json({ error: "Not authorized" });
|
|
}
|
|
|
|
const items = ShoppingListRepository.getItems(req.params.id);
|
|
|
|
res.json(items);
|
|
|
|
});
|
|
|
|
module.exports = router;
|