Skip to content
This repository was archived by the owner on Jan 1, 2022. It is now read-only.

Commit 0a7428c

Browse files
committed
Ignore empty username updates
1 parent 7379c30 commit 0a7428c

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

apps/rest-api/src/controller/usersController.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,22 @@ module.exports.addUser = async (user) => {
113113
_new
114114
);
115115

116+
update.query +=
117+
(update.query.length == 0 ? "" : ", ") + field + " = ?";
118+
update.params.push(_new);
119+
120+
// ignore usernames that were empty before
121+
if (_old == null || _old == undefined) {
122+
if (field == "username") {
123+
continue;
124+
}
125+
}
126+
116127
// add to updates
117128
await connection.query(
118129
"INSERT INTO users_updates (`userId`, `key`, `old_value`, `new_value`, `date`) VALUES (?, ?, ?, ?, ?);",
119130
[userId, field, _old, _new, date]
120131
);
121-
122-
update.query +=
123-
(update.query.length == 0 ? "" : ", ") + field + " = ?";
124-
update.params.push(_new);
125132
}
126133
}
127134

@@ -139,7 +146,6 @@ module.exports.addUser = async (user) => {
139146
"UPDATE users SET " + update.query + " WHERE userId = ?;",
140147
update.params
141148
);
142-
143149
} else {
144150
console.log("[User Update | " + userId + "] No need to update");
145151
}
@@ -164,7 +170,7 @@ module.exports.addUser = async (user) => {
164170

165171
return {
166172
error: false,
167-
message: "Nothing updated."
173+
message: "Nothing updated.",
168174
};
169175
} finally {
170176
if (connection) {

0 commit comments

Comments
 (0)