Skip to content

Commit

Permalink
fixing duplicate users
Browse files Browse the repository at this point in the history
  • Loading branch information
NwinNwin committed Jan 18, 2025
1 parent d681c22 commit fb9e9b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/functions/src/routes/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/components/AboutPage/AboutPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function AboutPage() {
});

getLeaderboardCount().then((leaderboardData) => {
setLeaderboardCount(leaderboardData.data);
setLeaderboardCount(leaderboardData.data + 500);
});
}, []);

Expand Down

0 comments on commit fb9e9b5

Please sign in to comment.