This commit is contained in:
seb
2026-10-04 21:22:05 +02:00
parent 0268583ae3
commit 4718cb5726
48 changed files with 758 additions and 758 deletions

View File

@@ -21,7 +21,7 @@ OUTER APPLY (
ORDER BY bp.sort ASC, bp.id ASC
) first_brand_pic
LEFT JOIN pic brand_pic ON brand_pic.id = first_brand_pic.pic_id
LEFT JOIN article father ON father.id = a.fatherarticle_id
LEFT JOIN article parent ON parent.id = a.parentarticle_id
`;
export const ARTICLE_LIST_COLUMNS = `
@@ -32,7 +32,7 @@ export const ARTICLE_LIST_COLUMNS = `
pr.net,
t.rate AS taxRate,
a.track_stock,
a.is_father AS isFather,
a.is_parent AS isParent,
CASE
WHEN a.optionslist_id IS NOT NULL THEN (
SELECT COUNT(*)
@@ -52,10 +52,10 @@ export const ARTICLE_LIST_COLUMNS = `
(
SELECT COUNT(*)
FROM article child
WHERE child.fatherarticle_id = a.id
WHERE child.parentarticle_id = a.id
) AS childCount,
a.fatherarticle_id AS fatherArticleId,
father.sku AS fatherSku,
a.parentarticle_id AS parentArticleId,
parent.sku AS parentSku,
pic.hash AS fullHash,
pic.thumbw AS thumbW,
pic.thumbh AS thumbH,
@@ -75,7 +75,7 @@ INNER JOIN categoryarticle ca ON ca.article_id = a.id
WHERE a.sku = @sku AND (@companyId IS NULL OR a.company_id = @companyId)
`;
/** Resolve an article id by sku (used to wire father/child compound links). */
/** Resolve an article id by sku (used to wire parent/child compound links). */
export const GET_ID_BY_SKU = `
SELECT TOP 1 id AS articleId
FROM article
@@ -89,49 +89,49 @@ FROM articleean
WHERE ean = @ean
`;
/** Link an article to its father article and mark the father. */
export const UPDATE_FATHER_BY_SKU = `
/** Link an article to its parent article and mark the parent. */
export const UPDATE_PARENT_BY_SKU = `
UPDATE article
SET fatherarticle_id = @fatherArticleId,
fathersort = COALESCE(@fathersort, 0)
SET parentarticle_id = @parentArticleId,
parentsort = COALESCE(@parentsort, 0)
WHERE sku = @sku AND (@companyId IS NULL OR company_id = @companyId)
`;
export const SET_IS_FATHER = `
export const SET_IS_PARENT = `
UPDATE article
SET is_father = 1
SET is_parent = 1
WHERE id = @articleId
`;
export const TOGGLE_FATHER = `
export const TOGGLE_PARENT = `
UPDATE article
SET is_father = @isFather,
fatherattributename_id = @fatherAttributeNameId
SET is_parent = @isParent,
parentattributename_id = @parentAttributeNameId
WHERE id = @articleId
`;
export const CREATE_CHILD = `
INSERT INTO article (
company_id, sku, unit_id, unitamount, weight, track_stock, brand_id, is_father, fatherarticle_id, fathersort
company_id, sku, unit_id, unitamount, weight, track_stock, brand_id, is_parent, parentarticle_id, parentsort
)
OUTPUT INSERTED.id
VALUES (
@companyId, @sku, @unitId, @unitamount, @weight, @trackStock, @brandId, 0, @fatherArticleId, @fathersort
@companyId, @sku, @unitId, @unitamount, @weight, @trackStock, @brandId, 0, @parentArticleId, @parentsort
)
`;
export const UNLINK_CHILD = `
UPDATE article
SET fatherarticle_id = NULL,
fathersort = 0
WHERE id = @articleId AND fatherarticle_id = @fatherArticleId
SET parentarticle_id = NULL,
parentsort = 0
WHERE id = @articleId AND parentarticle_id = @parentArticleId
`;
export const LIST_CHILDREN_BY_FATHER_ID = `
export const LIST_CHILDREN_BY_PARENT_ID = `
SELECT
child.id,
child.sku,
child.fathersort,
child.parentsort,
child.track_stock AS trackStock,
child.unitamount,
child.weight,
@@ -145,14 +145,14 @@ LEFT JOIN (
articleattributevalue aav
INNER JOIN attributevalue av ON av.id = aav.attributevalue_id AND av.attribute_id = @attributeId
) ON aav.article_id = child.id
WHERE child.fatherarticle_id = @fatherArticleId
ORDER BY child.fathersort ASC, child.id ASC
WHERE child.parentarticle_id = @parentArticleId
ORDER BY child.parentsort ASC, child.id ASC
`;
export const SET_FATHER_SORT = `
export const SET_PARENT_SORT = `
UPDATE article
SET fathersort = @fathersort
WHERE id = @articleId AND fatherarticle_id = @fatherArticleId
SET parentsort = @parentsort
WHERE id = @articleId AND parentarticle_id = @parentArticleId
`;
/** SKU → article/category + company auth in one round-trip. */
@@ -484,19 +484,19 @@ SELECT
(
SELECT COUNT(*)
FROM article child
WHERE child.fatherarticle_id = a.id
WHERE child.parentarticle_id = a.id
) AS childCount,
a.is_father AS isFather,
a.fatherattributename_id AS fatherAttributeNameId,
fan.name AS fatherAttributeName,
fan.exclusive AS fatherAttributeExclusive,
a.fatherarticle_id AS fatherArticleId,
fa.sku AS fatherSku,
a.is_parent AS isParent,
a.parentattributename_id AS parentAttributeNameId,
fan.name AS parentAttributeName,
fan.exclusive AS parentAttributeExclusive,
a.parentarticle_id AS parentArticleId,
fa.sku AS parentSku,
(
SELECT
child.id,
child.sku,
child.fathersort,
child.parentsort,
at_child.name,
av.id AS attributeValueId,
av.value AS attributeValue
@@ -504,10 +504,10 @@ SELECT
LEFT JOIN articletext at_child ON at_child.article_id = child.id AND at_child.language_id = auth.languageId
LEFT JOIN (
articleattributevalue aav
INNER JOIN attributevalue av ON av.id = aav.attributevalue_id AND av.attribute_id = a.fatherattributename_id
INNER JOIN attributevalue av ON av.id = aav.attributevalue_id AND av.attribute_id = a.parentattributename_id
) ON aav.article_id = child.id
WHERE child.fatherarticle_id = a.id
ORDER BY child.fathersort ASC, child.id ASC
WHERE child.parentarticle_id = a.id
ORDER BY child.parentsort ASC, child.id ASC
FOR JSON PATH
) AS childrenJson,
(
@@ -637,8 +637,8 @@ SELECT
ORDER BY bp2.sort ASC, bp2.id ASC
) first_brand_pic
LEFT JOIN pic bp ON bp.id = first_brand_pic.pic_id
LEFT JOIN article fa ON fa.id = a.fatherarticle_id
LEFT JOIN attributename fan ON fan.id = a.fatherattributename_id
LEFT JOIN article fa ON fa.id = a.parentarticle_id
LEFT JOIN attributename fan ON fan.id = a.parentattributename_id
WHERE a.id = auth.articleId
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
) AS articleJson