Permalink
Browse files

fixed transformation bug for factories

  • Loading branch information...
dreampulse committed Sep 24, 2014
1 parent 5081350 commit b2895bf54eb6dba1700c0d1efb9e7256c4dbe4d4
Showing with 120 additions and 116 deletions.
  1. +30 −29 browser-dist/modelizer-angular.js
  2. +30 −29 browser-dist/modelizer.js
  3. +30 −29 lib/angular-client.js
  4. +30 −29 lib/modelizer-client.js
@@ -22,25 +22,22 @@ Model.AngularConnector = function (connectionUrl) {
var $http = angular.injector(['ng']).get('$http');
var findUnpackInterceptor = function (model, callback) {
var unpackInterceptor = function (model, callback) {
return function (err, docs) {
if (err == undefined) {
for (var i = 0; i < docs.length; i++) {
model._transform(model, docs[i], 'unpack');
if (Array.isArray(docs)) { // result is a collection
for (var i = 0; i < docs.length; i++) {
model._transform(model, docs[i], 'unpack');
}
} else {
model._transform(model, docs, 'unpack');
}
}
callback(err, docs);
}
}
var findOneUnpackInterceptor = function (model, callback) {
return function (err, doc) {
if (err == undefined) {
model._transform(model, doc, 'unpack');
}
callback(err, doc);
callback(err, docs);
}
}
};
// ajax Call to the server backend
@@ -72,14 +69,14 @@ Model.AngularConnector = function (connectionUrl) {
return {
find: function (search, callback) {
if (isEmptyObject(search)) {
ajaxCall('GET', connectionUrl + theModel.modelName + '/all', undefined, findUnpackInterceptor(theModel, callback));
ajaxCall('GET', connectionUrl + theModel.modelName + '/all', undefined, unpackInterceptor(theModel, callback));
} else {
ajaxCall('POST', connectionUrl + theModel.modelName + '/find', search, findUnpackInterceptor(theModel, callback));
ajaxCall('POST', connectionUrl + theModel.modelName + '/find', search, unpackInterceptor(theModel, callback));
}
},
findOne: function (search, callback) {
assert(search.hasOwnProperty("_id"), "Only searching for id implemented so far");
ajaxCall('GET', connectionUrl + theModel.modelName + '/' + search._id, undefined, findOneUnpackInterceptor(theModel, callback));
ajaxCall('GET', connectionUrl + theModel.modelName + '/' + search._id, undefined, unpackInterceptor(theModel, callback));
},
save: function (doc, callback) {
theModel._transform(theModel, doc, 'pack');
@@ -99,22 +96,26 @@ Model.AngularConnector = function (connectionUrl) {
} else if (theModel.factorys.hasOwnProperty(opName)) { // call is an factory
if (err) {
deferred.reject(err);
return deferred.promise;
}
unpackInterceptor(theModel, function(err, result) {
// restore object from document
if (Array.isArray(result)) { // result is a collection
// für jedes document in der DB ein object anlegen
for (var i = 0; i < result.length; i++) {
result[i] = theModel.loadFromDoc(result[i]);
if (err) {
deferred.reject(err);
return deferred.promise;
}
} else { // result is one object
result = theModel.loadFromDoc(result); // restore one object
}
deferred.resolve(result);
// restore object from document
if (Array.isArray(result)) { // result is a collection
// für jedes document in der DB ein object anlegen
for (var i = 0; i < result.length; i++) {
result[i] = theModel.loadFromDoc(result[i]);
}
} else { // result is one object
result = theModel.loadFromDoc(result); // restore one object
}
deferred.resolve(result);
})(err, result);
} else {
assert(false, "operation or factory is not defined");
View
@@ -1480,25 +1480,22 @@ var Model = require('./model');
// Using the REST-Interface
Model.ClientConnector = function (host, port) {
var findUnpackInterceptor = function (model, callback) {
var unpackInterceptor = function (model, callback) {
return function (err, docs) {
if (err == undefined) {
for (var i = 0; i < docs.length; i++) {
model._transform(model, docs[i], 'unpack');
if (Array.isArray(docs)) { // result is a collection
for (var i = 0; i < docs.length; i++) {
model._transform(model, docs[i], 'unpack');
}
} else {
model._transform(model, docs, 'unpack');
}
}
callback(err, docs);
}
}
var findOneUnpackInterceptor = function (model, callback) {
return function (err, doc) {
if (err == undefined) {
model._transform(model, doc, 'unpack');
}
callback(err, doc);
callback(err, docs);
}
}
};
var cookie;
@@ -1596,14 +1593,14 @@ Model.ClientConnector = function (host, port) {
return {
find: function (search, callback) {
if (isEmptyObject(search)) {
ajaxCall('GET', '/' + theModel.modelName + '/all', undefined, findUnpackInterceptor(theModel, callback));
ajaxCall('GET', '/' + theModel.modelName + '/all', undefined, unpackInterceptor(theModel, callback));
} else {
ajaxCall('POST', '/' + theModel.modelName + '/find', search, findUnpackInterceptor(theModel, callback));
ajaxCall('POST', '/' + theModel.modelName + '/find', search, unpackInterceptor(theModel, callback));
}
},
findOne: function (search, callback) {
assert(search.hasOwnProperty("_id"), "Only searching for id implemented so far");
ajaxCall('GET', '/' + theModel.modelName + '/' + search._id, undefined, findOneUnpackInterceptor(theModel, callback));
ajaxCall('GET', '/' + theModel.modelName + '/' + search._id, undefined, unpackInterceptor(theModel, callback));
},
save: function (doc, callback) {
theModel._transform(theModel, doc, 'pack');
@@ -1623,22 +1620,26 @@ Model.ClientConnector = function (host, port) {
} else if (theModel.factorys.hasOwnProperty(opName)) { // call is an factory
if (err) {
deferred.reject(err);
return deferred.promise;
}
unpackInterceptor(theModel, function(err, result) {
// restore object from document
if (Array.isArray(result)) { // result is a collection
// für jedes document in der DB ein object anlegen
for (var i = 0; i < result.length; i++) {
result[i] = theModel.loadFromDoc(result[i]);
if (err) {
deferred.reject(err);
return deferred.promise;
}
} else { // result is one object
result = theModel.loadFromDoc(result); // restore one object
}
deferred.resolve(result);
// restore object from document
if (Array.isArray(result)) { // result is a collection
// für jedes document in der DB ein object anlegen
for (var i = 0; i < result.length; i++) {
result[i] = theModel.loadFromDoc(result[i]);
}
} else { // result is one object
result = theModel.loadFromDoc(result); // restore one object
}
deferred.resolve(result);
})(err, result);
} else {
assert(false, "operation or factory is not defined");
View
@@ -21,25 +21,22 @@ Model.AngularConnector = function (connectionUrl) {
var $http = angular.injector(['ng']).get('$http');
var findUnpackInterceptor = function (model, callback) {
var unpackInterceptor = function (model, callback) {
return function (err, docs) {
if (err == undefined) {
for (var i = 0; i < docs.length; i++) {
model._transform(model, docs[i], 'unpack');
if (Array.isArray(docs)) { // result is a collection
for (var i = 0; i < docs.length; i++) {
model._transform(model, docs[i], 'unpack');
}
} else {
model._transform(model, docs, 'unpack');
}
}
callback(err, docs);
}
}
var findOneUnpackInterceptor = function (model, callback) {
return function (err, doc) {
if (err == undefined) {
model._transform(model, doc, 'unpack');
}
callback(err, doc);
callback(err, docs);
}
}
};
// ajax Call to the server backend
@@ -71,14 +68,14 @@ Model.AngularConnector = function (connectionUrl) {
return {
find: function (search, callback) {
if (isEmptyObject(search)) {
ajaxCall('GET', connectionUrl + theModel.modelName + '/all', undefined, findUnpackInterceptor(theModel, callback));
ajaxCall('GET', connectionUrl + theModel.modelName + '/all', undefined, unpackInterceptor(theModel, callback));
} else {
ajaxCall('POST', connectionUrl + theModel.modelName + '/find', search, findUnpackInterceptor(theModel, callback));
ajaxCall('POST', connectionUrl + theModel.modelName + '/find', search, unpackInterceptor(theModel, callback));
}
},
findOne: function (search, callback) {
assert(search.hasOwnProperty("_id"), "Only searching for id implemented so far");
ajaxCall('GET', connectionUrl + theModel.modelName + '/' + search._id, undefined, findOneUnpackInterceptor(theModel, callback));
ajaxCall('GET', connectionUrl + theModel.modelName + '/' + search._id, undefined, unpackInterceptor(theModel, callback));
},
save: function (doc, callback) {
theModel._transform(theModel, doc, 'pack');
@@ -98,22 +95,26 @@ Model.AngularConnector = function (connectionUrl) {
} else if (theModel.factorys.hasOwnProperty(opName)) { // call is an factory
if (err) {
deferred.reject(err);
return deferred.promise;
}
unpackInterceptor(theModel, function(err, result) {
// restore object from document
if (Array.isArray(result)) { // result is a collection
// für jedes document in der DB ein object anlegen
for (var i = 0; i < result.length; i++) {
result[i] = theModel.loadFromDoc(result[i]);
if (err) {
deferred.reject(err);
return deferred.promise;
}
} else { // result is one object
result = theModel.loadFromDoc(result); // restore one object
}
deferred.resolve(result);
// restore object from document
if (Array.isArray(result)) { // result is a collection
// für jedes document in der DB ein object anlegen
for (var i = 0; i < result.length; i++) {
result[i] = theModel.loadFromDoc(result[i]);
}
} else { // result is one object
result = theModel.loadFromDoc(result); // restore one object
}
deferred.resolve(result);
})(err, result);
} else {
assert(false, "operation or factory is not defined");
View
@@ -19,25 +19,22 @@ var Model = require('./model');
// Using the REST-Interface
Model.ClientConnector = function (host, port) {
var findUnpackInterceptor = function (model, callback) {
var unpackInterceptor = function (model, callback) {
return function (err, docs) {
if (err == undefined) {
for (var i = 0; i < docs.length; i++) {
model._transform(model, docs[i], 'unpack');
if (Array.isArray(docs)) { // result is a collection
for (var i = 0; i < docs.length; i++) {
model._transform(model, docs[i], 'unpack');
}
} else {
model._transform(model, docs, 'unpack');
}
}
callback(err, docs);
}
}
var findOneUnpackInterceptor = function (model, callback) {
return function (err, doc) {
if (err == undefined) {
model._transform(model, doc, 'unpack');
}
callback(err, doc);
callback(err, docs);
}
}
};
var cookie;
@@ -135,14 +132,14 @@ Model.ClientConnector = function (host, port) {
return {
find: function (search, callback) {
if (isEmptyObject(search)) {
ajaxCall('GET', '/' + theModel.modelName + '/all', undefined, findUnpackInterceptor(theModel, callback));
ajaxCall('GET', '/' + theModel.modelName + '/all', undefined, unpackInterceptor(theModel, callback));
} else {
ajaxCall('POST', '/' + theModel.modelName + '/find', search, findUnpackInterceptor(theModel, callback));
ajaxCall('POST', '/' + theModel.modelName + '/find', search, unpackInterceptor(theModel, callback));
}
},
findOne: function (search, callback) {
assert(search.hasOwnProperty("_id"), "Only searching for id implemented so far");
ajaxCall('GET', '/' + theModel.modelName + '/' + search._id, undefined, findOneUnpackInterceptor(theModel, callback));
ajaxCall('GET', '/' + theModel.modelName + '/' + search._id, undefined, unpackInterceptor(theModel, callback));
},
save: function (doc, callback) {
theModel._transform(theModel, doc, 'pack');
@@ -162,22 +159,26 @@ Model.ClientConnector = function (host, port) {
} else if (theModel.factorys.hasOwnProperty(opName)) { // call is an factory
if (err) {
deferred.reject(err);
return deferred.promise;
}
unpackInterceptor(theModel, function(err, result) {
// restore object from document
if (Array.isArray(result)) { // result is a collection
// für jedes document in der DB ein object anlegen
for (var i = 0; i < result.length; i++) {
result[i] = theModel.loadFromDoc(result[i]);
if (err) {
deferred.reject(err);
return deferred.promise;
}
} else { // result is one object
result = theModel.loadFromDoc(result); // restore one object
}
deferred.resolve(result);
// restore object from document
if (Array.isArray(result)) { // result is a collection
// für jedes document in der DB ein object anlegen
for (var i = 0; i < result.length; i++) {
result[i] = theModel.loadFromDoc(result[i]);
}
} else { // result is one object
result = theModel.loadFromDoc(result); // restore one object
}
deferred.resolve(result);
})(err, result);
} else {
assert(false, "operation or factory is not defined");

0 comments on commit b2895bf

Please sign in to comment.