const { PrismaClient } = require('@prisma/client') const prisma = new PrismaClient() async function checkSupplyOrderTypes() { try { console.log('🔍 ПРОВЕРЯЕМ ТИПЫ ЗАКАЗОВ ПОСТАВОК...') // Найдем пользователя фулфилмента const user = await prisma.user.findFirst({ where: { phone: '79999999999' }, include: { organization: true } }) if (!user || user.organization?.type !== 'FULFILLMENT') { console.log('❌ Пользователь фулфилмента не найден') return } console.log('🏢 ФУЛФИЛМЕНТ ОРГАНИЗАЦИЯ:') console.log(' Название:', user.organization.name) console.log(' ID:', user.organization.id) // Проверяем все заказы поставок для этого фулфилмента const supplyOrders = await prisma.supplyOrder.findMany({ where: { fulfillmentCenterId: user.organization.id }, include: { items: { include: { product: { select: { name: true, article: true, type: true } } } }, organization: { select: { name: true, type: true } }, partner: { select: { name: true, type: true } } }, orderBy: { updatedAt: 'desc' } }) console.log(`\n📋 НАЙДЕНО ЗАКАЗОВ ПОСТАВОК: ${supplyOrders.length}`) supplyOrders.forEach((order, index) => { console.log(`\n${index + 1}. ЗАКАЗ ${order.id}`) console.log(` 📅 Статус: ${order.status}`) console.log(` 🏷️ Тип расходников (consumableType): ${order.consumableType || 'НЕ УКАЗАН'}`) console.log(` 👤 Заказчик: ${order.organization?.name} (${order.organization?.type})`) console.log(` 🏪 Поставщик: ${order.partner?.name} (${order.partner?.type})`) console.log(` 📦 Элементов в заказе: ${order.items.length}`) order.items.forEach((item, itemIndex) => { console.log(` ${itemIndex + 1}. "${item.product.name}"`) console.log(` Артикул: ${item.product.article}`) console.log(` Тип товара: ${item.product.type}`) console.log(` Количество: ${item.quantity}`) }) console.log(' ---') }) // Анализируем проблемы console.log('\n🔍 АНАЛИЗ ПРОБЛЕМ:') const problemOrders = supplyOrders.filter(order => { // Проверяем заказы с неправильным consumableType if (order.organization?.type === 'FULFILLMENT' && order.consumableType === 'SELLER_CONSUMABLES') { return true } if (order.organization?.type === 'SELLER' && order.consumableType === 'FULFILLMENT_CONSUMABLES') { return true } return false }) if (problemOrders.length > 0) { console.log(`❌ НАЙДЕНО ПРОБЛЕМНЫХ ЗАКАЗОВ: ${problemOrders.length}`) problemOrders.forEach(order => { console.log(` Заказ ${order.id}: заказчик ${order.organization?.type}, тип расходников ${order.consumableType}`) }) } else { console.log('✅ Все заказы имеют корректные типы расходников') } // Проверяем созданные Supply записи console.log('\n📦 ПРОВЕРЯЕМ СОЗДАННЫЕ SUPPLY ЗАПИСИ:') const supplies = await prisma.supply.findMany({ where: { organizationId: user.organization.id }, select: { id: true, name: true, article: true, type: true, sellerOwnerId: true, currentStock: true, createdAt: true }, orderBy: { updatedAt: 'desc' } }) supplies.forEach((supply, index) => { console.log(` ${index + 1}. "${supply.name}" (${supply.article})`) console.log(` Тип: ${supply.type}`) console.log(` Владелец-селлер: ${supply.sellerOwnerId || 'НЕТ'}`) console.log(` Остаток: ${supply.currentStock}`) console.log(` Создан: ${supply.createdAt.toISOString().split('T')[0]}`) }) } catch (error) { console.error('❌ Ошибка:', error.message) } finally { await prisma.$disconnect() } } checkSupplyOrderTypes()