aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-09-12 15:34:20 -0700
committerAdam Soltys <[email protected]>2024-09-12 15:34:20 -0700
commitb00fee005fc69f79d300fa71a3619d97f4571c23 (patch)
tree2b535b49cf1f136ce30d573bd8e17b49ab78ddbf
parentf76ffaf514d42f9d74698d9fddc2e98e54667578 (diff)
downloadcoinos-server-b00fee005fc69f79d300fa71a3619d97f4571c23.tar.gz
coinos-server-b00fee005fc69f79d300fa71a3619d97f4571c23.zip
default account
-rw-r--r--lib/invoices.ts2
-rw-r--r--lib/migrate.ts10
-rw-r--r--routes/invoices.ts3
-rw-r--r--routes/users.ts2
4 files changed, 13 insertions, 4 deletions
diff --git a/lib/invoices.ts b/lib/invoices.ts
index 0919c948..c18a120b 100644
--- a/lib/invoices.ts
+++ b/lib/invoices.ts
@@ -37,6 +37,8 @@ export let generate = async ({ invoice, user, sender = undefined }) => {
else if (sender) user = await getUser(sender.username);
if (!user) fail("user not provided");
+ if (account === user.id) account = undefined;
+
let rates = await g("rates");
if (!currency) currency = user.currency;
if (!rate) rate = rates[currency];
diff --git a/lib/migrate.ts b/lib/migrate.ts
index c6de972c..8896f54b 100644
--- a/lib/migrate.ts
+++ b/lib/migrate.ts
@@ -13,7 +13,15 @@ async function migrate(id) {
let user = await g(`user:${id}`);
if (typeof user === "string") user = await g(`user:${user}`);
- if (user) return user;
+ if (user) {
+ let accounts = await db.lLen(`${user.id}:accounts`);
+ if (!accounts) {
+ await s(`account:${user.id}`, { id: user.id });
+ await db.lPush(`${user.id}:accounts`, user.id);
+ }
+
+ return user;
+ }
user = await ga(`user:${id}`);
diff --git a/routes/invoices.ts b/routes/invoices.ts
index f4034408..3dd60de0 100644
--- a/routes/invoices.ts
+++ b/routes/invoices.ts
@@ -35,9 +35,8 @@ export default {
} = req;
try {
- res.send(await generate({ invoice, user, sender }));
+ res.send(await generate({ invoice, user, sender }));
} catch (e) {
- console.log(e);
err("problem generating invoice", e.message);
bail(res, e.message);
}
diff --git a/routes/users.ts b/routes/users.ts
index eeb764ec..83303aa9 100644
--- a/routes/users.ts
+++ b/routes/users.ts
@@ -597,7 +597,7 @@ export default {
let { user } = req;
let accounts = [];
- for (let id of await db.lRange(`${user.id}:accounts`, 0, 1)) {
+ for (let id of await db.lRange(`${user.id}:accounts`, 0, -1)) {
let account = await g(`account:${id}`);
account.balance = await g(`balance:${id}`);