Werk hoofdapplicatie bij
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>
This commit is contained in:
@@ -1,35 +1,53 @@
|
||||
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.locals.title = "Producten";
|
||||
|
||||
res.render(
|
||||
"products/index",
|
||||
{
|
||||
|
||||
title:"Producten",
|
||||
|
||||
products
|
||||
|
||||
products,
|
||||
categories,
|
||||
user: req.user
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
create(req, res) {
|
||||
|
||||
const { name, category_id } = req.body;
|
||||
|
||||
if (!name || name.trim().length === 0) {
|
||||
req.flash("error", "Geef een productnaam op");
|
||||
return res.redirect("/products");
|
||||
}
|
||||
|
||||
ProductService.createProduct({
|
||||
name: name.trim(),
|
||||
category_id: category_id || null
|
||||
});
|
||||
|
||||
req.flash("success", "Product toegevoegd");
|
||||
res.redirect("/products");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
module.exports =
|
||||
new ProductController();
|
||||
Reference in New Issue
Block a user