diff options
| author | Adam Soltys <[email protected]> | 2023-03-20 20:14:08 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-03-20 20:14:08 -0700 |
| commit | c99665a0a0ac79176726169a49d5f9ebaae325bc (patch) | |
| tree | 2ff3e55048dadc4a9afe88908dd8ae609aa1ad5b /routes/users.js | |
| parent | cfca71ffceb3a462fc81919bd05ac33082935b46 (diff) | |
| download | coinos-server-c99665a0a0ac79176726169a49d5f9ebaae325bc.tar.gz coinos-server-c99665a0a0ac79176726169a49d5f9ebaae325bc.zip | |
prevent negative fees
Diffstat (limited to 'routes/users.js')
| -rw-r--r-- | routes/users.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/routes/users.js b/routes/users.js index 9ac668f4..89a04004 100644 --- a/routes/users.js +++ b/routes/users.js @@ -1,7 +1,7 @@ import { g, s, db } from "$lib/db"; import config from "$config"; import store from "$lib/store"; -import { fields, nada, pick, uniq, wait } from "$lib/utils"; +import { fields, nada, pick, uniq, wait, fail } from "$lib/utils"; import bcrypt from "bcrypt"; import jwt from "jsonwebtoken"; import { authenticator } from "otplib"; @@ -46,6 +46,17 @@ export default { let uid = k.split(":")[1]; let user = await g(`user:${uid}`); user.balance = await g(k); + + 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); + } + + user.expected = total; users.push(user); } |
