[firestore][android] Resolve a few issues with basic operations
This commit is contained in:
parent
bf35c349ae
commit
867a08da7b
|
@ -30,7 +30,7 @@ public class FirestoreSerialize {
|
||||||
static WritableMap snapshotToWritableMap(DocumentSnapshot documentSnapshot) {
|
static WritableMap snapshotToWritableMap(DocumentSnapshot documentSnapshot) {
|
||||||
WritableMap documentMap = Arguments.createMap();
|
WritableMap documentMap = Arguments.createMap();
|
||||||
|
|
||||||
documentMap.putString(KEY_PATH, documentSnapshot.getId());
|
documentMap.putString(KEY_PATH, documentSnapshot.getReference().getPath());
|
||||||
documentMap.putMap(KEY_DATA, objectMapToWritable(documentSnapshot.getData()));
|
documentMap.putMap(KEY_DATA, objectMapToWritable(documentSnapshot.getData()));
|
||||||
// Missing fields from web SDK
|
// Missing fields from web SDK
|
||||||
// createTime
|
// createTime
|
||||||
|
|
|
@ -69,11 +69,14 @@ public class RNFirebaseDocumentReference {
|
||||||
|
|
||||||
public void set(final ReadableMap data, final ReadableMap options, final Promise promise) {
|
public void set(final ReadableMap data, final ReadableMap options, final Promise promise) {
|
||||||
Map<String, Object> map = Utils.recursivelyDeconstructReadableMap(data);
|
Map<String, Object> map = Utils.recursivelyDeconstructReadableMap(data);
|
||||||
|
Task<Void> task;
|
||||||
SetOptions setOptions = null;
|
SetOptions setOptions = null;
|
||||||
if (options != null && options.hasKey("merge") && options.getBoolean("merge")) {
|
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
|
@Override
|
||||||
public void onComplete(@NonNull Task<Void> task) {
|
public void onComplete(@NonNull Task<Void> task) {
|
||||||
if (task.isSuccessful()) {
|
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);
|
Map<String, Object> map = Utils.recursivelyDeconstructReadableMap(data);
|
||||||
this.ref.update(map).addOnCompleteListener(new OnCompleteListener<Void>() {
|
this.ref.update(map).addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -67,11 +67,12 @@ public class RNFirebaseFirestore extends ReactContextBaseJavaModule {
|
||||||
break;
|
break;
|
||||||
case "SET":
|
case "SET":
|
||||||
Map<String, Object> options = (Map) write.get("options");
|
Map<String, Object> options = (Map) write.get("options");
|
||||||
SetOptions setOptions = null;
|
|
||||||
if (options != null && options.containsKey("merge") && (boolean)options.get("merge")) {
|
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;
|
break;
|
||||||
case "UPDATE":
|
case "UPDATE":
|
||||||
batch = batch.update(ref, data);
|
batch = batch.update(ref, data);
|
||||||
|
@ -135,9 +136,9 @@ public class RNFirebaseFirestore extends ReactContextBaseJavaModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@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);
|
RNFirebaseDocumentReference ref = getDocumentForAppPath(appName, path);
|
||||||
ref.update(data, options, promise);
|
ref.update(data, promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -6,7 +6,7 @@ import DocumentReference from './DocumentReference';
|
||||||
import Path from './Path';
|
import Path from './Path';
|
||||||
import Query from './Query';
|
import Query from './Query';
|
||||||
import QuerySnapshot from './QuerySnapshot';
|
import QuerySnapshot from './QuerySnapshot';
|
||||||
import firestoreAutoId from '../../utils';
|
import { firestoreAutoId } from '../../utils';
|
||||||
|
|
||||||
import type { Direction, Operator } from './Query';
|
import type { Direction, Operator } from './Query';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue