From 7fe146f97ddd3f5a8d0c1a996a73cb296c28b9cc Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Mon, 7 Jul 2025 01:07:34 -0700 Subject: implement score deletion --- backend/schema.prisma | 4 ++-- backend/src/index.ts | 3 ++- backend/src/routes/score.ts | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) (limited to 'backend') 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, -- cgit v1.2.3