This commit is contained in:
seb
2026-10-08 18:48:28 +02:00
parent 30b573cc63
commit b165f86811
10 changed files with 139 additions and 30 deletions

View File

@@ -44,6 +44,8 @@ import {
parseCategoryTreeResponse,
normalizeCategoryNode,
cleanCategorySlugPath,
getCategoryChildren,
getCategoryDescendantIds,
} from '../utils/categoryUtils';
/**
@@ -307,6 +309,35 @@ const actions = {
return categoryId;
},
/**
* Delete a category and all its descendants recursively.
* Calls DELETE /api/category/:id?recursive=true.
*
* @param {number|string} categoryId
*/
async deleteCategoryRecursive(categoryId) {
const { categories, rootCategoryId } = categoryAutomat.state;
if (rootCategoryId != null && String(categoryId) === String(rootCategoryId)) {
throw new Error('Root-Kategorie kann nicht gelöscht werden');
}
const removedIds = getCategoryDescendantIds(categories, categoryId);
await categoryApi.delete(categoryId, { recursive: true });
if (categories) {
const next = { ...categories };
for (const id of removedIds) {
delete next[String(id)];
}
categoryAutomat.setState({ categories: next });
refreshCategoryViewChildren(next);
}
return categoryId;
},
/**
* Toggle the POS flag on a category.
* @param {{ categoryId: number|string, pos: boolean }} param0