This commit is contained in:
seb
2026-08-01 05:10:03 +02:00
parent ee895fab5f
commit 9be9f7f74c
12 changed files with 164 additions and 79 deletions

View File

@@ -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,
};
};
}