diff options
| author | Adam Soltys <[email protected]> | 2020-01-27 23:16:22 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-01-27 23:16:22 -0800 |
| commit | e34f41697eb4b96508dc27197b91ef06bd47a641 (patch) | |
| tree | bdc18dc5253f99c74e70e1460745f4b3bb778b4b | |
| parent | 5eb6950c8f6dfea83c230c403c51c64234f23e3d (diff) | |
| download | coinos-server-e34f41697eb4b96508dc27197b91ef06bd47a641.tar.gz coinos-server-e34f41697eb4b96508dc27197b91ef06bd47a641.zip | |
test existence on username change
| -rw-r--r-- | bitcoinPayments.js | 2 | ||||
| -rw-r--r-- | liquidPayments.js | 2 | ||||
| -rw-r--r-- | sockets.js | 2 | ||||
| -rw-r--r-- | users.js | 15 |
4 files changed, 17 insertions, 4 deletions
diff --git a/bitcoinPayments.js b/bitcoinPayments.js index abdc072d..95fbcc5b 100644 --- a/bitcoinPayments.js +++ b/bitcoinPayments.js @@ -133,7 +133,7 @@ module.exports = (app, bc, db, addresses, payments, emit) => { let payments = await db.Payment.findAll({ where: { user_id: user.id }, order: [['id', 'DESC']], - limit: 20 + limit: 12 }); emit(user.username, "payments", payments); diff --git a/liquidPayments.js b/liquidPayments.js index 19e1d8e7..0b259761 100644 --- a/liquidPayments.js +++ b/liquidPayments.js @@ -133,7 +133,7 @@ module.exports = (app, db, addresses, payments, emit) => { let payments = await db.Payment.findAll({ where: { user_id: user.id }, order: [['id', 'DESC']], - limit: 20 + limit: 12 }); emit(user.username, "payments", payments); @@ -46,7 +46,7 @@ module.exports = (app, db, server) => { model: db.Payment, as: "payments", order: [["id", "DESC"]], - limit: 20 + limit: 12 } ], where: { @@ -104,6 +104,7 @@ module.exports = (addresses, auth, app, bc, db, emit) => { app.post("/user", auth, async (req, res) => { let { user } = req; let { + username, currency, email, phone, @@ -125,6 +126,18 @@ module.exports = (addresses, auth, app, bc, db, emit) => { requestPhone(user); } + let exists = await db.User.findOne({ + where: { + username + } + }); + + if (username !== user.username && exists) { + res.status(500).send("username taken"); + } else { + user.username = username; + } + user.currency = currency; user.email = email; user.phone = phone; @@ -145,7 +158,7 @@ module.exports = (addresses, auth, app, bc, db, emit) => { } await user.save(); - emit(req.user.username, "user", req.user); + emit(user.username, "user", req.user); res.send(user); }); |
