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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user