Do not use toplevel arrays

This commit is contained in:
Johannes Zellner
2021-05-04 17:41:33 +02:00
parent 7d8d6d4913
commit bec42c69c8

View File

@@ -42,7 +42,9 @@ function postProcess(result) {
result.twoFactorAuthenticationEnabled = !!result.twoFactorAuthenticationEnabled;
result.active = !!result.active;
result.loginLocations = safe.JSON.parse(result.loginLocationsJson) || [];
// we have a locations property to not store top-level array
const loginLocations = safe.JSON.parse(result.loginLocationsJson) || {};
result.loginLocations = loginLocations.locations || [];
delete result.loginLocationsJson;
return result;
@@ -252,7 +254,7 @@ function update(userId, user, callback) {
args.push(user[k] ? 1 : 0);
} else if (k === 'loginLocations') {
fields.push('loginLocationsJson = ?');
args.push(JSON.stringify({ loginLocations: user[k] }));
args.push(JSON.stringify({ locations: user[k] }));
} else {
fields.push(k + ' = ?');
args.push(user[k]);