diff options
| author | Adam Soltys <[email protected]> | 2023-03-16 08:52:55 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-03-16 08:52:55 -0700 |
| commit | d3a35dad2f335a6291f5d656e101956a51bdaa6b (patch) | |
| tree | 6553552e34ad9ee3288c86d59e42ee5fb5af6ec7 /routes | |
| parent | 36539ce56cea91bf74a97557b127473bd659b924 (diff) | |
| download | coinos-server-d3a35dad2f335a6291f5d656e101956a51bdaa6b.tar.gz coinos-server-d3a35dad2f335a6291f5d656e101956a51bdaa6b.zip | |
fix balance endpoint
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/payments.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/routes/payments.js b/routes/payments.js index 62c5f737..c09fcf93 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -399,5 +399,29 @@ export default { } catch (e) { bail(res, e.message); } + }, + + async fix({ body: { uid }, user }, res) { + try { + if (!user.admin) fail("unauthorized"); + + let { username } = await g(`user:${uid}`); + let balance = await g(`balance:${uid}`); + + let payments = await db.lRange(`${uid}:payments`, 0, -1); + + let total = 0; + for (let pid of payments) { + let p = await g(`payment:${pid}`); + total += p.amount; + if (p.amount < 0) total -= ((p.fee || 0) + (p.ourfee || 0)); + } + + l('corrected balance', username, uid, balance, total); + await s(`balance:${uid}`, total); + res.send("ok"); + } catch (e) { + bail(res, e.message); + } } }; |
