forked from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from Arquisoft/97-mejorar-documentación-openapi
97 mejorar documentación openapi
- Loading branch information
Showing
8 changed files
with
651 additions
and
112 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ const express = require('express'); | |
const mongoose = require('mongoose'); | ||
const bcrypt = require('bcrypt'); | ||
const bodyParser = require('body-parser'); | ||
const { Group, User, UserGroup } = require('./user-model'); | ||
const jwt = require('jsonwebtoken'); | ||
const { User } = require('./user-model'); | ||
|
||
const app = express(); | ||
const port = 8001; | ||
|
@@ -67,7 +68,14 @@ app.post('/adduser', async (req, res) => { | |
}); | ||
|
||
await newUser.save(); | ||
res.json(newUser); | ||
|
||
const token = jwt.sign({ userId: newUser._id }, 'your-secret-key', { expiresIn: '1h' }); | ||
|
||
res.json({ | ||
username: newUser.username, | ||
createdAt: newUser.createdAt, | ||
token: token | ||
}); | ||
} catch (error) { | ||
res.status(400).json({ error: error.message }); | ||
}}); | ||
|
@@ -125,7 +133,6 @@ app.post('/users/add-friend', async (req, res) => { | |
|
||
res.json({ message: 'Friend added successfully' }); | ||
} catch (error) { | ||
console.error('Error adding friend:', error); | ||
res.status(500).json({ error: 'Internal Server Error' }); | ||
} | ||
}); | ||
|
@@ -165,7 +172,7 @@ app.get('/friends', async (req, res) => { | |
// Buscar al usuario por su nombre de usuario | ||
const user = await User.findOne({ username }); | ||
Check failure Code scanning / SonarCloud NoSQL operations should not be vulnerable to injection attacks High
Change this code to not construct database queries directly from user-controlled data. See more on SonarCloud
|
||
if (!user) { | ||
return res.status(500).json({ error: 'User not found' }); | ||
return res.status(404).json({ error: 'User not found' }); | ||
} | ||
// Devuelve la lista de amigos | ||
res.json({ friends: user.friends }); | ||
|
@@ -178,7 +185,7 @@ app.get('/friends', async (req, res) => { | |
app.get('/userInfo', async (req, res) => { | ||
try { | ||
const username = checkInput(req.query.user); | ||
const user = await User.findOne({username:username}); | ||
const user = await User.findOne({username:username}, {username: 1, createdAt: 1, games: 1}); | ||
res.json(user); | ||
} catch (error) { | ||
res.status(400).json({ error: error.message }); | ||
|