aboutsummaryrefslogtreecommitdiffstats
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/schema.prisma4
-rw-r--r--backend/src/index.ts3
-rw-r--r--backend/src/routes/score.ts30
3 files changed, 34 insertions, 3 deletions
diff --git a/backend/schema.prisma b/backend/schema.prisma
index a613628..f51093b 100644
--- a/backend/schema.prisma
+++ b/backend/schema.prisma
@@ -34,9 +34,9 @@ model Game {
}
model Score {
- id Int @id @default(autoincrement())
+ id Int @id @default(autoincrement()) // This is the numerical score number (global)
gameInternalName String
- chartId String
+ chartId String // Refers to the unqiue chart identifier
userId Int
timestamp BigInt // in UNIX milliseconds
data Json
diff --git a/backend/src/index.ts b/backend/src/index.ts
index ec38ee6..114dfac 100644
--- a/backend/src/index.ts
+++ b/backend/src/index.ts
@@ -54,7 +54,8 @@ app.get('/api/session', userRoutes.handleGetCurrentSession);
app.get('/api/supportedGames', gameRoutes.handleGetSupportedGames);
app.post('/api/uploadScore', requireAuth, scoreRoutes.handleScoreUpload);
-app.get('/api/scores', scoreRoutes.handleGetScores);
+app.get('/api/scores', requireAuth, scoreRoutes.handleGetScores);
+app.delete('/api/scores', requireAuth, scoreRoutes.handleScoreDeletion);
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
diff --git a/backend/src/routes/score.ts b/backend/src/routes/score.ts
index d0fdc56..54e4784 100644
--- a/backend/src/routes/score.ts
+++ b/backend/src/routes/score.ts
@@ -110,6 +110,36 @@ export const handleScoreUpload = async (
}
};
+export const handleScoreDeletion = async (
+ req: express.Request,
+ res: express.Response,
+) => {
+ try {
+ const { userId, internalGameName, scoreId } = req.query;
+ if (!userId || !internalGameName || !scoreId) {
+ return res.status(400).json({ error: "Missing required parameters" });
+ }
+
+ const userIdNumber = parseInt(userId as string);
+ const scoreIdNumber = parseInt(scoreId as string);
+
+ await prisma.score.deleteMany({
+ where: {
+ userId: userIdNumber,
+ gameInternalName: internalGameName as string,
+ id: scoreIdNumber,
+ },
+ });
+
+ res.status(200).json({ message: "Scores deleted successfully" });
+ } catch (error) {
+ console.error("Score deletion endpoint error:", error);
+ res
+ .status(500)
+ .json({ error: "Internal server error. Unable to delete scores" });
+ }
+};
+
export const handleGetScores = async (
req: express.Request,
res: express.Response,
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage