u
This commit is contained in:
37
src/store/article/getBySku.js
Normal file
37
src/store/article/getBySku.js
Normal 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;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user