Add category image add/delete with categorypic SQL layer
This commit is contained in:
19
README.md
19
README.md
@@ -224,6 +224,8 @@ Company-scoped POS terminals. Auth via `resolveCompanyAccess`.
|
||||
| `delete` | `({ googleAuthId, id })` | `void` — `Category has children` if child categories remain; FK `categoryarticle` also blocks deletion |
|
||||
| `getTreeForCompany` | `(googleAuthId, companyId)` | `{ languageId, tree, articles }` — tree rows carry `name` + `slug` |
|
||||
| `getCategoryArticles` | `(googleAuthId, categoryId)` | `{ id, sku, name, slug, net, taxRate, optionsCount, articleListCount, childCount, fatherArticleId, fatherSku, fullHash, thumbW, thumbH, thumbHash }[]` |
|
||||
| `addImage` | `(googleAuthId, categoryId, imageBuffer)` | `{ id, thumbW, thumbH, thumbHash }` |
|
||||
| `deleteImage` | `(googleAuthId, categoryId)` | `{ id, thumbW: null, thumbH: null, thumbHash: null }` |
|
||||
|
||||
### `createUnderParent` (transaction)
|
||||
|
||||
@@ -240,6 +242,21 @@ Company-scoped POS terminals. Auth via `resolveCompanyAccess`.
|
||||
|
||||
`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`.
|
||||
|
||||
`addImage` accepts a full-size AVIF `Buffer`. Full image: if already AVIF and ≤1000×1000, stored as-is; otherwise scaled to max 1000×1000 (`pic.fullbinary`). Thumb always scaled to max 200×200 (`pic.thumbbinary`) via `sharp`. Assigns random `fullHash` (`pic.hash`, unique), computes `thumbhash`, links `categorypic`. Auth via `resolveCategoryAccess`. Errors: `Category not found`, `Not authorized`.
|
||||
|
||||
`addImage` returns:
|
||||
|
||||
```js
|
||||
{
|
||||
id, // category id
|
||||
thumbW, // thumb width
|
||||
thumbH, // thumb height
|
||||
thumbHash, // base64 thumbhash of thumb preview
|
||||
}
|
||||
```
|
||||
|
||||
`deleteImage` removes all `categorypic` rows for the category. Returns `{ id, thumbW: null, thumbH: null, thumbHash: null }`. Errors: `Category not found`, `Image not found`, `Not authorized`.
|
||||
|
||||
---
|
||||
|
||||
## `article`
|
||||
@@ -357,6 +374,8 @@ res.set('Content-Type', thumb.contentType).send(thumb.buffer);
|
||||
| `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 })` |
|
||||
| `POST /api/category/:id/image` | `category.addImage(googleAuthId, categoryId, imageBuffer)` |
|
||||
| `DELETE /api/category/:id/image` | `category.deleteImage(googleAuthId, categoryId)` |
|
||||
| `GET /api/unit` | `unit.list(googleAuthId, companyId)` |
|
||||
| `PUT /api/unit` | `unit.upsert(googleAuthId, companyId, { si, basesi, basesifactor, symbol, name })` |
|
||||
| `DELETE /api/unit` | `unit.delete(googleAuthId, companyId, si)` |
|
||||
|
||||
Reference in New Issue
Block a user