u
This commit is contained in:
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user