From 18ff74b17f988ea3f81724bd76b9bb144da946bd Mon Sep 17 00:00:00 2001 From: nelo Date: Wed, 14 Jun 2017 14:27:16 +0200 Subject: [PATCH] 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}});