aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-08-20 23:19:56 -0700
committerAdam Soltys <[email protected]>2025-08-20 23:19:56 -0700
commit3b07e42a1b2495ac50b42ff70f2fc4fe0d4017b3 (patch)
tree85f391e9a03fd1cc9285d632ce55529adc019625
parent3f9a8ec7e8a3f81e510b6b162ad52321746fde7a (diff)
downloadcoinos-server-3b07e42a1b2495ac50b42ff70f2fc4fe0d4017b3.tar.gz
coinos-server-3b07e42a1b2495ac50b42ff70f2fc4fe0d4017b3.zip
invoice update
-rw-r--r--index.ts1
-rw-r--r--routes/invoices.ts18
2 files changed, 18 insertions, 1 deletions
diff --git a/index.ts b/index.ts
index 9dc98912..84c67777 100644
--- a/index.ts
+++ b/index.ts
@@ -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);