updated team tests
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 43s
Pull Request Pipeline / lint (pull_request) Successful in 55s

This commit is contained in:
2026-05-22 00:48:21 +02:00
parent df64ef4b93
commit 6fb4a8996c
6 changed files with 258 additions and 41 deletions

View File

@@ -16,12 +16,12 @@ class ScoreEntryDao extends DatabaseAccessor<AppDatabase>
/* Create */
/// Adds a score entry to the database.
Future<void> addScore({
Future<bool> addScore({
required String playerId,
required String matchId,
required ScoreEntry entry,
}) async {
await into(scoreEntryTable).insert(
final rowsAffected = await into(scoreEntryTable).insert(
ScoreEntryTableCompanion.insert(
playerId: playerId,
matchId: matchId,
@@ -31,6 +31,8 @@ class ScoreEntryDao extends DatabaseAccessor<AppDatabase>
),
mode: InsertMode.insertOrReplace,
);
return rowsAffected > 0;
}
Future<void> addScoresAsList({

View File

@@ -212,7 +212,7 @@ class TeamDao extends DatabaseAccessor<AppDatabase> with _$TeamDaoMixin {
await (update(teamTable)..where((t) => t.id.equals(teamId))).write(
const TeamTableCompanion(score: Value(null)),
);
await db.scoreEntryDao.deleteAllScoresForMatch(matchId: matchId);
await _deleteAllScoresForMembersOfTeam(teamId: teamId, matchId: matchId);
final rowsAffected =
await (update(teamTable)..where((t) => t.id.equals(teamId))).write(
@@ -238,7 +238,7 @@ class TeamDao extends DatabaseAccessor<AppDatabase> with _$TeamDaoMixin {
await (update(teamTable)..where((t) => t.id.equals(teamId))).write(
const TeamTableCompanion(score: Value(null)),
);
await db.scoreEntryDao.deleteAllScoresForMatch(matchId: matchId);
await _deleteAllScoresForMembersOfTeam(teamId: teamId, matchId: matchId);
return true;
}
@@ -300,16 +300,17 @@ class TeamDao extends DatabaseAccessor<AppDatabase> with _$TeamDaoMixin {
required List<Team> winners,
required String matchId,
}) async {
List<bool?> success = List.generate(winners.length, (index) => null);
for (int i = 0; i < winners.length; i++) {
success[i] = await updateTeamScore(
teamId: winners[i].id,
matchId: matchId,
score: 1,
);
// Reset all team scores .
await removeAllTeamScores(matchId: matchId);
// Reset all score entries
for (final team in winners) {
await _deleteAllScoresForMembersOfTeam(teamId: team.id, matchId: matchId);
}
return success.every((result) => result == true);
for (final team in winners) {
await updateTeamScore(teamId: team.id, matchId: matchId, score: 1);
}
return true;
}
/// Removes the winner status from all Teams with the given [matchId] by setting its score to null.
@@ -349,4 +350,24 @@ class TeamDao extends DatabaseAccessor<AppDatabase> with _$TeamDaoMixin {
}
return success.every((result) => result == true);
}
/// Helper method to delete all scores for members of a team in a specific match.
Future<bool> _deleteAllScoresForMembersOfTeam({
required String teamId,
required String matchId,
}) async {
final playerMatchQuery = select(db.playerMatchTable)
..where((pm) => pm.teamId.equals(teamId) & pm.matchId.equals(matchId));
final playerMatches = await playerMatchQuery.get();
if (playerMatches.isEmpty) return false;
for (final pm in playerMatches) {
await db.scoreEntryDao.deleteAllScoresForPlayerInMatch(
playerId: pm.playerId,
matchId: matchId,
);
}
return true;
}
}