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) {
this.$http.put(`/production/api/changeTime?time=${time}`, {tickets: ids}).then(
this.$http.put(`/production/api/Tickets/${time}/changeTime`, {tickets: ids}).then(
() => {
index.forEach(
i => {

View File

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

View File

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

View File

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

View File

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