adonis-lucid-mongodb
Advanced tools
Comparing version 0.11.0 to 0.11.1
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"scripts": { | ||
@@ -11,0 +11,0 @@ "lint": "standard", |
@@ -37,6 +37,6 @@ 'use strict' | ||
FieldTypes.getFormatedField = function (key, value) { | ||
if (this.constructor.dateFields && this.constructor.dateFields.indexOf(key) > -1) { | ||
if (this.constructor.dateFields && this.constructor.dateFields.indexOf(key) > -1 && moment.isMoment(value)) { | ||
return this.formatDate(value) | ||
} | ||
if (this.constructor.geoFields && this.constructor.geoFields.indexOf(key) > -1) { | ||
if (this.constructor.geoFields && this.constructor.geoFields.indexOf(key) > -1 && value instanceof GeoPoint) { | ||
return { | ||
@@ -52,3 +52,3 @@ lat: value.latitude(), | ||
* | ||
* @method getStoreValues | ||
* @method getStoreAbleValues | ||
* | ||
@@ -60,3 +60,3 @@ * @param {Object} values | ||
*/ | ||
FieldTypes.getStoreValues = function (values) { | ||
FieldTypes.getStoreAbleValues = function (values) { | ||
return _(values).transform((result, value, key) => { | ||
@@ -77,1 +77,24 @@ if (this.constructor.dateFields && this.constructor.dateFields.indexOf(key) > -1) { | ||
} | ||
/** | ||
* | ||
* @method fillDataFromDb | ||
* | ||
* @param {Object} values | ||
* @return {Object} | ||
* | ||
* @public | ||
*/ | ||
FieldTypes.fillDataFromDb = function (values) { | ||
_.map(values, (value, key) => { | ||
if (this.constructor.dateFields && this.constructor.dateFields.indexOf(key) > -1) { | ||
this.attributes[key] = moment(value) | ||
} else if (this.constructor.geoFields && this.constructor.geoFields.indexOf(key) > -1 && | ||
_.isObject(value) && _.isArray(value.coordinates)) { | ||
this.attributes[key] = new GeoPoint(value.coordinates[1], value.coordinates[0]) | ||
} else { | ||
this.attributes[key] = value | ||
} | ||
}) | ||
return this | ||
} |
@@ -32,3 +32,3 @@ 'use strict' | ||
const insertHandler = function * () { | ||
const values = this.getStoreValues(this.attributes) | ||
const values = this.getStoreAbleValues(this.attributes) | ||
if (!values || _.size(values) < 1) { | ||
@@ -75,3 +75,3 @@ throw CE.ModelException.invalidState(`Cannot save empty ${this.constructor.name} model`) | ||
yield query.connect() | ||
const dirtyValues = this.getStoreValues(this.$dirty) | ||
const dirtyValues = this.getStoreAbleValues(this.$dirty) | ||
if (!_.size(dirtyValues) && !this.unsetFields.length) { | ||
@@ -78,0 +78,0 @@ return 0 |
@@ -0,0 +0,0 @@ 'use strict' |
@@ -85,3 +85,3 @@ 'use strict' | ||
const modelInstance = new this.queryBuilder.HostModel() | ||
modelInstance.attributes = value | ||
modelInstance.fillDataFromDb(value) | ||
modelInstance.exists = true | ||
@@ -88,0 +88,0 @@ modelInstance.original = _.clone(modelInstance.attributes) |
216016
7915