Fix dates in memory adapter
This commit is contained in:
parent
9fc4e5e887
commit
2fd2157d28
|
@ -70,7 +70,7 @@ Memory.prototype.exists = function exists(model, id, callback) {
|
|||
|
||||
Memory.prototype.find = function find(model, id, callback) {
|
||||
process.nextTick(function () {
|
||||
callback(null, id in this.cache[model] && JSON.parse(this.cache[model][id]));
|
||||
callback(null, id in this.cache[model] && this.fromDb(model, this.cache[model][id]));
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
|
@ -79,10 +79,34 @@ Memory.prototype.destroy = function destroy(model, id, callback) {
|
|||
process.nextTick(callback);
|
||||
};
|
||||
|
||||
Memory.prototype.fromDb = function(model, data) {
|
||||
if (!data) return null;
|
||||
data = JSON.parse(data);
|
||||
var props = this._models[model].properties;
|
||||
Object.keys(data).forEach(function (key) {
|
||||
var val = data[key];
|
||||
if (typeof val === 'undefined' || val === null) {
|
||||
return;
|
||||
}
|
||||
if (props[key]) {
|
||||
switch(props[key].type.name) {
|
||||
case 'Date':
|
||||
val = new Date(val.toString().replace(/GMT.*$/, 'GMT'));
|
||||
break;
|
||||
case 'Boolean':
|
||||
val = new Boolean(val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
data[key] = val;
|
||||
});
|
||||
return data;
|
||||
};
|
||||
|
||||
Memory.prototype.all = function all(model, filter, callback) {
|
||||
var self = this;
|
||||
var nodes = Object.keys(this.cache[model]).map(function (key) {
|
||||
return JSON.parse(this.cache[model][key]);
|
||||
return this.fromDb(model, this.cache[model][key]);
|
||||
}.bind(this));
|
||||
|
||||
if (filter) {
|
||||
|
|
Loading…
Reference in New Issue