feat: AR-ProjectManagement initial commit — JavaScript (Node.js / React) Express + Prisma (backend) / React + Axios (frontend)

This commit is contained in:
2026-07-03 12:16:44 -04:00
commit 0c1a9a802c
100 changed files with 56764 additions and 0 deletions
+215
View File
@@ -0,0 +1,215 @@
// AR-ProjectManagement — Prisma Schema
// Base de datos: PostgreSQL 16
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// ============================================================
// ENUMS
// ============================================================
enum Role {
SUPER_ADMIN
DIRECTOR
GERENTE
JEFE_AREA
COLABORADOR
FINANCIERO
AUDITOR
}
enum ProjectStatus {
ACTIVO
PAUSADO
COMPLETADO
EN_RIESGO
CANCELADO
}
enum TaskStatus {
PENDIENTE
EN_PROCESO
BLOQUEADA
EN_VERIFICACION
NO_CONFORME
APROBADO_TECNICO
ACEPTADO_FORMAL
COMPLETADA
}
enum Priority {
CRITICO
ALTO
MEDIO
BAJO
}
// ============================================================
// MODULO 1: USUARIOS Y AUTENTICACION
// ============================================================
model User {
id String @id @default(uuid())
email String @unique
passwordHash String @map("password_hash")
firstName String @map("first_name")
lastName String @map("last_name")
role Role @default(COLABORADOR)
isActive Boolean @default(true) @map("is_active")
isTwoFactorEnabled Boolean @default(false) @map("is_two_factor_enabled")
twoFactorSecret String? @map("two_factor_secret")
loginAttempts Int @default(0) @map("login_attempts")
lockedUntil DateTime? @map("locked_until")
lastLoginAt DateTime? @map("last_login_at")
lastLoginIp String? @map("last_login_ip")
avatarUrl String? @map("avatar_url")
phone String?
department String?
jobTitle String? @map("job_title")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
refreshTokens RefreshToken[]
auditLogs AuditLog[]
projectMembers ProjectMember[]
tasksAssigned Task[] @relation("TaskAssignee")
tasksCreated Task[] @relation("TaskCreator")
comments Comment[]
@@map("users")
}
model RefreshToken {
id String @id @default(uuid())
token String @unique
userId String @map("user_id")
expiresAt DateTime @map("expires_at")
createdAt DateTime @default(now()) @map("created_at")
revokedAt DateTime? @map("revoked_at")
ipAddress String? @map("ip_address")
userAgent String? @map("user_agent")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("refresh_tokens")
}
// ============================================================
// LOG DE AUDITORIA INMUTABLE
// ============================================================
model AuditLog {
id String @id @default(uuid())
userId String? @map("user_id")
action String
entity String
entityId String? @map("entity_id")
oldValues Json? @map("old_values")
newValues Json? @map("new_values")
ipAddress String? @map("ip_address")
userAgent String? @map("user_agent")
createdAt DateTime @default(now()) @map("created_at")
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
@@map("audit_logs")
}
// ============================================================
// MODULO 3: PROYECTOS
// ============================================================
model Project {
id String @id @default(uuid())
code String @unique
name String
description String?
type String
category String
client String?
startDate DateTime @map("start_date")
plannedEndDate DateTime @map("planned_end_date")
actualEndDate DateTime? @map("actual_end_date")
budget Decimal @db.Decimal(15, 2)
contingencyPct Decimal @default(10) @map("contingency_pct") @db.Decimal(5, 2)
currency String @default("USD")
priority Priority @default(MEDIO)
status ProjectStatus @default(ACTIVO)
currentPhase String? @map("current_phase")
methodology String?
tags String[]
ragStatus String @default("VERDE") @map("rag_status")
progressPct Decimal @default(0) @map("progress_pct") @db.Decimal(5, 2)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
members ProjectMember[]
tasks Task[]
@@map("projects")
}
model ProjectMember {
id String @id @default(uuid())
projectId String @map("project_id")
userId String @map("user_id")
role String
joinedAt DateTime @default(now()) @map("joined_at")
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([projectId, userId])
@@map("project_members")
}
// ============================================================
// MODULO 4: TAREAS
// ============================================================
model Task {
id String @id @default(uuid())
projectId String @map("project_id")
parentId String? @map("parent_id")
wbsId String? @map("wbs_id")
title String
description String?
assigneeId String? @map("assignee_id")
createdById String @map("created_by_id")
startDate DateTime? @map("start_date")
dueDate DateTime? @map("due_date")
estimatedHours Decimal? @map("estimated_hours") @db.Decimal(8, 2)
actualHours Decimal? @map("actual_hours") @db.Decimal(8, 2)
progressPct Decimal @default(0) @map("progress_pct") @db.Decimal(5, 2)
status TaskStatus @default(PENDIENTE)
priority Priority @default(MEDIO)
estimatedCost Decimal? @map("estimated_cost") @db.Decimal(15, 2)
actualCost Decimal? @map("actual_cost") @db.Decimal(15, 2)
tags String[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
assignee User? @relation("TaskAssignee", fields: [assigneeId], references: [id])
creator User @relation("TaskCreator", fields: [createdById], references: [id])
parent Task? @relation("TaskChildren", fields: [parentId], references: [id])
children Task[] @relation("TaskChildren")
comments Comment[]
@@map("tasks")
}
model Comment {
id String @id @default(uuid())
taskId String @map("task_id")
userId String @map("user_id")
content String
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
task Task @relation(fields: [taskId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id])
@@map("comments")
}
+205
View File
@@ -0,0 +1,205 @@
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(); });