diff options
| author | Adam Soltys <[email protected]> | 2020-08-03 21:38:29 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-08-03 21:38:29 -0700 |
| commit | 2bcd5e9cd2233934b6d78724a07172b187ceb0b0 (patch) | |
| tree | dba0c6451c1fa962dda1c3aa848abaa36d7012ab /routes/invoices.js | |
| parent | 1f44dadfb24913d9a6835f3b18340ede580e886a (diff) | |
| download | coinos-server-2bcd5e9cd2233934b6d78724a07172b187ceb0b0.tar.gz coinos-server-2bcd5e9cd2233934b6d78724a07172b187ceb0b0.zip | |
user urls
Diffstat (limited to 'routes/invoices.js')
| -rw-r--r-- | routes/invoices.js | 23 |
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); })); |
