salix/services/loopback/common/methods/ticket/changeTime.js

38 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',
2017-06-29 07:48:00 +00:00
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-12 06:21:36 +00:00
var hour = `${time}:00`;
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 (?)`;
2017-07-12 06:21:36 +00:00
var params = [hour, tickets];
2017-10-25 11:47:39 +00:00
FakeProduction.updateAll({ticketFk: {inq: tickets}}, {hour: hour}, function(err, res) {
2017-10-25 11:47:39 +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 09:48:57 +00:00
};
2017-10-25 11:47:39 +00:00
};