63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
const express = require('express');
|
|
const mongoose = require('mongoose');
|
|
const router = express.Router();
|
|
|
|
const routineSchema = new mongoose.Schema({
|
|
title: String,
|
|
createdBy: { type: String, default: "coach-id-ejemplo" },
|
|
language: { type: String, enum: ['es', 'en', 'fr'], default: 'es' },
|
|
duration: Number,
|
|
musicUrl: { type: String, default: "" },
|
|
nombreCompetencia: String,
|
|
tipoCompetencia: { type: String, enum: ['libre', 'técnica'], default: 'libre' },
|
|
modalidad: { type: String, enum: ['solo', 'duo', 'equipo'], default: 'solo' },
|
|
participantes: [
|
|
{
|
|
atletaId: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
|
|
rol: String,
|
|
idPersonalizado: String
|
|
}
|
|
],
|
|
elements: [
|
|
{
|
|
code: String,
|
|
startTime: Number,
|
|
duration: Number,
|
|
position: {
|
|
x: Number,
|
|
y: Number
|
|
}
|
|
}
|
|
],
|
|
createdAt: { type: Date, default: Date.now }
|
|
});
|
|
|
|
const Routine = mongoose.model('Routine', routineSchema);
|
|
|
|
router.post('/', async (req, res) => {
|
|
try {
|
|
console.log("📩 Recibido en backend:", JSON.stringify(req.body, null, 2)); // 👈 LOG
|
|
|
|
const nuevaRutina = new Routine(req.body);
|
|
await nuevaRutina.save();
|
|
|
|
console.log("✅ Rutina guardada.");
|
|
res.status(201).json({ message: 'Rutina creada correctamente' });
|
|
} catch (err) {
|
|
console.error("❌ Error al guardar rutina:", err); // 👈 ERROR DETALLADO
|
|
res.status(500).json({ error: 'Error al guardar la rutina' });
|
|
}
|
|
});
|
|
|
|
// Ruta para obtener todas las rutinas
|
|
router.get('/routines', async (req, res) => {
|
|
try {
|
|
const routines = await Routine.find(); // Obtén todas las rutinas de la base de datos
|
|
res.json(routines);
|
|
} catch (error) {
|
|
res.status(500).json({ message: 'Error al obtener las rutinas', error });
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|