From 98d8dedfa1fe39039bf6beb2e1443770b29c6384 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 16 Sep 2020 23:43:07 -0700 Subject: hoist params variable up a scope --- routes/send.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/routes/send.js b/routes/send.js index 9080dc0c..44f71f06 100644 --- a/routes/send.js +++ b/routes/send.js @@ -67,22 +67,25 @@ module.exports = ah(async (req, res, next) => { }); let a2; + let acc = { + user_id: recipient.id, + asset, + pubkey: null + }; + if (recipient.account.asset === asset && !recipient.account.pubkey) - ({ a2 } = recipient); + ({ account: a2 } = recipient); else { - let params = { - user_id: recipient.id, - asset, - pubkey: null - }; - a2 = await db.Account.findOne({ - where: params, + where: acc, lock: transaction.LOCK.UPDATE, transaction }); } + console.log("a2", a2.id); + console.log("acc", acc); + if (a2) { a2.balance += amount; await a2.save({ transaction }); @@ -105,18 +108,16 @@ module.exports = ah(async (req, res, next) => { limit: 1 }); - l.info("existing", existing); - if (existing) { ({ domain, ticker, precision, name } = existing); } } - params = { asset, ...params, ...{ domain, ticker, precision, name } }; - params.balance = amount; - params.pending = 0; - params.network = 'liquid'; - a2 = await db.Account.create(params, { transaction }); + acc = { ...acc, ...{ domain, ticker, precision, name } }; + acc.balance = amount; + acc.pending = 0; + acc.network = 'liquid'; + a2 = await db.Account.create(acc, { transaction }); } let p2 = await db.Payment.create( -- cgit v1.2.3