1- import { firebase , DocumentSnapshot , QuerySnapshot } from "./firebase-common" ;
1+ import { firebase , DocumentSnapshot , QuerySnapshot , GeoPoint } from "./firebase-common" ;
22import * as application from "tns-core-modules/application" ;
33import { ios as iOSUtils } from "tns-core-modules/utils/utils" ;
44import { getClass } from "tns-core-modules/utils/types" ;
@@ -645,10 +645,10 @@ firebase.toJsObject = objCObj => {
645645 node [ key ] = firebase . firestore . _getDocumentReference ( val , path . substring ( 0 , lastSlashIndex ) , path . substring ( lastSlashIndex + 1 ) ) ;
646646 break ;
647647 case 'FIRGeoPoint' :
648- node [ key ] = {
649- latitude : ( < FIRGeoPoint > val ) . latitude ,
650- longitude : ( < FIRGeoPoint > val ) . longitude
651- } ;
648+ node [ key ] = firestore . GeoPoint (
649+ ( < FIRGeoPoint > val ) . latitude ,
650+ ( < FIRGeoPoint > val ) . longitude
651+ ) ;
652652 break ;
653653 default :
654654 console . log ( "Please report this at https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues: iOS toJsObject is missing a converter for class '" + getClass ( val ) + "'. Casting to String as a fallback." ) ;
@@ -2246,7 +2246,7 @@ firebase.firestore.set = (collectionPath: string, documentPath: string, document
22462246 return ;
22472247 }
22482248
2249- fixServerTimestamp ( document ) ;
2249+ fixSpecialFields ( document ) ;
22502250
22512251 const docRef : FIRDocumentReference = FIRFirestore . firestore ( )
22522252 . collectionWithPath ( collectionPath )
@@ -2278,10 +2278,18 @@ firebase.firestore.set = (collectionPath: string, documentPath: string, document
22782278 } ) ;
22792279} ;
22802280
2281- function fixServerTimestamp ( item ) {
2281+ function fixSpecialFields ( item ) {
22822282 for ( let k in item ) {
2283- if ( item . hasOwnProperty ( k ) && item [ k ] === "SERVER_TIMESTAMP" ) {
2284- item [ k ] = FIRFieldValue . fieldValueForServerTimestamp ( ) ;
2283+ if ( item . hasOwnProperty ( k ) ) {
2284+ if ( item [ k ] === "SERVER_TIMESTAMP" ) {
2285+ item [ k ] = FIRFieldValue . fieldValueForServerTimestamp ( ) ;
2286+ } else if ( item [ k ] instanceof GeoPoint ) {
2287+ const geo = < GeoPoint > item [ k ] ;
2288+ item [ k ] = new FIRGeoPoint ( {
2289+ latitude : geo . latitude ,
2290+ longitude : geo . longitude
2291+ } ) ;
2292+ }
22852293 }
22862294 }
22872295}
@@ -2294,7 +2302,7 @@ firebase.firestore.update = (collectionPath: string, documentPath: string, docum
22942302 return ;
22952303 }
22962304
2297- fixServerTimestamp ( document ) ;
2305+ fixSpecialFields ( document ) ;
22982306
22992307 const docRef : FIRDocumentReference = FIRFirestore . firestore ( )
23002308 . collectionWithPath ( collectionPath )
@@ -2307,7 +2315,6 @@ firebase.firestore.update = (collectionPath: string, documentPath: string, docum
23072315 resolve ( ) ;
23082316 }
23092317 } ) ;
2310-
23112318 } catch ( ex ) {
23122319 console . log ( "Error in firebase.firestore.update: " + ex ) ;
23132320 reject ( ex ) ;
0 commit comments