diff --git a/Packages/ohif-core/both/index.js b/Packages/ohif-core/both/index.js index cbe6bea3f..416aa3427 100644 --- a/Packages/ohif-core/both/index.js +++ b/Packages/ohif-core/both/index.js @@ -1,3 +1,4 @@ +import './lib'; import './utils'; import './schema.js'; diff --git a/Packages/ohif-core/both/lib/index.js b/Packages/ohif-core/both/lib/index.js new file mode 100644 index 000000000..9dac2ed16 --- /dev/null +++ b/Packages/ohif-core/both/lib/index.js @@ -0,0 +1 @@ +import './object.js'; diff --git a/Packages/ohif-core/client/lib/object.js b/Packages/ohif-core/both/lib/object.js similarity index 64% rename from Packages/ohif-core/client/lib/object.js rename to Packages/ohif-core/both/lib/object.js index 658c3e2c7..6ff06f9d7 100644 --- a/Packages/ohif-core/client/lib/object.js +++ b/Packages/ohif-core/both/lib/object.js @@ -4,13 +4,14 @@ OHIF.object = {}; // Transforms a shallow object with keys separated by "." into a nested object OHIF.object.getNestedObject = shallowObject => { - var nestedObject = {}; - for (var key in shallowObject) { - var value = shallowObject[key]; - var propertyArray = key.split('.'); - var currentObject = nestedObject; + const nestedObject = {}; + for (let key in shallowObject) { + if (!shallowObject.hasOwnProperty(key)) continue; + const value = shallowObject[key]; + const propertyArray = key.split('.'); + let currentObject = nestedObject; while (propertyArray.length) { - var currentProperty = propertyArray.shift(); + const currentProperty = propertyArray.shift(); if (!propertyArray.length) { currentObject[currentProperty] = value; } else { @@ -28,11 +29,12 @@ OHIF.object.getNestedObject = shallowObject => { // Transforms a nested object into a shallowObject merging its keys with "." character OHIF.object.getShallowObject = nestedObject => { - var shallowObject = {}; - var putValues = function(baseKey, nestedObject, resultObject) { - for (var key in nestedObject) { - var currentKey = baseKey ? baseKey + '.' + key : key; - var currentValue = nestedObject[key]; + const shallowObject = {}; + const putValues = (baseKey, nestedObject, resultObject) => { + for (let key in nestedObject) { + if (!nestedObject.hasOwnProperty(key)) continue; + let currentKey = baseKey ? `${baseKey}.${key}` : key; + const currentValue = nestedObject[key]; if (typeof currentValue === 'object') { if (currentValue instanceof Array) { currentKey += '[]'; diff --git a/Packages/ohif-core/client/lib/index.js b/Packages/ohif-core/client/lib/index.js index cd12ec3bc..7716263f0 100644 --- a/Packages/ohif-core/client/lib/index.js +++ b/Packages/ohif-core/client/lib/index.js @@ -1,6 +1,5 @@ import './blaze.js'; import './cornerstone.js'; -import './object.js'; import './string.js'; import './ui.js'; import './utils.js'; diff --git a/Packages/ohif-user/server/user.js b/Packages/ohif-user/server/user.js index 3f11d7f16..9411f7a26 100644 --- a/Packages/ohif-user/server/user.js +++ b/Packages/ohif-user/server/user.js @@ -24,17 +24,23 @@ class UserData { // Check if there is an user logged in OHIF.MongoUtils.validateUser(); - // Build the query to update only the current user's data - const query = { _id: Meteor.userId() }; + // Get the user data + const user = Meteor.user(); // Build the path to the persistent data with the given key const persistentPath = `profile.persistent.${key}`; - // Build the data to be updated - const data = { $set: { [persistentPath]: value } }; + // Build the query to update the user's data + let query; + if (!user.profile.persistent) { + const persistentData = OHIF.object.getNestedObject({ [key]: value }); + query = { $set: { 'profile.persistent': persistentData } }; + } else { + query = { $set: { [persistentPath]: value } }; + } // Update the user's profile data with the persistent information - Accounts.users.update(query, data, OHIF.MongoUtils.writeCallback); + Accounts.users.update(user._id, query, OHIF.MongoUtils.writeCallback); } }