Versie 1.0
This commit is contained in:
@@ -1,4 +1,21 @@
|
||||
const router = require("express").Router();
|
||||
const multer = require("multer");
|
||||
|
||||
const upload = multer({
|
||||
storage: multer.memoryStorage(),
|
||||
limits: { fileSize: 2 * 1024 * 1024 }
|
||||
});
|
||||
|
||||
function uploadCsv(req, res, next) {
|
||||
upload.single("file")(req, res, (error) => {
|
||||
if (error) {
|
||||
req.flash("error", "Het CSV-bestand is te groot of ongeldig.");
|
||||
return res.redirect("/products");
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
const auth = require("../middleware/auth");
|
||||
|
||||
@@ -11,6 +28,9 @@ require("../controllers/HouseholdController");
|
||||
const ProductController =
|
||||
require("../controllers/ProductController");
|
||||
|
||||
const CategoryController =
|
||||
require("../controllers/CategoryController");
|
||||
|
||||
const ShoppingListController =
|
||||
require("../controllers/ShoppingListController");
|
||||
|
||||
@@ -35,12 +55,67 @@ router.get(
|
||||
|
||||
);
|
||||
|
||||
router.get(
|
||||
"/categories",
|
||||
auth,
|
||||
CategoryController.index.bind(CategoryController)
|
||||
);
|
||||
|
||||
router.post(
|
||||
"/categories",
|
||||
auth,
|
||||
CategoryController.create.bind(CategoryController)
|
||||
);
|
||||
|
||||
router.get(
|
||||
"/categories/:id/edit",
|
||||
auth,
|
||||
CategoryController.editForm.bind(CategoryController)
|
||||
);
|
||||
|
||||
router.post(
|
||||
"/categories/:id",
|
||||
auth,
|
||||
CategoryController.update.bind(CategoryController)
|
||||
);
|
||||
|
||||
router.post(
|
||||
"/categories/:id/delete",
|
||||
auth,
|
||||
CategoryController.remove.bind(CategoryController)
|
||||
);
|
||||
|
||||
router.post(
|
||||
"/products",
|
||||
auth,
|
||||
ProductController.create.bind(ProductController)
|
||||
);
|
||||
|
||||
router.post(
|
||||
"/products/import",
|
||||
auth,
|
||||
uploadCsv,
|
||||
ProductController.import.bind(ProductController)
|
||||
);
|
||||
|
||||
router.get(
|
||||
"/products/:id/edit",
|
||||
auth,
|
||||
ProductController.editForm.bind(ProductController)
|
||||
);
|
||||
|
||||
router.post(
|
||||
"/products/:id",
|
||||
auth,
|
||||
ProductController.update.bind(ProductController)
|
||||
);
|
||||
|
||||
router.post(
|
||||
"/products/:id/delete",
|
||||
auth,
|
||||
ProductController.remove.bind(ProductController)
|
||||
);
|
||||
|
||||
router.get(
|
||||
"/lists",
|
||||
auth,
|
||||
|
||||
Reference in New Issue
Block a user