Merge branch 'dev' of https://git.verdnatura.es/salix into dev

# Conflicts:
#	services/production/common/methods/ticket-state/change-state.js
This commit is contained in:
Dani Herrero 2017-06-14 09:58:30 +02:00
commit e43827ab28
6 changed files with 77 additions and 13 deletions

View File

@ -1,4 +1,3 @@
module.exports = function(self) {
self.setup = function() {
@ -26,7 +25,20 @@ module.exports = function(self) {
for(let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
}
};
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}});
};
self.rawSql = function(query, params, cb) {

View File

@ -28,19 +28,23 @@ module.exports = function(TicketState) {
});
TicketState.changeState = function(tickets, state, cb) {
changeState(tickets, state, cb);
TicketState.getEmployee().then(function(emp){
changeState(emp, tickets, state, cb);
});
};
var changeState = function(tickets, state, cb){
TicketState.updateAll(where(tickets), {"state": state}, function(error, response){
if(!error)
cb(null, true);
cb(error);
var changeState = function(emp, tickets, state, cb){
var inserts = [];
tickets.forEach(function(t) {
inserts.push({ticketFk: t, stateFk: state, employeeFk: emp});
}, this);
TicketState.create(inserts, function(err, res){
if(!err)
cb(null, res);
});
}
var where = function(tickets){
return {"where": {"ticketFk": {"inq": tickets } } };
}
}

View File

@ -1,4 +1,3 @@
module.exports = function(self) {
self.setup = function() {
@ -26,7 +25,20 @@ module.exports = function(self) {
for(let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
}
};
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}});
};
self.rawSql = function(query, params, cb) {

View File

@ -28,10 +28,20 @@
"helmet#noSniff": {},
"helmet#noCache": {
"enabled": false
},
"loopback-context#per-request": {
"params": {
"enableHttpContext": true
}
}
},
"session": {},
"auth": {},
"auth": {
"loopback#token": {}
},
"auth:after": {
"./middleware/currentUser": {}
},
"parse": {},
"routes": {
"loopback#rest": {

View File

@ -0,0 +1,13 @@
module.exports = function(options) {
return function storeCurrentUser(req, res, next) {
if (!req.accessToken) {
return next();
}
let LoopBackContext = require('loopback-context');
let loopbackContext = LoopBackContext.getCurrentContext();
if (loopbackContext) {
loopbackContext.set('currentUser', req.accessToken.userId);
}
next();
};
};

View File

@ -1,3 +1,5 @@
let loopBackContext = require('loopback-context');
let app = require('../../server/server');
module.exports = function(self) {
@ -26,7 +28,18 @@ module.exports = function(self) {
for(let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
}
};
self.getUser = function() {
let currentUser = loopBackContext.getCurrentContext();
let userId = currentUser.get('currentUser');
return userId;
};
self.getEmployee = function() {
let userId = self.getUser();
let employee = app.models.Employee;
return employee.findOne({where: {userFk: userId}});
};
self.rawSql = function(query, params, cb) {