From 699635202922e2d43668a187f9538db4dcc28855 Mon Sep 17 00:00:00 2001 From: nelo Date: Wed, 14 Jun 2017 12:55:10 +0200 Subject: [PATCH 1/2] get warehouses --- .../methods/warehouse/list-warehouses.js | 24 +++++++++++++ .../production/common/models/warehouse.js | 9 +++++ .../production/common/models/warehouse.json | 35 +++++++++++++++++++ services/production/server/model-config.json | 4 +++ 4 files changed, 72 insertions(+) create mode 100644 services/production/common/methods/warehouse/list-warehouses.js create mode 100644 services/production/common/models/warehouse.js create mode 100644 services/production/common/models/warehouse.json diff --git a/services/production/common/methods/warehouse/list-warehouses.js b/services/production/common/methods/warehouse/list-warehouses.js new file mode 100644 index 000000000..326244943 --- /dev/null +++ b/services/production/common/methods/warehouse/list-warehouses.js @@ -0,0 +1,24 @@ +module.exports = function(Warehouse) { + Warehouse.remoteMethod('list', { + description: 'List production warehouses', + returns: { + arg: 'warehouses', + type: 'object' + }, + http: { + verb: 'get', + path: '/list' + } + }); + + Warehouse.list = function(cb) { + Warehouse.find(where(), function(err, warehouses){ + if(!err) + cb(null, warehouses); + }); + }; + + var where = function(){ + return {"where": {"tpv": {"neq": 0}}} + } +} \ No newline at end of file diff --git a/services/production/common/models/warehouse.js b/services/production/common/models/warehouse.js new file mode 100644 index 000000000..b46253ae1 --- /dev/null +++ b/services/production/common/models/warehouse.js @@ -0,0 +1,9 @@ +var app = require('../../server/server'); + +module.exports = function(Warehouse) { + var models = app.models; + + // Methods + + require('../methods/warehouse/list-warehouses.js')(Warehouse); +}; \ No newline at end of file diff --git a/services/production/common/models/warehouse.json b/services/production/common/models/warehouse.json new file mode 100644 index 000000000..208914085 --- /dev/null +++ b/services/production/common/models/warehouse.json @@ -0,0 +1,35 @@ +{ + "name": "Warehouse", + "base": "MyModel", + "validateUpsert": true, + "properties": { + "id": { + "id": true, + "type": "Number", + "forceId": false + }, + "name": { + "type": "String" + }, + "tpv": { + "type": "Number" + }, + "inventary": { + "type": "Number" + } + }, + "acls": [ + { + "accessType": "*", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "DENY" + }, + { + "accessType": "*", + "principalType": "ROLE", + "principalId": "root", + "permission": "ALLOW" + } + ] +} diff --git a/services/production/server/model-config.json b/services/production/server/model-config.json index 7f29155b0..edfa734b5 100644 --- a/services/production/server/model-config.json +++ b/services/production/server/model-config.json @@ -52,5 +52,9 @@ "TicketState":{ "dataSource": "vn", "public": true + }, + "Warehouse":{ + "dataSource": "vn", + "public": true } } From 18ff74b17f988ea3f81724bd76b9bb144da946bd Mon Sep 17 00:00:00 2001 From: nelo Date: Wed, 14 Jun 2017 14:27:16 +0200 Subject: [PATCH 2/2] get user and employee --- services/client/common/models/my-model.js | 5 +++-- .../production/common/methods/ticket-state/change-state.js | 6 +++--- services/production/common/models/my-model.js | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/services/client/common/models/my-model.js b/services/client/common/models/my-model.js index bfa55efbd..9246e02a9 100644 --- a/services/client/common/models/my-model.js +++ b/services/client/common/models/my-model.js @@ -1,3 +1,6 @@ +let loopBackContext = require('loopback-context'); +let app = require('../../server/server'); + module.exports = function(self) { self.setup = function() { @@ -28,14 +31,12 @@ module.exports = function(self) { }; self.getUser = function() { - let loopBackContext = require('loopback-context'); let currentUser = loopBackContext.getCurrentContext(); let userId = currentUser.get('currentUser'); return userId; }; self.getEmployee = function() { - let app = require('../../server/server'); let userId = self.getUser(); let employee = app.models.Employee; return employee.findOne({where: {userFk: userId}}); diff --git a/services/production/common/methods/ticket-state/change-state.js b/services/production/common/methods/ticket-state/change-state.js index c778330c7..90f2f041d 100644 --- a/services/production/common/methods/ticket-state/change-state.js +++ b/services/production/common/methods/ticket-state/change-state.js @@ -28,12 +28,11 @@ module.exports = function(TicketState) { }); TicketState.changeState = function(tickets, state, cb) { - TicketState.getEmployee().then(function(emp){ - changeState(emp, tickets, state, cb); + icketState.getEmployee().then(function(emp){ + changeState(emp, tickets, state, cb); }); }; - var changeState = function(emp, tickets, state, cb){ var inserts = []; @@ -47,4 +46,5 @@ module.exports = function(TicketState) { }); } + } \ 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 bfa55efbd..9246e02a9 100644 --- a/services/production/common/models/my-model.js +++ b/services/production/common/models/my-model.js @@ -1,3 +1,6 @@ +let loopBackContext = require('loopback-context'); +let app = require('../../server/server'); + module.exports = function(self) { self.setup = function() { @@ -28,14 +31,12 @@ module.exports = function(self) { }; self.getUser = function() { - let loopBackContext = require('loopback-context'); let currentUser = loopBackContext.getCurrentContext(); let userId = currentUser.get('currentUser'); return userId; }; self.getEmployee = function() { - let app = require('../../server/server'); let userId = self.getUser(); let employee = app.models.Employee; return employee.findOne({where: {userFk: userId}});