diff --git a/README.md b/README.md index b7c6134..3a3a50c 100644 --- a/README.md +++ b/README.md @@ -311,7 +311,7 @@ Company-scoped POS terminals. Auth via `resolveCompanyAccess`. `getCategoryArticles` / `getTreeForCompany().articles[]` keep the flat list shape (`net`, `taxRate`, single `fullHash`/`thumbW`/`thumbH`/`thumbHash`). -`listSearchIndex` returns every article in the company (reachable via the category tree) with `id`, `sku`, `name`, and `eans` (all EANs as a flat string array). Designed for client-side search / autocomplete preload. Auth via `resolveCompanyAccess`. Errors: `Company not found`, `Not authorized`. +`listSearchIndex` returns every article in the company (reachable via the category tree) with `id`, `sku`, `name`, `eans`, and `categoryIds` (all EANs as a flat string array). Designed for client-side search / autocomplete preload. Auth via `resolveCompanyAccess`. Errors: `Company not found`, `Not authorized`. `parentId` is the category id. Creates `article` + `articletext` (company default language) + `categoryarticle` in one transaction. Allocates `sku` via `getnextnumberwithprefixandpadding` (`type` `sku`; creates `numbers` row with empty prefix if missing). Default unit `pc` is ensured if missing (`unitamount` 1, `weight` 0). Auth via `resolveCategoryAccess(googleAuthId, parentId)` — `Parent not found` / `Not authorized`. diff --git a/src/sql/article.js b/src/sql/article.js index c7d38f8..a1bd579 100644 --- a/src/sql/article.js +++ b/src/sql/article.js @@ -187,7 +187,14 @@ SELECT WHERE ae.article_id = a.id ORDER BY ae.ean FOR JSON PATH - ) AS eansJson + ) AS eansJson, + ( + SELECT ca2.category_id + FROM categoryarticle ca2 + WHERE ca2.article_id = a.id + ORDER BY ca2.category_id + FOR JSON PATH + ) AS categoryIdsJson FROM article a LEFT JOIN articletext at ON at.article_id = a.id AND at.language_id = @languageId diff --git a/src/store/article/listSearchIndex.js b/src/store/article/listSearchIndex.js index 7d37835..f2684e6 100644 --- a/src/store/article/listSearchIndex.js +++ b/src/store/article/listSearchIndex.js @@ -18,6 +18,9 @@ export default function listSearchIndex(pool) { sku: row.sku, name: row.name, eans: row.eansJson ? JSON.parse(row.eansJson).map((r) => r.ean) : [], + categoryIds: row.categoryIdsJson + ? JSON.parse(row.categoryIdsJson).map((r) => r.category_id) + : [], })); }; }