salix/services/production/common/methods/ticket/change-time.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-06-28 06:57:33 +00:00
module.exports = function(Ticket) {
Ticket.remoteMethodCtx('changeTime', {
2017-06-29 07:48:00 +00:00
description: 'Change time of tickets',
accepts: [{
2017-06-28 06:57:33 +00:00
arg: 'time',
type: 'string',
required: true,
2017-06-29 07:48:00 +00:00
description: 'New time of tickets',
2017-06-28 06:57:33 +00:00
http: {source: 'path'}
2017-06-29 07:48:00 +00:00
}],
returns: {
arg: 'response',
type: 'boolean'
2017-06-28 06:57:33 +00:00
},
http: {
2017-06-29 07:48:00 +00:00
verb: 'put',
path: '/:time/changeTime'
2017-06-28 06:57:33 +00:00
}
});
Ticket.changeTime = function(ctx, time, cb) {
var tickets = ctx.req.body.tickets;
var FakeProduction = Ticket.app.models.FakeProduction;
2017-07-11 07:36:11 +00:00
var hour = `${time}`;
2017-06-28 06:57:33 +00:00
2017-06-29 07:48:00 +00:00
var query = `update Ticket set date = CONCAT(DATE(date), ' ', ?) where id in (?)`;
var params = [time, tickets];
FakeProduction.updateAll({ticketFk: {inq: tickets}}, {hour: hour}, function(err, res){
2017-06-28 06:57:33 +00:00
if(err)
cb(err, null)
2017-06-29 09:48:57 +00:00
else
Ticket.rawSql(query, params, cb).then(function(response) {
cb(null, response);
});
2017-06-28 06:57:33 +00:00
});
2017-06-29 12:08:57 +00:00
2017-06-29 09:48:57 +00:00
};
2017-06-28 06:57:33 +00:00
}