From 9a1c19cf60dd289081a9c0b463f68f93acf92590 Mon Sep 17 00:00:00 2001 From: seb Date: Sun, 4 Oct 2026 16:22:23 +0200 Subject: [PATCH] u --- src/store/articleproperty/setByArticleSku.js | 9 ++++++++- src/store/propertyname/update.js | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/store/articleproperty/setByArticleSku.js b/src/store/articleproperty/setByArticleSku.js index 373953e..3868216 100644 --- a/src/store/articleproperty/setByArticleSku.js +++ b/src/store/articleproperty/setByArticleSku.js @@ -27,7 +27,8 @@ export default function setByArticleSku(provider) { /** * Replaces all properties for an article by its SKU. - * Enforces exclusive flag on property names. + * Enforces exclusive flag on property names. An exclusive property that already has a value + * is never overwritten: a different value throws `Exclusive property cannot be overwritten: `. * * @param {number} googleAuthId - The id of the Google auth user. * @param {string} sku - The article SKU. @@ -79,6 +80,12 @@ export default function setByArticleSku(provider) { } const value = item.value != null ? String(item.value).trim() : ''; + if (isExclusive) { + const existing = oldProps.find((p) => p.propertyId === propertyId); + if (existing && existing.value !== '' && existing.value !== value) { + throw new Error(`Exclusive property cannot be overwritten: ${prop.name}`); + } + } const sort = item.sort != null && Number.isInteger(item.sort) ? item.sort : i; validated.push({ propertyId, diff --git a/src/store/propertyname/update.js b/src/store/propertyname/update.js index 76082ae..83659ca 100644 --- a/src/store/propertyname/update.js +++ b/src/store/propertyname/update.js @@ -47,6 +47,16 @@ export default function update(provider) { const sort = input.sort !== undefined && Number.isInteger(input.sort) ? input.sort : existing.rows[0].sort; const exclusive = input.exclusive !== undefined ? (Boolean(input.exclusive) ? 1 : 0) : existing.rows[0].exclusive; + if (exclusive && !existing.rows[0].exclusive) { + const multi = await runner.query( + `SELECT article_id FROM articleproperty WHERE property_id = @id GROUP BY article_id HAVING COUNT(*) > 1`, + { id }, + ); + if (multi.rows.length > 0) { + throw new Error(`Cannot set property exclusive: ${multi.rows.length} article(s) have multiple values`); + } + } + await runner.query(updateSql, { id, companyId,