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:
@@ -188,6 +188,7 @@ Company-scoped brands. Auth via `resolveCompanyAccess`.
|
||||
| --- | --- | --- |
|
||||
| `createUnderParent` | `({ googleAuthId, parentId, name })` | `{ id, parentId, sort, name, slug }` |
|
||||
| `rename` | `({ googleAuthId, id, name })` | `{ id, name, slug }` |
|
||||
| `move` | `({ googleAuthId, id, parentId })` | `{ id, parentId, sort }` |
|
||||
| `order` | `({ googleAuthId, parentId, categoryIds })` | `{ categoryIds }` |
|
||||
| `delete` | `({ googleAuthId, id })` | `void` — blocked by FK if `categoryarticle` or child categories remain |
|
||||
| `getTreeForCompany` | `(googleAuthId, companyId)` | `{ languageId, tree, articles }` — tree rows carry `name` + `slug` |
|
||||
@@ -206,6 +207,8 @@ Company-scoped brands. Auth via `resolveCompanyAccess`.
|
||||
|
||||
`order` reorders the direct children of `parentId` to the given `categoryIds` order (each child's `sort` set to its index `0..n-1`). Since a category can have multiple parents, `parentId` scopes which sibling list is reordered. `categoryIds` must be exactly the current children of `parentId` (same set, no dups) else `Invalid category order`. Auth via `resolveCategoryAccess` on `parentId`. Returns `{ categoryIds }`. For `PUT /api/category/order`.
|
||||
|
||||
`move` moves a category to a new parent. Both `id` (source) and `parentId` (target) are validated via `resolveCategoryAccess` — the target must be a real category of the same authorized company, else `Parent not found`. Moving into itself or into a descendant (cycle) → `Invalid parent`. The moved category gets the next sibling `sort` under the new parent. Returns `{ id, parentId, sort }`. For `POST /api/category/:id/move`.
|
||||
|
||||
---
|
||||
|
||||
## `article`
|
||||
@@ -321,6 +324,7 @@ res.set('Content-Type', thumb.contentType).send(thumb.buffer);
|
||||
| `POST /api/category` | `category.createUnderParent({ googleAuthId, parentId, name })` |
|
||||
| `PATCH /api/category/:id` | `category.rename({ googleAuthId, id, name })` |
|
||||
| `PUT /api/category/order` | `category.order({ googleAuthId, parentId, categoryIds })` |
|
||||
| `POST /api/category/:id/move` | `category.move({ googleAuthId, id, parentId })` |
|
||||
| `DELETE /api/category/:id` | `category.delete({ googleAuthId, id })` |
|
||||
| `GET /api/unit?companyId=` | `unit.list(googleAuthId, companyId)` |
|
||||
| `PUT /api/unit` | `unit.upsert(googleAuthId, companyId, { si, basesi, basesifactor, symbol, name })` |
|
||||
|
||||
Reference in New Issue
Block a user