u
This commit is contained in:
@@ -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 { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/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 ensureDefaultUnit from '../unit/ensureDefault.js';
|
||||
import nextSku from '../numbers/nextSku.js';
|
||||
@@ -50,12 +51,20 @@ export default function createUnderParent(provider) {
|
||||
const sku = await allocateSku(companyId, runner);
|
||||
const slug = slugify(name);
|
||||
|
||||
const article = await runner.query(createArticleSql, {
|
||||
let article;
|
||||
try {
|
||||
article = await runner.query(createArticleSql, {
|
||||
sku,
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user