This commit is contained in:
seb
2026-10-09 16:44:18 +02:00
parent 56274ecb1d
commit 5e62be468f
9 changed files with 175 additions and 71 deletions

View File

@@ -5,7 +5,7 @@
*
* Everything is created through the existing dashback API:
* - categories: POST /api/category ({ parentId, name })
* - brands: PUT /api/brand ({ name }) → { brand: { id } }
* - brands: POST /api/brand ({ name }) → { brand: { id } }
* - articles: POST /api/article ({ categoryId, name }) → { article: { sku } }
* - price: PUT /api/article/:sku/prices ({ prices: [{ price, tax }] })
* - brand: PUT /api/article/:sku/brand ({ brandId })
@@ -111,8 +111,8 @@ function createEnsureCategory(cache) {
}
/**
* Upsert a brand by name → brandId.
* PUT /api/brand upserts by name (same name ⇒ update, otherwise create).
* Ensure a brand by name → brandId.
* POST /api/brand inserts (409 Brand already exists on duplicate).
*/
function createEnsureBrand(cache) {
return async function ensureBrand(name) {
@@ -121,8 +121,8 @@ function createEnsureBrand(cache) {
const key = clean.toLowerCase();
if (cache.brandByKey.has(key)) return cache.brandByKey.get(key);
const res = await brand.upsert({ name: clean });
requireObject(res, 'PUT /api/brand');
const res = await brand.create({ name: clean });
requireObject(res, 'POST /api/brand');
requireObject(res.brand, 'brand');
requireDefined(res.brand.id, 'brand.id');
cache.brandByKey.set(key, res.brand.id);