Funcionalidad para seleccionar atletas al crear rutina
This commit is contained in:
parent
3b145e4022
commit
acebb76bc0
routes
|
@ -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;
|
Loading…
Reference in New Issue