diff options
| author | Adam Soltys <[email protected]> | 2022-10-05 12:15:48 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-10-05 12:15:48 -0700 |
| commit | fb91aa048617f0894e01c1e890ec957a3170539f (patch) | |
| tree | 5630fbe3bb5eb67fc0fba2bba79b8b763609d93a /routes/users.js | |
| parent | 160d95f693d7d8a17e864313b06790a841d4e160 (diff) | |
| download | coinos-server-fb91aa048617f0894e01c1e890ec957a3170539f.tar.gz coinos-server-fb91aa048617f0894e01c1e890ec957a3170539f.zip | |
prettier
Diffstat (limited to 'routes/users.js')
| -rw-r--r-- | routes/users.js | 114 |
1 files changed, 60 insertions, 54 deletions
diff --git a/routes/users.js b/routes/users.js index 3063758d..c270902c 100644 --- a/routes/users.js +++ b/routes/users.js @@ -29,20 +29,20 @@ app.get("/me", auth, async (req, res) => { let user = req.user.get({ plain: true }); let payments = await req.user.getPayments({ where: { - account_id: user.account_id, + account_id: user.account_id }, order: [["id", "DESC"]], limit: 12, include: [ { model: db.Account, - as: "account", + as: "account" }, { model: db.Payment, - as: "fee_payment", - }, - ], + as: "fee_payment" + } + ] }); user.accounts = await req.user.getAccounts(); user.payments = payments; @@ -56,11 +56,11 @@ app.get("/users/:username", async (req, res) => { const { username } = req.params; const user = await db.User.findOne({ - attributes: ["username", "banner", "profile"], + attributes: ["username", "banner", "profile", "address"], where: Sequelize.where( Sequelize.fn("lower", Sequelize.col("username")), username.toLowerCase() - ), + ) }); if (user) res.send(user); @@ -80,7 +80,7 @@ app.post("/register", async (req, res) => { app.post("/disable2fa", auth, async (req, res) => { let { user, - body: { token }, + body: { token } } = req; if ( @@ -120,7 +120,7 @@ app.post("/2fa", auth, async (req, res) => { app.get("/exists", async (req, res) => { let exists = await db.User.findOne({ - where: { username: req.query.username }, + where: { username: req.query.username } }); res.send(!!exists); @@ -142,11 +142,11 @@ app.post("/user", auth, async (req, res) => { tokens, twofa, unit, - username, + username } = req.body; let exists = await db.User.findOne({ - where: { username }, + where: { username } }); let token; @@ -161,7 +161,7 @@ app.post("/user", auth, async (req, res) => { token = jwt.sign({ username }, config.jwt); res.cookie("token", token, { - expires: new Date(Date.now() + 432000000), + expires: new Date(Date.now() + 432000000) }); } @@ -193,7 +193,7 @@ app.post("/keys", auth, async (req, res) => { const { key: hex } = req.body; const key = await db.Key.create({ user_id: req.user.id, - hex, + hex }); emit(req.user.username, "key", key); res.send(key); @@ -205,8 +205,8 @@ app.post("/keys/delete", auth, async (req, res) => { await db.Key.findOne({ where: { user_id: req.user.id, - hex, - }, + hex + } }) ).destroy(); }); @@ -222,12 +222,12 @@ app.post("/updateSeeds", auth, async (req, res) => { await db.Account.update( { seed }, { - where: { id, user_id: user.id }, + where: { id, user_id: user.id } } ); const account = await db.Account.findOne({ - where: { id }, + where: { id } }); emit(user.username, "account", account); @@ -244,8 +244,16 @@ app.post("/accounts/delete", auth, async (req, res) => { }); app.post("/accounts", auth, async (req, res) => { - const { name, seed, pubkey, ticker, precision, path, privkey, network } = - req.body; + const { + name, + seed, + pubkey, + ticker, + precision, + path, + privkey, + network + } = req.body; const { user } = req; let account = await db.Account.create({ @@ -260,7 +268,7 @@ app.post("/accounts", auth, async (req, res) => { privkey, seed, path, - network, + network }); emit(user.username, "account", account); @@ -346,14 +354,14 @@ app.post("/logout", optionalAuth, async (req, res) => { if (username) { l("logging out", username); let i = req.user.subscriptions.findIndex( - (s) => JSON.stringify(s) === subscription + s => JSON.stringify(s) === subscription ); if (i > -1) { req.user.subscriptions.splice(i, 1); } await req.user.save(); Object.keys(logins).map( - (k) => logins[k]["username"] === username && delete logins[k] + k => logins[k]["username"] === username && delete logins[k] ); } @@ -373,15 +381,15 @@ app.post("/account", auth, async (req, res) => { privkey, path, hide, - index, + index } = req.body; try { - await db.transaction(async (transaction) => { + await db.transaction(async transaction => { let account = await db.Account.findOne({ where: { id, user_id: user.id }, lock: transaction.LOCK.UPDATE, - transaction, + transaction }); let params = { @@ -394,14 +402,14 @@ app.post("/account", auth, async (req, res) => { path, hide, index, - privkey, + privkey }; if (!account || (account.pubkey && !pubkey)) delete params.pubkey; await db.Account.update(params, { where: { id, user_id: user.id }, - transaction, + transaction }); await account.reload({ transaction }); @@ -420,7 +428,7 @@ app.post("/shiftAccount", auth, async (req, res) => { try { const account = await db.Account.findOne({ - where: { id }, + where: { id } }); if (account.user_id !== user.id) @@ -430,14 +438,14 @@ app.post("/shiftAccount", auth, async (req, res) => { await user.save(); let payments = await db.Payment.findAll({ where: { - account_id: id, + account_id: id }, order: [["id", "DESC"]], limit: 12, include: { model: db.Account, - as: "account", - }, + as: "account" + } }); user = user.get({ plain: true }); @@ -454,18 +462,16 @@ app.post("/shiftAccount", auth, async (req, res) => { } }); -app.get("/vapidPublicKey", function (req, res) { +app.get("/vapidPublicKey", function(req, res) { res.send(config.vapid.publicKey); }); -app.post("/subscribe", auth, async function (req, res) { +app.post("/subscribe", auth, async function(req, res) { let { subscriptions } = req.user; let { subscription } = req.body; if (!subscriptions) subscriptions = []; if ( - !subscriptions.find( - (s) => JSON.stringify(s) === JSON.stringify(subscription) - ) + !subscriptions.find(s => JSON.stringify(s) === JSON.stringify(subscription)) ) subscriptions.push(subscription); req.user.subscriptions = subscriptions; @@ -475,10 +481,10 @@ app.post("/subscribe", auth, async function (req, res) { }); let redeeming = {}; -app.post("/redeem", optionalAuth, async function (req, res) { +app.post("/redeem", optionalAuth, async function(req, res) { const { redeemcode } = req.body; try { - await db.transaction(async (transaction) => { + await db.transaction(async transaction => { if (redeeming[redeemcode]) fail("redemption in progress"); redeeming[redeemcode] = true; if (!redeemcode) fail("no code provided"); @@ -487,14 +493,14 @@ app.post("/redeem", optionalAuth, async function (req, res) { const source = await db.Payment.findOne({ where: { - redeemcode: req.body.redeemcode, + redeemcode: req.body.redeemcode }, include: { model: db.Account, - as: "account", + as: "account" }, lock: transaction.LOCK.UPDATE, - transaction, + transaction }); l("redeeming", redeemcode); @@ -511,7 +517,7 @@ app.post("/redeem", optionalAuth, async function (req, res) { user = await register( { username: redeemcode.substr(0, 8), - password: "", + password: "" }, ip, false @@ -520,7 +526,7 @@ app.post("/redeem", optionalAuth, async function (req, res) { let payload = { username: user.username }; let token = jwt.sign(payload, config.jwt); res.cookie("token", token, { - expires: new Date(Date.now() + 432000000), + expires: new Date(Date.now() + 432000000) }); delete redeeming[redeemcode]; @@ -545,7 +551,7 @@ app.post("/redeem", optionalAuth, async function (req, res) { confirmed, network, received: true, - fee, + fee }, { transaction } ); @@ -568,14 +574,14 @@ app.post("/redeem", optionalAuth, async function (req, res) { } }); -app.post("/checkRedeemCode", auth, async function (req, res) { +app.post("/checkRedeemCode", auth, async function(req, res) { const { redeemcode } = req.body; const payment = await db.Payment.findOne({ where: { redeemcode } }); res.send(payment); }); -app.post("/password", auth, async function (req, res) { +app.post("/password", auth, async function(req, res) { const { user } = req; const { password } = req.body; @@ -583,7 +589,7 @@ app.post("/password", auth, async function (req, res) { res.send(await bcrypt.compare(password, user.password)); }); -app.get("/isInternal", auth, async function (req, res) { +app.get("/isInternal", auth, async function(req, res) { let { user } = req; let { address } = req.query; if (!address) throw new Error("Address not provided"); @@ -593,8 +599,8 @@ app.get("/isInternal", auth, async function (req, res) { include: { attributes: ["username"], model: db.User, - as: "user", - }, + as: "user" + } }); if (invoice) { @@ -613,21 +619,21 @@ app.get("/isInternal", auth, async function (req, res) { res.send(false); }); -app.get("/invoices", auth, async function (req, res) { +app.get("/invoices", auth, async function(req, res) { let invoices = await db.Invoice.findAll({ - where: { user_id: req.user.id }, + where: { user_id: req.user.id } }); res.send(invoices); }); -app.post("/signMessage", auth, async function (req, res) { +app.post("/signMessage", auth, async function(req, res) { let { address, message } = req.body; let invoices = await db.Invoice.findAll({ - where: { user_id: req.user.id }, + where: { user_id: req.user.id } }); - if (invoices.find((i) => i.address === address)) { + if (invoices.find(i => i.address === address)) { if (config.bitcoin.walletpass) await bc.walletPassphrase(config.bitcoin.walletpass, 300); return res.send(await bc.signMessage(address, message)); |
