Skip to content

Commit

Permalink
Made view work with the new endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Mario committed Apr 21, 2024
1 parent 489a687 commit 2f4e6a3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
37 changes: 17 additions & 20 deletions webapp/src/components/questionView/CreationHistoricalRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,26 @@ class CreationHistoricalRecord{


async sendRecord(user) {
const apiUrl = (process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000') + "/record";

const body = {
user:user,
game:this.record.game
}
try {
const apiUrl = (process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000') + "/record";

const body = {
user: user,
game: this.record.game
};

try {
const response = await axios.post(apiUrl, body, {
headers: {
'Content-Type': 'application/json'
}
headers: {
'Content-Type': 'application/json'
}
});

if (!response.ok) {
throw new Error('Error al enviar el registro');
}

const data = await response.json();
console.log(data);
} catch (error) {
console.error('Error:', error);
}


console.log('Registro enviado:', response.data);
} catch (error) {
console.error('Error al enviar el registro:', error.message);
}
}

}
export default CreationHistoricalRecord;
4 changes: 1 addition & 3 deletions webapp/src/components/ranking/RankingRetriever.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class RankingRetriever{
try {
const response = await axios.get(this.apiUrl + '/top10');//finding the top ten
const receivedTopTenRanking = await response.data;
console.log(receivedTopTenRanking)
return receivedTopTenRanking;
} catch (error) {
console.log(error)
Expand Down Expand Up @@ -80,8 +79,7 @@ class RankingRetriever{
try {
const response = await axios.get(this.apiUrl + '/'+user);//finding the top ten
const receivedMyRanking = await response.data;
console.log(receivedMyRanking)
return receivedMyRanking;
return receivedMyRanking.userCompetitiveStats;
} catch (error) {
console.log(error)
throw new Error(error);
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/ranking/RankingView.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const RankingView = () => {
}
}

if(rankingData==null){
if(rankingData==null || myRankingData == null){
getRanking();
}

Expand Down Expand Up @@ -57,7 +57,7 @@ const RankingView = () => {
<td colSpan="4"></td>
</tr>
<tr>
<td>0</td>
<td>{myRankingData.position}</td>
<td>{myRankingData._id}</td>
<td>{myRankingData.totalPoints}</td>
<td>{myRankingData.totalCompetitiveGames}</td>
Expand Down
7 changes: 5 additions & 2 deletions webapp/src/components/ranking/RankingView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,13 @@ describe('RankingView component', () => {
});

mockAxios.onGet('http://localhost:8000/record/ranking/myUser').reply(200,
{
{usersCompetitiveStats:
{
"_id": "myUser",
"totalPoints": 250,
"totalCompetitiveGames": 1
"totalCompetitiveGames": 1,
"position":10
}
}
);
const user = { username: 'myUser' };
Expand Down

0 comments on commit 2f4e6a3

Please sign in to comment.