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

@@ -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);