diff options
| author | Adam Soltys <[email protected]> | 2021-02-19 21:46:21 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2021-02-19 21:46:21 -0800 |
| commit | fb2a1a9f7262c58636b62fe1eee1b95e88a481c8 (patch) | |
| tree | fc05ad9ac87f402ec48e08d8792e44df72631d23 /routes/invoices.js | |
| parent | 035afbbbc1c00f15d3956dbd21adb3a9c82c223e (diff) | |
| download | coinos-server-fb2a1a9f7262c58636b62fe1eee1b95e88a481c8.tar.gz coinos-server-fb2a1a9f7262c58636b62fe1eee1b95e88a481c8.zip | |
instant lightning->liquid conversion
Diffstat (limited to 'routes/invoices.js')
| -rw-r--r-- | routes/invoices.js | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/routes/invoices.js b/routes/invoices.js index 3ef0b4e3..9a24a8c0 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -21,11 +21,14 @@ app.get( app.post( "/invoice", + optionalAuth, ah(async (req, res, next) => { try { - let { invoice, user } = req.body; + let { liquidAddress, invoice, user } = req.body; let { blindkey } = invoice; + if (liquidAddress) convert[invoice.text] = liquidAddress; + if (!user) ({ user } = req); else { user = await db.User.findOne({ @@ -35,6 +38,7 @@ app.post( }); } if (!user) throw new Error("user not provided"); + if (!invoice.currency) invoice.currency = user.currency; invoice.user_id = user.id; invoice.account_id = user.account_id; @@ -49,15 +53,17 @@ app.post( if (!invoice.tip) invoice.tip = 0; - const exists = await db.Invoice.findOne({ - where: { - [Op.or]: { - address: invoice.address || "", - unconfidential: invoice.unconfidential || "", - text: invoice.text + const exists = + invoice.text && + (await db.Invoice.findOne({ + where: { + [Op.or]: { + address: invoice.address || "", + unconfidential: invoice.unconfidential || "", + text: invoice.text + } } - } - }); + })); invoice = exists ? await exists.update(invoice) |
