diff options
| author | Adam Soltys <[email protected]> | 2022-11-12 01:41:20 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-11-12 01:41:20 -0800 |
| commit | a8daf636b6c595d01e6b1cddfe8227b2b7aaed13 (patch) | |
| tree | ffae8dfb83810345c710ab8855bd48ac0ed313f0 /routes/invoices.js | |
| parent | 258e85fcfd05128800fb296114668de5b9af73f4 (diff) | |
| download | coinos-server-a8daf636b6c595d01e6b1cddfe8227b2b7aaed13.tar.gz coinos-server-a8daf636b6c595d01e6b1cddfe8227b2b7aaed13.zip | |
request endpoints
Diffstat (limited to 'routes/invoices.js')
| -rw-r--r-- | routes/invoices.js | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/routes/invoices.js b/routes/invoices.js index 6cde7de8..fa44f6e6 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -61,7 +61,15 @@ app.get("/invoice/:text", async (req, res, next) => { app.post("/invoice", optionalAuth, async (req, res, next) => { try { let { type = "bech32", liquidAddress, id, invoice, user, tx } = req.body; - let { blindkey, currency, tip, amount, rate, network, requester } = invoice; + let { + blindkey, + currency, + tip, + amount, + rate, + network, + request_id + } = invoice; let address, unconfidential, text; if (amount < 0) throw new Error("amount out of range"); @@ -151,11 +159,25 @@ app.post("/invoice", optionalAuth, async (req, res, next) => { if (blindkey) await lq.importBlindingKey(invoice.address, blindkey); } - if (requester) { - emit(requester, "invoice", { + if (request_id) { + console.log("REQ ID", request_id) + let request = await db.Request.findOne({ + where: { id: request_id }, + + include: { + model: db.User, + as: "requester", + attributes: ["username"] + } + }); + request.invoice_id = invoice.id; + await request.save(); + + emit(request.requester.username, "invoice", { amount: invoice.amount, currency: invoice.currency, rate: invoice.rate, + request_id, uuid: invoice.uuid, user: { username: user.username, profile: user.profile } }); |
