diff options
| -rw-r--r-- | index.ts | 1 | ||||
| -rw-r--r-- | routes/invoices.ts | 18 |
2 files changed, 18 insertions, 1 deletions
@@ -47,6 +47,7 @@ app.get("/locations", locations.list); app.get("/invoice/:id", invoices.get); app.get("/invoices", auth, invoices.list); app.post("/invoice", optional, invoices.create); +app.post("/invoice/:id", invoices.update); app.post("/sign", auth, invoices.sign); app.get("/assetlinks.json", (_, res) => res.sendFile("assetlinks.json")); diff --git a/routes/invoices.ts b/routes/invoices.ts index 013cedba..6be1efec 100644 --- a/routes/invoices.ts +++ b/routes/invoices.ts @@ -1,5 +1,5 @@ import config from "$config"; -import { db } from "$lib/db"; +import { db, g, s } from "$lib/db"; import { generate } from "$lib/invoices"; import { err } from "$lib/logging"; import { bail, fail, fields, getInvoice, getUser } from "$lib/utils"; @@ -49,6 +49,22 @@ export default { } }, + async update(req, res) { + try { + const { id } = req.params; + const { body } = req; + if (!body.invoice?.tip || body.invoice.tip < 0) fail("Invalid tip"); + + const invoice = await g(`invoice:${id}`); + invoice.tip = body.invoice.tip; + await s(`invoice:${id}`, invoice); + + res.send(invoice); + } catch (e) { + bail(res, e.message); + } + }, + async list(req, res) { const { id } = req.user; let invoices = await db.lRange(`${id}:invoices`, 0, -1); |
