This commit is contained in:
seb
2026-07-31 15:36:48 +02:00
parent 818d799f63
commit 6cc6dbb9e8
13 changed files with 1096 additions and 998 deletions

View File

@@ -0,0 +1,16 @@
import resolveCategoryAccess from './resolveCategoryAccess.js';
import queryCategoryArticles from './queryCategoryArticles.js';
export default function getCategoryArticles(pool) {
const access = resolveCategoryAccess(pool);
const articles = queryCategoryArticles(pool);
return async (googleAuthId, categoryId) => {
const { languageId, posCustomerGroupId } = await access(
googleAuthId,
categoryId,
);
return articles({ categoryId, languageId, posCustomerGroupId });
};
}

View File

@@ -1,11 +1,10 @@
import {
GET_ROOT_CATEGORY_ARTICLES,
GET_TREE_FOR_COMPANY,
} from '../../sql/category.js';
import { GET_TREE_FOR_COMPANY } from '../../sql/category.js';
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
import queryCategoryArticles from './queryCategoryArticles.js';
export default function getTreeForCompany(pool) {
const access = resolveCompanyAccess(pool);
const articles = queryCategoryArticles(pool);
return async (googleAuthId, companyId) => {
const { rootCategoryId, languageId, posCustomerGroupId } = await access(
@@ -13,24 +12,19 @@ export default function getTreeForCompany(pool) {
companyId,
);
const [treeResult, articlesResult] = await Promise.all([
const [treeResult, articleRows] = await Promise.all([
pool
.request()
.input('rootId', rootCategoryId)
.input('languageId', languageId)
.query(GET_TREE_FOR_COMPANY),
pool
.request()
.input('rootCategoryId', rootCategoryId)
.input('languageId', languageId)
.input('posCustomerGroupId', posCustomerGroupId)
.query(GET_ROOT_CATEGORY_ARTICLES),
articles({ categoryId: rootCategoryId, languageId, posCustomerGroupId }),
]);
return {
languageId,
tree: treeResult.recordset,
articles: articlesResult.recordset,
articles: articleRows,
};
};
}

View File

@@ -0,0 +1,14 @@
import { GET_CATEGORY_ARTICLES } from '../../sql/category.js';
export default function queryCategoryArticles(pool) {
return async ({ categoryId, languageId, posCustomerGroupId }) => {
const result = await pool
.request()
.input('categoryId', categoryId)
.input('languageId', languageId)
.input('posCustomerGroupId', posCustomerGroupId)
.query(GET_CATEGORY_ARTICLES);
return result.recordset;
};
}

View File

@@ -23,6 +23,7 @@ export default function resolveCategoryAccess(pool) {
companyId: row.companyId,
rootCategoryId: row.rootCategoryId,
languageId: row.languageId,
posCustomerGroupId: row.posCustomerGroupId ?? null,
};
};
}