This commit is contained in:
seb
2026-07-31 18:15:15 +02:00
parent c2e128cb55
commit 6b1701d4dc
6 changed files with 194 additions and 38 deletions

View File

@@ -1,8 +1,10 @@
import { GET_BY_SKU, GET_CATEGORY_ID_BY_SKU } from '../../sql/article.js';
import { GET_CATEGORY_ID_BY_SKU } from '../../sql/article.js';
import resolveCategoryAccess from '../category/resolveCategoryAccess.js';
import queryBySku from './queryBySku.js';
export default function getBySku(pool) {
const access = resolveCategoryAccess(pool);
const load = queryBySku(pool);
return async (googleAuthId, sku) => {
const categoryLookup = await pool
@@ -15,23 +17,13 @@ export default function getBySku(pool) {
throw new Error('Article not found');
}
const { languageId, posCustomerGroupId } = await access(
googleAuthId,
categoryId,
);
const { languageId } = await access(googleAuthId, categoryId);
const result = await pool
.request()
.input('sku', sku)
.input('languageId', languageId)
.input('posCustomerGroupId', posCustomerGroupId)
.query(GET_BY_SKU);
const row = result.recordset[0];
if (!row) {
const article = await load(sku, languageId);
if (!article) {
throw new Error('Article not found');
}
return row;
return article;
};
}