import { RESOLVE_ARTICLE_ACCESS_BY_SKU } from '../../sql/article.js'; export default function resolveArticleBySku(pool) { return async (googleAuthId, sku) => { const result = await pool .request() .input('sku', sku) .input('googleAuthId', googleAuthId) .query(RESOLVE_ARTICLE_ACCESS_BY_SKU); const row = result.recordset[0]; if (!row?.articleId || !row?.categoryId) { throw new Error('Article not found'); } 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: row.languageId, companyId: row.companyId, rootCategoryId: row.rootCategoryId, posCustomerGroupId: row.posCustomerGroupId ?? null, }; }; }