Files
hMarket/backend/prisma/seed.js
2026-03-01 20:26:44 +03:00

140 lines
6.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function main() {
console.log('Örnek veriler ekleniyor...')
// Kullanıcılar
const user1 = await prisma.user.create({
data: {
email: 'mustafa@example.com',
username: 'mustafa',
firstName: 'Mustafa',
lastName: 'ÖZKAYA',
password: '$2a$10$dummy',
avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=mustafa',
}
})
const user2 = await prisma.user.create({
data: {
email: 'ahmet@example.com',
username: 'ahmet',
firstName: 'Ahmet',
lastName: 'Yılmaz',
password: '$2a$10$dummy',
avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=ahmet',
}
})
const user3 = await prisma.user.create({
data: {
email: 'ayse@example.com',
username: 'ayse',
firstName: 'Ayşe',
lastName: 'Kaya',
password: '$2a$10$dummy',
avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=ayse',
}
})
console.log('✅ Kullanıcılar oluşturuldu')
// Kategoriler
const cat1 = await prisma.category.create({ data: { name: 'Sebze & Meyve', icon: '🥬', color: '#4CAF50' } })
const cat2 = await prisma.category.create({ data: { name: 'Et & Tavuk', icon: '🥩', color: '#F44336' } })
const cat3 = await prisma.category.create({ data: { name: 'Süt & Süt Ürünleri', icon: '🥛', color: '#2196F3' } })
const cat4 = await prisma.category.create({ data: { name: 'Ekmek & Unlu Mamüller', icon: '🍞', color: '#FF9800' } })
const cat5 = await prisma.category.create({ data: { name: 'İçecekler', icon: '🥤', color: '#9C27B0' } })
const cat6 = await prisma.category.create({ data: { name: 'Temizlik', icon: '🧹', color: '#607D8B' } })
const cat7 = await prisma.category.create({ data: { name: 'Atıştırmalık', icon: '🍪', color: '#795548' } })
const cat8 = await prisma.category.create({ data: { name: 'Dondurma', icon: '🍦', color: '#E91E63' } })
console.log('✅ Kategoriler oluşturuldu')
// Ürünler
const products = await Promise.all([
prisma.product.create({ data: { name: 'Domates', categoryId: cat1.id, unit: 'kg' } }),
prisma.product.create({ data: { name: 'Soğan', categoryId: cat1.id, unit: 'kg' } }),
prisma.product.create({ data: { name: 'Salatalık', categoryId: cat1.id, unit: 'adet' } }),
prisma.product.create({ data: { name: 'Tavuk Göğsü', categoryId: cat2.id, unit: 'kg' } }),
prisma.product.create({ data: { name: 'Kıyma', categoryId: cat2.id, unit: 'kg' } }),
prisma.product.create({ data: { name: 'Kırmızı Et', categoryId: cat2.id, unit: 'kg' } }),
prisma.product.create({ data: { name: 'Süt', categoryId: cat3.id, unit: 'L' } }),
prisma.product.create({ data: { name: 'Yoğurt', categoryId: cat3.id, unit: 'adet' } }),
prisma.product.create({ data: { name: 'Ekmek', categoryId: cat4.id, unit: 'adet' } }),
prisma.product.create({ data: { name: 'Cola', categoryId: cat5.id, unit: 'adet' } }),
prisma.product.create({ data: { name: 'Bulaşık Deterjanı', categoryId: cat6.id, unit: 'adet' } }),
prisma.product.create({ data: { name: 'Baklava', categoryId: cat7.id, unit: 'kg' } }),
prisma.product.create({ data: { name: 'Dondurma', categoryId: cat8.id, unit: 'L' } }),
])
console.log('✅ Ürünler oluşturuldu')
// Market Listeleri
const list1 = await prisma.shoppingList.create({
data: {
name: 'Haftalık Market',
description: 'Bu hafta alınacaklar',
color: '#4CAF50',
ownerId: user1.id,
}
})
// Listeye üye ekle
await prisma.listMember.create({
data: {
userId: user2.id,
listId: list1.id,
role: 'admin'
}
})
// Liste Öğeleri (productId kullan)
await prisma.listItem.create({ data: { productId: products[0].id, quantity: 2, unit: 'kg', listId: list1.id } }) // Domates
await prisma.listItem.create({ data: { productId: products[1].id, quantity: 1, unit: 'kg', listId: list1.id } }) // Soğan
await prisma.listItem.create({ data: { productId: products[2].id, quantity: 3, unit: 'adet', listId: list1.id, isPurchased: true } }) // Salatalık
await prisma.listItem.create({ data: { productId: products[3].id, quantity: 1, unit: 'kg', listId: list1.id } }) // Tavuk
await prisma.listItem.create({ data: { productId: products[4].id, quantity: 0.5, unit: 'kg', listId: list1.id } }) // Kıyma
await prisma.listItem.create({ data: { productId: products[6].id, quantity: 2, unit: 'L', listId: list1.id, isPurchased: true } }) // Süt
await prisma.listItem.create({ data: { productId: products[7].id, quantity: 4, unit: 'adet', listId: list1.id } }) // Yoğurt
await prisma.listItem.create({ data: { productId: products[8].id, quantity: 2, unit: 'adet', listId: list1.id } }) // Ekmek
await prisma.listItem.create({ data: { productId: products[9].id, quantity: 6, unit: 'adet', listId: list1.id } }) // Cola
await prisma.listItem.create({ data: { productId: products[10].id, quantity: 1, unit: 'adet', listId: list1.id, isPurchased: true } }) // Deterjan
console.log('✅ İlk liste oluşturuldu')
// İkinci liste
const list2 = await prisma.shoppingList.create({
data: {
name: 'Bayram Alışverişi',
description: 'Bayram için gerekli malzemeler',
color: '#E91E63',
ownerId: user1.id,
}
})
await prisma.listItem.create({ data: { productId: products[5].id, quantity: 2, unit: 'kg', listId: list2.id } }) // Kırmızı Et
await prisma.listItem.create({ data: { productId: products[11].id, quantity: 1, unit: 'kg', listId: list2.id } }) // Baklava
await prisma.listItem.create({ data: { productId: products[12].id, quantity: 2, unit: 'L', listId: list2.id } }) // Dondurma
console.log('✅ İkinci liste oluşturuldu')
console.log('\n🎉 Örnek veriler başarıyla eklendi!')
console.log(` - 3 kullanıcı`)
console.log(` - 8 kategori`)
console.log(` - ${await prisma.product.count()} ürün`)
console.log(` - 2 liste`)
console.log(` - 13 liste öğesi`)
}
main()
.catch((e) => {
console.error(e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})