list for all models

This commit is contained in:
nelo 2017-06-21 07:28:03 +02:00
parent 509dab5ce4
commit ce15b68a92
6 changed files with 62 additions and 33 deletions

View File

@ -25,7 +25,9 @@ module.exports = function(self) {
for(let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
}
};
self.defineScope = function(serverFilter) {
this.remoteMethod('list', {
accepts: [
{
@ -43,10 +45,23 @@ module.exports = function(self) {
path: '/list'
}
});
};
self.list = function(filter, cb) {};
this.list = function(clientFilter, cb) {
var where = {"and": []};
(clientFilter) ? where.and.push(clientFilter.where) : undefined;
(serverFilter) ? where.and.push(serverFilter.where) : undefined;
var order = (clientFilter && clientFilter.order) ? clientFilter.order : (serverFilter && serverFilter.order) ? serverFilter.order : undefined;
var limit = (serverFilter && serverFilter.limit) ? serverFilter.limit : (clientFilter && clientFilter.limit) ? clientFilter.limit : undefined;
var filter = {"where": where, "order": order, "limit": limit};
filter = removeEmpty(filter);
this.find(filter, function(err, states) {
(!err) ? cb(null, states) : cb(err, null);
});
};
};
self.rawSql = function(query, params, cb) {
this.dataSource.connector.execute(query, params, function(error, response) {

View File

@ -1,10 +1,6 @@
module.exports = function(State) {
State.list = function(filter, cb) {
State.find(where(filter), function(err, states) {
if(!err){
cb(null, states);
}
});
};
function where(filter) {

View File

@ -1,19 +0,0 @@
module.exports = function(Warehouse) {
Warehouse.list = function(filter, cb) {
Warehouse.find(where(filter), function(err, warehouses){
if(!err)
cb(null, warehouses);
else
cb(err, null);
});
};
var where = function(filter){
if(!filter)
return {"where": {"tpv": {"neq": 0}}}
else {
filter.where.tpv = {"neq": 0}
return filter;
}
}
}

View File

@ -0,0 +1,7 @@
module.exports = function(Warehouse) {
var serverFilter = {"where": {"tpv": {"neq": 0}}};
Warehouse.defineScope(serverFilter);
}

View File

@ -25,7 +25,9 @@ module.exports = function(self) {
for(let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
}
};
self.defineScope = function(serverFilter) {
this.remoteMethod('list', {
accepts: [
{
@ -43,10 +45,23 @@ module.exports = function(self) {
path: '/list'
}
});
};
self.list = function(filter, cb) {};
this.list = function(clientFilter, cb) {
var where = {"and": []};
(clientFilter) ? where.and.push(clientFilter.where) : undefined;
(serverFilter) ? where.and.push(serverFilter.where) : undefined;
var order = (clientFilter && clientFilter.order) ? clientFilter.order : (serverFilter && serverFilter.order) ? serverFilter.order : undefined;
var limit = (serverFilter && serverFilter.limit) ? serverFilter.limit : (clientFilter && clientFilter.limit) ? clientFilter.limit : undefined;
var filter = {"where": where, "order": order, "limit": limit};
filter = removeEmpty(filter);
this.find(filter, function(err, states) {
(!err) ? cb(null, states) : cb(err, null);
});
};
};
self.rawSql = function(query, params, cb) {
this.dataSource.connector.execute(query, params, function(error, response) {

View File

@ -25,7 +25,9 @@ module.exports = function(self) {
for(let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
}
};
self.defineScope = function(serverFilter) {
this.remoteMethod('list', {
accepts: [
{
@ -43,10 +45,23 @@ module.exports = function(self) {
path: '/list'
}
});
};
self.list = function(filter, cb) {};
this.list = function(clientFilter, cb) {
var where = {"and": []};
(clientFilter) ? where.and.push(clientFilter.where) : undefined;
(serverFilter) ? where.and.push(serverFilter.where) : undefined;
var order = (clientFilter && clientFilter.order) ? clientFilter.order : (serverFilter && serverFilter.order) ? serverFilter.order : undefined;
var limit = (serverFilter && serverFilter.limit) ? serverFilter.limit : (clientFilter && clientFilter.limit) ? clientFilter.limit : undefined;
var filter = {"where": where, "order": order, "limit": limit};
filter = removeEmpty(filter);
this.find(filter, function(err, states) {
(!err) ? cb(null, states) : cb(err, null);
});
};
};
self.rawSql = function(query, params, cb) {
this.dataSource.connector.execute(query, params, function(error, response) {