fix: player count calc error
Some checks failed
Pull Request Pipeline / test (pull_request) Failing after 44s
Pull Request Pipeline / lint (pull_request) Failing after 52s

This commit is contained in:
2026-05-20 19:58:59 +02:00
parent 869c70ff63
commit 679e869229

View File

@@ -170,22 +170,18 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
.getSingleOrNull() ?? .getSingleOrNull() ??
''; '';
final previousNameCount = (await getNameCount(name: previousPlayerName))!; final previousNameCount = (await getNameCount(name: previousPlayerName))!;
print('previousNameCount: $previousNameCount');
// Update name count for the new name // Update name count for the new name
final count = await calculateNameCount(name: name); final newNameCount = await calculateNameCount(name: name);
print('count: $count'); // Updating player name
final rowsAffected = final rowsAffected =
await (update(playerTable)..where((p) => p.id.equals(playerId))).write( await (update(playerTable)..where((p) => p.id.equals(playerId))).write(
PlayerTableCompanion(name: Value(name)), PlayerTableCompanion(name: Value(name)),
); );
// Updating the name count for the new name
if (count > 0) {
await (update(playerTable)..where((p) => p.name.equals(name))).write( await (update(playerTable)..where((p) => p.name.equals(name))).write(
PlayerTableCompanion(nameCount: Value(count)), PlayerTableCompanion(nameCount: Value(newNameCount)),
); );
}
if (previousNameCount > 0) { if (previousNameCount > 0) {
// Get the player with that name and the hightest nameCount, and update their nameCount to previousNameCount // Get the player with that name and the hightest nameCount, and update their nameCount to previousNameCount