39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
module.exports = function(Ticket) {
|
|
Ticket.remoteMethodCtx('changeTime', {
|
|
description: 'Change time of tickets',
|
|
accepts: [{
|
|
arg: 'time',
|
|
type: 'string',
|
|
required: true,
|
|
description: 'New time of tickets',
|
|
http: {source: 'path'}
|
|
}],
|
|
returns: {
|
|
arg: 'response',
|
|
type: 'boolean'
|
|
},
|
|
http: {
|
|
verb: 'put',
|
|
path: '/:time/changeTime'
|
|
}
|
|
});
|
|
|
|
Ticket.changeTime = function(ctx, time, cb) {
|
|
var tickets = ctx.req.body.tickets;
|
|
var FakeProduction = Ticket.app.models.FakeProduction;
|
|
var hour = `${time}:00`;
|
|
|
|
var query = `update Ticket set date = CONCAT(DATE(date), ' ', ?) where id in (?)`;
|
|
var params = [hour, tickets];
|
|
|
|
FakeProduction.updateAll({ticketFk: {inq: tickets}}, {hour: hour}, function(err, res){
|
|
if(err)
|
|
cb(err, null)
|
|
else
|
|
Ticket.rawSql(query, params, cb).then(function(response) {
|
|
cb(null, response);
|
|
});
|
|
});
|
|
|
|
};
|
|
} |