Last active
May 19, 2021 10:12
-
-
Save SUPERCILEX/b0a15816a117dc109decad1bb30dd09e to your computer and use it in GitHub Desktop.
This file contains 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
fun Team.addScout() { | |
val scoutRef: DocumentReference = FirebaseFirestore.getInstance() | |
.collection("teams") | |
.document(id /* Field in Team */) | |
.collection("scouts") | |
.document() // Creating a document ref with a truly random id | |
scoutRef.set(Scout(scoutRef.id, templateId)) | |
firestoreBatch { | |
val metricsRef = scoutRef.collection("metrics") | |
dataGatheredFromAQuery.forEach { metric -> | |
set(metricsRef.document(metric.id), metric) | |
} | |
} | |
} | |
inline fun firestoreBatch(transaction: WriteBatch.() -> Unit): Task<Void> = FirebaseFirestore.getInstance().batch().run { | |
transaction() | |
commit() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment