From 7b44409491e984dd816b3b5353052bee21aa66e6 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 16 Jul 2020 07:50:05 -0700 Subject: get invoice endpoint --- routes/invoices.js | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/routes/invoices.js b/routes/invoices.js index bb2673cc..a4a6c0da 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -1,25 +1,49 @@ const { Op } = require("sequelize"); +app.get("/invoice", auth, async (req, res) => { + try { + const invoice = await db.Invoice.findOne({ + where: { + uuid: req.query.uuid, + }, + }); + + res.send(invoice); + } catch (e) { + l.error("couldn't find invoice", e); + } +}); + app.post("/invoice", auth, async (req, res) => { const { invoice } = req.body; invoice.user_id = req.user.id; - l.info("creating invoice", invoice.text, req.user.username, invoice.network, invoice.amount, invoice.tip, invoice.currency, invoice.rate.toFixed(2)); + l.info( + "creating invoice", + invoice.text, + req.user.username, + invoice.network, + invoice.amount, + invoice.tip, + invoice.currency, + invoice.rate.toFixed(2) + ); - if (invoice.network === 'LBTC') { - invoice.unconfidential = (await lq.getAddressInfo(invoice.address)).unconfidential; - } + if (invoice.network === "LBTC") { + invoice.unconfidential = ( + await lq.getAddressInfo(invoice.address) + ).unconfidential; + } const exists = await db.Invoice.findOne({ where: { [Op.or]: { address: invoice.address || "undefined", - text: invoice.text - } - } + text: invoice.text, + }, + }, }); - res.send( exists ? await exists.update(invoice) : await db.Invoice.create(invoice) ); -- cgit v1.2.3