47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
import { PrismaClient, PerfilUsuario } from "@prisma/client";
|
|
import bcrypt from "bcryptjs";
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
// Criar usuário admin inicial
|
|
const adminEmail = "admin@advx.com.br";
|
|
|
|
const existingAdmin = await prisma.usuario.findUnique({
|
|
where: { email: adminEmail },
|
|
});
|
|
|
|
if (existingAdmin) {
|
|
await prisma.usuario.update({
|
|
where: { email: adminEmail },
|
|
data: {
|
|
perfil: PerfilUsuario.ADVOGADO_ADMIN,
|
|
nome: "Administrador",
|
|
senha: await bcrypt.hash("admin123", 10),
|
|
ativo: true,
|
|
},
|
|
});
|
|
} else {
|
|
await prisma.usuario.create({
|
|
data: {
|
|
nome: "Administrador",
|
|
email: adminEmail,
|
|
senha: await bcrypt.hash("admin123", 10),
|
|
perfil: PerfilUsuario.ADVOGADO_ADMIN,
|
|
ativo: true,
|
|
},
|
|
});
|
|
}
|
|
|
|
console.log(`Seed concluído com sucesso!`);
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error("Erro durante o seed:", e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|