aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-07-16 07:50:05 -0700
committerAdam Soltys <[email protected]>2020-07-16 07:50:05 -0700
commit7b44409491e984dd816b3b5353052bee21aa66e6 (patch)
treecae988a6210215411c7a9c60b514d29fb8231212
parent3cfa224f4c0d71b79970654de740c57b5c8a7d2a (diff)
downloadcoinos-server-7b44409491e984dd816b3b5353052bee21aa66e6.tar.gz
coinos-server-7b44409491e984dd816b3b5353052bee21aa66e6.zip
get invoice endpoint
-rw-r--r--routes/invoices.js40
1 files 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)
);