57 lines
3.1 KiB
JavaScript
57 lines
3.1 KiB
JavaScript
|
|
const { PrismaClient } = require('@prisma/client');
|
||
|
|
const bcrypt = require('bcryptjs');
|
||
|
|
|
||
|
|
const prisma = new PrismaClient();
|
||
|
|
|
||
|
|
async function main() {
|
||
|
|
console.log("Seeding database...");
|
||
|
|
try {
|
||
|
|
const password = await bcrypt.hash('password123', 10);
|
||
|
|
|
||
|
|
const userData = [
|
||
|
|
{ email: 'ghazali@falahos.my', name: 'Abu Hamid Al-Ghazali', passwordHash: password, flhBalance: 5000 },
|
||
|
|
{ email: 'ibnabbas@falahos.my', name: 'Abdullah Ibn Abbas', passwordHash: password, flhBalance: 3000 },
|
||
|
|
{ email: 'rabia@falahos.my', name: "Rabi'a Al-Adawiyya", passwordHash: password, flhBalance: 2000 },
|
||
|
|
{ email: 'demo@falahos.my', name: 'Demo User', passwordHash: password, flhBalance: 500 },
|
||
|
|
];
|
||
|
|
|
||
|
|
const users = [];
|
||
|
|
for (const u of userData) {
|
||
|
|
let user = await prisma.user.findUnique({ where: { email: u.email } });
|
||
|
|
if (!user) {
|
||
|
|
user = await prisma.user.create({ data: u });
|
||
|
|
}
|
||
|
|
users.push(user);
|
||
|
|
}
|
||
|
|
|
||
|
|
const listings = [
|
||
|
|
{ title: 'Digital Quran Study Planner', description: 'Comprehensive digital planner for Quran memorization tracking with daily logs and revision schedules.', category: 'E-Books', priceFlh: 150, sellerId: users[0].id },
|
||
|
|
{ title: 'Islamic Art Calligraphy Print', description: 'Beautiful "Bismillah" calligraphy print, handmade. High-quality 300gsm paper, A3 size.', category: 'Design', priceFlh: 250, sellerId: users[1].id },
|
||
|
|
{ title: 'Online Arabic Course - Beginner', description: '12-week structured Arabic course with weekly live sessions, worksheets, and community support.', category: 'Courses', priceFlh: 500, sellerId: users[2].id },
|
||
|
|
{ title: 'Halal Snack Box - Monthly Subscription', description: 'Curated box of halal-certified snacks delivered monthly. International treats included.', category: 'Other', priceFlh: 80, sellerId: users[3].id },
|
||
|
|
{ title: 'Digital Dhikr Counter App', description: 'Beautiful dhikr counter with daily adhkar tracking, goals, and badges.', category: 'Software', priceFlh: 30, sellerId: users[0].id },
|
||
|
|
{ title: 'Handcrafted Tasbih (Prayer Beads)', description: 'Premium olive wood tasbih, 33 beads with tassel. Handcrafted by artisans. Gift box included.', category: 'Other', priceFlh: 120, sellerId: users[1].id },
|
||
|
|
{ title: 'Islamic Parenting E-Book Bundle', description: '5 e-books on raising righteous children: discipline, faith, education, screen time, character.', category: 'E-Books', priceFlh: 45, sellerId: users[2].id },
|
||
|
|
{ title: 'Tajweed Mastery Video Course', description: 'Complete Tajweed rules with 20 video lessons, practice exercises, and progress quizzes.', category: 'Courses', priceFlh: 350, sellerId: users[0].id },
|
||
|
|
];
|
||
|
|
|
||
|
|
let created = 0;
|
||
|
|
for (const l of listings) {
|
||
|
|
const existing = await prisma.listing.findFirst({ where: { title: l.title } });
|
||
|
|
if (!existing) {
|
||
|
|
await prisma.listing.create({ data: l });
|
||
|
|
created++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
console.log(`Successfully seeded ${users.length} users and ${created} new listings.`);
|
||
|
|
} catch (error) {
|
||
|
|
console.error("Error during seeding:", error);
|
||
|
|
process.exit(1);
|
||
|
|
} finally {
|
||
|
|
await prisma.$disconnect();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
main();
|