Skip to content

Commit 2a8dd38

Browse files
committed
merge finalfixes to master
2 parents 448ec2e + b0f8d32 commit 2a8dd38

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Backend/controllers/quizController.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,15 @@ export const getFinishedQuizzes = async(req, res) => {
131131
}
132132
export const updateFinished = async (req, res) => {
133133
try {
134-
const quizId = req.params.quizId;
134+
const userId = req.params.id;
135+
const quizId = req.body.quizId;
135136

136137
const updatedQuiz = await Quiz.findOneAndUpdate(
137-
{ _id: quizId }, // filter by quiz ID and user ID
138-
{ $set: { completed: true } }, // update `completed` to true
139-
{ new: true } // return the updated document
140-
);
138+
{ _id: quizId, user: userId },
139+
{ $set: { completed: true } },
140+
{ new: true }
141+
);
142+
console.log(updatedQuiz);
141143
if (!updatedQuiz) {
142144
return res.status(404).json({ error: 'Quiz not found or does not belong to the user' });
143145
}

Frontend/src/Pages/Results/Results.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import "../../Styles/Pages/Results/Results.css"
22
import { Podium, ResultCard } from "../../Components/Components"
33
import { useState, useEffect } from "react"
4+
import { useNavigate } from "react-router-dom"
45

56
const URI = import.meta.env.VITE_APP_URI
67
const userId = JSON.parse(localStorage.getItem('id'));
@@ -9,6 +10,10 @@ const Results = () => {
910
const win = "You beat the Quiz!"
1011
const lose = "Better luck next time..."
1112
const monstersSlain = localStorage.getItem('results') || 0;
13+
const navigate = useNavigate()
14+
const goHome =() =>{
15+
navigate('/home')
16+
}
1217
console.log("Monsters slain", monstersSlain)
1318
const [totalCoins, setTotalCoins] = useState(0)
1419

@@ -51,7 +56,7 @@ const Results = () => {
5156
</div>
5257
</div>
5358
</div>
54-
<button className="from-results-to-home">Continue</button>
59+
<button className="from-results-to-home" onClick={goHome}>Continue</button>
5560
</div>
5661
</>
5762
)

0 commit comments

Comments
 (0)