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>
53 lines
1.0 KiB
JavaScript
53 lines
1.0 KiB
JavaScript
const ProductService =
|
|
require("../services/ProductService");
|
|
|
|
const db = require("../config/database");
|
|
|
|
|
|
class ProductController {
|
|
|
|
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",
|
|
{
|
|
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(); |