module.exports = Self => { Self.remoteMethodCtx('deny', { description: 'sets a ticket request to denied and returns the changes', accessType: 'WRITE', accepts: [{ arg: 'id', type: 'number', 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, options) => { const myOptions = {}; let tx; if (typeof options == 'object') Object.assign(myOptions, options); if (!myOptions.transaction) { tx = await Self.beginTransaction({}); myOptions.transaction = tx; } try { const userId = ctx.req.accessToken.userId; const worker = await Self.app.models.Worker.findOne({where: {userFk: userId}}, myOptions); const params = { isOk: false, attenderFk: worker.id, response: ctx.args.observation, }; const request = await Self.app.models.TicketRequest.findById(ctx.args.id, null, myOptions); await request.updateAttributes(params, myOptions); if (tx) await tx.commit(); return request; } catch (e) { if (tx) await tx.rollback(); throw e; } }; };