From 059364a742dede6995cea609d56f0bae64c0e853 Mon Sep 17 00:00:00 2001 From: adrian Date: Sun, 7 Apr 2024 21:18:23 +0200 Subject: [PATCH 1/2] fixed ranking bugs --- users/userservice/package-lock.json | 12 +----------- users/userservice/package.json | 3 +-- users/userservice/user-service.js | 9 +++------ webapp/src/components/ranking/RankingLayout.jsx | 4 ++-- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/users/userservice/package-lock.json b/users/userservice/package-lock.json index 56afbed..f21b26c 100644 --- a/users/userservice/package-lock.json +++ b/users/userservice/package-lock.json @@ -12,8 +12,7 @@ "bcrypt": "^5.1.1", "body-parser": "^1.20.2", "express": "^4.18.2", - "mongoose": "^8.0.4", - "ramda": "^0.29.1" + "mongoose": "^8.0.4" }, "devDependencies": { "jest": "^29.7.0", @@ -4525,15 +4524,6 @@ "integrity": "sha512-kJt5qhMxoszgU/62PLP1CJytzd2NKetjSRnyuj31fDd3Rlcz3fzlFdFLD1SItunPwyqEOkca6GbV612BWfaBag==", "dev": true }, - "node_modules/ramda": { - "version": "0.29.1", - "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.29.1.tgz", - "integrity": "sha512-OfxIeWzd4xdUNxlWhgFazxsA/nl3mS4/jGZI5n00uWOoSSFRhC1b6gl6xvmzUamgmqELraWp0J/qqVlXYPDPyA==", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/ramda" - } - }, "node_modules/range-parser": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", diff --git a/users/userservice/package.json b/users/userservice/package.json index 2113d2f..3da52b0 100644 --- a/users/userservice/package.json +++ b/users/userservice/package.json @@ -21,8 +21,7 @@ "bcrypt": "^5.1.1", "body-parser": "^1.20.2", "express": "^4.18.2", - "mongoose": "^8.0.4", - "ramda": "^0.29.1" + "mongoose": "^8.0.4" }, "devDependencies": { "jest": "^29.7.0", diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index 7cdf1c3..e4dcff6 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -3,7 +3,6 @@ const express = require('express'); const mongoose = require('mongoose'); const bcrypt = require('bcrypt'); const bodyParser = require('body-parser'); -const R = require('ramda'); const User = require('./user-model') @@ -45,10 +44,8 @@ app.get('/rankings/:filter', async (req, res) => { const userRanking = getRankingFor(loggedUser) */ const category = req.params.filter; - const usersRanking = (await User.find()); - const ascendingUsers = R.sortBy(R.prop("ranking." + category + ".points"), usersRanking); - const sortedUsers = R.reverse(ascendingUsers); - const sortedRanking = sortedUsers.map( (user, index) => { + const usersRanking = (await User.find()).sort((a, b) => b.ranking[category].points - a.ranking[category].points) + .map((user, index) => { return { // User global data name: user.username, @@ -61,7 +58,7 @@ app.get('/rankings/:filter', async (req, res) => { }) //res.json(userRanking, usersRanking) - res.json(sortedRanking) + res.status(200).json(usersRanking) } catch (error) { res.status(400).json({ error: error.message }); } diff --git a/webapp/src/components/ranking/RankingLayout.jsx b/webapp/src/components/ranking/RankingLayout.jsx index 63377d3..ce54a5d 100644 --- a/webapp/src/components/ranking/RankingLayout.jsx +++ b/webapp/src/components/ranking/RankingLayout.jsx @@ -34,8 +34,8 @@ const RankingsLayout = () => { Monuments From 747e8296976749aefab65a36f7c8fee87ee75028 Mon Sep 17 00:00:00 2001 From: adrian Date: Sun, 7 Apr 2024 21:23:12 +0200 Subject: [PATCH 2/2] added tourist attractions to rankings --- webapp/src/components/ranking/RankingLayout.jsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/webapp/src/components/ranking/RankingLayout.jsx b/webapp/src/components/ranking/RankingLayout.jsx index ce54a5d..666b88e 100644 --- a/webapp/src/components/ranking/RankingLayout.jsx +++ b/webapp/src/components/ranking/RankingLayout.jsx @@ -37,6 +37,10 @@ const RankingsLayout = () => { onClick={() => handleFilterClick('foods')}> Foods +