From 9408889ba681eec5697e032890544af902dd5631 Mon Sep 17 00:00:00 2001 From: Tim Kainz Date: Wed, 11 Mar 2026 18:31:33 +0100 Subject: [PATCH] add seeding for team-service --- .../write-prompts-md.instructions.md | 2 +- .../dist/csv/teams.csv | 7 ++++ .../src/services/team-service.ts | 36 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 backend_splatournament_manager/dist/csv/teams.csv diff --git a/.github/instructions/write-prompts-md.instructions.md b/.github/instructions/write-prompts-md.instructions.md index 7be53d5..8068d4e 100644 --- a/.github/instructions/write-prompts-md.instructions.md +++ b/.github/instructions/write-prompts-md.instructions.md @@ -19,7 +19,7 @@ Document all AI prompts and track which files were modified as a result of each ### Prompt Entry Format Each prompt entry should follow this structure: -1. **Prompt text**: Write the actual prompt as a bullet point while rewriting it so it's nicer to read but still closely resembles the original (`-`) +1. **Prompt text**: Write the actual prompt as a bullet point while only fixing grammatical errors (`-`) 2. **Separator**: Add `

` after the prompt text 3. **File changes header**: Add the line `Folgende Dateien wurden in diesem Prompt verändert:` 4. **File list**: List all affected files as indented sub-bullets (4 spaces + `-`) diff --git a/backend_splatournament_manager/dist/csv/teams.csv b/backend_splatournament_manager/dist/csv/teams.csv new file mode 100644 index 0000000..52f1196 --- /dev/null +++ b/backend_splatournament_manager/dist/csv/teams.csv @@ -0,0 +1,7 @@ +name,tag,description +Team Alpha,ALPH,A competitive esports team +Team Beta,BETA,New challengers on the scene +Team Gamma,GAMM,Veteran tournament winners +Team Delta,DELT,Rising stars in the community +Team Epsilon,EPSI,Strategic gameplay specialists +Team Zeta,ZETA,Fast-paced aggressive players diff --git a/backend_splatournament_manager/src/services/team-service.ts b/backend_splatournament_manager/src/services/team-service.ts index 83d4484..823ef07 100644 --- a/backend_splatournament_manager/src/services/team-service.ts +++ b/backend_splatournament_manager/src/services/team-service.ts @@ -1,8 +1,11 @@ import { Team, TournamentTeam, TeamMember } from '../models/team'; import { Database, RunResult } from 'sqlite3'; +import fs from 'fs'; +import path from 'path'; export class TeamService { private db: Database; + private csvFilename = 'csv/teams.csv'; constructor(db: Database) { this.db = db; @@ -38,6 +41,8 @@ export class TeamService { FOREIGN KEY (userId) REFERENCES Users (id) ON DELETE CASCADE, UNIQUE (teamId, userId) )`); + + this.seedDb(); }); } @@ -230,5 +235,36 @@ export class TeamService { ); }); } + + private seedDb() { + const csvPath = path.join(process.cwd(), "dist", this.csvFilename); + if (fs.existsSync(csvPath)) { + this.db.get(`SELECT COUNT(*) as count FROM Teams`, (err: Error | null, row: any) => { + if (err) { + console.error('Error checking Teams table:', err); + return; + } + if (row.count === 0) { + fs.readFile(csvPath, 'utf8', (err, data) => { + if (err) { + console.error('Error reading teams CSV:', err); + return; + } + const lines = data.split('\n'); + lines.shift(); + const stmt = this.db.prepare(`INSERT INTO Teams (name, tag, description) VALUES (?, ?, ?)`); + lines.forEach((line: string) => { + const [name, tag, description] = line.split(','); + if (name && tag) { + stmt.run([name.trim(), tag.trim(), description?.trim() || '']); + } + }); + stmt.finalize(); + console.log('Teams seeded successfully'); + }); + } + }); + } + } }