seed-admin.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { PrismaClient } from '@prisma/client';
  2. import bcrypt from 'bcryptjs';
  3. const prisma = new PrismaClient();
  4. async function main() {
  5. console.log('🌱 Iniciando seeding de usuarios administrativos...');
  6. // Admin principal
  7. const adminPassword = await bcrypt.hash('admin123', 12);
  8. const adminIdentificacion = '0000000001';
  9. const admin = await prisma.user.upsert({
  10. where: { identificacion: adminIdentificacion },
  11. update: {},
  12. create: {
  13. email: 'amesas@utb.edu.ec',
  14. username: `${adminIdentificacion}-ADM`,
  15. identificacion: adminIdentificacion,
  16. name: 'Armando',
  17. lastname: 'Mesas',
  18. password: adminPassword,
  19. role: 'ADMIN',
  20. isExternalAuth: false,
  21. },
  22. });
  23. console.log('✅ Admin creado:', admin.username);
  24. // Doctor ejemplo
  25. const doctorPassword = await bcrypt.hash('doctor123', 12);
  26. const doctorIdentificacion = '0000000002';
  27. const doctor = await prisma.user.upsert({
  28. where: { identificacion: doctorIdentificacion },
  29. update: {},
  30. create: {
  31. email: 'shoria@utb.edu.ec',
  32. username: `${doctorIdentificacion}-DOC`,
  33. identificacion: doctorIdentificacion,
  34. name: 'Susana',
  35. lastname: 'Horia',
  36. password: doctorPassword,
  37. role: 'DOCTOR',
  38. isExternalAuth: false,
  39. },
  40. });
  41. console.log('✅ Doctor creado:', doctor.username);
  42. console.log('\n📋 Credenciales creadas:');
  43. console.log('----------------------------');
  44. console.log('Admin: 0000000001-ADM / admin123');
  45. console.log('Doctor: 0000000002-DOC / doctor123');
  46. console.log('----------------------------\n');
  47. }
  48. main()
  49. .then(async () => {
  50. await prisma.$disconnect();
  51. })
  52. .catch(async (e) => {
  53. console.error(e);
  54. await prisma.$disconnect();
  55. process.exit(1);
  56. });