Add article.listSearchIndex for client-side search preload
Returns all company articles with id, sku, name, and eans as a flat array. Walks the category tree to find reachable articles. Single query using recursive CTE + FOR JSON for eans.
This commit is contained in:
23
src/store/article/listSearchIndex.js
Normal file
23
src/store/article/listSearchIndex.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { SEARCH_ARTICLES } from '../../sql/article.js';
|
||||
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
|
||||
|
||||
export default function listSearchIndex(pool) {
|
||||
const access = resolveCompanyAccess(pool);
|
||||
|
||||
return async (googleAuthId, companyId) => {
|
||||
const { rootCategoryId, languageId } = await access(googleAuthId, companyId);
|
||||
|
||||
const result = await pool
|
||||
.request()
|
||||
.input('rootCategoryId', rootCategoryId)
|
||||
.input('languageId', languageId)
|
||||
.query(SEARCH_ARTICLES);
|
||||
|
||||
return result.recordset.map((row) => ({
|
||||
id: row.id,
|
||||
sku: row.sku,
|
||||
name: row.name,
|
||||
eans: row.eansJson ? JSON.parse(row.eansJson).map((r) => r.ean) : [],
|
||||
}));
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user