u
This commit is contained in:
@@ -1,26 +1,31 @@
|
||||
import { GET_CATEGORY_ID_BY_SKU } from '../../sql/article.js';
|
||||
import resolveCategoryAccess from '../category/resolveCategoryAccess.js';
|
||||
import { RESOLVE_ARTICLE_ACCESS_BY_SKU } from '../../sql/article.js';
|
||||
|
||||
export default function resolveArticleBySku(pool) {
|
||||
const access = resolveCategoryAccess(pool);
|
||||
|
||||
return async (googleAuthId, sku) => {
|
||||
const lookup = await pool
|
||||
const result = await pool
|
||||
.request()
|
||||
.input('sku', sku)
|
||||
.query(GET_CATEGORY_ID_BY_SKU);
|
||||
.input('googleAuthId', googleAuthId)
|
||||
.query(RESOLVE_ARTICLE_ACCESS_BY_SKU);
|
||||
|
||||
const row = lookup.recordset[0];
|
||||
if (!row?.categoryId || !row?.articleId) {
|
||||
const row = result.recordset[0];
|
||||
if (!row?.articleId || !row?.categoryId) {
|
||||
throw new Error('Article not found');
|
||||
}
|
||||
|
||||
const { languageId } = await access(googleAuthId, row.categoryId);
|
||||
if (!row.companyId || !row.rootCategoryId || !row.languageId) {
|
||||
throw new Error('Parent not found');
|
||||
}
|
||||
if (!row.companyuserId) {
|
||||
throw new Error('Not authorized');
|
||||
}
|
||||
|
||||
return {
|
||||
articleId: row.articleId,
|
||||
categoryId: row.categoryId,
|
||||
languageId,
|
||||
languageId: row.languageId,
|
||||
companyId: row.companyId,
|
||||
rootCategoryId: row.rootCategoryId,
|
||||
posCustomerGroupId: row.posCustomerGroupId ?? null,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user