40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
module.exports = Self => {
|
|
Self.remoteMethodCtx('deny', {
|
|
description: 'sets a ticket request to denied and returns the changes',
|
|
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,
|
|
attenderFk: worker.id,
|
|
response: ctx.args.observation,
|
|
};
|
|
|
|
let request = await Self.app.models.TicketRequest.findById(ctx.args.id);
|
|
return request.updateAttributes(params);
|
|
};
|
|
};
|