aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-02-03 21:25:52 +0000
committerAdam Soltys <[email protected]>2023-02-03 13:26:51 -0800
commitf4c51cddc3d6c45fa1de5fd928b1b2a0f95774f8 (patch)
tree911c6d2064b1ad386318c09435ab99ad054a9996 /routes
parent17a2a698de2a522f05d9ec813411b5a01b95234d (diff)
downloadcoinos-server-f4c51cddc3d6c45fa1de5fd928b1b2a0f95774f8.tar.gz
coinos-server-f4c51cddc3d6c45fa1de5fd928b1b2a0f95774f8.zip
delete user endpoint
Diffstat (limited to 'routes')
-rw-r--r--routes/nostr.js2
-rw-r--r--routes/payments.js18
-rw-r--r--routes/users.js20
3 files changed, 37 insertions, 3 deletions
diff --git a/routes/nostr.js b/routes/nostr.js
index 2900e949..005a4be9 100644
--- a/routes/nostr.js
+++ b/routes/nostr.js
@@ -44,7 +44,7 @@ export default {
let ids = await db.sMembers(pubkey);
let events = ids.length
- ? (await db.mget(ids.map(k => "ev:" + k))).map(JSON.parse)
+ ? (await db.mGet(ids.map(k => "ev:" + k))).map(JSON.parse)
: [];
res.send(events.map(e => ({ ...e, user })));
diff --git a/routes/payments.js b/routes/payments.js
index 970bc187..37f4c953 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -238,5 +238,21 @@ export default {
await bc.sendRawTransaction(hex);
res.send({ txid });
- }
+ },
+
+ async del({ params: { username }, headers: { authorization }}, res) {
+if (!authorization.includes(config.admin)) return res.code(401).send("unauthorized")
+ let { id, pubkey } = await g(`user:${await g(`user:${username}`)}`);
+ let invoices = await db.lRange(`${id}:invoices`, 0, -1);
+ let payments = await db.lRange(`${id}:payments`, 0, -1);
+
+ for (let {id} of invoices) db.del(`invoice:${id}`);
+ for (let {id} of payments) db.del(`payment:${id}`);
+ db.del(`user:${username}`);
+ db.del(`user:${id}`);
+ db.del(`user:${pubkey}`);
+
+ res.send({});
+ }
};
+
diff --git a/routes/users.js b/routes/users.js
index 10cc358d..4fcc50df 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -237,7 +237,8 @@ export default {
if (!p.with) continue;
let id = await g(`user:${p.with.username}`);
- let u = await g(`user:${id}`);
+ let u = id && await g(`user:${id}`);
+
if (!u) {
u = await got(`${classic}/admin/migrate/${p.with.username}`, {
headers: { authorization: `Bearer ${config.admin}` }
@@ -372,5 +373,22 @@ export default {
await s(`${id}:contacts`, contacts);
res.send(contacts);
+ },
+
+ async del({ params: { username }, headers: { authorization } }, res) {
+ if (!(authorization && authorization.includes(config.admin)))
+ return res.code(401).send("unauthorized");
+
+ let { id, pubkey } = await g(`user:${await g(`user:${username}`)}`);
+ let invoices = await db.lRange(`${id}:invoices`, 0, -1);
+ let payments = await db.lRange(`${id}:payments`, 0, -1);
+
+ for (let { id } of invoices) db.del(`invoice:${id}`);
+ for (let { id } of payments) db.del(`payment:${id}`);
+ db.del(`user:${username}`);
+ db.del(`user:${id}`);
+ db.del(`user:${pubkey}`);
+
+ res.send({});
}
};