Skip to content

Commit

Permalink
structure development of logic to implement
Browse files Browse the repository at this point in the history
  • Loading branch information
pelazas committed Mar 5, 2024
1 parent ab72d7c commit 43f96fe
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
11 changes: 11 additions & 0 deletions game/gameservice/game-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const mongoose = require('mongoose');

const gameSchema = new mongoose.Schema({
// ONE TO MANY CON QUESTIONS
// ONE TO MANY CON USERS
});


const Game = mongoose.model('Game', gameSchema);

module.exports = Game
5 changes: 5 additions & 0 deletions game/gameservice/gameservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ app.get('/', (req, res) => {
"hi": "game service"
});
});
/*
PETICIONES A HACER:
1. Crear game dado un array de preguntas y un array de usuarios.
*/

const server = app.listen(port, () => {
console.log(`Question generator Service listening at http://localhost:${port}`);
Expand Down
7 changes: 7 additions & 0 deletions users/userservice/user-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ const userSchema = new mongoose.Schema({
type: Date,
default: Date.now,
},

// many to one con group
// many to one con lastgame
// int preguntas acertadas
// int preguntas falladas
// int puntuacion

});

const User = mongoose.model('User', userSchema);
Expand Down
16 changes: 9 additions & 7 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ app.use(bodyParser.json());
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb';
mongoose.connect(mongoUri);



// Function to validate required fields in the request body
function validateRequiredFields(req, requiredFields) {
for (const field of requiredFields) {
if (!(field in req.body)) {
Expand All @@ -28,10 +25,8 @@ function validateRequiredFields(req, requiredFields) {

app.post('/adduser', async (req, res) => {
try {
// Check if required fields are present in the request body
validateRequiredFields(req, ['username', 'password']);

// Encrypt the password before saving it
const hashedPassword = await bcrypt.hash(req.body.password, 10);

const newUser = new User({
Expand All @@ -45,13 +40,20 @@ app.post('/adduser', async (req, res) => {
res.status(400).json({ error: error.message });
}});


/*
FUNCIONES A HACER:
1. Update User al finalizar una partida -> puntos, lastGame, preguntas acertadas/falladas
2. Obtener ultimo juego por usuario
3. Obtener estadisticas por usuario (puntos, partidas jugadas, preguntas acertadas/falladas)
4. Checkear si existe usuario con username
*/

const server = app.listen(port, () => {
console.log(`User Service listening at http://localhost:${port}`);
});

// Listen for the 'close' event on the Express.js server
server.on('close', () => {
// Close the Mongoose connection
mongoose.connection.close();
});

Expand Down

0 comments on commit 43f96fe

Please sign in to comment.