import { PrismaClient } from '@prisma/client'; import * as bcrypt from 'bcrypt'; const prisma = new PrismaClient(); async function main() { const email = (process.env.SEED_ADMIN_EMAIL || 'admin@abshode.local').toLowerCase(); const password = process.env.SEED_ADMIN_PASSWORD || 'Admin@12345'; const name = process.env.SEED_ADMIN_NAME || 'Super Admin'; const passwordHash = await bcrypt.hash(password, 10); const user = await prisma.user.upsert({ where: { email }, update: { passwordHash, name, isActive: true, role: 'super_admin' }, create: { email, passwordHash, name, role: 'super_admin', isActive: true, }, }); const sample = await prisma.tenant.upsert({ where: { slug: 'demo-hamkar' }, update: {}, create: { product: 'hamkar', slug: 'demo-hamkar', nameFa: 'نسخه دمو همکار', nameEn: 'Demo Hamkar', domain: 'demo-hamkar.local', avatarUrl: null, primaryColor: '#1d4ed8', secondaryColor: '#0f172a', backgroundColor: '#ffffff', nodeServer: 'https://demo-hamkar.local/server', nodeWs: 'wss://demo-hamkar.local/prc/ws', appUrl: 'https://demo-hamkar.local', adminUrl: 'https://demo-hamkar.local/admin', isActive: true, notes: 'نمونه اولیه برای تست اسکفولد', }, }); console.log('Seeded admin:', { id: user.id, email: user.email }); console.log('Seeded tenant:', { id: sample.id, slug: sample.slug }); console.log('Login with:', email, '/', password); } main() .catch((e) => { console.error(e); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });