Last active
March 1, 2020 23:35
-
-
Save hiranya911/6c1546f20962c246ef601b143e421fa0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Latest security rules look for a `familyName` field instead of `surname`. This | |
// function will not therefore work. | |
fun addPerson(firstName: String, surname: String): Task<Void> { | |
val data = hashMapOf( | |
"firstName" to firstName, | |
"surname" to surname | |
) | |
return db.collection("people").document() | |
.set(data) | |
} | |
// New documents doesn't have a `surname` field. The assertion will fail for | |
// those documents. | |
fun getPerson(personId: String) { | |
db.collection("people").document(personId) | |
.get() | |
.addOnSuccessListener { snapshot -> | |
val data = snapshot.data ?: hashMapOf() | |
val surname = data["surname"] | |
assert(surname is String) | |
updateView(surname) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment