Add category.move to reparent a category.

Validates both source and target via resolveCategoryAccess so the new
parent must be a category of the same authorized company, and guards
against moving into a descendant (cycle). Assigns next sibling sort.
This commit is contained in:
seb
2026-08-03 03:01:02 +02:00
parent b070607357
commit d8d66ce105
5 changed files with 114 additions and 0 deletions

View File

@@ -103,6 +103,30 @@ SET sort = @sort
WHERE id = @id AND parent_id = @parentId
`;
/** True if @id is an ancestor of @parentId (would create a cycle when moving). */
export const IS_ANCESTOR = `
WITH ancestors AS (
SELECT id, parent_id
FROM category
WHERE id = @parentId
UNION ALL
SELECT c.id, c.parent_id
FROM category c
INNER JOIN ancestors a ON c.id = a.parent_id
)
SELECT id
FROM ancestors
WHERE id = @id
`;
export const MOVE = `
UPDATE category
SET parent_id = @parentId, sort = @sort
WHERE id = @id
`;
export const DELETE = `
DELETE FROM category
WHERE id = @id