add seeding for team-service
This commit is contained in:
@@ -19,7 +19,7 @@ Document all AI prompts and track which files were modified as a result of each
|
|||||||
### Prompt Entry Format
|
### Prompt Entry Format
|
||||||
Each prompt entry should follow this structure:
|
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 `<br><br>` after the prompt text
|
2. **Separator**: Add `<br><br>` after the prompt text
|
||||||
3. **File changes header**: Add the line `Folgende Dateien wurden in diesem Prompt verändert:`
|
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 + `-`)
|
4. **File list**: List all affected files as indented sub-bullets (4 spaces + `-`)
|
||||||
|
|||||||
7
backend_splatournament_manager/dist/csv/teams.csv
vendored
Normal file
7
backend_splatournament_manager/dist/csv/teams.csv
vendored
Normal file
@@ -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
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
import { Team, TournamentTeam, TeamMember } from '../models/team';
|
import { Team, TournamentTeam, TeamMember } from '../models/team';
|
||||||
import { Database, RunResult } from 'sqlite3';
|
import { Database, RunResult } from 'sqlite3';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
export class TeamService {
|
export class TeamService {
|
||||||
private db: Database;
|
private db: Database;
|
||||||
|
private csvFilename = 'csv/teams.csv';
|
||||||
|
|
||||||
constructor(db: Database) {
|
constructor(db: Database) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
@@ -38,6 +41,8 @@ export class TeamService {
|
|||||||
FOREIGN KEY (userId) REFERENCES Users (id) ON DELETE CASCADE,
|
FOREIGN KEY (userId) REFERENCES Users (id) ON DELETE CASCADE,
|
||||||
UNIQUE (teamId, userId)
|
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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user