diff options
| author | Adam Soltys <[email protected]> | 2024-08-26 21:17:43 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-08-26 21:17:43 -0700 |
| commit | fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7 (patch) | |
| tree | aa8f34e1692bd2d638a2c996eeadb58671d07aea /routes/invoices.ts | |
| parent | 00e43ddc0bf3d6dd719fc9295d156567fa2fecfb (diff) | |
| download | coinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.tar.gz coinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.zip | |
typescript
Diffstat (limited to 'routes/invoices.ts')
| -rw-r--r-- | routes/invoices.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/routes/invoices.ts b/routes/invoices.ts new file mode 100644 index 00000000..5cc60e05 --- /dev/null +++ b/routes/invoices.ts @@ -0,0 +1,38 @@ +import { g, s } from "$lib/db"; +import { generate } from "$lib/invoices"; +import { bail, fail, pick } from "$lib/utils"; +import whitelist from "$lib/whitelist"; +import got from "got"; +import config from "$config"; +import ln from "$lib/ln"; + +export default { + async get({ params: { id } }, res) { + let invoice = await g(`invoice:${id}`); + if (typeof invoice === "string") invoice = await g(`invoice:${invoice}`); + + if (invoice) { + delete invoice.secret; + invoice.user = pick(await g(`user:${invoice.uid}`), [ + "id", + "profile", + "banner", + "currency", + "username", + "pubkey", + ]); + + invoice.items ||= []; + } + if (invoice) res.send(invoice); + else res.code(500).send("invoice not found"); + }, + + async create({ body: { invoice, user }, user: sender }, res) { + try { + res.send(await generate({ invoice, user, sender })); + } catch (e) { + bail(res, e.message); + } + }, +}; |
