rawsql with promises

This commit is contained in:
nelo 2017-06-29 11:48:57 +02:00
parent e9c0fa5cc9
commit 2e7a225249
5 changed files with 39 additions and 27 deletions

View File

@ -55,7 +55,7 @@ export default class ProductionActions {
); );
} }
_changeTime(ids, time, index) { _changeTime(ids, time, index) {
this.$http.put(`/production/api/changeTime?time=${time}`, {tickets: ids}).then( this.$http.put(`/production/api/Tickets/${time}/changeTime`, {tickets: ids}).then(
() => { () => {
index.forEach( index.forEach(
i => { i => {

View File

@ -79,10 +79,16 @@ module.exports = function(self) {
}; };
self.rawSql = function(query, params, cb) { self.rawSql = function(query, params, cb) {
this.dataSource.connector.execute(query, params, function(error, response) { var connector = this.dataSource.connector;
if (error) return new Promise(function(resolve, reject) {
connector.execute(query, params, function(error, response) {
if (error && !reject)
cb(error, null); cb(error, null);
return response; else if (error && reject)
reject(error);
else
resolve(response);
});
}); });
}; };

View File

@ -20,11 +20,6 @@ module.exports = function(Ticket) {
Ticket.changeTime = function(ctx, time, cb) { Ticket.changeTime = function(ctx, time, cb) {
var tickets = ctx.req.body.tickets; var tickets = ctx.req.body.tickets;
changeTime(tickets, time, cb);
};
var changeTime = function(tickets, time, cb){
var FakeProduction = Ticket.app.models.FakeProduction; var FakeProduction = Ticket.app.models.FakeProduction;
var hour = `${time}:00`; var hour = `${time}:00`;
@ -34,11 +29,10 @@ module.exports = function(Ticket) {
FakeProduction.updateAll({ticketFk: {inq: tickets}}, {hour: hour}, function(err, res){ FakeProduction.updateAll({ticketFk: {inq: tickets}}, {hour: hour}, function(err, res){
if(err) if(err)
cb(err, null) cb(err, null)
else{ else
var response = Ticket.rawSql(query, params, cb); Ticket.rawSql(query, params, cb).then(function(response) {
cb(null, response); cb(null, response);
}
}); });
});
} };
} }

View File

@ -79,10 +79,16 @@ module.exports = function(self) {
}; };
self.rawSql = function(query, params, cb) { self.rawSql = function(query, params, cb) {
this.dataSource.connector.execute(query, params, function(error, response) { var connector = this.dataSource.connector;
if (error) return new Promise(function(resolve, reject) {
connector.execute(query, params, function(error, response) {
if (error && !reject)
cb(error, null); cb(error, null);
return response; else if (error && reject)
reject(error);
else
resolve(response);
});
}); });
}; };

View File

@ -79,10 +79,16 @@ module.exports = function(self) {
}; };
self.rawSql = function(query, params, cb) { self.rawSql = function(query, params, cb) {
this.dataSource.connector.execute(query, params, function(error, response) { var connector = this.dataSource.connector;
if (error) return new Promise(function(resolve, reject) {
connector.execute(query, params, function(error, response) {
if (error && !reject)
cb(error, null); cb(error, null);
return response; else if (error && reject)
reject(error);
else
resolve(response);
});
}); });
}; };