diff options
| author | Adam Soltys <[email protected]> | 2025-09-18 16:36:25 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-09-18 16:38:11 -0700 |
| commit | 3ec79e2f938423d1442886454204973d804f37d9 (patch) | |
| tree | 472d55a4eef98a8a5368996eca892b77c3d96c11 /routes | |
| parent | 7d11696ce6c555d3f0adc4a0da03d2c895d0a596 (diff) | |
| download | coinos-server-3ec79e2f938423d1442886454204973d804f37d9.tar.gz coinos-server-3ec79e2f938423d1442886454204973d804f37d9.zip | |
allow invoice owners to modify the webhook
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/invoices.ts | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/routes/invoices.ts b/routes/invoices.ts index 54b1a30b..7e98599e 100644 --- a/routes/invoices.ts +++ b/routes/invoices.ts @@ -53,13 +53,18 @@ export default { try { const { id } = req.params; const { body } = req; - if (body.invoice?.tip == null || body.invoice.tip < 0) fail("Invalid tip"); + const { tip, webhook, secret } = body.invoice; + if (tip == null || tip < 0) fail("Invalid tip"); let invoice = await g(`invoice:${id}`); - const user = await g(`user:${invoice.uid}`); - invoice.tip = body.invoice.tip; - invoice.webhook = body.invoice.webhook; - invoice.secret = body.invoice.secret; + const user = req.user || (await g(`user:${invoice.uid}`)); + + if (tip) invoice.tip = tip; + if (invoice.uid === user?.id) { + if (webhook) invoice.webhook = webhook; + if (secret) invoice.secret = secret; + } + invoice = await generate({ invoice, user }); await s(`invoice:${id}`, invoice); |
