Compare commits
2 Commits
ee0c32ca49
...
acebb76bc0
Author | SHA1 | Date |
---|---|---|
|
acebb76bc0 | |
|
3b145e4022 |
1
.env
1
.env
|
@ -1 +1,2 @@
|
|||
MONGODB_URI=mongodb://127.0.0.1:27017/swimartdb
|
||||
MONGO_URI=mongodb://localhost:27017/swimartdb
|
||||
|
|
|
@ -138,3 +138,30 @@ async function saveRoutine() {
|
|||
alert('❌ Error: ' + result.error);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
const listaAtletas = document.getElementById('listaAtletas');
|
||||
|
||||
try {
|
||||
const res = await fetch('/users/athletes');
|
||||
const atletas = await res.json();
|
||||
|
||||
atletas.forEach(atleta => {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'form-check';
|
||||
|
||||
div.innerHTML = `
|
||||
<input class="form-check-input" type="checkbox" value="${atleta._id}" id="atleta-${atleta._id}">
|
||||
<label class="form-check-label" for="atleta-${atleta._id}">
|
||||
${atleta.name}
|
||||
</label>
|
||||
`;
|
||||
|
||||
listaAtletas.appendChild(div);
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
console.error('Error al cargar atletas:', err);
|
||||
listaAtletas.innerHTML = '<p class="text-danger">No se pudieron cargar los atletas.</p>';
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { MongoClient } = require('mongodb');
|
||||
const uri = process.env.MONGO_URI;
|
||||
const client = new MongoClient(uri);
|
||||
|
||||
router.get('/athletes', async (req, res) => {
|
||||
try {
|
||||
await client.connect();
|
||||
const db = client.db('swimartdb');
|
||||
const athletes = await db.collection('users')
|
||||
.find({ role: 'athlete' })
|
||||
.project({ _id: 1, name: 1 })
|
||||
.toArray();
|
||||
res.json(athletes);
|
||||
} catch (err) {
|
||||
console.error('Error al obtener atletas:', err);
|
||||
res.status(500).json({ error: 'Error interno del servidor' });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
|
@ -16,6 +16,10 @@ app.use(express.static(path.join(__dirname, 'public')));
|
|||
const authRoutes = require('./routes/auth');
|
||||
const routineRoutes = require('./routes/routines');
|
||||
|
||||
// Deteccion rol atleta
|
||||
const userRoutes = require('./routes/users');
|
||||
app.use('/users', userRoutes);
|
||||
|
||||
app.use('/auth', authRoutes); // login, register
|
||||
app.use('/routines', routineRoutes); // rutinas
|
||||
|
||||
|
|
Loading…
Reference in New Issue