module.exports = Self => { Self.remoteMethodCtx('confirmTransaction', { description: 'Confirm a web payment', accessType: 'WRITE', accepts: [{ arg: 'id', type: 'number', required: true, description: 'Transaction id' }], returns: { type: 'object', root: true }, http: { path: `/confirmTransaction`, verb: 'POST' } }); Self.confirmTransaction = async(ctx, id, options) => { const models = Self.app.models; const userId = ctx.req.accessToken.userId; let tx; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); if (!myOptions.transaction) { tx = await Self.beginTransaction({}); myOptions.transaction = tx; } try { const oldTpvTransaction = await models.TpvTransaction.findById(id, null, myOptions); const confirm = await Self.rawSql('CALL hedera.tpvTransaction_confirmById(?)', [id], myOptions); const tpvTransaction = await models.TpvTransaction.findById(id, null, myOptions); const oldInstance = {status: oldTpvTransaction.status}; const newInstance = {status: tpvTransaction.status}; const logRecord = { originFk: tpvTransaction.clientFk, userFk: userId, action: 'update', changedModel: 'TpvTransaction', changedModelId: id, oldInstance: oldInstance, newInstance: newInstance }; await models.ClientLog.create(logRecord, myOptions); if (tx) await tx.commit(); return confirm; } catch (e) { if (tx) await tx.rollback(); throw e; } }; };