import { PrismaClient } from '@prisma/client'; import * as bcrypt from 'bcryptjs'; const prisma = new PrismaClient(); async function main() { // Create admin user const adminPassword = await bcrypt.hash('admin123', 10); const admin = await prisma.user.upsert({ where: { email: 'admin@example.com' }, update: {}, create: { email: 'admin@example.com', username: 'admin', password: adminPassword, firstName: 'Admin', lastName: 'User', }, }); // Create regular user const userPassword = await bcrypt.hash('user123', 10); const user = await prisma.user.upsert({ where: { email: 'user@example.com' }, update: {}, create: { email: 'user@example.com', username: 'user', password: userPassword, firstName: 'Regular', lastName: 'User', }, }); // Create sample blogs await prisma.blog.createMany({ data: [ { title: 'Welcome to KLC Backend', content: 'This is a sample blog post created by the admin user.', category: 'General', tags: ['welcome', 'introduction'], publishedAt: new Date(), }, { title: 'Getting Started with Prisma', content: 'Learn how to use Prisma ORM with NestJS.', category: 'Technical', tags: ['prisma', 'database', 'tutorial'], publishedAt: new Date(), }, ], }); console.log('Seed data created successfully!'); console.log('Admin user:', { email: admin.email, username: admin.username }); console.log('Regular user:', { email: user.email, username: user.username }); } main() .catch((e) => { console.error(e); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });