From 722df5105c098f404e09e884a817acf92d939648 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Sun, 29 Jun 2025 23:55:33 -0700 Subject: add route to list supported games --- backend/package.json | 5 ++++- backend/pnpm-lock.yaml | 3 +++ backend/prisma/seed.ts | 8 +++----- backend/schema.prisma | 11 ++++++----- backend/src/index.ts | 3 +++ backend/src/routes/gameRoutes.ts | 19 +++++++++++++++++++ 6 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 backend/src/routes/gameRoutes.ts diff --git a/backend/package.json b/backend/package.json index 4686f00..b5873c7 100644 --- a/backend/package.json +++ b/backend/package.json @@ -5,9 +5,11 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "seed": "ts-node prisma/seed.ts", "dev": "ts-node-dev src/index.ts" }, + "prisma": { + "seed": "ts-node prisma/seed.ts" + }, "keywords": [], "author": "", "license": "ISC", @@ -31,6 +33,7 @@ "@types/node": "^24.0.3", "@types/sqlite3": "^5.1.0", "prisma": "^6.10.1", + "ts-node": "^10.9.2", "ts-node-dev": "^2.0.0", "typescript": "^5.8.3" } diff --git a/backend/pnpm-lock.yaml b/backend/pnpm-lock.yaml index f84146a..2122141 100644 --- a/backend/pnpm-lock.yaml +++ b/backend/pnpm-lock.yaml @@ -60,6 +60,9 @@ importers: prisma: specifier: ^6.10.1 version: 6.10.1(typescript@5.8.3) + ts-node: + specifier: ^10.9.2 + version: 10.9.2(@types/node@24.0.7)(typescript@5.8.3) ts-node-dev: specifier: ^2.0.0 version: 2.0.0(@types/node@24.0.7)(typescript@5.8.3) diff --git a/backend/prisma/seed.ts b/backend/prisma/seed.ts index d0e3c73..4222708 100644 --- a/backend/prisma/seed.ts +++ b/backend/prisma/seed.ts @@ -1,14 +1,12 @@ -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from "@prisma/client"; const prisma = new PrismaClient(); async function main() { await prisma.game.createMany({ - data: [ - { name: 'Dancerush' }, - ], + data: [{ internalName: "dancerush", formattedName: "DANCERUSH STARDOM", description: "A suffle dancing game from KONAMI"}], }); - console.log('Initial seed data inserted'); + console.log("Initial seed data inserted"); } main() diff --git a/backend/schema.prisma b/backend/schema.prisma index 88a131f..3b91f85 100644 --- a/backend/schema.prisma +++ b/backend/schema.prisma @@ -26,16 +26,17 @@ model Session { } model Game { - id Int @id @default(autoincrement()) - name String @unique + internalName String @id + formattedName String + description String scores Score[] } model Score { id Int @id @default(autoincrement()) - gameId Int + gameInternalName String userId Int - data Json // arbitrary data in json format - game Game @relation(fields: [gameId], references: [id]) + data Json + game Game @relation(fields: [gameInternalName], references: [internalName]) user User @relation(fields: [userId], references: [id]) } diff --git a/backend/src/index.ts b/backend/src/index.ts index 3e2c559..c776ce1 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -8,6 +8,7 @@ import { startSessionCleanup } from './utils/session'; // Routes import * as authRoutes from './routes/authRoutes'; import * as userRoutes from './routes/userRoutes'; +import * as gameRoutes from './routes/gameRoutes'; const app = express(); const port = 5000; @@ -49,6 +50,8 @@ app.post('/api/logout', requireAuth, authRoutes.handleLogout); app.get('/api/me', userRoutes.handleMeRoute); app.get('/api/session', userRoutes.handleGetCurrentSession); +app.get('/api/supportedGames', gameRoutes.handleGetSupportedGames); + app.listen(port, () => { console.log(`Server listening on port ${port}`); }); diff --git a/backend/src/routes/gameRoutes.ts b/backend/src/routes/gameRoutes.ts new file mode 100644 index 0000000..26e7171 --- /dev/null +++ b/backend/src/routes/gameRoutes.ts @@ -0,0 +1,19 @@ +import express from 'express'; +import { prisma } from '../config/db'; + +export const handleGetSupportedGames = async (req: express.Request, res: express.Response) => { + try { + const supportedGames = await prisma.game.findMany({ + select: { + internalName: true, + formattedName: true, + description: true + } + }); + res.status(200).json(supportedGames); + + } catch (error) { + console.error('Supported Games endpoint error:', error); + res.status(500).json({ error: 'Internal server error. Unable to fetch supported games' }); + } +} -- cgit v1.2.3