module.exports = Self => { Self.remoteMethodCtx('toBook', { description: 'To book the invoiceIn', accessType: 'WRITE', accepts: { arg: 'id', type: 'number', required: true, description: 'The invoiceIn id', http: {source: 'path'} }, returns: { type: 'object', root: true }, http: { path: '/:id/toBook', verb: 'POST' } }); Self.toBook = async(ctx, id, options) => { let tx; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); if (!myOptions.transaction) { tx = await Self.beginTransaction({}); myOptions.transaction = tx; } try { await Self.rawSql(`CALL vn.invoiceInBookingMain(?)`, [id], myOptions); if (tx) await tx.commit(); } catch (e) { if (tx) await tx.rollback(); throw e; } }; };