From fac366e2562c000d3b70415d12010bb60e6306e8 Mon Sep 17 00:00:00 2001 From: Mikko Paderes Date: Wed, 16 May 2018 11:05:22 +0800 Subject: [PATCH] Fix regressions --- addon/serializers/cloud-firestore.js | 12 ++++-------- addon/transforms/timestamp.js | 6 +++++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/addon/serializers/cloud-firestore.js b/addon/serializers/cloud-firestore.js index 1dec0081..d9de77fb 100644 --- a/addon/serializers/cloud-firestore.js +++ b/addon/serializers/cloud-firestore.js @@ -1,5 +1,6 @@ import { inject } from '@ember/service'; import { pluralize } from 'ember-inflector'; +import { typeOf } from '@ember/utils'; import JSONSerializer from 'ember-data/serializers/json'; import { @@ -25,11 +26,7 @@ export default JSONSerializer.extend({ * @override */ extractRelationship(relationshipModelName, relationshipHash) { - if ( - relationshipHash !== null - && typeof relationshipHash === 'object' - && relationshipHash.firestore - ) { + if (typeOf(relationshipHash) === 'object' && relationshipHash.firestore) { const path = buildPathFromRef(relationshipHash); const pathNodes = path.split('/'); const belongsToId = pathNodes[pathNodes.length - 1]; @@ -53,8 +50,7 @@ export default JSONSerializer.extend({ if (descriptor.kind === 'belongsTo') { if ( Object.prototype.hasOwnProperty.call(resourceHash, name) - && resourceHash[name] !== null - && typeof resourceHash[name] === 'object' + && typeOf(resourceHash[name]) === 'object' && resourceHash[name].firestore ) { const path = buildPathFromRef(resourceHash[name]); @@ -153,7 +149,7 @@ export default JSONSerializer.extend({ getAdapterOptionAttribute(snapshot, key) { if ( snapshot.adapterOptions - && Object.prototype.hasOwnProperty.call(snapshot, key) + && Object.prototype.hasOwnProperty.call(snapshot.adapterOptions, key) ) { return snapshot.adapterOptions[key]; } diff --git a/addon/transforms/timestamp.js b/addon/transforms/timestamp.js index a3c80846..4754ffdb 100644 --- a/addon/transforms/timestamp.js +++ b/addon/transforms/timestamp.js @@ -13,7 +13,11 @@ export default Transform.extend({ * @override */ deserialize(serialized) { - return serialized.toDate(); + if (typeOf(serialized) === 'object' && serialized.toDate) { + return serialized.toDate(); + } + + return serialized; }, /**