backend-manager 2.3.13 → 2.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -75,7 +75,8 @@ Module.prototype.updateStats = function (existingData) {
|
|
|
75
75
|
|
|
76
76
|
return new Promise(async function(resolve, reject) {
|
|
77
77
|
const stats = self.libraries.admin.firestore().doc(`meta/stats`);
|
|
78
|
-
const
|
|
78
|
+
const gatheringOnline = self.libraries.admin.database().ref(`gatherings/online`);
|
|
79
|
+
const sessionsApp = self.libraries.admin.database().ref(`sessions/app`);
|
|
79
80
|
|
|
80
81
|
let error = null;
|
|
81
82
|
let update = {};
|
|
@@ -106,7 +107,7 @@ Module.prototype.updateStats = function (existingData) {
|
|
|
106
107
|
|
|
107
108
|
await self.getAllSubscriptions()
|
|
108
109
|
.then(r => {
|
|
109
|
-
_.set(update, 'subscriptions
|
|
110
|
+
_.set(update, 'subscriptions', r)
|
|
110
111
|
})
|
|
111
112
|
.catch(e => {
|
|
112
113
|
error = new Error(`Failed getting subscriptions: ${e}`);
|
|
@@ -116,12 +117,25 @@ Module.prototype.updateStats = function (existingData) {
|
|
|
116
117
|
return reject(error);
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
await
|
|
120
|
+
await gatheringOnline
|
|
120
121
|
.once('value')
|
|
121
122
|
.then((snap) => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
_.
|
|
123
|
+
const data = snap.val() || {};
|
|
124
|
+
const keys = Object.keys(data);
|
|
125
|
+
const existing = _.get(update, 'users.online', 0)
|
|
126
|
+
_.set(update, 'users.online', existing + keys.length)
|
|
127
|
+
})
|
|
128
|
+
.catch(e => {
|
|
129
|
+
error = new Error(`Failed getting online users: ${e}`);
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
await sessionsApp
|
|
133
|
+
.once('value')
|
|
134
|
+
.then((snap) => {
|
|
135
|
+
const data = snap.val() || {};
|
|
136
|
+
const keys = Object.keys(data);
|
|
137
|
+
const existing = _.get(update, 'users.online', 0)
|
|
138
|
+
_.set(update, 'users.online', existing + keys.length)
|
|
125
139
|
})
|
|
126
140
|
.catch(e => {
|
|
127
141
|
error = new Error(`Failed getting online users: ${e}`);
|
|
@@ -174,18 +188,43 @@ Module.prototype.getAllSubscriptions = function () {
|
|
|
174
188
|
.where('plan.expires.timestampUNIX', '>=', new Date().getTime() / 1000)
|
|
175
189
|
.get()
|
|
176
190
|
.then(function(snapshot) {
|
|
177
|
-
|
|
191
|
+
const stats = {
|
|
192
|
+
totals: {
|
|
193
|
+
total: 0,
|
|
194
|
+
exempt: 0,
|
|
195
|
+
},
|
|
196
|
+
plans: {}
|
|
197
|
+
};
|
|
178
198
|
|
|
179
199
|
snapshot
|
|
180
200
|
.forEach((doc, i) => {
|
|
181
201
|
const data = doc.data();
|
|
182
202
|
const planId = _.get(data, 'plan.id', 'basic');
|
|
183
|
-
|
|
184
|
-
|
|
203
|
+
const frequency = _.get(data, 'plan.payment.frequency', 'unknown');
|
|
204
|
+
const isAdmin = _.get(data, 'roles.admin', false);
|
|
205
|
+
const isVip = _.get(data, 'roles.vip', false);
|
|
206
|
+
|
|
207
|
+
if (!stats.plans[planId]) {
|
|
208
|
+
stats.plans[planId] = {
|
|
209
|
+
total: 0,
|
|
210
|
+
monthly: 0,
|
|
211
|
+
annually: 0,
|
|
212
|
+
exempt: 0,
|
|
213
|
+
}
|
|
185
214
|
}
|
|
215
|
+
|
|
216
|
+
if (isAdmin || isVip) {
|
|
217
|
+
stats.totals.exempt++;
|
|
218
|
+
stats.plans[planId].exempt++;
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
stats.totals.total++;
|
|
223
|
+
stats.plans[planId].total++;
|
|
224
|
+
stats.plans[planId][frequency] = (stats.plans[planId][frequency] || 0) + 1
|
|
186
225
|
});
|
|
187
226
|
|
|
188
|
-
return resolve(
|
|
227
|
+
return resolve(stats);
|
|
189
228
|
})
|
|
190
229
|
.catch(function(e) {
|
|
191
230
|
return reject(e)
|