diff --git a/services/client/common/models/my-model.js b/services/client/common/models/my-model.js index f6dfad090..37f8d846b 100644 --- a/services/client/common/models/my-model.js +++ b/services/client/common/models/my-model.js @@ -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); diff --git a/services/production/common/methods/state/find.js b/services/production/common/methods/state/find.js index f40937891..af8a7c217 100644 --- a/services/production/common/methods/state/find.js +++ b/services/production/common/methods/state/find.js @@ -1,30 +1,25 @@ module.exports = function(State) { - State.remoteMethod('productionStates', { - description: 'Get production states', - returns: { - arg: 'states', - type: 'object' - }, - http: { - verb: 'get', - path: '/productionStates' - } - }); - - State.productionStates = function(cb) { - State.find(where(), function(err, states) { + State.list = function(filter, cb) { + State.find(where(filter), function(err, states) { if(!err){ cb(null, states); } }); }; - function where() { - return { - where: { - "order": {gt: 0} - }, - order: "order, name" + function where(filter) { + + if(!filter) + return { + where: { + "order": {gt: 0 } + }, + order: "order, name" + } + else{ + filter.where.order = {gt: 0 }; + filter.order = "order, name"; + return filter; } } diff --git a/services/production/common/methods/ticket-state/change-state.js b/services/production/common/methods/ticket-state/change-state.js index 687b8ba22..5384ba86f 100644 --- a/services/production/common/methods/ticket-state/change-state.js +++ b/services/production/common/methods/ticket-state/change-state.js @@ -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){ diff --git a/services/production/common/methods/warehouse/list-warehouses.js b/services/production/common/methods/warehouse/list-warehouses.js index 9f650e67f..c1a2413ee 100644 --- a/services/production/common/methods/warehouse/list-warehouses.js +++ b/services/production/common/methods/warehouse/list-warehouses.js @@ -1,18 +1,6 @@ module.exports = function(Warehouse) { - Warehouse.remoteMethod('list', { - description: 'List production warehouses', - returns: { - type: [Warehouse], - root: true - }, - 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; + } } } \ No newline at end of file diff --git a/services/production/common/models/my-model.js b/services/production/common/models/my-model.js index f6dfad090..37f8d846b 100644 --- a/services/production/common/models/my-model.js +++ b/services/production/common/models/my-model.js @@ -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); diff --git a/services/service/models/my-model.js b/services/service/models/my-model.js index f6dfad090..37f8d846b 100644 --- a/services/service/models/my-model.js +++ b/services/service/models/my-model.js @@ -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);