aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-01-27 23:16:22 -0800
committerAdam Soltys <[email protected]>2020-01-27 23:16:22 -0800
commite34f41697eb4b96508dc27197b91ef06bd47a641 (patch)
treebdc18dc5253f99c74e70e1460745f4b3bb778b4b
parent5eb6950c8f6dfea83c230c403c51c64234f23e3d (diff)
downloadcoinos-server-e34f41697eb4b96508dc27197b91ef06bd47a641.tar.gz
coinos-server-e34f41697eb4b96508dc27197b91ef06bd47a641.zip
test existence on username change
-rw-r--r--bitcoinPayments.js2
-rw-r--r--liquidPayments.js2
-rw-r--r--sockets.js2
-rw-r--r--users.js15
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);
diff --git a/sockets.js b/sockets.js
index cffb4c1c..439f3d48 100644
--- a/sockets.js
+++ b/sockets.js
@@ -46,7 +46,7 @@ module.exports = (app, db, server) => {
model: db.Payment,
as: "payments",
order: [["id", "DESC"]],
- limit: 20
+ limit: 12
}
],
where: {
diff --git a/users.js b/users.js
index 498bc33b..d797b2f8 100644
--- a/users.js
+++ b/users.js
@@ -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);
});