Files

206 lines
5.8 KiB
JavaScript

const { PrismaClient } = require('@prisma/client');
const bcrypt = require('bcryptjs');
const prisma = new PrismaClient();
async function main() {
// Users
const passwordHash = await bcrypt.hash('Admin123!', 12);
const superAdmin = await prisma.user.upsert({
where: { email: 'admin@arpm.com' },
update: {},
create: {
email: 'admin@arpm.com',
passwordHash,
firstName: 'Admin',
lastName: 'Sistema',
role: 'SUPER_ADMIN',
},
});
const director = await prisma.user.upsert({
where: { email: 'director@arpm.com' },
update: {},
create: {
email: 'director@arpm.com',
passwordHash,
firstName: 'Carlos',
lastName: 'Ramírez',
role: 'DIRECTOR',
department: 'Dirección',
jobTitle: 'Director General',
},
});
const gerente = await prisma.user.upsert({
where: { email: 'gerente@arpm.com' },
update: {},
create: {
email: 'gerente@arpm.com',
passwordHash,
firstName: 'Ana',
lastName: 'Torres',
role: 'GERENTE',
department: 'Proyectos',
jobTitle: 'Gerente de Proyectos',
},
});
const colaborador = await prisma.user.upsert({
where: { email: 'colaborador@arpm.com' },
update: {},
create: {
email: 'colaborador@arpm.com',
passwordHash,
firstName: 'Luis',
lastName: 'Mendoza',
role: 'COLABORADOR',
department: 'Ingeniería',
jobTitle: 'Desarrollador Senior',
},
});
// Projects
const proj1 = await prisma.project.upsert({
where: { code: 'PRY-2026-001' },
update: {},
create: {
code: 'PRY-2026-001',
name: 'Construcción Torre Corporativa Norte',
description: 'Proyecto de construcción de edificio de 20 pisos para uso corporativo',
type: 'Construcción',
category: 'Infraestructura',
client: 'Inmobiliaria Del Valle',
startDate: new Date('2026-01-15'),
plannedEndDate: new Date('2027-12-31'),
budget: 15000000.00,
priority: 'ALTO',
status: 'ACTIVO',
currentPhase: 'Cimentación',
methodology: 'PMI',
ragStatus: 'VERDE',
progressPct: 12.5,
tags: ['construcción', 'corporativo', 'norte'],
},
});
const proj2 = await prisma.project.upsert({
where: { code: 'PRY-2026-002' },
update: {},
create: {
code: 'PRY-2026-002',
name: 'Álbum Musical "Horizontes"',
description: 'Producción completa del cuarto álbum del artista Marco Solís',
type: 'Producción Musical',
category: 'Entretenimiento',
client: 'Sony Music Latin',
startDate: new Date('2026-03-01'),
plannedEndDate: new Date('2026-09-30'),
budget: 250000.00,
priority: 'MEDIO',
status: 'ACTIVO',
currentPhase: 'Grabación',
methodology: 'Agile',
ragStatus: 'AMARILLO',
progressPct: 35.0,
tags: ['música', 'álbum', 'producción'],
},
});
const proj3 = await prisma.project.upsert({
where: { code: 'PRY-2026-003' },
update: {},
create: {
code: 'PRY-2026-003',
name: 'Implementación ERP Empresarial',
description: 'Migración y modernización del sistema ERP corporativo',
type: 'Software',
category: 'Tecnología',
client: 'Grupo Empresarial XYZ',
startDate: new Date('2026-02-01'),
plannedEndDate: new Date('2026-11-30'),
budget: 800000.00,
priority: 'CRITICO',
status: 'EN_RIESGO',
currentPhase: 'Desarrollo',
methodology: 'Scrum',
ragStatus: 'ROJO',
progressPct: 48.0,
tags: ['erp', 'software', 'migración'],
},
});
// Project members
for (const proj of [proj1, proj2, proj3]) {
await prisma.projectMember.upsert({
where: { projectId_userId: { projectId: proj.id, userId: gerente.id } },
update: {},
create: { projectId: proj.id, userId: gerente.id, role: 'GERENTE' },
});
await prisma.projectMember.upsert({
where: { projectId_userId: { projectId: proj.id, userId: colaborador.id } },
update: {},
create: { projectId: proj.id, userId: colaborador.id, role: 'COLABORADOR' },
});
}
// Sample tasks for ERP project
const task1 = await prisma.task.create({
data: {
projectId: proj3.id,
title: 'Análisis de requerimientos',
description: 'Levantamiento y documentación de todos los requerimientos del negocio',
createdById: gerente.id,
assigneeId: colaborador.id,
status: 'COMPLETADA',
priority: 'CRITICO',
estimatedHours: 80,
actualHours: 92,
progressPct: 100,
startDate: new Date('2026-02-01'),
dueDate: new Date('2026-02-28'),
},
});
await prisma.task.create({
data: {
projectId: proj3.id,
parentId: task1.id,
title: 'Entrevistas con stakeholders',
createdById: gerente.id,
assigneeId: colaborador.id,
status: 'COMPLETADA',
priority: 'ALTO',
estimatedHours: 20,
progressPct: 100,
},
});
await prisma.task.create({
data: {
projectId: proj3.id,
title: 'Desarrollo módulo de inventarios',
description: 'Implementación del módulo de gestión de inventarios con integración WMS',
createdById: gerente.id,
assigneeId: colaborador.id,
status: 'EN_PROCESO',
priority: 'CRITICO',
estimatedHours: 200,
actualHours: 120,
progressPct: 55,
startDate: new Date('2026-03-15'),
dueDate: new Date('2026-06-30'),
},
});
console.log('Seed completado:');
console.log(' Usuarios: admin@arpm.com, director@arpm.com, gerente@arpm.com, colaborador@arpm.com');
console.log(' Password para todos: Admin123!');
console.log(' Proyectos: PRY-2026-001, PRY-2026-002, PRY-2026-003');
}
main()
.catch((e) => { console.error(e); process.exit(1); })
.finally(async () => { await prisma.$disconnect(); });