diff --git a/src/controllers/connector/Profile.js b/src/controllers/connector/Profile.js index be4c7e5..8571e7f 100644 --- a/src/controllers/connector/Profile.js +++ b/src/controllers/connector/Profile.js @@ -59,9 +59,23 @@ class Profile extends AbstractFeed { { chargers: true, _id: false }, { lean: true } ); + + profile.chargers = this._calculateChargers(profile); + return profile.chargers; } + _calculateChargers(chargers) { + const chargerValues = {}; + + for (const charger of Object.keys(chargers)) { + // todo: wait for core team and add formula + chargerValues[charger] = chargers[charger].value; + } + + return chargerValues; + } + async _detectSubscription(modelObject, currentUserId, requestedUserId) { if (!currentUserId) { return; diff --git a/src/controllers/prism/Profile.js b/src/controllers/prism/Profile.js index 33669b6..2c98ba6 100644 --- a/src/controllers/prism/Profile.js +++ b/src/controllers/prism/Profile.js @@ -137,7 +137,7 @@ class Profile extends Abstract { userId, }, { - $set: { [path]: chargePercent }, + $set: { [path]: { value: chargePercent, lastUpdated: Date.now() } }, } ); diff --git a/src/models/Profile.js b/src/models/Profile.js index 36cad96..e99f973 100644 --- a/src/models/Profile.js +++ b/src/models/Profile.js @@ -15,20 +15,44 @@ module.exports = MongoDB.makeModel( }, chargers: { votes: { - type: Number, - default: 100, + value: { + type: Number, + default: 100, + }, + lastUpdated: { + type: Date, + default: Date.now(), + }, }, posts: { - type: Number, - default: 100, + value: { + type: Number, + default: 100, + }, + lastUpdated: { + type: Date, + default: Date.now(), + }, }, comments: { - type: Number, - default: 100, + value: { + type: Number, + default: 100, + }, + lastUpdated: { + type: Date, + default: Date.now(), + }, }, postbw: { - type: Number, - default: 100, + value: { + type: Number, + default: 100, + }, + lastUpdated: { + type: Date, + default: Date.now(), + }, }, }, personal: {