# 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 it into AVIF full and thumb 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}>` — 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. **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. | | `[tx]` | `object` | Optional transaction to run within. | **Returns** `Promise` **Throws** `Error` — If the category is the root category. **Example** ```js await store.category.delete({ googleAuthId: 42, id: 5 }); ``` ## `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.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>` — The articles in the category. **Example** ```js const articles = await store.category.getCategoryArticles(42, 5); // => [{ id, sku, name, ... }] ``` ## `category.getTreeForCompany` *Source: `src/store/category/getTreeForCompany.js`* Returns the full category tree for the user's selected company together with its articles 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, articles: Array}>` — The category tree, articles and language. **Example** ```js const tree = await store.category.getTreeForCompany(42); // => { languageId, tree: [{ id, posterminalIds, ... }], articles: [...] } ``` ## `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 } ```