[firestore][android] Resolve a few issues with basic operations

This commit is contained in:
Chris Bianca 2017-09-27 17:20:32 +01:00
parent bf35c349ae
commit 867a08da7b
4 changed files with 14 additions and 10 deletions

View File

@ -30,7 +30,7 @@ public class FirestoreSerialize {
static WritableMap snapshotToWritableMap(DocumentSnapshot documentSnapshot) {
WritableMap documentMap = Arguments.createMap();
documentMap.putString(KEY_PATH, documentSnapshot.getId());
documentMap.putString(KEY_PATH, documentSnapshot.getReference().getPath());
documentMap.putMap(KEY_DATA, objectMapToWritable(documentSnapshot.getData()));
// Missing fields from web SDK
// createTime

View File

@ -69,11 +69,14 @@ public class RNFirebaseDocumentReference {
public void set(final ReadableMap data, final ReadableMap options, final Promise promise) {
Map<String, Object> map = Utils.recursivelyDeconstructReadableMap(data);
Task<Void> task;
SetOptions setOptions = null;
if (options != null && options.hasKey("merge") && options.getBoolean("merge")) {
setOptions = SetOptions.merge();
task = this.ref.set(map, SetOptions.merge());
} else {
task = this.ref.set(map);
}
this.ref.set(map, setOptions).addOnCompleteListener(new OnCompleteListener<Void>() {
task.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
@ -89,7 +92,7 @@ public class RNFirebaseDocumentReference {
});
}
public void update(final ReadableMap data, final ReadableMap options, final Promise promise) {
public void update(final ReadableMap data, final Promise promise) {
Map<String, Object> map = Utils.recursivelyDeconstructReadableMap(data);
this.ref.update(map).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override

View File

@ -67,11 +67,12 @@ public class RNFirebaseFirestore extends ReactContextBaseJavaModule {
break;
case "SET":
Map<String, Object> options = (Map) write.get("options");
SetOptions setOptions = null;
if (options != null && options.containsKey("merge") && (boolean)options.get("merge")) {
setOptions = SetOptions.merge();
batch = batch.set(ref, data, SetOptions.merge());
} else {
batch = batch.set(ref, data);
}
batch = batch.set(ref, data, setOptions);
break;
case "UPDATE":
batch = batch.update(ref, data);
@ -135,9 +136,9 @@ public class RNFirebaseFirestore extends ReactContextBaseJavaModule {
}
@ReactMethod
public void documentUpdate(String appName, String path, ReadableMap data, ReadableMap options, final Promise promise) {
public void documentUpdate(String appName, String path, ReadableMap data, final Promise promise) {
RNFirebaseDocumentReference ref = getDocumentForAppPath(appName, path);
ref.update(data, options, promise);
ref.update(data, promise);
}
/*

View File

@ -6,7 +6,7 @@ import DocumentReference from './DocumentReference';
import Path from './Path';
import Query from './Query';
import QuerySnapshot from './QuerySnapshot';
import firestoreAutoId from '../../utils';
import { firestoreAutoId } from '../../utils';
import type { Direction, Operator } from './Query';