Skip to content

Commit

Permalink
Merge pull request #100 from Arquisoft/97-mejorar-documentación-openapi
Browse files Browse the repository at this point in the history
97 mejorar documentación openapi
  • Loading branch information
CANCI0 authored Apr 7, 2024
2 parents 964ec70 + ddede46 commit c5e1804
Show file tree
Hide file tree
Showing 8 changed files with 651 additions and 112 deletions.
635 changes: 537 additions & 98 deletions gatewayservice/openapi.yaml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions questionservice/question-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ app.get("/questions", async (req, res) => {
.status(400)
.json({ error: `El límite de preguntas son ${MAX_QUESTIONS}` });
}
if(locale !== "en" && locale !== "es"){
locale = "es";
if(req.query.locale !== "en" && req.query.locale !== "es"){
req.query.locale = "es";
}
try {
var tematica = req.query.tematica ? req.query.tematica : "all";
var n = req.query.n ? req.query.n : 10;
var locale = req.query.locale ? req.query.locale : "es";
var locale = req.query.locale;
var data = gen.getQuestions(tematica, n, locale);
res.json(data);
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions questionservice/questionGen/GeneratorChooser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ class GeneratorChooser {
}
}

getQuestions(tematica, n) {
getQuestions(tematica, n, locale) {
if (tematica === "all") {
var questions = [];
for (let i = 0; i < n; i++) {
let rand = Math.floor(Math.random() * this.tematicas.length);
let randTematica = this.tematicas[rand];
let q = this.generators.get(randTematica).generateRandomQuestions(1);
let q = this.generators.get(randTematica).generateRandomQuestions(1, locale);
questions.push(q);
}
return questions.flat();
} else {
return this.generators.get(tematica).generateRandomQuestions(n);
return this.generators.get(tematica).generateRandomQuestions(n, locale);
}
}

Expand Down
3 changes: 1 addition & 2 deletions questionservice/questionGen/GenericGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,9 @@ class GenericGenerator {
default:
break;
}

questionObj.pregunta =
this.preguntasMap.get(propiedadPregunta)[locale].replace('%', entidadLabel);

return questionObj;
}

Expand Down
1 change: 0 additions & 1 deletion statsservice/stats-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ app.get("/stats", async (req, res) => {
res.json(data);

} catch (error) {

res.status(400).json({ error: "Error al obtener las estadísticas:"+error.message });
}
});
Expand Down
94 changes: 94 additions & 0 deletions users/userservice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions users/userservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.2.0"
},
"devDependencies": {
Expand Down
17 changes: 12 additions & 5 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 });
}});
Expand Down Expand Up @@ -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' });
}
});
Expand Down Expand Up @@ -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 });
Expand All @@ -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 });
Expand Down

0 comments on commit c5e1804

Please sign in to comment.