const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('updateEditableTicket', { description: 'Change data of a ticket', accessType: 'WRITE', accepts: [ { arg: 'id', type: 'number', required: true, description: 'Ticket id', http: {source: 'path'} }, { arg: 'data', description: 'Model instance data', type: 'Object', required: true, http: {source: 'body'} } ], returns: { type: 'object', root: true }, http: { path: '/:id/updateEditableTicket', verb: 'POST' } }); Self.updateEditableTicket = async(ctx, id, data) => { let ticketIsEditable = await Self.app.models.Ticket.isEditable(ctx, id); if (!ticketIsEditable) throw new UserError('This ticket can not be modified'); let ticket = await Self.app.models.Ticket.findById(id); await ticket.updateAttributes(data); }; };