From 43f96fee6e9a63dd7bcb1bc8f0929a1ee1dc25f2 Mon Sep 17 00:00:00 2001 From: carlospelazas Date: Tue, 5 Mar 2024 19:35:04 +0100 Subject: [PATCH] structure development of logic to implement --- game/gameservice/game-model.js | 11 +++++++++++ game/gameservice/gameservice.js | 5 +++++ users/userservice/user-model.js | 7 +++++++ users/userservice/user-service.js | 16 +++++++++------- 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 game/gameservice/game-model.js diff --git a/game/gameservice/game-model.js b/game/gameservice/game-model.js new file mode 100644 index 0000000..c1f5882 --- /dev/null +++ b/game/gameservice/game-model.js @@ -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 \ No newline at end of file diff --git a/game/gameservice/gameservice.js b/game/gameservice/gameservice.js index 0826c5d..766d943 100644 --- a/game/gameservice/gameservice.js +++ b/game/gameservice/gameservice.js @@ -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}`); diff --git a/users/userservice/user-model.js b/users/userservice/user-model.js index 71d81b5..07700b1 100644 --- a/users/userservice/user-model.js +++ b/users/userservice/user-model.js @@ -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); diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index be95842..4457bfe 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -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)) { @@ -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({ @@ -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(); });