 
     public func join(to teamID: String, as member: TeamMember) -> Completable {
         let dataStore = self._resolver.resolveDataStore()
-        return team(for: teamID, dataStore: dataStore)
-            .take(1)
-            .flatMap { team -> Observable<Never> in
-                guard team != nil else { return Observable.error(TeamRepositoryError.teamNotFound) }
-                return dataStore.write { writer in
-                    let teamPath = dataStore.collection("team").document(teamID)
-                    let memberPath = teamPath.collection("member").document(member.memberID)
-                    writer.setDocumentData(member.data, at: memberPath)
-
-                    let reversePath = dataStore.collection("member_team").document(member.memberID)
-                    writer.mergeDocumentData([teamID: true], at: reversePath)
-                }.asObservable()
-            }
-            .asCompletable()
+        return dataStore.write { writer in
+            let teamPath = dataStore.collection("team").document(teamID)
+            let memberPath = teamPath.collection("member").document(member.memberID)
+            writer.setDocumentData(member.data, at: memberPath)
+            
+            let reversePath = dataStore.collection("member_team").document(member.memberID)
+            writer.mergeDocumentData([teamID: true], at: reversePath)
+        }
     }
 
     public func leave(from teamID: String, as memberID: String) -> Completable {
         let dataStore = self._resolver.resolveDataStore()
-
         return dataStore.write { writer in
             let teamPath = dataStore.collection("team").document()
             let teamMemberPath = teamPath.collection("member").document(memberID)

        }
    }

//
//    public func updateMember(_ member: TeamMember, in teamID: String) -> Completable {
//        guard let currentUser = Auth.auth().currentUser else {
//            return Completable.error(TeamRepositoryError.notAuthenticated)
//        }
//        let memberID = currentUser.uid
//
//        return Completable.create { observer in
//            let memberRef = Database.database().reference().child("team_members").child(teamID).child(memberID)
//            memberRef.observeSingleEvent(of: .value, with: { snapshot in
//                if !snapshot.exists() {
//                    observer(.error(TeamRepositoryError.notInTeam))
//                } else {
//                    memberRef.setValue(member.value) { (error, _) in
//                        if let error = error {
//                            observer(.error(error))
//                        } else {
//                            observer(.completed)
//                        }
//                    }
//                }
//            }, withCancel: { error in
//                observer(.error(error))
//            })
//            return Disposables.create()
//        }
//    }
//
//    public func updateTeam(_ newTeam: Team) -> Completable {
//        guard Auth.auth().currentUser != nil else {
//            return Completable.error(TeamRepositoryError.notAuthenticated)
//        }
//
//        return team(for: newTeam.teamID)
//            .take(1)
//            .flatMap { team -> Observable<Never> in
//                guard team != nil else { return Observable.error(TeamRepositoryError.teamNotFound) }
//                return Observable.create { observer in
//                    let teamRef = Database.database().reference().child("teams").child(newTeam.teamID)
//                    teamRef.setValue(newTeam.value) { (error, _) in
//                        if let error = error {
//                            observer.onError(error)
//                        } else {
//                            observer.onCompleted()
//                        }
//                    }
//                    return Disposables.create()
//                }
//            }
//            .asCompletable()
//    }
}

import FirebaseAuth
import RxSwift

public protocol TeamRepository {
    func team(for teamID: String) -> Observable<Team?>
    func members(in teamID: String) -> Observable<CollectionChange<TeamMember>>
