import { categoryPelayananSurat } from "@/lib/categoryPelayananSurat"; import { confDesa } from "@/lib/configurationDesa"; import permissionConfig from "@/lib/listPermission.json"; // JSON yang kita buat import { prisma } from "@/server/lib/prisma"; const category = [ { id: "lainnya", name: "Lainnya" }, { id: "kebersihan", name: "Kebersihan" }, { id: "keamanan", name: "Keamanan" }, { id: "pelayanan", name: "Pelayanan" }, { id: "infrastruktur", name: "Infrastruktur" }, ] const role = [ { id: "developer", name: "developer" } ] const user = [ { id: "bip", name: "Bip", email: "bip@bip.com", password: "bip", roleId: "developer" } ]; (async () => { const allKeys: string[] = []; function collectKeys(items: any[]) { items.forEach((item) => { allKeys.push(item.key); if (item.children) collectKeys(item.children); }); } collectKeys(permissionConfig.menus); for (const r of role) { await prisma.role.upsert({ where: { id: r.id }, create: { id: r.id, name: r.name, permissions: allKeys as any, }, update: { name: r.name, permissions: allKeys as any, } }) console.log(`✅ Role ${r.name} seeded successfully`) } for (const u of user) { await prisma.user.upsert({ where: { email: u.email }, create: u, update: u }) console.log(`✅ User ${u.email} seeded successfully`) } for (const c of category) { await prisma.categoryPengaduan.upsert({ where: { id: c.id }, create: c, update: c }) console.log(`✅ Category ${c.name} seeded successfully`) } for (const cp of categoryPelayananSurat) { await prisma.categoryPelayanan.upsert({ where: { id: cp.id }, create: cp, update: cp }) console.log(`✅ Category Pelayanan ${cp.name} seeded successfully`) } for (const c of confDesa) { await prisma.configuration.upsert({ where: { id: c.id }, create: c, update: c }) console.log(`✅ Configuration ${c.name} seeded successfully`) } })().catch((e) => { console.error(e) process.exit(1) }).finally(() => { console.log("✅ Seeding completed successfully ") process.exit(0) })