Funcionalidad para seleccionar atletas al crear rutina

This commit is contained in:
angel.alducin 2025-04-24 09:16:24 -06:00
parent 3b145e4022
commit acebb76bc0
1 changed files with 22 additions and 0 deletions
routes

22
routes/users.js Normal file
View File

@ -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;