From c99665a0a0ac79176726169a49d5f9ebaae325bc Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 20 Mar 2023 20:14:08 -0700 Subject: prevent negative fees --- routes/users.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'routes/users.js') 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); } -- cgit v1.2.3