# article This document is auto-generated from the JSDoc comments in `src/store` by running `npm run api-doc`. ## `article.addImage` *Source: `src/store/article/addImage.js`* Adds an image to an article by its SKU, processing it into AVIF variants. ```js const fn = addImage(pool); const result = await fn(42, 'SKU-1', imageBuffer); // => { picId, sort, full: { w, h, size }, thumb: { w, h }, fullHash, thumbHash } ``` ## `article.createUnderParent` *Source: `src/store/article/createUnderParent.js`* Creates a new article under a given parent category, allocating a SKU and a default unit. ```js const fn = createUnderParent(pool); const article = await fn({ googleAuthId: 42, parentId: 5, name: 'Cola' }); // => { id, parentId, name, sku } ``` ## `article.delete` *Source: `src/store/article/delete.js`* Deletes an article by its SKU, refusing when it still has children. ```js const fn = del(pool); await fn(42, 'SKU-1'); ``` ## `article.deleteImage` *Source: `src/store/article/deleteImage.js`* Deletes an image from an article by its SKU and full image hash. ```js const fn = deleteImage(pool); await fn(42, 'SKU-1', 'abc123'); ``` ## `article.getBySku` *Source: `src/store/article/getBySku.js`* Returns the full detail of an article by its SKU, including unit, brand, categories, photos, EANs and prices. ```js const fn = getBySku(pool); const article = await fn(42, 'SKU-1'); // => { article: { id, sku, name, unit, brand, categoryIds, photos, eans, prices, ... } } ``` ## `article.getHistoryBySku` *Source: `src/store/article/getHistoryBySku.js`* Returns the change history of an article by its SKU. ```js const fn = getHistoryBySku(pool); const history = await fn(42, 'SKU-1'); // => [{ id, companyuserId, date, text }] ``` ## `article.listExport` *Source: `src/store/article/listExport.js`* Returns articles for export, optionally scoped to a category, including category breadcrumbs and image hashes. ```js const fn = listExport(pool); const articles = await fn(42, null); // => [{ id, sku, name, slug, unitSi, net, taxRate, eans, categoryBreadcrumbs, fullHashes, ... }] ``` ## `article.listSearchIndex` *Source: `src/store/article/listSearchIndex.js`* Returns a lightweight search index of all articles for a company. ```js const fn = listSearchIndex(pool); const articles = await fn(42); // => [{ id, sku, name, eans, categoryIds }] ``` ## `article.orderImages` *Source: `src/store/article/orderImages.js`* Reorders the images of an article by its SKU. ```js const fn = orderImages(pool); const result = await fn(42, 'SKU-1', { fullHashes: ['a', 'b'] }); // => { fullHashes: ['a', 'b'] } ``` ## `article.setBrandIdBySku` *Source: `src/store/article/setBrandIdBySku.js`* Sets (or clears) the brand of an article by its SKU. ```js const fn = setBrandIdBySku(pool); const article = await fn(42, 'SKU-1', 3); // => { id, sku, name, ... } ``` ## `article.setCategoryIdsBySku` *Source: `src/store/article/setCategoryIdsBySku.js`* Replaces the category membership of an article by its SKU. ```js const fn = setCategoryIdsBySku(pool); const article = await fn(42, 'SKU-1', [5, 9]); // => { id, sku, name, ... } ``` ## `article.setEansBySku` *Source: `src/store/article/setEansBySku.js`* Replaces the EAN list of an article by its SKU. ```js const fn = setEansBySku(pool); const article = await fn(42, 'SKU-1', ['4001234567890']); // => { id, sku, name, ... } ``` ## `article.setPricesBySku` *Source: `src/store/article/setPricesBySku.js`* Replaces the price list of an article by its SKU. ```js const fn = setPricesBySku(pool); const article = await fn(42, 'SKU-1', [{ price: 1.5, tax: 19, minmultiplier: 1 }]); // => { id, sku, name, ... } ``` ## `article.setWeightBySku` *Source: `src/store/article/setWeightBySku.js`* Sets the weight of an article by its SKU. ```js const fn = setWeightBySku(pool); const article = await fn(42, 'SKU-1', 1.5); // => { id, sku, name, ... } ``` ## `article.updateBySku` *Source: `src/store/article/updateBySku.js`* Updates an article's name and/or unit (SI and amount), recording history. ```js const fn = updateBySku(pool); const article = await fn(42, 'SKU-1', { name: 'Cola 1L', unitSi: 'l', unitamount: 1 }); // => { id, sku, name, ... } ```