rawsql with promises
This commit is contained in:
parent
e9c0fa5cc9
commit
2e7a225249
|
@ -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 => {
|
||||
|
|
|
@ -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)
|
||||
var connector = this.dataSource.connector;
|
||||
return new Promise(function(resolve, reject) {
|
||||
connector.execute(query, params, function(error, response) {
|
||||
if (error && !reject)
|
||||
cb(error, null);
|
||||
return response;
|
||||
else if (error && reject)
|
||||
reject(error);
|
||||
else
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
else
|
||||
Ticket.rawSql(query, params, cb).then(function(response) {
|
||||
cb(null, response);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
|
@ -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)
|
||||
var connector = this.dataSource.connector;
|
||||
return new Promise(function(resolve, reject) {
|
||||
connector.execute(query, params, function(error, response) {
|
||||
if (error && !reject)
|
||||
cb(error, null);
|
||||
return response;
|
||||
else if (error && reject)
|
||||
reject(error);
|
||||
else
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -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)
|
||||
var connector = this.dataSource.connector;
|
||||
return new Promise(function(resolve, reject) {
|
||||
connector.execute(query, params, function(error, response) {
|
||||
if (error && !reject)
|
||||
cb(error, null);
|
||||
return response;
|
||||
else if (error && reject)
|
||||
reject(error);
|
||||
else
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue