120 lines
2.9 KiB
JavaScript
120 lines
2.9 KiB
JavaScript
import 'dotenv/config';
|
||
|
||
import { prisma } from '../src/prisma-client.js';
|
||
|
||
const managerEmail = 'manager@fregat.local';
|
||
const clientEmail = 'client@fregat.local';
|
||
|
||
const company = await prisma.company.upsert({
|
||
where: { inn: '7701000000' },
|
||
update: {},
|
||
create: {
|
||
name: 'Fregat Client LLC',
|
||
inn: '7701000000',
|
||
},
|
||
});
|
||
|
||
const manager = await prisma.user.upsert({
|
||
where: { email: managerEmail },
|
||
update: { fullName: 'Default Manager' },
|
||
create: {
|
||
email: managerEmail,
|
||
fullName: 'Default Manager',
|
||
role: 'MANAGER',
|
||
},
|
||
});
|
||
|
||
await prisma.user.upsert({
|
||
where: { email: clientEmail },
|
||
update: { fullName: 'Demo Client', companyId: company.id },
|
||
create: {
|
||
email: clientEmail,
|
||
fullName: 'Demo Client',
|
||
role: 'CLIENT',
|
||
companyId: company.id,
|
||
},
|
||
});
|
||
|
||
const warehouseMain = await prisma.warehouse.upsert({
|
||
where: { code: 'MSK-01' },
|
||
update: { name: 'Main warehouse' },
|
||
create: { code: 'MSK-01', name: 'Main warehouse' },
|
||
});
|
||
|
||
const warehouseReserve = await prisma.warehouse.upsert({
|
||
where: { code: 'SPB-01' },
|
||
update: { name: 'Reserve warehouse' },
|
||
create: { code: 'SPB-01', name: 'Reserve warehouse' },
|
||
});
|
||
|
||
const products = [
|
||
{
|
||
sku: 'FILM-100',
|
||
name: 'Пленка прозрачная 100мкм',
|
||
description: 'Готовая продукция для стандартной упаковки',
|
||
isCustomizable: false,
|
||
qtyMain: 1250,
|
||
qtyReserve: 420,
|
||
},
|
||
{
|
||
sku: 'FILM-200-COLOR',
|
||
name: 'Пленка цветная 200мкм',
|
||
description: 'Продукция с дополнительной окраской',
|
||
isCustomizable: true,
|
||
qtyMain: 860,
|
||
qtyReserve: 230,
|
||
},
|
||
];
|
||
|
||
for (const product of products) {
|
||
const dbProduct = await prisma.product.upsert({
|
||
where: { sku: product.sku },
|
||
update: {
|
||
name: product.name,
|
||
description: product.description,
|
||
isCustomizable: product.isCustomizable,
|
||
isActive: true,
|
||
},
|
||
create: {
|
||
sku: product.sku,
|
||
name: product.name,
|
||
description: product.description,
|
||
isCustomizable: product.isCustomizable,
|
||
isActive: true,
|
||
},
|
||
});
|
||
|
||
await prisma.productStock.upsert({
|
||
where: {
|
||
productId_warehouseId: {
|
||
productId: dbProduct.id,
|
||
warehouseId: warehouseMain.id,
|
||
},
|
||
},
|
||
update: { availableQty: product.qtyMain },
|
||
create: {
|
||
productId: dbProduct.id,
|
||
warehouseId: warehouseMain.id,
|
||
availableQty: product.qtyMain,
|
||
},
|
||
});
|
||
|
||
await prisma.productStock.upsert({
|
||
where: {
|
||
productId_warehouseId: {
|
||
productId: dbProduct.id,
|
||
warehouseId: warehouseReserve.id,
|
||
},
|
||
},
|
||
update: { availableQty: product.qtyReserve },
|
||
create: {
|
||
productId: dbProduct.id,
|
||
warehouseId: warehouseReserve.id,
|
||
availableQty: product.qtyReserve,
|
||
},
|
||
});
|
||
}
|
||
|
||
console.log('Seed complete. Use manager header x-user-id:', manager.id);
|
||
await prisma.$disconnect();
|