diff options
| author | Adam Soltys <[email protected]> | 2024-09-08 20:57:06 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-09-08 20:57:06 -0700 |
| commit | 5c105c8f4738ab1ead3c5b92f465f899cf0a7446 (patch) | |
| tree | 9cea2d1b46cdab9869f742e3286c9fb0762f8948 /routes/users.ts | |
| parent | 92bd9085a576517e06dc000d1e1ff11d27bc34b4 (diff) | |
| download | coinos-server-5c105c8f4738ab1ead3c5b92f465f899cf0a7446.tar.gz coinos-server-5c105c8f4738ab1ead3c5b92f465f899cf0a7446.zip | |
refactor rpc helper, accounts endpoints
Diffstat (limited to 'routes/users.ts')
| -rw-r--r-- | routes/users.ts | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/routes/users.ts b/routes/users.ts index 3fcaad66..f49ca212 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -564,12 +564,25 @@ export default { } }, - async items(req, _) { - let { - params: { id }, - } = req; - let item = await g(`item:${id}`); - return item; + async accounts(req, res) { + let { user } = req; + + let balance = await g(`balance:${user.id}`); + let accounts: any = [ + { + balance, + type: "Cash", + mint: "https://mint.coinos.io", + }, + ]; + + for (let id of await db.lRange(`${user.id}:accounts`, 0, 1)) { + let account = await g(`account:${id}`); + account.balance = await g(`balance:${id}`); + accounts.push(account); + } + + res.send(accounts); }, async hidepay(req, res) { @@ -591,4 +604,18 @@ export default { await s(`user:${u.id}`, u); res.send({}); }, + + async createAccount(req, res) { + let { type, seed } = req.body; + let { user } = req; + + let id = v4(); + let account = { id, seed, type }; + + await s(`account:${id}`, account); + await s(`balance:${id}`, 0); + await db.lPush(`${user.id}:accounts`, id); + + res.send(account); + }, }; |
