feat(article): add article import with V/K compound linking

Add article.importRows to create articles by SKU from CSV-style rows,
running in two passes so fatherSku links to rows later in the file still
resolve. Existing SKUs are skipped, duplicate EANs are dropped, prices and
taxes are ensured, brands are upserted by name, and parent categories are
resolved/created via breadcrumb path.

Also add:
- article.setFatherBySku to link/unlink a child to its father article
- category.ensureByPath to resolve or create categories by path (tx-aware)
- supporting SQL constants (GET_ID_BY_SKU, EAN_EXISTS, father-link helpers,
  GET_BY_PARENT_AND_NAME)
- regenerated API docs
This commit is contained in:
seb
2026-08-11 05:36:07 +02:00
parent fb88cb92a5
commit af416246b4
8 changed files with 655 additions and 0 deletions

View File

@@ -59,6 +59,39 @@ INNER JOIN categoryarticle ca ON ca.article_id = a.id
WHERE a.sku = @sku
`;
/** Resolve an article id by sku (used to wire father/child compound links). */
export const GET_ID_BY_SKU = `
SELECT TOP 1 id AS articleId
FROM article
WHERE sku = @sku
`;
/** True if an EAN is already assigned to any article (duplicate guard). */
export const EAN_EXISTS = `
SELECT TOP 1 1 AS used
FROM articleean
WHERE ean = @ean
`;
/** Link an article to its father article and mark the father. */
export const UPDATE_FATHER_BY_SKU = `
UPDATE article
SET fatherarticle_id = @fatherArticleId
WHERE sku = @sku
`;
export const SET_IS_FATHER = `
UPDATE article
SET is_father = 1
WHERE id = @articleId
`;
export const SET_FATHER_SORT = `
UPDATE article
SET fathersort = @fathersort
WHERE id = @articleId AND fatherarticle_id = @fatherArticleId
`;
/** SKU → article/category + company auth in one round-trip. */
export const RESOLVE_ARTICLE_ACCESS_BY_SKU = `
WITH article_cat AS (

View File

@@ -92,6 +92,16 @@ FROM category
WHERE parent_id = @parentId
`;
/** Resolve a child category by its parent id and name (language-sensitive). */
export const GET_BY_PARENT_AND_NAME = `
SELECT c.id
FROM category c
INNER JOIN categorytext ct
ON ct.category_id = c.id AND ct.language_id = @languageId
WHERE c.parent_id = @parentId
AND ct.name = @name
`;
export const LIST_CHILD_IDS = `
SELECT id
FROM category