limit team members to 4 and display member count in list

This commit is contained in:
2026-03-11 18:40:28 +01:00
parent 9408889ba6
commit 4074d0287c
5 changed files with 68 additions and 24 deletions

View File

@@ -1,7 +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
Team Alpha,ALP,A competitive esports team
Team Beta,BET,New challengers on the scene
Team Gamma,GAM,Veteran tournament winners
Team Delta,DEL,Rising stars in the community
Team Epsilon,EPS,Strategic gameplay specialists
Team Zeta,ZET,Fast-paced aggressive players
1 name tag description
2 Team Alpha ALPH ALP A competitive esports team
3 Team Beta BETA BET New challengers on the scene
4 Team Gamma GAMM GAM Veteran tournament winners
5 Team Delta DELT DEL Rising stars in the community
6 Team Epsilon EPSI EPS Strategic gameplay specialists
7 Team Zeta ZETA ZET Fast-paced aggressive players

View File

@@ -48,10 +48,16 @@ export class TeamService {
getAllTeams(): Promise<Team[]> {
return new Promise<Team[]>((resolve, reject) => {
this.db.all(`SELECT * FROM Teams`, (err: Error | null, rows: Team[]) => {
if (err) return reject(err);
resolve(rows);
});
this.db.all(
`SELECT t.*, COUNT(tm.id) as memberCount
FROM Teams t
LEFT JOIN TeamMembers tm ON t.id = tm.teamId
GROUP BY t.id`,
(err: Error | null, rows: Team[]) => {
if (err) return reject(err);
resolve(rows);
}
);
});
}
@@ -165,18 +171,30 @@ export class TeamService {
addTeamMember(teamId: number, userId: number, role: 'owner' | 'member' = 'member'): Promise<TeamMember> {
return new Promise<TeamMember>((resolve, reject) => {
const stmt = this.db.prepare(`INSERT INTO TeamMembers (teamId, userId, role) VALUES (?, ?, ?)`);
stmt.run(teamId, userId, role, function (this: RunResult, err: Error | null) {
if (err) return reject(err);
resolve({
id: (this as any).lastID,
teamId,
userId,
role,
joinedAt: new Date().toISOString(),
});
});
stmt.finalize();
// First check if team already has 4 members
this.db.get(
`SELECT COUNT(*) as count FROM TeamMembers WHERE teamId = ?`,
[teamId],
(err: Error | null, row: any) => {
if (err) return reject(err);
if (row.count >= 4) {
return reject(new Error('Team already has maximum of 4 members'));
}
const stmt = this.db.prepare(`INSERT INTO TeamMembers (teamId, userId, role) VALUES (?, ?, ?)`);
stmt.run(teamId, userId, role, function (this: RunResult, err: Error | null) {
if (err) return reject(err);
resolve({
id: (this as any).lastID,
teamId,
userId,
role,
joinedAt: new Date().toISOString(),
});
});
stmt.finalize();
}
);
});
}