Skip to content

Commit

Permalink
change db again to localhost. Records now have correctAnswers: Number
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfdzs committed Apr 16, 2024
1 parent 4145632 commit 8e234f3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb+srv://wiq_es01b_admin:[email protected]/wiq?retryWrites=true&w=majority&appName=WIQ
MONGODB_URI: mongodb://localhost:27017/users

userservice:
container_name: userservice-${teamname:-defaultASW}
Expand All @@ -37,7 +37,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb+srv://wiq_es01b_admin:[email protected]/wiq?retryWrites=true&w=majority&appName=WIQ
MONGODB_URI: mongodb://localhost:27017/users

questionsgenerator:
container_name: questionsgenerator-${teamname:-defaultASW}
Expand All @@ -51,7 +51,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb+srv://wiq_es01b_admin:[email protected]/wiq?retryWrites=true&w=majority&appName=WIQ
MONGODB_URI: mongodb://localhost:27017/questions

record:
container_name: record-${teamname:-defaultASW}
Expand All @@ -66,7 +66,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb+srv://wiq_es01b_admin:[email protected]/wiq?retryWrites=true&w=majority&appName=WIQ
MONGODB_URI: mongodb://localhost:27017/records

gatewayservice:
container_name: gatewayservice-${teamname:-defaultASW}
Expand Down
6 changes: 3 additions & 3 deletions questionsgenerator/questionGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ class questionGenerator {

const tittle = template.tittle.replace('?', correctLabel);

const question = {
const question = new Question({
tittle: tittle,
answers: answers,
correctAnswer: correctAnswer,
category: category
}
});

await Question.create(question);
await question.save();

} else {
console.error("No templates.");
Expand Down
4 changes: 4 additions & 0 deletions record/historial-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const gameSchema = mongoose.Schema({
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
},
correctAnswers : {
type: Number,
required : true,
},
questions: {
type: [{
question: String,
Expand Down
9 changes: 8 additions & 1 deletion record/historial-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const port = 8004;
app.use(express.json());

//Connect to MongoDB
mongoose.connect(mongoURI, { useNewUrlParser: true, useUnifiedTopology: true });
mongoose.connect(mongoURI);

// Temporary storage for game questions
const gameQuestions = {};
Expand Down Expand Up @@ -49,10 +49,17 @@ app.post('/saveGameRecord', async (req, res) => {
return res.status(400).json({ error: "No game questions found for this user" });
}

var correctAnswers = 0;
gameQuestions[username].forEach(question => {
if(question.selectedAnswer === question.correctAnswer)
correctAnswers++;
});

const user = await User.findOne({ username });

const game = new Game({
user: user,
correctAnswers: correctAnswers,
questions: gameQuestions[username]
});

Expand Down
2 changes: 1 addition & 1 deletion users/authservice/auth-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ app.use(express.json());
const mongoURI = process.env.MONGODB_URI;
console.log("debajo de la const: " + mongoURI);

mongoose.connect(mongoURI, { useNewUrlParser: true, useUnifiedTopology: true});
mongoose.connect(mongoURI);

// Function to validate required fields in the request body
function validateRequiredFields(req, requiredFields) {
Expand Down
4 changes: 2 additions & 2 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ app.use(bodyParser.json());
// Connect to MongoDB
const mongoURI = process.env.MONGODB_URI;

mongoose.connect(mongoURI, { useNewUrlParser: true, useUnifiedTopology: true});
mongoose.connect(mongoURI);

// Function to validate required fields in the request body
function validateRequiredFields(req, requiredFields) {
Expand Down Expand Up @@ -60,7 +60,7 @@ app.post('/adduser', async (req, res) => {
password: hashedPassword,
});

await User.create(newUser);
await newUser.save();
res.json(newUser);
} catch (error) {
res.status(400).json({ error: error.message });
Expand Down

0 comments on commit 8e234f3

Please sign in to comment.