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 /users.js | |
| parent | 5eb6950c8f6dfea83c230c403c51c64234f23e3d (diff) | |
| download | coinos-server-e34f41697eb4b96508dc27197b91ef06bd47a641.tar.gz coinos-server-e34f41697eb4b96508dc27197b91ef06bd47a641.zip | |
test existence on username change
Diffstat (limited to 'users.js')
| -rw-r--r-- | users.js | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -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); }); |
