diff options
| author | Adam Soltys <[email protected]> | 2023-05-23 20:31:28 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-05-23 20:31:28 -0700 |
| commit | f7357de3a0f9e3207572446919d46f82bb71c9b9 (patch) | |
| tree | 0e951cc15999791f809d57dba07703d435c4154b | |
| parent | dd5eeb5e3768e6e614c7b206510f602781c8ba2b (diff) | |
| download | coinos-server-f7357de3a0f9e3207572446919d46f82bb71c9b9.tar.gz coinos-server-f7357de3a0f9e3207572446919d46f82bb71c9b9.zip | |
payment totals
| -rw-r--r-- | routes/payments.js | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/routes/payments.js b/routes/payments.js index 1e1a495a..f298379a 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -4,7 +4,7 @@ import { emit } from "$lib/sockets"; import { v4 } from "uuid"; import { db, g, s, t } from "$lib/db"; import { l, err, warn } from "$lib/logging"; -import { bail, fail, btc, sats } from "$lib/utils"; +import { bail, fail, btc, sats, SATS } from "$lib/utils"; import { requirePin } from "$lib/auth"; import { debit, credit, confirm, types } from "$lib/payments"; import got from "got"; @@ -149,11 +149,24 @@ export default { .filter(p => p) .sort((a, b) => b.created - a.created); - let total = payments.length; + let count = payments.length; + + let totals = payments.reduce( + (a, b) => ({ + [b.currency]: { + sats: (a[b.currency] ? a[b.currency].sats : 0) + b.amount, + fiat: ( + parseFloat(a[b.currency] ? a[b.currency].fiat : 0) + + (b.amount * b.rate) / SATS + ).toFixed(2) + } + }), + {} + ); if (limit) payments = payments.slice(offset, offset + limit); - res.send({ payments, total }); + res.send({ payments, count, totals }); }, async get({ params: { hash } }, res) { @@ -185,7 +198,8 @@ export default { async pot({ params: { name } }, res) { let amount = await g(`pot:${name}`); - if (typeof amount === 'undefined' || amount === null) return bail(res, "pot not found"); + if (typeof amount === "undefined" || amount === null) + return bail(res, "pot not found"); let payments = (await db.lRange(`pot:${name}:payments`, 0, -1)) || []; payments = await Promise.all(payments.map(hash => g(`payment:${hash}`))); |
