u
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user