diff options
| author | Adam Soltys <[email protected]> | 2022-10-26 00:02:39 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-10-26 00:02:39 -0700 |
| commit | 75acb68fc7dddc4ce1547786908b8df168ec7fdf (patch) | |
| tree | b33846fdde9498d251a198a933aa57268bf9cbad | |
| parent | 42b0a9243389bb86db6d9d276b3d60b769aa725a (diff) | |
| download | coinos-server-75acb68fc7dddc4ce1547786908b8df168ec7fdf.tar.gz coinos-server-75acb68fc7dddc4ce1547786908b8df168ec7fdf.zip | |
save recipient id with payment
| -rw-r--r-- | lib/sendInternal.js | 63 |
1 files changed, 33 insertions, 30 deletions
diff --git a/lib/sendInternal.js b/lib/sendInternal.js index 2e98ed22..625fd42f 100644 --- a/lib/sendInternal.js +++ b/lib/sendInternal.js @@ -56,38 +56,10 @@ export default async ( await account.decrement({ balance: amount }, { transaction }); await account.reload({ transaction }); - let params = { - amount: -amount, - account_id: account.id, - memo, - user_id: user.id, - rate: store.rates[user.currency], - currency: user.currency, - confirmed: true, - hash: `#${v4().substr(0, 6)} ${ - username ? `Payment to ${username}` : "Internal Transfer" - }`, - network: "COINOS" - }; - - if (!username) { - l("creating redeemable payment"); - params.redeemcode = v4(); - params.hash = `${hostname}/redeem/${params.redeemcode}`; - } - - let payment = await db.Payment.create(params, { transaction }); - - payment = payment.get({ plain: true }); - payment.account = account.get({ plain: true }); - - l("sent internal", user.username, -payment.amount); - - emit(user.username, "payment", payment); - emit(user.username, "account", account); + let params, recipient; if (username) { - let recipient = await db.User.findOne( + recipient = await db.User.findOne( { where: { username }, include: { @@ -210,6 +182,37 @@ export default async ( callWebhook(invoice, p2); } + params = { + amount: -amount, + account_id: account.id, + memo, + user_id: user.id, + rate: store.rates[user.currency], + currency: user.currency, + confirmed: true, + with_id: recipient && recipient.id, + hash: `#${v4().substr(0, 6)} ${ + username ? `Payment to ${username}` : "Internal Transfer" + }`, + network: "COINOS" + }; + + if (!username) { + l("creating redeemable payment"); + params.redeemcode = v4(); + params.hash = `${hostname}/redeem/${params.redeemcode}`; + } + + let payment = await db.Payment.create(params, { transaction }); + + payment = payment.get({ plain: true }); + payment.account = account.get({ plain: true }); + + l("sent internal", user.username, -payment.amount); + + emit(user.username, "payment", payment); + emit(user.username, "account", account); + return payment; }); }; |
