This commit is contained in:
seb
2026-09-25 11:34:00 +02:00
parent 387147ccf3
commit b5255bdd17

View File

@@ -6,6 +6,7 @@ import { CREATE as MSSQL_CREATE_ARTICLETEXT } from '../../providers/mssql/querie
import { CREATE as SQLITE_CREATE_ARTICLETEXT } from '../../providers/sqlite3/queries/articletext.js'; import { CREATE as SQLITE_CREATE_ARTICLETEXT } from '../../providers/sqlite3/queries/articletext.js';
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js'; import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js'; import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
import { isUniqueConstraintError } from '../../providers/provider.js';
import resolveCategoryAccess from '../category/resolveCategoryAccess.js'; import resolveCategoryAccess from '../category/resolveCategoryAccess.js';
import ensureDefaultUnit from '../unit/ensureDefault.js'; import ensureDefaultUnit from '../unit/ensureDefault.js';
import nextSku from '../numbers/nextSku.js'; import nextSku from '../numbers/nextSku.js';
@@ -50,12 +51,20 @@ export default function createUnderParent(provider) {
const sku = await allocateSku(companyId, runner); const sku = await allocateSku(companyId, runner);
const slug = slugify(name); const slug = slugify(name);
const article = await runner.query(createArticleSql, { let article;
sku, try {
unitId, article = await runner.query(createArticleSql, {
unitamount: 1, sku,
weight: 0, unitId,
}); unitamount: 1,
weight: 0,
});
} catch (err) {
if (isUniqueConstraintError(err)) {
throw new Error(`SKU "${sku}" already exists`);
}
throw err;
}
const id = article.rows[0]?.id ?? article.insertId; const id = article.rows[0]?.id ?? article.insertId;