This commit is contained in:
seb
2026-07-31 16:17:33 +02:00
parent 14297a1568
commit 7e1e96d3cd
6 changed files with 132 additions and 46 deletions

View File

@@ -0,0 +1,37 @@
import { GET_BY_SKU, GET_CATEGORY_ID_BY_SKU } from '../../sql/article.js';
import resolveCategoryAccess from '../category/resolveCategoryAccess.js';
export default function getBySku(pool) {
const access = resolveCategoryAccess(pool);
return async (googleAuthId, sku) => {
const categoryLookup = await pool
.request()
.input('sku', sku)
.query(GET_CATEGORY_ID_BY_SKU);
const categoryId = categoryLookup.recordset[0]?.categoryId;
if (!categoryId) {
throw new Error('Article not found');
}
const { languageId, posCustomerGroupId } = 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) {
throw new Error('Article not found');
}
return row;
};
}