Add categoryIds to article.listSearchIndex response
This commit is contained in:
@@ -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`).
|
`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`.
|
`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`.
|
||||||
|
|
||||||
|
|||||||
@@ -187,7 +187,14 @@ SELECT
|
|||||||
WHERE ae.article_id = a.id
|
WHERE ae.article_id = a.id
|
||||||
ORDER BY ae.ean
|
ORDER BY ae.ean
|
||||||
FOR JSON PATH
|
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
|
FROM article a
|
||||||
LEFT JOIN articletext at
|
LEFT JOIN articletext at
|
||||||
ON at.article_id = a.id AND at.language_id = @languageId
|
ON at.article_id = a.id AND at.language_id = @languageId
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ export default function listSearchIndex(pool) {
|
|||||||
sku: row.sku,
|
sku: row.sku,
|
||||||
name: row.name,
|
name: row.name,
|
||||||
eans: row.eansJson ? JSON.parse(row.eansJson).map((r) => r.ean) : [],
|
eans: row.eansJson ? JSON.parse(row.eansJson).map((r) => r.ean) : [],
|
||||||
|
categoryIds: row.categoryIdsJson
|
||||||
|
? JSON.parse(row.categoryIdsJson).map((r) => r.category_id)
|
||||||
|
: [],
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user