Skip to content

Commit

Permalink
fix issue with test on game service
Browse files Browse the repository at this point in the history
  • Loading branch information
pelazas committed May 1, 2024
1 parent 75fd513 commit f56e49a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 3 additions & 5 deletions game/gameservice/GameController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
let Game = require('./game-model');
const { createGame } = require('./queries/CreateGame');
const mongoose = require('mongoose');

let GameController = {
/* HACER EN USER - GET LAST GAME BY USER
Expand All @@ -11,10 +10,9 @@ let GameController = {
},*/
create: async (req, res) => {
try{
const { questions, players } = req.body;
console.log(questions, players)
const game = await createGame(questions, players);
res.json(game);
const { questions, players } = req.body;
const game = await createGame(questions, players);
res.json(game);
} catch(error){
res.status(500).json({ message: error.message });
}
Expand Down
10 changes: 6 additions & 4 deletions game/gameservice/gameservice.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// gameservice.js
const express = require('express');
const axios = require('axios');
const mongoose = require('mongoose');
const { createGame } = require('./queries/CreateGame');
const bodyParser = require('body-parser');
const GameController = require('./GameController');

const app = express();
const port = 8004;

// app.use(bodyParser.json());
app.use(express.json());
app.use(bodyParser.json());

const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb';
mongoose.connect(mongoUri);
Expand All @@ -29,4 +27,8 @@ const server = app.listen(port, () => {
console.log(`Question generator Service listening at http://localhost:${port}`);
});

server.on('close', () => {
mongoose.connection.close();
});

module.exports = server;
4 changes: 2 additions & 2 deletions game/gameservice/queries/CreateGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const uuid = require('uuid')
async function createGame(questions, players) {
try {
// Create a new Game instance
if(players.length == 0){
if(players.length === 0){
throw new Error('No players found')
}
if(players[0].uuid == null || players[0].uuid == undefined){
if(players[0].uuid === null || players[0].uuid === undefined){
throw new Error('No players found')
}
const game = new Game({
Expand Down

0 comments on commit f56e49a

Please sign in to comment.