list for my model

This commit is contained in:
nelo 2017-06-20 13:06:13 +02:00
parent 729ddf3358
commit 50e086fbc0
5 changed files with 79 additions and 25 deletions

View File

@ -25,7 +25,29 @@ module.exports = function(self) {
for(let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
}
this.remoteMethod('list', {
accepts: [
{
arg: 'filter',
type: 'object',
description: 'Filter defining where'
}
],
returns: {
type: [this.modelName],
root: true
},
http: {
verb: 'get',
path: '/list'
}
});
};
self.list = function(filter, cb) {};
self.rawSql = function(query, params, cb) {
this.dataSource.connector.execute(query, params, function(error, response) {
cb(error, response);

View File

@ -2,13 +2,6 @@ module.exports = function(TicketState) {
TicketState.remoteMethodCtx('changeState', {
description: 'Change state of tickets',
accepts: [
{
arg: 'tickets',
type: 'array',
required: true,
description: 'Array of tickets',
http: {source: 'path'}
},
{
arg: 'state',
type: 'number',
@ -23,11 +16,13 @@ module.exports = function(TicketState) {
},
http: {
verb: 'put',
path: '/:tickets/:state/changeState'
path: '/:state/changeState'
}
});
TicketState.changeState = function(ctx, tickets, state, cb) {
TicketState.changeState = function(ctx, state, cb) {
var tickets = ctx.req.body.tickets;
TicketState.connectToService(ctx, "client");
TicketState.app.models.Employee.findOne({where: {userFk: ctx.req.accessToken.userId}}, function(err, emp){

View File

@ -1,18 +1,6 @@
module.exports = function(Warehouse) {
Warehouse.remoteMethod('list', {
description: 'List production warehouses',
returns: {
arg: 'warehouses',
type: 'array'
},
http: {
verb: 'get',
path: '/list'
}
});
Warehouse.list = function(cb) {
Warehouse.find(where(), function(err, warehouses){
Warehouse.list = function(filter, cb) {
Warehouse.find(where(filter), function(err, warehouses){
if(!err)
cb(null, warehouses);
else
@ -20,7 +8,12 @@ module.exports = function(Warehouse) {
});
};
var where = function(){
return {"where": {"tpv": {"neq": 0}}}
var where = function(filter){
if(!filter)
return {"where": {"tpv": {"neq": 0}}}
else {
filter.where.tpv = {"neq": 0}
return filter;
}
}
}

View File

@ -25,7 +25,29 @@ module.exports = function(self) {
for(let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
}
this.remoteMethod('list', {
accepts: [
{
arg: 'filter',
type: 'object',
description: 'Filter defining where'
}
],
returns: {
type: [this.modelName],
root: true
},
http: {
verb: 'get',
path: '/list'
}
});
};
self.list = function(filter, cb) {};
self.rawSql = function(query, params, cb) {
this.dataSource.connector.execute(query, params, function(error, response) {
cb(error, response);

View File

@ -25,7 +25,29 @@ module.exports = function(self) {
for(let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
}
this.remoteMethod('list', {
accepts: [
{
arg: 'filter',
type: 'object',
description: 'Filter defining where'
}
],
returns: {
type: [this.modelName],
root: true
},
http: {
verb: 'get',
path: '/list'
}
});
};
self.list = function(filter, cb) {};
self.rawSql = function(query, params, cb) {
this.dataSource.connector.execute(query, params, function(error, response) {
cb(error, response);