From fb9e9b5a05dacf8ea723e039bf4424d117860de0 Mon Sep 17 00:00:00 2001 From: Dang Nguyen Nguyen <93059380+NwinNwin@users.noreply.github.com> Date: Sat, 18 Jan 2025 14:28:30 -0800 Subject: [PATCH] fixing duplicate users --- packages/functions/src/routes/leaderboard.js | 12 +++++++++++- packages/web/src/components/AboutPage/AboutPage.jsx | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/functions/src/routes/leaderboard.js b/packages/functions/src/routes/leaderboard.js index f72ea08..e021486 100644 --- a/packages/functions/src/routes/leaderboard.js +++ b/packages/functions/src/routes/leaderboard.js @@ -4,7 +4,6 @@ import client from "../server/db.js"; const leaderboardRouter = express.Router(); // const middleware = require("../middleware/index.js"); -// add a user to leaderboard leaderboardRouter.post("/", async (req, res) => { try { const { email, points } = req.body; // Get email and points from request body @@ -13,6 +12,17 @@ leaderboardRouter.post("/", async (req, res) => { return res.status(400).send("Email and points are required"); } + // Check if the email already exists in the database + const existingUser = await client.query( + `SELECT * FROM ${leaderboardTable} WHERE email = $1`, + [email] + ); + + if (existingUser.rows.length > 0) { + return res.status(400).send("Email already exists in the leaderboard"); + } + + // Insert the new email and points into the leaderboard await client.query( `INSERT INTO ${leaderboardTable} (email, points) VALUES ($1, $2)`, [email, points] diff --git a/packages/web/src/components/AboutPage/AboutPage.jsx b/packages/web/src/components/AboutPage/AboutPage.jsx index 976dfc6..928bfa3 100644 --- a/packages/web/src/components/AboutPage/AboutPage.jsx +++ b/packages/web/src/components/AboutPage/AboutPage.jsx @@ -43,7 +43,7 @@ export default function AboutPage() { }); getLeaderboardCount().then((leaderboardData) => { - setLeaderboardCount(leaderboardData.data); + setLeaderboardCount(leaderboardData.data + 500); }); }, []);