This commit is contained in:
seb
2026-07-31 18:15:15 +02:00
parent c2e128cb55
commit 6b1701d4dc
6 changed files with 194 additions and 38 deletions

View File

@@ -1,7 +1,8 @@
import { GET_BY_SKU, GET_CATEGORY_ID_BY_SKU } from '../../sql/article.js';
import { GET_CATEGORY_ID_BY_SKU } from '../../sql/article.js';
import { UPDATE_BY_ARTICLE_AND_LANGUAGE } from '../../sql/articletext.js';
import resolveCategoryAccess from '../category/resolveCategoryAccess.js';
import request from '../request.js';
import queryBySku from './queryBySku.js';
function slugify(name) {
return name
@@ -15,6 +16,7 @@ function slugify(name) {
export default function updateBySku(pool) {
const access = resolveCategoryAccess(pool);
const load = queryBySku(pool);
return async (googleAuthId, sku, { name }) => {
if (!name?.trim()) {
@@ -31,10 +33,7 @@ export default function updateBySku(pool) {
throw new Error('Article not found');
}
const { languageId, posCustomerGroupId } = await access(
googleAuthId,
row.categoryId,
);
const { languageId } = await access(googleAuthId, row.categoryId);
const slug = slugify(name);
const tx = pool.transaction();
@@ -52,18 +51,13 @@ export default function updateBySku(pool) {
throw new Error('Article not found');
}
const result = await request(pool, tx)
.input('sku', sku)
.input('languageId', languageId)
.input('posCustomerGroupId', posCustomerGroupId)
.query(GET_BY_SKU);
await tx.commit();
const article = result.recordset[0];
const article = await load(sku, languageId);
if (!article) {
throw new Error('Article not found');
}
await tx.commit();
return article;
} catch (err) {
try {