salix/modules/ticket/back/methods/ticket-request/deny.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-04-05 13:20:12 +00:00
module.exports = Self => {
Self.remoteMethodCtx('deny', {
2019-07-25 07:55:09 +00:00
description: 'sets a ticket request to denied and returns the changes',
2019-04-05 13:20:12 +00:00
accessType: 'WRITE',
accepts: [{
arg: 'id',
type: 'Integer',
required: true,
description: 'The request ID',
}, {
arg: 'observation',
type: 'String',
required: true,
description: 'The request observation',
}],
returns: {
type: 'number',
root: true
},
http: {
path: `/:id/deny`,
verb: 'post'
}
});
Self.deny = async ctx => {
let userId = ctx.req.accessToken.userId;
let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}});
let params = {
isOk: false,
2019-10-22 11:44:36 +00:00
attenderFk: worker.id,
2019-07-25 07:55:09 +00:00
response: ctx.args.observation,
2019-04-05 13:20:12 +00:00
};
let request = await Self.app.models.TicketRequest.findById(ctx.args.id);
return request.updateAttributes(params);
};
};