This commit is contained in:
seb
2026-09-29 20:10:49 +02:00
parent 23d6742a9f
commit 9885c489f0
17 changed files with 715 additions and 3 deletions

View File

@@ -97,7 +97,26 @@ export default function getBySku(provider) {
stock: Number(w.stock ?? 0),
})),
optionsCount: a.optionsCount,
optionslistId: a.optionslistId ?? null,
options: parseJsonArray(a.optionslistItemsJson).map((o) => ({
id: o.id,
articleId: o.articleId,
sku: o.sku,
name: o.name ?? null,
count: Number(o.count ?? 1),
sort: Number(o.sort ?? 0),
mandated: Boolean(o.mandated),
})),
articleListCount: a.articleListCount,
articlelistId: a.articlelistId ?? null,
articlelist: parseJsonArray(a.articlelistItemsJson).map((item) => ({
id: item.id,
articleId: item.articleId,
sku: item.sku,
name: item.name ?? null,
count: Number(item.count ?? 1),
sort: Number(item.sort ?? 0),
})),
childCount: a.childCount,
isFather: Boolean(a.isFather),
fatherAttributeNameId: a.fatherAttributeNameId ?? null,

View File

@@ -42,12 +42,19 @@ export default function toggleFather(provider) {
}
const currentRes = await runner.query(
'SELECT fatherarticle_id FROM article WHERE id = @articleId',
'SELECT fatherarticle_id, articlelist_id, optionslist_id FROM article WHERE id = @articleId',
{ articleId },
);
const currentArt = currentRes.rows[0];
if (currentArt?.articlelist_id != null) {
throw new Error('A Stückliste article cannot become a father');
}
if (currentArt?.optionslist_id != null) {
throw new Error('An article with options cannot become a father');
}
// If article is a child, verify attribute is not used by father or any father up the chain
let currentFatherId = currentRes.rows[0]?.fatherarticle_id;
let currentFatherId = currentArt?.fatherarticle_id;
const visited = new Set();
while (currentFatherId != null && !visited.has(currentFatherId)) {
visited.add(currentFatherId);