Visualizacion de los atletas en rutinas
This commit is contained in:
parent
1cca9e10df
commit
2d05c94412
|
@ -6,7 +6,6 @@
|
|||
<title>Equipos Disponibles</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="css/equipoDisponible.css" rel="stylesheet">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-primary fixed-top">
|
||||
|
@ -28,7 +27,8 @@
|
|||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</nav>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h2>Rutinas Disponibles</h2>
|
||||
<div class="card-container" id="routinesList"></div>
|
||||
|
@ -36,38 +36,37 @@
|
|||
|
||||
<script>
|
||||
// Función para cargar las rutinas
|
||||
async function loadRoutines() {
|
||||
const response = await fetch('/routines'); // Llama a la API para obtener las rutinas
|
||||
const routines = await response.json();
|
||||
const routinesList = document.getElementById('routinesList');
|
||||
routinesList.innerHTML = ''; // Limpiar cualquier contenido anterior
|
||||
async function loadRoutines() {
|
||||
const response = await fetch('/routines');
|
||||
const routines = await response.json();
|
||||
const routinesList = document.getElementById('routinesList');
|
||||
routinesList.innerHTML = '';
|
||||
|
||||
// Iterar sobre las rutinas y crear cards
|
||||
routines.forEach(routine => {
|
||||
const card = document.createElement('div');
|
||||
card.classList.add('card', 'text-center', 'border-primary');
|
||||
card.innerHTML = `
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">${routine.nombreCompetencia}</h5>
|
||||
<p class="card-text"><strong>Competencia:</strong> ${routine.tipoCompetencia}</p>
|
||||
<p class="card-text"><strong>Modalidad:</strong> ${routine.modalidad}</p>
|
||||
<h6>Atletas:</h6>
|
||||
<ul>
|
||||
${Array.isArray(routine.participants) && routine.participants.length > 0
|
||||
? routine.participants.map(participant =>
|
||||
`<li>${participant.atletaId.nombre} - ${participant.rol}</li>`
|
||||
).join('')
|
||||
: '<li>No hay atletas asignados</li>'}
|
||||
</ul>
|
||||
</div>
|
||||
`;
|
||||
routinesList.appendChild(card); // Agregar la card al contenedor
|
||||
});
|
||||
}
|
||||
|
||||
// Cargar rutinas cuando se cargue la página
|
||||
document.addEventListener('DOMContentLoaded', loadRoutines);
|
||||
routines.forEach(routine => {
|
||||
const card = document.createElement('div');
|
||||
card.classList.add('card', 'text-center', 'border-primary', 'm-2');
|
||||
card.innerHTML = `
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">${routine.nombreCompetencia}</h5>
|
||||
<p class="card-text"><strong>Competencia:</strong> ${routine.tipoCompetencia}</p>
|
||||
<p class="card-text"><strong>Modalidad:</strong> ${routine.modalidad}</p>
|
||||
<h6>Atletas:</h6>
|
||||
<ul>
|
||||
${
|
||||
Array.isArray(routine.participantes) && routine.participantes.length > 0
|
||||
? routine.participantes.map(p =>
|
||||
`<li>${p.atletaId?.name || 'Atleta desconocido'} - ${p.rol}</li>`
|
||||
).join('')
|
||||
: '<li>No hay atletas asignados</li>'
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
`;
|
||||
routinesList.appendChild(card);
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', loadRoutines);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// routes/routines.js
|
||||
const express = require('express');
|
||||
const mongoose = require('mongoose');
|
||||
const router = express.Router();
|
||||
const User = require('./user');
|
||||
|
||||
// Definición del esquema de rutina
|
||||
const routineSchema = new mongoose.Schema({
|
||||
|
@ -40,7 +40,7 @@ const Routine = mongoose.model('Routine', routineSchema);
|
|||
// Ruta para obtener todas las rutinas
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
const routines = await Routine.find().populate('participantes.atletaId', 'nombre');
|
||||
const routines = await Routine.find().populate('participantes.atletaId', 'name');
|
||||
res.json(routines);
|
||||
} catch (error) {
|
||||
console.error("❌ Error al obtener rutinas:", error);
|
||||
|
@ -51,7 +51,17 @@ router.get('/', async (req, res) => {
|
|||
// Ruta para crear una nueva rutina
|
||||
router.post('/', async (req, res) => {
|
||||
try {
|
||||
const newRoutine = new Routine(req.body);
|
||||
const participantesConvertidos = req.body.participantes.map(part => ({
|
||||
atletaId: new mongoose.Types.ObjectId(part.atletaId),
|
||||
rol: part.rol,
|
||||
idPersonalizado: part.idPersonalizado
|
||||
}));
|
||||
|
||||
const newRoutine = new Routine({
|
||||
...req.body,
|
||||
participantes: participantesConvertidos
|
||||
});
|
||||
|
||||
await newRoutine.save();
|
||||
res.status(201).json({ message: 'Rutina guardada exitosamente', routine: newRoutine });
|
||||
} catch (error) {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const userSchema = new mongoose.Schema({
|
||||
name: String,
|
||||
role: String
|
||||
});
|
||||
|
||||
module.exports = mongoose.models.User || mongoose.model('User', userSchema);
|
Loading…
Reference in New Issue