feat(products): expose structured product specs
This commit is contained in:
@@ -37,6 +37,29 @@ const PRODUCT_ROWS = [
|
|||||||
{ sku: '753600', productType: PRODUCT_TYPES.STANDARD, widthMm: 75, lengthM: 120, thicknessMicron: 47, sleeveBrand: 'фрегат', quantityPerBox: '24' },
|
{ 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) {
|
function sentenceCase(value) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return value;
|
return value;
|
||||||
@@ -103,6 +126,8 @@ const warehouseReserve = await prisma.warehouse.upsert({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const activeSkus = PRODUCT_ROWS.map((item) => item.sku);
|
const activeSkus = PRODUCT_ROWS.map((item) => item.sku);
|
||||||
|
assertUniqueProductRows(PRODUCT_ROWS);
|
||||||
|
|
||||||
await prisma.product.updateMany({
|
await prisma.product.updateMany({
|
||||||
where: { sku: { notIn: activeSkus } },
|
where: { sku: { notIn: activeSkus } },
|
||||||
data: { isActive: false },
|
data: { isActive: false },
|
||||||
|
|||||||
@@ -177,6 +177,12 @@ type Product {
|
|||||||
sku: String!
|
sku: String!
|
||||||
name: String!
|
name: String!
|
||||||
description: String
|
description: String
|
||||||
|
productType: String
|
||||||
|
widthMm: Int
|
||||||
|
lengthM: Int
|
||||||
|
thicknessMicron: Int
|
||||||
|
sleeveBrand: String
|
||||||
|
quantityPerBox: String
|
||||||
isCustomizable: Boolean!
|
isCustomizable: Boolean!
|
||||||
isActive: Boolean!
|
isActive: Boolean!
|
||||||
availableInWarehouses: [ProductWarehouseBalance!]!
|
availableInWarehouses: [ProductWarehouseBalance!]!
|
||||||
|
|||||||
Reference in New Issue
Block a user