From be16090d086a05ed03fc8149581c49c717826535 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 26 Dec 2024 14:35:46 -0800 Subject: invoices list --- index.ts | 10 ++++++++-- routes/invoices.ts | 11 +++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index 36dd4c9f..07e6d9d4 100644 --- a/index.ts +++ b/index.ts @@ -46,6 +46,7 @@ app.get("/rates", rates.index); app.get("/locations", locations.list); app.get("/invoice/:id", invoices.get); +app.get("/invoices", auth, invoices.list); app.post("/invoice", optional, invoices.create); app.get("/nostr.json", nostr.identities); @@ -134,8 +135,13 @@ app.post("/claim", auth, ecash.claim); app.post("/mint", auth, ecash.mint); app.post("/melt", auth, ecash.melt); app.post("/ecash/:id", ecash.receive); -app.get("/liquid-asset-proof-c938c75d110b18aed74b45caf613ebfc1eeb9f77ab48f85016eca850489d07c2", (_, res) => res.send("Authorize linking the domain name coinos.io to the Liquid asset c938c75d110b18aed74b45caf613ebfc1eeb9f77ab48f85016eca850489d07c2")); - +app.get( + "/liquid-asset-proof-c938c75d110b18aed74b45caf613ebfc1eeb9f77ab48f85016eca850489d07c2", + (_, res) => + res.send( + "Authorize linking the domain name coinos.io to the Liquid asset c938c75d110b18aed74b45caf613ebfc1eeb9f77ab48f85016eca850489d07c2", + ), +); app.post("/echo", (req, res) => { console.log("echo", req.body); diff --git a/routes/invoices.ts b/routes/invoices.ts index 4f0f6feb..b170b607 100644 --- a/routes/invoices.ts +++ b/routes/invoices.ts @@ -1,7 +1,7 @@ -import { g } from "$lib/db"; +import { db, g } from "$lib/db"; import { generate } from "$lib/invoices"; import { err } from "$lib/logging"; -import { bail, pick } from "$lib/utils"; +import { bail, getInvoice, pick } from "$lib/utils"; export default { async get(req, res) { @@ -41,4 +41,11 @@ export default { bail(res, e.message); } }, + + async list(req, res) { + const { id } = req.user; + let invoices = await db.lRange(`${id}:invoices`, 0, -1); + invoices = await Promise.all(invoices.map((i) => getInvoice(i))); + res.send(invoices); + }, }; -- cgit v1.2.3