Revert to 4bd2f97
This commit is contained in:
@@ -39,18 +39,25 @@ class PlayerGroupDao extends DatabaseAccessor<AppDatabase>
|
||||
|
||||
/// Retrieves all players belonging to a specific group by [groupId].
|
||||
Future<List<Player>> getPlayersOfGroup({required String groupId}) async {
|
||||
final query = select(playerGroupTable)
|
||||
..where((pG) => pG.groupId.equals(groupId));
|
||||
final result = await query.get();
|
||||
final query = select(playerGroupTable).join([
|
||||
innerJoin(
|
||||
playerTable,
|
||||
playerTable.id.equalsExp(playerGroupTable.playerId),
|
||||
),
|
||||
])..where(playerGroupTable.groupId.equals(groupId));
|
||||
|
||||
List<Player> groupMembers = List.empty(growable: true);
|
||||
|
||||
for (var entry in result) {
|
||||
final player = await db.playerDao.getPlayerById(playerId: entry.playerId);
|
||||
groupMembers.add(player);
|
||||
}
|
||||
|
||||
return groupMembers;
|
||||
final result = await query.map((row) => row.readTable(playerTable)).get();
|
||||
return result
|
||||
.map(
|
||||
(row) => Player(
|
||||
id: row.id,
|
||||
createdAt: row.createdAt,
|
||||
name: row.name,
|
||||
nameCount: row.nameCount,
|
||||
description: row.description,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// Checks if a player with [playerId] is in the group with [groupId].
|
||||
@@ -60,7 +67,9 @@ class PlayerGroupDao extends DatabaseAccessor<AppDatabase>
|
||||
required String groupId,
|
||||
}) async {
|
||||
final query = select(playerGroupTable)
|
||||
..where((p) => p.playerId.equals(playerId) & p.groupId.equals(groupId));
|
||||
..where(
|
||||
(tbl) => tbl.playerId.equals(playerId) & tbl.groupId.equals(groupId),
|
||||
);
|
||||
final result = await query.getSingleOrNull();
|
||||
return result != null;
|
||||
}
|
||||
@@ -81,7 +90,7 @@ class PlayerGroupDao extends DatabaseAccessor<AppDatabase>
|
||||
await db.transaction(() async {
|
||||
// Remove all existing players from the group
|
||||
final deleteQuery = delete(db.playerGroupTable)
|
||||
..where((p) => p.groupId.equals(groupId));
|
||||
..where((tbl) => tbl.groupId.equals(groupId));
|
||||
await deleteQuery.go();
|
||||
|
||||
// Add new players to the player table if they don't exist
|
||||
@@ -121,7 +130,9 @@ class PlayerGroupDao extends DatabaseAccessor<AppDatabase>
|
||||
required String groupId,
|
||||
}) async {
|
||||
final query = delete(playerGroupTable)
|
||||
..where((p) => p.playerId.equals(playerId) & p.groupId.equals(groupId));
|
||||
..where(
|
||||
(tbl) => tbl.playerId.equals(playerId) & tbl.groupId.equals(groupId),
|
||||
);
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user