[firestore] Correctly support dates, GeoPoints and other types in where clause

This commit is contained in:
Chris Bianca
2017-10-31 15:32:08 +00:00
parent d8fd09adef
commit 6ae0049338
8 changed files with 247 additions and 21 deletions

View File

@@ -246,7 +246,7 @@ public class FirestoreSerialize {
return list;
}
private static Object parseTypeMap(FirebaseFirestore firestore, ReadableMap typeMap) {
public static Object parseTypeMap(FirebaseFirestore firestore, ReadableMap typeMap) {
String type = typeMap.getString("type");
if ("boolean".equals(type)) {
return typeMap.getBoolean("value");

View File

@@ -14,6 +14,7 @@ import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.DocumentListenOptions;
import com.google.firebase.firestore.EventListener;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.FirebaseFirestoreException;
import com.google.firebase.firestore.ListenerRegistration;
import com.google.firebase.firestore.Query;
@@ -115,22 +116,22 @@ public class RNFirebaseFirestoreCollectionReference {
}
private Query buildQuery() {
Query query = RNFirebaseFirestore.getFirestoreForApp(appName).collection(path);
query = applyFilters(query);
FirebaseFirestore firestore = RNFirebaseFirestore.getFirestoreForApp(appName);
Query query = firestore.collection(path);
query = applyFilters(firestore, query);
query = applyOrders(query);
query = applyOptions(query);
return query;
}
private Query applyFilters(Query query) {
List<Object> filtersList = Utils.recursivelyDeconstructReadableArray(filters);
for (Object f : filtersList) {
Map<String, Object> filter = (Map) f;
String fieldPath = (String) filter.get("fieldPath");
String operator = (String) filter.get("operator");
Object value = filter.get("value");
private Query applyFilters(FirebaseFirestore firestore, Query query) {
for (int i = 0; i < filters.size(); i++) {
ReadableMap filter = filters.getMap(i);
String fieldPath = filter.getString("fieldPath");
String operator = filter.getString("operator");
ReadableMap jsValue = filter.getMap("value");
Object value = FirestoreSerialize.parseTypeMap(firestore, jsValue);
switch (operator) {
case "EQUAL":