Add categoryIds to article.listSearchIndex response

This commit is contained in:
seb
2026-08-03 22:33:46 +02:00
parent 84bb561031
commit c8b1a73b62
3 changed files with 12 additions and 2 deletions

View File

@@ -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`.

View File

@@ -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

View File

@@ -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)
: [],
}));
};
}