correccion formaciones
This commit is contained in:
parent
e3c2d63ffa
commit
2e0e57d606
|
@ -1,262 +1,168 @@
|
|||
/* ------------------- ESTILO GLOBAL ------------------- */
|
||||
/* === Variables === */
|
||||
:root {
|
||||
--color-primary: #0d6efd;
|
||||
--color-success: #198754;
|
||||
--color-secondary: #6c757d;
|
||||
--color-light: #f9fafb;
|
||||
--color-border: #dee2e6;
|
||||
--radius-lg: 0.75rem;
|
||||
--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
|
||||
--transition-fast: all 0.25s ease;
|
||||
--font-family: 'Inter', sans-serif;
|
||||
}
|
||||
|
||||
html {
|
||||
overflow-y: scroll;
|
||||
scroll-behavior: smooth;
|
||||
}
|
||||
|
||||
/* === Reset === */
|
||||
body {
|
||||
font-family: var(--font-family);
|
||||
font-size: clamp(1rem, 1vw + 0.2rem, 1.1rem);
|
||||
line-height: 1.7;
|
||||
background-color: #f9fafb;
|
||||
font-size: 1rem;
|
||||
background-color: var(--color-light);
|
||||
color: #212529;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* ------------------- NAVBAR ------------------- */
|
||||
/* === Navbar === */
|
||||
.navbar {
|
||||
min-height: 72px;
|
||||
padding-top: 1rem !important;
|
||||
padding-bottom: 1rem !important;
|
||||
}
|
||||
|
||||
.navbar .nav-link {
|
||||
font-weight: 500;
|
||||
font-size: 1rem;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.navbar .nav-link:hover {
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.navbar * {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* ------------------- TARJETAS ------------------- */
|
||||
/* === Cards === */
|
||||
.card {
|
||||
border: none;
|
||||
border-radius: var(--radius-lg);
|
||||
box-shadow: var(--shadow-md);
|
||||
background-color: white;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
/* ------------------- FORMULARIOS ------------------- */
|
||||
/* === Forms === */
|
||||
.form-control,
|
||||
.form-select {
|
||||
border-radius: var(--radius-lg);
|
||||
border: 1px solid #ced4da;
|
||||
transition: var(--transition-fast);
|
||||
font-size: 1rem;
|
||||
border: 1px solid var(--color-border);
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.form-control:focus,
|
||||
.form-select:focus {
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
|
||||
}
|
||||
|
||||
/* ------------------- BOTONES ------------------- */
|
||||
/* === Botones === */
|
||||
button,
|
||||
.btn {
|
||||
border-radius: var(--radius-lg);
|
||||
padding: 0.6rem 1.2rem;
|
||||
font-weight: 600;
|
||||
font-size: 1rem;
|
||||
transition: var(--transition-fast);
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.btn-primary,
|
||||
.btn-success,
|
||||
.btn-outline-primary,
|
||||
.btn-outline-secondary {
|
||||
border-width: 2px;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: var(--color-primary);
|
||||
border-color: var(--color-primary);
|
||||
color: #fff;
|
||||
}
|
||||
.btn-primary:hover {
|
||||
background-color: #084298;
|
||||
border-color: #084298;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background-color: var(--color-success);
|
||||
border-color: var(--color-success);
|
||||
color: white;
|
||||
}
|
||||
.btn-success:hover {
|
||||
background-color: #145c32;
|
||||
border-color: #145c32;
|
||||
}
|
||||
|
||||
.btn-outline-primary {
|
||||
color: var(--color-primary);
|
||||
border-color: var(--color-primary);
|
||||
background-color: white;
|
||||
}
|
||||
.btn-outline-secondary:hover,
|
||||
.btn-outline-primary:hover {
|
||||
background-color: var(--color-primary);
|
||||
color: white;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.btn-outline-secondary {
|
||||
color: #6c757d;
|
||||
border-color: #6c757d;
|
||||
background-color: white;
|
||||
}
|
||||
.btn-outline-secondary:hover {
|
||||
background-color: #6c757d;
|
||||
color: white;
|
||||
}
|
||||
|
||||
button:disabled,
|
||||
.btn:disabled {
|
||||
opacity: 0.65;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* ------------------- PISCINA ------------------- */
|
||||
/* === Piscina === */
|
||||
#piscinaContainer {
|
||||
background-color: #e6f7ff;
|
||||
border: 2px dashed #007bff;
|
||||
padding: 1rem;
|
||||
border-radius: var(--radius-lg);
|
||||
width: fit-content;
|
||||
height: fit-content;
|
||||
min-width: 300px;
|
||||
min-height: 200px;
|
||||
aspect-ratio: 2 / 1;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
max-width: 100%;
|
||||
box-sizing: border-box;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#piscina {
|
||||
display: block;
|
||||
width: 100% !important;
|
||||
height: 100% !important;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image:
|
||||
linear-gradient(to right, rgba(0,0,0,0.05) 1px, transparent 1px),
|
||||
linear-gradient(to bottom, rgba(0,0,0,0.05) 1px, transparent 1px);
|
||||
background-size: 45px 45px;
|
||||
background-position: top left;
|
||||
overflow: hidden;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* ------------------- TIMELINE ------------------- */
|
||||
/* === Timeline === */
|
||||
.timeline-placeholder {
|
||||
display: flex;
|
||||
overflow-x: auto;
|
||||
gap: 10px;
|
||||
padding: 1rem;
|
||||
border: 1px solid #ddd;
|
||||
background: #ffffff;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: var(--radius-lg);
|
||||
box-shadow: 0 1px 4px rgba(0,0,0,0.05);
|
||||
padding: 1rem;
|
||||
background-color: white;
|
||||
box-shadow: var(--shadow-md);
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.timeline-placeholder .step {
|
||||
min-width: 100px;
|
||||
padding: 0.5rem;
|
||||
border: 1px solid #ccc;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 0.5rem;
|
||||
font-size: 0.85rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
box-shadow: 1px 1px 3px rgba(0,0,0,0.05);
|
||||
}
|
||||
.timeline-placeholder .step:hover {
|
||||
background-color: #dbeafe;
|
||||
font-weight: bold;
|
||||
transform: scale(1.03);
|
||||
}
|
||||
.step.active {
|
||||
background-color: #0d6efd !important;
|
||||
color: white !important;
|
||||
background-color: var(--color-primary);
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* ------------------- AUTOCOMPLETADO ------------------- */
|
||||
/* === Sugerencias figura === */
|
||||
#sugerenciasFigura {
|
||||
margin-top: 4px;
|
||||
padding: 6px 0;
|
||||
background-color: #fff;
|
||||
background: #fff;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
|
||||
max-height: 160px;
|
||||
overflow-y: auto;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
z-index: 10;
|
||||
max-height: 160px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
#sugerenciasFigura button {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 6px 12px;
|
||||
font-size: 0.9rem;
|
||||
border: none;
|
||||
background: none;
|
||||
text-align: left;
|
||||
color: #333;
|
||||
font-size: 0.9rem;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s ease;
|
||||
}
|
||||
#sugerenciasFigura button:hover {
|
||||
background-color: #edf6ff;
|
||||
color: #007bff;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* ------------------- VISTA PREVIA FIGURA ------------------- */
|
||||
#previewFigura img {
|
||||
margin-top: 8px;
|
||||
max-width: 100%;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 6px;
|
||||
height: auto;
|
||||
}
|
||||
#previewFigura p {
|
||||
font-size: 0.85rem;
|
||||
color: #555;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
/* ------------------- MULTIMEDIA ------------------- */
|
||||
/* === Audio === */
|
||||
#waveform {
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
margin-bottom: 10px;
|
||||
height: 80px;
|
||||
background: #f1f3f5;
|
||||
border-radius: 6px;
|
||||
}
|
||||
#audioPlayer {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ------------------- RESPONSIVO ------------------- */
|
||||
/* === Responsivo === */
|
||||
@media (max-width: 768px) {
|
||||
#piscina {
|
||||
min-height: 280px;
|
||||
}
|
||||
|
||||
.timeline-placeholder .step {
|
||||
min-width: 80px;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
#piscinaContainer {
|
||||
aspect-ratio: 1.5 / 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* === Ancho de página controlado === */
|
||||
main.container-xl {
|
||||
max-width: 1440px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
padding-left: 2rem;
|
||||
padding-right: 2rem;
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ atletas.forEach(a => {
|
|||
|
||||
select.addEventListener('change', () => {
|
||||
const datos = JSON.parse(select.value || '{}');
|
||||
select.dataset.id = datos.id; // << GUARDAS el ObjectId real
|
||||
|
||||
if (datos.idPers) {
|
||||
document.getElementById('idPersonalizado').value = datos.idPers;
|
||||
document.getElementById('idPersonalizado').disabled = true;
|
||||
|
@ -48,6 +50,7 @@ select.addEventListener('change', () => {
|
|||
document.getElementById('idPersonalizado').disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
let figurasFINA = [];
|
||||
try {
|
||||
const res = await fetch('/catalog/figurasFINA.json');
|
||||
|
@ -192,7 +195,7 @@ tipoPiscinaSelect.addEventListener('change', async () => {
|
|||
return;
|
||||
}
|
||||
|
||||
const idAtleta = select.value;
|
||||
const idAtleta = select.dataset.id;
|
||||
const rol = document.getElementById('rolAtleta').value.trim().toLowerCase();
|
||||
const idPersonalizado = document.getElementById('idPersonalizado').value.trim();
|
||||
const figura = inputFigura?.value.trim();
|
||||
|
@ -236,7 +239,6 @@ tipoPiscinaSelect.addEventListener('change', async () => {
|
|||
|
||||
function dibujarAtleta(atleta) {
|
||||
const color = atleta.rol === 'volador' ? 'purple' : atleta.rol === 'pilar' ? 'blue' : 'red';
|
||||
|
||||
const metros = convertirAMetros(atleta.x, atleta.y);
|
||||
|
||||
const circle = new Konva.Circle({
|
||||
|
@ -261,7 +263,6 @@ tipoPiscinaSelect.addEventListener('change', async () => {
|
|||
text.offsetX(text.width() / 2);
|
||||
text.offsetY(text.height() / 2);
|
||||
|
||||
|
||||
const figuraText = new Konva.Text({
|
||||
x: atleta.x - 25,
|
||||
y: atleta.y + 18,
|
||||
|
@ -281,6 +282,20 @@ tipoPiscinaSelect.addEventListener('change', async () => {
|
|||
});
|
||||
coordText.listening(false);
|
||||
|
||||
let flecha = null;
|
||||
if (atleta.direccion) {
|
||||
flecha = new Konva.Arrow({
|
||||
points: [atleta.direccion.x1, atleta.direccion.y1, atleta.direccion.x2, atleta.direccion.y2],
|
||||
stroke: 'black',
|
||||
fill: 'black',
|
||||
strokeWidth: 2,
|
||||
pointerLength: 10,
|
||||
pointerWidth: 10,
|
||||
dash: [4, 4]
|
||||
});
|
||||
layer.add(flecha);
|
||||
}
|
||||
|
||||
circle.on('dblclick', () => {
|
||||
const i = formacionActual.findIndex(a => a.idPersonalizado === atleta.idPersonalizado);
|
||||
const html = `
|
||||
|
@ -313,36 +328,32 @@ tipoPiscinaSelect.addEventListener('change', async () => {
|
|||
figuraText.x(newX - 25);
|
||||
figuraText.y(newY + 18);
|
||||
|
||||
if (flecha) {
|
||||
// Actualiza flecha si existe
|
||||
const dx = atleta.direccion.x2 - atleta.direccion.x1;
|
||||
const dy = atleta.direccion.y2 - atleta.direccion.y1;
|
||||
flecha.points([newX, newY, newX + dx, newY + dy]);
|
||||
}
|
||||
|
||||
layer.batchDraw();
|
||||
});
|
||||
|
||||
layer.add(circle);
|
||||
atletasKonva[atleta.idPersonalizado] = {
|
||||
circle,
|
||||
text,
|
||||
figuraText,
|
||||
coordText
|
||||
};
|
||||
layer.add(text);
|
||||
layer.add(figuraText);
|
||||
layer.add(coordText);
|
||||
|
||||
if (atleta.direccion) {
|
||||
const linea = new Konva.Arrow({
|
||||
points: [start.x, start.y, start.x, start.y],
|
||||
stroke: 'black',
|
||||
fill: 'black',
|
||||
strokeWidth: 2,
|
||||
pointerLength: 10,
|
||||
pointerWidth: 10,
|
||||
dash: [4, 4]
|
||||
});
|
||||
|
||||
layer.add(dir);
|
||||
}
|
||||
atletasKonva[atleta.idPersonalizado] = {
|
||||
circle,
|
||||
text,
|
||||
figuraText,
|
||||
coordText,
|
||||
flecha
|
||||
};
|
||||
|
||||
layer.draw();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
window.activarModoDireccion = function(index) {
|
||||
|
@ -418,55 +429,22 @@ const linea = new Konva.Arrow({
|
|||
}, 100);
|
||||
}
|
||||
|
||||
function animarTransicion(nuevaFormacion) {
|
||||
function animarTransicion(nuevaFormacion) {
|
||||
// Limpiar capa y diccionario de atletas previos
|
||||
layer.destroyChildren();
|
||||
atletasKonva = {};
|
||||
|
||||
// Redibujar cuadrícula
|
||||
dibujarCuadricula(layer, piscinaWidth, piscinaHeight);
|
||||
|
||||
// Dibujar cada atleta
|
||||
nuevaFormacion.forEach(a => {
|
||||
const obj = atletasKonva[a.idPersonalizado];
|
||||
if (obj) {
|
||||
const { circle, text, figuraText, coordText } = obj;
|
||||
|
||||
// Animar círculo
|
||||
new Konva.Tween({
|
||||
node: circle,
|
||||
duration: 1.0,
|
||||
x: a.x,
|
||||
y: a.y,
|
||||
easing: Konva.Easings.EaseInOut,
|
||||
}).play();
|
||||
|
||||
// Mover textos en paralelo
|
||||
new Konva.Tween({
|
||||
node: text,
|
||||
duration: 1.0,
|
||||
x: a.x - 10,
|
||||
y: a.y - 7,
|
||||
easing: Konva.Easings.EaseInOut,
|
||||
}).play();
|
||||
|
||||
new Konva.Tween({
|
||||
node: figuraText,
|
||||
duration: 1.0,
|
||||
x: a.x - 25,
|
||||
y: a.y + 18,
|
||||
easing: Konva.Easings.EaseInOut,
|
||||
}).play();
|
||||
|
||||
new Konva.Tween({
|
||||
node: coordText,
|
||||
duration: 1.0,
|
||||
x: a.x - 35,
|
||||
y: a.y + 30,
|
||||
easing: Konva.Easings.EaseInOut,
|
||||
onUpdate: () => {
|
||||
const metros = convertirAMetros(a.x, a.y);
|
||||
coordText.text(`${metros.metrosX}m, ${metros.metrosY}m`);
|
||||
}
|
||||
}).play();
|
||||
|
||||
} else {
|
||||
dibujarAtleta(a);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
layer.draw();
|
||||
}
|
||||
|
||||
|
||||
|
||||
btnGuardarFormacion.addEventListener('click', async () => {
|
||||
|
@ -484,7 +462,7 @@ const linea = new Konva.Arrow({
|
|||
notasTacticas: notas,
|
||||
duracion: duracion || 0,
|
||||
atletas: formacionActual.map(a => ({
|
||||
atletaId: a.atletaId._id || a.atletaId,
|
||||
atletaId: a.atletaId,
|
||||
idPersonalizado: a.idPersonalizado,
|
||||
x: a.x,
|
||||
y: a.y,
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- NAV -->
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-primary sticky-top shadow-sm px-4 py-3">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand fw-bold text-white" href="#">SwimmingArt</a>
|
||||
|
@ -24,7 +23,6 @@
|
|||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- MAIN -->
|
||||
<main class="container-xl px-4 my-4">
|
||||
<section class="mb-4">
|
||||
<h2 id="tituloRutina" class="fw-bold fs-2 mb-2">Editor de Formación</h2>
|
||||
|
@ -34,10 +32,9 @@
|
|||
</div>
|
||||
</section>
|
||||
|
||||
<div class="row gx-4 gy-4 align-items-start">
|
||||
<!-- Formulario Atleta -->
|
||||
<div class="col-lg-5 col-xl-4">
|
||||
<div class="card p-4 h-100">
|
||||
<div class="row gx-4 gy-4">
|
||||
<div class="col-lg-4">
|
||||
<div class="card p-4 h-100 d-flex flex-column">
|
||||
<h5 class="fw-semibold mb-3 text-primary">Agregar Atleta</h5>
|
||||
|
||||
<div class="mb-3">
|
||||
|
@ -58,7 +55,6 @@
|
|||
<div class="mb-3">
|
||||
<label for="idPersonalizado" class="form-label">ID personalizado</label>
|
||||
<input type="text" id="idPersonalizado" class="form-control" placeholder="Ej: A, 1, V2" readonly>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
|
@ -82,13 +78,12 @@
|
|||
<input type="text" id="codigoElemento" class="form-control" placeholder="Ej: TRE 1A, H4...">
|
||||
</div>
|
||||
|
||||
<button id="btnAgregarAtleta" class="btn btn-primary w-100">Añadir Atleta</button>
|
||||
<button id="btnAgregarAtleta" class="btn btn-primary mt-auto">Añadir Atleta</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Piscina y Línea de Tiempo -->
|
||||
<div class="col-lg-7 col-xl-8">
|
||||
<div class="card p-4 h-100">
|
||||
<div class="col-lg-8 d-flex flex-column gap-3">
|
||||
<div class="card p-4">
|
||||
<h5 class="fw-semibold mb-3 text-primary">Piscina</h5>
|
||||
|
||||
<div class="mb-3">
|
||||
|
@ -100,21 +95,26 @@
|
|||
</select>
|
||||
</div>
|
||||
|
||||
<div id="piscinaContainer" class="border rounded p-2 mb-4" style="width: 100%; max-width: 100%; height: auto;">
|
||||
<div id="piscinaContainer" class="border rounded p-2 mb-4" style="width: 100%; height: auto;">
|
||||
<div id="piscina"></div>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<button id="btnEditarFormacion" class="btn btn-outline-secondary btn-sm" disabled>Editar formación</button>
|
||||
<div class="d-flex align-items-center justify-content-between flex-wrap gap-2 mb-3">
|
||||
<button id="btnEditarFormacion" class="btn btn-outline-secondary btn-sm">Editar formación</button>
|
||||
<div class="flex-grow-1">
|
||||
<div id="waveform" style="height: 80px;"></div>
|
||||
<div class="text-end">
|
||||
<button id="playPauseBtn" class="btn btn-outline-primary btn-sm">Reproducir</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class="form-label fw-semibold">Línea de Tiempo</label>
|
||||
<label class="form-label fw-semibold mt-3">Línea de Tiempo</label>
|
||||
<div id="lineaTiempo" class="timeline-placeholder d-flex flex-wrap gap-2"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Datos de Formación -->
|
||||
<div class="card p-4 mt-4">
|
||||
<h5 class="fw-semibold mb-3 text-primary">Datos de Formación</h5>
|
||||
<div class="row gy-3">
|
||||
|
@ -138,15 +138,6 @@
|
|||
<button id="btnGuardarFormacion" class="btn btn-primary">Guardar Formación</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Reproductor de audio -->
|
||||
<div class="card p-4 mt-4">
|
||||
<h5 class="fw-semibold mb-3 text-primary">Reproductor de Audio</h5>
|
||||
<div id="waveform" class="mb-3"></div>
|
||||
<div class="text-end">
|
||||
<button id="playPauseBtn" class="btn btn-outline-secondary">Reproducir</button>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<audio id="audioPlayer" class="d-none" controls></audio>
|
||||
|
|
|
@ -5,20 +5,19 @@ const User = require('./user');
|
|||
const multer = require('multer');
|
||||
const path = require('path');
|
||||
|
||||
// Configuración de almacenamiento para música
|
||||
const storage = multer.diskStorage({
|
||||
destination: function (req, file, cb) {
|
||||
cb(null, 'uploads/music');
|
||||
},
|
||||
filename: function (req, file, cb) {
|
||||
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
|
||||
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1e9);
|
||||
cb(null, uniqueSuffix + path.extname(file.originalname));
|
||||
}
|
||||
});
|
||||
|
||||
const upload = multer({
|
||||
storage: storage,
|
||||
limits: { fileSize: 10 * 1024 * 1024 }, // máx 10MB
|
||||
limits: { fileSize: 10 * 1024 * 1024 },
|
||||
fileFilter: function (req, file, cb) {
|
||||
if (!file.originalname.match(/\.(mp3)$/)) {
|
||||
return cb(new Error('Solo se permiten archivos .mp3'));
|
||||
|
@ -63,7 +62,7 @@ const routineSchema = new mongoose.Schema({
|
|||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
],
|
||||
createdAt: { type: Date, default: Date.now }
|
||||
});
|
||||
|
||||
|
@ -105,7 +104,7 @@ router.get('/:id', async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
// POST agregar formación
|
||||
// POST agregar formación (corregido y robusto)
|
||||
router.post('/:id/formations', async (req, res) => {
|
||||
const { id } = req.params;
|
||||
if (!mongoose.Types.ObjectId.isValid(id)) {
|
||||
|
@ -116,13 +115,29 @@ router.post('/:id/formations', async (req, res) => {
|
|||
const rutina = await Routine.findById(id);
|
||||
if (!rutina) return res.status(404).json({ error: 'Rutina no encontrada' });
|
||||
|
||||
rutina.formaciones.push(req.body);
|
||||
const formacionLimpia = {
|
||||
...req.body,
|
||||
atletas: req.body.atletas.map(a => {
|
||||
const rawId = typeof a.atletaId === 'object' && a.atletaId?.id ? a.atletaId.id : a.atletaId;
|
||||
|
||||
const nuevosAtletas = req.body.atletas.map(a => a.atletaId);
|
||||
return {
|
||||
...a,
|
||||
atletaId: mongoose.Types.ObjectId.isValid(rawId)
|
||||
? new mongoose.Types.ObjectId(rawId)
|
||||
: undefined
|
||||
};
|
||||
}).filter(a => a.atletaId !== undefined)
|
||||
};
|
||||
|
||||
nuevosAtletas.forEach(idAtleta => {
|
||||
if (!rutina.participantes.includes(idAtleta.toString())) {
|
||||
rutina.participantes.push(idAtleta);
|
||||
rutina.formaciones.push(formacionLimpia);
|
||||
|
||||
formacionLimpia.atletas.forEach(({ atletaId }) => {
|
||||
if (
|
||||
atletaId &&
|
||||
mongoose.Types.ObjectId.isValid(atletaId) &&
|
||||
!rutina.participantes.map(p => p.toString()).includes(atletaId.toString())
|
||||
) {
|
||||
rutina.participantes.push(atletaId);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -134,7 +149,6 @@ router.post('/:id/formations', async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
// GET formaciones de rutina
|
||||
router.get('/:id/formations', async (req, res) => {
|
||||
try {
|
||||
|
@ -217,12 +231,10 @@ router.post('/upload/music', upload.single('music'), (req, res) => {
|
|||
res.status(200).json({ url: fileUrl });
|
||||
});
|
||||
|
||||
const { Types } = require('mongoose');
|
||||
|
||||
router.delete('/:id', async (req, res) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!Types.ObjectId.isValid(id)) {
|
||||
if (!mongoose.Types.ObjectId.isValid(id)) {
|
||||
return res.status(400).json({ error: 'ID inválido' });
|
||||
}
|
||||
|
||||
|
@ -239,7 +251,6 @@ router.delete('/:id', async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
// GET rutinas asignadas a un atleta
|
||||
router.get('/atleta/:id', async (req, res) => {
|
||||
const atletaId = req.params.id;
|
||||
|
@ -254,7 +265,4 @@ router.get('/atleta/:id', async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
|
Loading…
Reference in New Issue