Applicatie afmaken en GUI-flow herstellen
Voegt boodschappenlijsten, productbeheer, realtime synchronisatie en browsercache-updates toe. Herstelt login- en sessiegedrag en maakt database-seeding herhaalbaar.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,29 +1,50 @@
|
||||
const ProductService =
|
||||
require("../services/ProductService");
|
||||
|
||||
const db = require("../config/database");
|
||||
|
||||
class ProductController {
|
||||
|
||||
|
||||
index(req,res) {
|
||||
|
||||
index(req, res) {
|
||||
|
||||
const products =
|
||||
ProductService.getProducts();
|
||||
|
||||
const categories = db.prepare(
|
||||
"SELECT * FROM categories ORDER BY name"
|
||||
).all();
|
||||
|
||||
res.render(
|
||||
"products/index",
|
||||
{
|
||||
|
||||
title:"Producten",
|
||||
|
||||
products
|
||||
|
||||
products,
|
||||
categories
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
create(req, res) {
|
||||
const name = (req.body.name || "").trim();
|
||||
const categoryId = req.body.category_id
|
||||
? Number.parseInt(req.body.category_id, 10)
|
||||
: null;
|
||||
|
||||
if (!name || (categoryId !== null && !Number.isInteger(categoryId))) {
|
||||
req.flash("error", "Geef een geldige productnaam en categorie op.");
|
||||
return res.redirect("/products");
|
||||
}
|
||||
|
||||
ProductService.createProduct({
|
||||
name,
|
||||
category_id: categoryId
|
||||
});
|
||||
|
||||
req.flash("success", "Product toegevoegd.");
|
||||
res.redirect("/products");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user