# category This document is auto-generated from the JSDoc comments in `src/store` by running `npm run api-doc`. ## `category.addImage` *Source: `src/store/category/addImage.js`* Adds an image to a category, processing full, thumb, and 32px-edge small-thumb AVIF variants. **Parameters** | Name | Type | Description | | --- | --- | --- | | `googleAuthId` | `number` | The id of the Google auth user. | | `categoryId` | `number` | The id of the category. | | `image` | `Buffer` | The source image buffer. | | `[tx]` | `object` | Optional transaction to run within. | **Returns** `Promise<{id: number, fullHash: string, thumbW: number, thumbH: number, thumbHash: string, smallThumbW: number, smallThumbH: number}>` — The added image info. **Example** ```js const result = await store.category.addImage(42, 5, imageBuffer); // => { id, fullHash, thumbW, thumbH, thumbHash } ``` ## `category.createUnderParent` *Source: `src/store/category/createUnderParent.js`* Creates a new category under a given parent category. **Parameters** | Name | Type | Description | | --- | --- | --- | | `input` | `object` | The category creation input. | | `input.googleAuthId` | `number` | The id of the Google auth user. | | `input.parentId` | `number` | The id of the parent category. | | `input.name` | `string` | The category name. | | `[tx]` | `object` | Optional transaction to run within. | **Returns** `Promise<{id: number, parentId: number, sort: number, name: string, slug: string}>` — The created category. **Example** ```js const category = await store.category.createUnderParent({ googleAuthId: 42, parentId: 5, name: 'Drinks' }); // => { id, parentId, sort, name, slug } ``` ## `category.delete` *Source: `src/store/category/delete.js`* Deletes a category, refusing to delete the company's root category. If recursive is true, recursively deletes the subtree and articles that only belong to it. **Parameters** | Name | Type | Description | | --- | --- | --- | | `input` | `object` | The delete input. | | `input.googleAuthId` | `number` | The id of the Google auth user. | | `input.id` | `number` | The id of the category to delete. | | `[input.recursive=false]` | `boolean` | Whether to delete the category subtree recursively. | | `[tx]` | `object` | Optional transaction to run within. | **Returns** `Promise` **Throws** `Error` — If the category is the root category or contains articles/subcategories (when recursive is false). **Example** ```js await store.category.delete({ googleAuthId: 42, id: 5 }); await store.category.delete({ googleAuthId: 42, id: 5, recursive: true }); ``` ## `category.deleteImage` *Source: `src/store/category/deleteImage.js`* Deletes the image of a category. **Parameters** | Name | Type | Description | | --- | --- | --- | | `googleAuthId` | `number` | The id of the Google auth user. | | `categoryId` | `number` | The id of the category. | | `[tx]` | `object` | Optional transaction to run within. | **Returns** `Promise<{id: number, thumbW: null, thumbH: null, thumbHash: null}>` — The cleared image info. **Throws** `Error` — If the image is not found. **Example** ```js const result = await store.category.deleteImage(42, 5); // => { id: 5, thumbW: null, thumbH: null, thumbHash: null } ``` ## `category.ensureByPath` *Source: `src/store/category/ensureByPath.js`* Resolves a category by breadcrumb path under a given parent, creating any missing categories along the way. Returns the leaf category id. **Parameters** | Name | Type | Description | | --- | --- | --- | | `input` | `object` | The category resolution input. | | `input.googleAuthId` | `number` | The id of the Google auth user. | | `input.parentId` | `number` | The id of the parent category to start from. | | `input.path` | `string` | The breadcrumb path, e.g. `'Haupt | Flowers | CBN'`. | | `[tx]` | `object` | Optional transaction to run within. | **Returns** `Promise` — The id of the leaf category. **Example** ```js const id = await store.category.ensureByPath({ googleAuthId: 42, parentId: 5, path: 'Haupt | Flowers | CBN' }); // => 12 ``` ## `category.generateImage` *Source: `src/store/category/generateImage.js`* Generates a mosaic image directly from the category's and its subcategories' articles (grouped by subcategory) and sets it as the new main picture for the category. **Parameters** | Name | Type | Description | | --- | --- | --- | | `googleAuthId` | `number` | The id of the Google auth user. | | `inputOrCategoryId` | `number|object` | The id of the category or an options object. | | `[maybeOptsOrSize={}]` | `object|number` | Options object or numeric size. | | `[maybeOptsOrSize.size]` | `number` | Grid size (2 for 2x2, 3 for 3x3, 4 for 4x4). Defaults to 3 (falls back to 2 if < 7 images). | | `[maybeTx]` | `object` | Optional transaction to run within. | **Returns** `Promise<{id: number, fullHash: string, thumbW: number, thumbH: number, thumbHash: string, smallThumbW: number, smallThumbH: number, size: number, grid: string, articleCount: number}>` — The new main image info. **Throws** `Error` — If the category is not found, not authorized, size is invalid, or no images are found. **Example** ```js const result = await store.category.generateImage(42, 5, { size: 3 }); // => { id: 5, fullHash, thumbW, thumbH, thumbHash, smallThumbW, smallThumbH, size: 3, grid: '3x3', articleCount: 12 } ``` ## `category.getCategoryArticles` *Source: `src/store/category/getCategoryArticles.js`* Returns the articles belonging to a single category. **Parameters** | Name | Type | Description | | --- | --- | --- | | `googleAuthId` | `number` | The id of the Google auth user. | | `categoryId` | `number` | The id of the category. | | `[tx]` | `object` | Optional transaction to run within. | **Returns** `Promise, warehouses: Array<{id: number, name: string, stock: number}>}>>` — The articles in the category. **Example** ```js const articles = await store.category.getCategoryArticles(42, 5); // => [{ id, sku, name, brand, ... }] ``` ## `category.getTreeForCompany` *Source: `src/store/category/getTreeForCompany.js`* Returns the full category tree for the user's selected company together with the article count and the posterminal ids assigned to each category. **Parameters** | Name | Type | Description | | --- | --- | --- | | `googleAuthId` | `number` | The id of the Google auth user. | | `[tx]` | `object` | Optional transaction to run within. | **Returns** `Promise<{languageId: number, tree: Array<{id: number, parentId: number|null, sort: number, name: string|null, slug: string|null, fullHash: string|null, thumbW: number|null, thumbH: number|null, thumbHash: string|null, articleCount: number, posterminalIds: number[]}>, articleCount: number}>` — The category tree and article count. **Example** ```js const tree = await store.category.getTreeForCompany(42); // => { languageId, tree: [{ id, articleCount, posterminalIds, ... }], articleCount: 25 } ``` ## `category.move` *Source: `src/store/category/move.js`* Moves a category to a new parent, preventing cycles and cross-company moves. **Parameters** | Name | Type | Description | | --- | --- | --- | | `input` | `object` | The move input. | | `input.googleAuthId` | `number` | The id of the Google auth user. | | `input.id` | `number` | The id of the category to move. | | `input.parentId` | `number` | The id of the new parent category. | | `[tx]` | `object` | Optional transaction to run within. | **Returns** `Promise<{id: number, parentId: number, sort: number}>` — The moved category. **Throws** `Error` — If the move would create a cycle or cross companies. **Example** ```js const result = await store.category.move({ googleAuthId: 42, id: 5, parentId: 9 }); // => { id, parentId, sort } ``` ## `category.order` *Source: `src/store/category/order.js`* Reorders the child categories of a given parent. **Parameters** | Name | Type | Description | | --- | --- | --- | | `input` | `object` | The reorder input. | | `input.googleAuthId` | `number` | The id of the Google auth user. | | `input.parentId` | `number` | The id of the parent category. | | `input.categoryIds` | `Array` | The child category ids in their new order. | | `[tx]` | `object` | Optional transaction to run within. | **Returns** `Promise<{categoryIds: Array}>` — The applied order. **Throws** `Error` — If the order is invalid. **Example** ```js const result = await store.category.order({ googleAuthId: 42, parentId: 5, categoryIds: [3, 1, 2] }); // => { categoryIds: [3, 1, 2] } ``` ## `category.rename` *Source: `src/store/category/rename.js`* Renames a category and updates its slug. **Parameters** | Name | Type | Description | | --- | --- | --- | | `input` | `object` | The rename input. | | `input.googleAuthId` | `number` | The id of the Google auth user. | | `input.id` | `number` | The id of the category to rename. | | `input.name` | `string` | The new category name. | | `[tx]` | `object` | Optional transaction to run within. | **Returns** `Promise<{id: number, name: string, slug: string}>` — The renamed category. **Throws** `Error` — If the name is empty or the category is not found. **Example** ```js const result = await store.category.rename({ googleAuthId: 42, id: 5, name: 'Soft Drinks' }); // => { id, name, slug } ```