u
This commit is contained in:
25
src/store/article/resolveArticleBySku.js
Normal file
25
src/store/article/resolveArticleBySku.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { GET_CATEGORY_ID_BY_SKU } from '../../sql/article.js';
|
||||
import resolveCategoryAccess from '../category/resolveCategoryAccess.js';
|
||||
|
||||
export default function resolveArticleBySku(pool) {
|
||||
const access = resolveCategoryAccess(pool);
|
||||
|
||||
return async (googleAuthId, sku) => {
|
||||
const lookup = await pool
|
||||
.request()
|
||||
.input('sku', sku)
|
||||
.query(GET_CATEGORY_ID_BY_SKU);
|
||||
|
||||
const row = lookup.recordset[0];
|
||||
if (!row?.categoryId || !row?.articleId) {
|
||||
throw new Error('Article not found');
|
||||
}
|
||||
|
||||
await access(googleAuthId, row.categoryId);
|
||||
|
||||
return {
|
||||
articleId: row.articleId,
|
||||
categoryId: row.categoryId,
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user