Multi tenant DB, registratie per huishouden V1.2
This commit is contained in:
@@ -8,7 +8,7 @@ class CategoryController {
|
||||
|
||||
res.render("categories/index", {
|
||||
title: "Categorieën",
|
||||
categories: CategoryService.getCategories()
|
||||
categories: CategoryService.getCategories(req.user.household_id)
|
||||
});
|
||||
|
||||
}
|
||||
@@ -17,7 +17,7 @@ class CategoryController {
|
||||
editForm(req, res) {
|
||||
const categoryId = Number.parseInt(req.params.id, 10);
|
||||
const category = Number.isInteger(categoryId)
|
||||
? CategoryService.getCategory(categoryId)
|
||||
? CategoryService.getCategory(categoryId, req.user.household_id)
|
||||
: null;
|
||||
|
||||
if (!category) {
|
||||
@@ -41,7 +41,7 @@ class CategoryController {
|
||||
return res.redirect("/categories");
|
||||
}
|
||||
|
||||
CategoryService.createCategory({ name, icon });
|
||||
CategoryService.createCategory({ name, icon, household_id: req.user.household_id });
|
||||
req.flash("success", "Categorie toegevoegd.");
|
||||
res.redirect("/categories");
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class CategoryController {
|
||||
return res.redirect("/categories");
|
||||
}
|
||||
|
||||
const result = CategoryService.updateCategory(categoryId, { name, icon });
|
||||
const result = CategoryService.updateCategory(categoryId, req.user.household_id, { name, icon });
|
||||
|
||||
if (result.changes === 0) {
|
||||
req.flash("error", "Categorie niet gevonden.");
|
||||
@@ -77,7 +77,7 @@ class CategoryController {
|
||||
return res.redirect("/categories");
|
||||
}
|
||||
|
||||
if (CategoryService.categoryHasProducts(categoryId)) {
|
||||
if (CategoryService.categoryHasProducts(categoryId, req.user.household_id)) {
|
||||
req.flash(
|
||||
"error",
|
||||
"Deze categorie is nog aan producten gekoppeld en kan niet worden verwijderd."
|
||||
@@ -85,7 +85,7 @@ class CategoryController {
|
||||
return res.redirect("/categories");
|
||||
}
|
||||
|
||||
const result = CategoryService.deleteCategory(categoryId);
|
||||
const result = CategoryService.deleteCategory(categoryId, req.user.household_id);
|
||||
|
||||
if (result.changes === 0) {
|
||||
req.flash("error", "Categorie niet gevonden.");
|
||||
|
||||
Reference in New Issue
Block a user