This commit is contained in:
seb
2026-10-08 03:02:56 +02:00
parent 69eb2c9a0d
commit 4e308cc177
7 changed files with 65 additions and 13 deletions

View File

@@ -1,10 +1,12 @@
import {
ADD_EAN as MSSQL_ADD_EAN,
DELETE_EANS_BY_ARTICLE as MSSQL_DELETE_EANS,
EAN_EXISTS_FOR_OTHER_ARTICLE as MSSQL_CHECK_CONFLICT,
} from '../../providers/mssql/queries/article.js';
import {
ADD_EAN as SQLITE_ADD_EAN,
DELETE_EANS_BY_ARTICLE as SQLITE_DELETE_EANS,
EAN_EXISTS_FOR_OTHER_ARTICLE as SQLITE_CHECK_CONFLICT,
} from '../../providers/sqlite3/queries/article.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';
@@ -21,6 +23,7 @@ export default function setEansBySku(provider) {
const addEanSql = isSqlite ? SQLITE_ADD_EAN : MSSQL_ADD_EAN;
const deleteEansSql = isSqlite ? SQLITE_DELETE_EANS : MSSQL_DELETE_EANS;
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
const checkConflictSql = isSqlite ? SQLITE_CHECK_CONFLICT : MSSQL_CHECK_CONFLICT;
/**
* Replaces the EAN list of an article by its SKU.
@@ -55,7 +58,19 @@ export default function setEansBySku(provider) {
}
const runSet = async (runner) => {
const { articleId, languageId, companyuserId } = await resolve(googleAuthId, sku, runner);
const { articleId, languageId, companyuserId, companyId } = await resolve(googleAuthId, sku, runner);
// Guard: EAN cannot be used by another article in the same company
for (const ean of normalized) {
const conflict = await runner.query(checkConflictSql, {
ean,
companyId,
articleId,
});
if (conflict.rows[0]) {
throw new Error('EAN already in use');
}
}
// Read old EANs for history
const oldEanRes = await runner.query(