u
This commit is contained in:
16
src/store/category/getCategoryArticles.js
Normal file
16
src/store/category/getCategoryArticles.js
Normal 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 });
|
||||
};
|
||||
}
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
14
src/store/category/queryCategoryArticles.js
Normal file
14
src/store/category/queryCategoryArticles.js
Normal 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;
|
||||
};
|
||||
}
|
||||
@@ -23,6 +23,7 @@ export default function resolveCategoryAccess(pool) {
|
||||
companyId: row.companyId,
|
||||
rootCategoryId: row.rootCategoryId,
|
||||
languageId: row.languageId,
|
||||
posCustomerGroupId: row.posCustomerGroupId ?? null,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user