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:
commit
e43827ab28
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
module.exports = function(self) {
|
module.exports = function(self) {
|
||||||
|
|
||||||
self.setup = function() {
|
self.setup = function() {
|
||||||
|
@ -26,7 +25,20 @@ module.exports = function(self) {
|
||||||
for(let method in disableMethods) {
|
for(let method in disableMethods) {
|
||||||
//this.disableRemoteMethod(method, disableMethods[method]);
|
//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) {
|
self.rawSql = function(query, params, cb) {
|
||||||
|
|
|
@ -28,19 +28,23 @@ module.exports = function(TicketState) {
|
||||||
});
|
});
|
||||||
|
|
||||||
TicketState.changeState = function(tickets, state, cb) {
|
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){
|
var changeState = function(emp, tickets, state, cb){
|
||||||
if(!error)
|
var inserts = [];
|
||||||
cb(null, true);
|
|
||||||
cb(error);
|
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 } } };
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
module.exports = function(self) {
|
module.exports = function(self) {
|
||||||
|
|
||||||
self.setup = function() {
|
self.setup = function() {
|
||||||
|
@ -26,7 +25,20 @@ module.exports = function(self) {
|
||||||
for(let method in disableMethods) {
|
for(let method in disableMethods) {
|
||||||
//this.disableRemoteMethod(method, disableMethods[method]);
|
//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) {
|
self.rawSql = function(query, params, cb) {
|
||||||
|
|
|
@ -28,10 +28,20 @@
|
||||||
"helmet#noSniff": {},
|
"helmet#noSniff": {},
|
||||||
"helmet#noCache": {
|
"helmet#noCache": {
|
||||||
"enabled": false
|
"enabled": false
|
||||||
|
},
|
||||||
|
"loopback-context#per-request": {
|
||||||
|
"params": {
|
||||||
|
"enableHttpContext": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"session": {},
|
"session": {},
|
||||||
"auth": {},
|
"auth": {
|
||||||
|
"loopback#token": {}
|
||||||
|
},
|
||||||
|
"auth:after": {
|
||||||
|
"./middleware/currentUser": {}
|
||||||
|
},
|
||||||
"parse": {},
|
"parse": {},
|
||||||
"routes": {
|
"routes": {
|
||||||
"loopback#rest": {
|
"loopback#rest": {
|
||||||
|
|
|
@ -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();
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,3 +1,5 @@
|
||||||
|
let loopBackContext = require('loopback-context');
|
||||||
|
let app = require('../../server/server');
|
||||||
|
|
||||||
module.exports = function(self) {
|
module.exports = function(self) {
|
||||||
|
|
||||||
|
@ -26,7 +28,18 @@ module.exports = function(self) {
|
||||||
for(let method in disableMethods) {
|
for(let method in disableMethods) {
|
||||||
//this.disableRemoteMethod(method, disableMethods[method]);
|
//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) {
|
self.rawSql = function(query, params, cb) {
|
||||||
|
|
Loading…
Reference in New Issue