get user and employee

This commit is contained in:
nelo 2017-06-14 14:27:16 +02:00
parent 6996352029
commit 18ff74b17f
3 changed files with 9 additions and 7 deletions

View File

@ -1,3 +1,6 @@
let loopBackContext = require('loopback-context');
let app = require('../../server/server');
module.exports = function(self) { module.exports = function(self) {
self.setup = function() { self.setup = function() {
@ -28,14 +31,12 @@ module.exports = function(self) {
}; };
self.getUser = function() { self.getUser = function() {
let loopBackContext = require('loopback-context');
let currentUser = loopBackContext.getCurrentContext(); let currentUser = loopBackContext.getCurrentContext();
let userId = currentUser.get('currentUser'); let userId = currentUser.get('currentUser');
return userId; return userId;
}; };
self.getEmployee = function() { self.getEmployee = function() {
let app = require('../../server/server');
let userId = self.getUser(); let userId = self.getUser();
let employee = app.models.Employee; let employee = app.models.Employee;
return employee.findOne({where: {userFk: userId}}); return employee.findOne({where: {userFk: userId}});

View File

@ -28,12 +28,11 @@ module.exports = function(TicketState) {
}); });
TicketState.changeState = function(tickets, state, cb) { TicketState.changeState = function(tickets, state, cb) {
TicketState.getEmployee().then(function(emp){ icketState.getEmployee().then(function(emp){
changeState(emp, tickets, state, cb); changeState(emp, tickets, state, cb);
}); });
}; };
var changeState = function(emp, tickets, state, cb){ var changeState = function(emp, tickets, state, cb){
var inserts = []; var inserts = [];
@ -47,4 +46,5 @@ module.exports = function(TicketState) {
}); });
} }
} }

View File

@ -1,3 +1,6 @@
let loopBackContext = require('loopback-context');
let app = require('../../server/server');
module.exports = function(self) { module.exports = function(self) {
self.setup = function() { self.setup = function() {
@ -28,14 +31,12 @@ module.exports = function(self) {
}; };
self.getUser = function() { self.getUser = function() {
let loopBackContext = require('loopback-context');
let currentUser = loopBackContext.getCurrentContext(); let currentUser = loopBackContext.getCurrentContext();
let userId = currentUser.get('currentUser'); let userId = currentUser.get('currentUser');
return userId; return userId;
}; };
self.getEmployee = function() { self.getEmployee = function() {
let app = require('../../server/server');
let userId = self.getUser(); let userId = self.getUser();
let employee = app.models.Employee; let employee = app.models.Employee;
return employee.findOne({where: {userFk: userId}}); return employee.findOne({where: {userFk: userId}});