deleteSessions method

Future<List<DeletedSession>> deleteSessions(
  1. Session session, {
  2. UuidValue? authUserId,
  3. UuidValue? serverSideSessionId,
  4. String? method,
  5. Transaction? transaction,
})

Deletes the sessions matching the given filters.

If authUserId is provided, only sessions for that user will be deleted. If method is provided, only sessions created with that method will be deleted. If serverSideSessionId is provided, only the session with that ID will be deleted.

Returns a list with DeletedSessions.

Implementation

Future<List<DeletedSession>> deleteSessions(
  Session session, {
  UuidValue? authUserId,
  UuidValue? serverSideSessionId,
  String? method,
  Transaction? transaction,
}) async {
  final serverSideSessions = await ServerSideSession.db.deleteWhere(
    session,
    where: (row) {
      Expression<dynamic> expression = Constant.bool(true);

      if (authUserId != null) {
        expression &= row.authUserId.equals(authUserId);
      }

      if (serverSideSessionId != null) {
        expression &= row.id.equals(serverSideSessionId);
      }

      if (method != null) {
        expression &= row.method.equals(method);
      }

      return expression;
    },
    transaction: transaction,
  );

  return serverSideSessions
      .map(
        (session) => (
          authUserId: session.authUserId,
          sessionId: session.id!,
        ),
      )
      .toList();
}