module.exports = Self => { Self.remoteMethod('addDropOff', { description: 'Add a dropOff note in a ticket', accessType: 'WRITE', accepts: [{ arg: 'ticketFk', type: 'number', required: true, description: 'ticket ID' }, { arg: 'note', type: 'string', required: true, description: 'note text' }], http: { path: `/addDropOff`, verb: 'post' } }); Self.addDropOff = async(ticketFk, note, options) => { const models = Self.app.models; const myOptions = {}; let tx; if (typeof options == 'object') Object.assign(myOptions, options); if (!myOptions.transaction) { tx = await Self.beginTransaction({}); myOptions.transaction = tx; } try { const observationTypeDropOff = await models.ObservationType.findOne({ where: {code: 'dropOff'} }, myOptions); await models.TicketObservation.create({ ticketFk: ticketFk, observationTypeFk: observationTypeDropOff.id, description: note }, myOptions); if (tx) await tx.commit(); } catch (error) { if (tx) await tx.rollback(); throw error; } }; };