u
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user