From 174cfe86650884f2678649da4f0314b2f86ef87a Mon Sep 17 00:00:00 2001 From: Ruslan Bakiev <572431+veikab@users.noreply.github.com> Date: Fri, 3 Apr 2026 14:52:30 +0700 Subject: [PATCH] feat(products): expose structured product specs --- scripts/seed.js | 25 +++++++++++++++++++++++++ src/schema.graphql | 6 ++++++ 2 files changed, 31 insertions(+) diff --git a/scripts/seed.js b/scripts/seed.js index 0ca56f6..480c773 100644 --- a/scripts/seed.js +++ b/scripts/seed.js @@ -37,6 +37,29 @@ const PRODUCT_ROWS = [ { sku: '753600', productType: PRODUCT_TYPES.STANDARD, widthMm: 75, lengthM: 120, thicknessMicron: 47, sleeveBrand: 'фрегат', quantityPerBox: '24' }, ]; +function assertUniqueProductRows(rows) { + const seen = new Map(); + + for (const row of rows) { + const signature = [ + row.productType, + row.widthMm, + row.lengthM, + row.thicknessMicron, + row.sleeveBrand, + ].join('|'); + + const duplicate = seen.get(signature); + if (duplicate) { + throw new Error( + `Duplicate product signature detected for ${row.sku} and ${duplicate.sku}: ${signature}`, + ); + } + + seen.set(signature, row); + } +} + function sentenceCase(value) { if (!value) { return value; @@ -103,6 +126,8 @@ const warehouseReserve = await prisma.warehouse.upsert({ }); const activeSkus = PRODUCT_ROWS.map((item) => item.sku); +assertUniqueProductRows(PRODUCT_ROWS); + await prisma.product.updateMany({ where: { sku: { notIn: activeSkus } }, data: { isActive: false }, diff --git a/src/schema.graphql b/src/schema.graphql index 6339163..462fb0d 100644 --- a/src/schema.graphql +++ b/src/schema.graphql @@ -177,6 +177,12 @@ type Product { sku: String! name: String! description: String + productType: String + widthMm: Int + lengthM: Int + thicknessMicron: Int + sleeveBrand: String + quantityPerBox: String isCustomizable: Boolean! isActive: Boolean! availableInWarehouses: [ProductWarehouseBalance!]!