aboutsummaryrefslogtreecommitdiffstats
path: root/routes/invoices.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-08-03 21:38:29 -0700
committerAdam Soltys <[email protected]>2020-08-03 21:38:29 -0700
commit2bcd5e9cd2233934b6d78724a07172b187ceb0b0 (patch)
treedba0c6451c1fa962dda1c3aa848abaa36d7012ab /routes/invoices.js
parent1f44dadfb24913d9a6835f3b18340ede580e886a (diff)
downloadcoinos-server-2bcd5e9cd2233934b6d78724a07172b187ceb0b0.tar.gz
coinos-server-2bcd5e9cd2233934b6d78724a07172b187ceb0b0.zip
user urls
Diffstat (limited to 'routes/invoices.js')
-rw-r--r--routes/invoices.js23
1 files changed, 16 insertions, 7 deletions
diff --git a/routes/invoices.js b/routes/invoices.js
index fdfb39d8..f344e9f9 100644
--- a/routes/invoices.js
+++ b/routes/invoices.js
@@ -14,14 +14,23 @@ app.get("/invoice", auth, ah(async (req, res, next) => {
}
}));
-app.post("/invoice", auth, ah(async (req, res, next) => {
- const { invoice } = req.body;
- invoice.user_id = req.user.id;
+app.post("/invoice", ah(async (req, res, next) => {
+ let { invoice, user } = req.body;
+ if (!user) ({ user } = req);
+ else {
+ user = await db.User.findOne({
+ where: {
+ username: user.username,
+ }
+ });
+ }
+ if (!user) throw new Error("user not provided");
+ invoice.user_id = user.id;
l.info(
"creating invoice",
invoice.text,
- req.user.username,
+ user.username,
invoice.network,
invoice.amount,
invoice.tip,
@@ -44,7 +53,7 @@ app.post("/invoice", auth, ah(async (req, res, next) => {
},
});
- res.send(
- exists ? await exists.update(invoice) : await db.Invoice.create(invoice)
- );
+ invoice = exists ? await exists.update(invoice) : await db.Invoice.create(invoice);
+ addresses[invoice.address] = user.username;
+ res.send(invoice);
}));