@resolveio/server-lib 2.1.4-newrole → 2.2.0-newrole
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/collections/billing-logged-in-users.collection.d.ts +7 -0
- package/collections/billing-logged-in-users.collection.js +68 -0
- package/managers/subscription.manager.js +48 -19
- package/models/billing-logged-in-users.model.d.ts +7 -0
- package/models/billing-logged-in-users.model.js +2 -0
- package/package.json +1 -1
- package/publications/billing-logged-in-users.d.ts +1 -0
- package/publications/billing-logged-in-users.js +63 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Model, Document } from 'mongoose';
|
|
2
|
+
import { BillingLoggedInUserModel } from '../models/billing-logged-in-users.model';
|
|
3
|
+
interface ResolveIOModel extends BillingLoggedInUserModel, Document {
|
|
4
|
+
}
|
|
5
|
+
export declare let BillingLoggedInUsers: Model<ResolveIOModel>;
|
|
6
|
+
export declare const BillingLoggedInUserVersions: Model<ResolveIOModel>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
var mongoose_1 = require("mongoose");
|
|
15
|
+
var index_1 = require("../index");
|
|
16
|
+
var simpl_schema_1 = require("simpl-schema");
|
|
17
|
+
var schema = {
|
|
18
|
+
_id: {
|
|
19
|
+
type: String,
|
|
20
|
+
optional: true
|
|
21
|
+
},
|
|
22
|
+
__v: {
|
|
23
|
+
type: Number,
|
|
24
|
+
optional: true
|
|
25
|
+
},
|
|
26
|
+
updatedAt: {
|
|
27
|
+
type: Date,
|
|
28
|
+
optional: true
|
|
29
|
+
},
|
|
30
|
+
createdAt: {
|
|
31
|
+
type: Date,
|
|
32
|
+
optional: true
|
|
33
|
+
},
|
|
34
|
+
date: {
|
|
35
|
+
type: Date
|
|
36
|
+
},
|
|
37
|
+
id_user: {
|
|
38
|
+
type: String
|
|
39
|
+
},
|
|
40
|
+
user: {
|
|
41
|
+
type: String
|
|
42
|
+
},
|
|
43
|
+
client: {
|
|
44
|
+
type: String
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var DefaultSchema = new mongoose_1.Schema(schema, {
|
|
48
|
+
skipVersioning: true,
|
|
49
|
+
versionKey: false,
|
|
50
|
+
timestamps: true
|
|
51
|
+
});
|
|
52
|
+
DefaultSchema.index({ client: 1, id_user: 1, date: 1 });
|
|
53
|
+
exports.BillingLoggedInUsers = null;
|
|
54
|
+
if (index_1.ResolveIOServer.getSupportDB()) {
|
|
55
|
+
exports.BillingLoggedInUsers = index_1.ResolveIOServer.getSupportDB().model('billing-logged-in-users', DefaultSchema);
|
|
56
|
+
exports.BillingLoggedInUsers['simplschema'] = new simpl_schema_1.default(schema);
|
|
57
|
+
}
|
|
58
|
+
var vSchema = __assign({}, schema);
|
|
59
|
+
vSchema._id = {
|
|
60
|
+
type: mongoose_1.Schema.Types.Mixed
|
|
61
|
+
};
|
|
62
|
+
var VersionSchema = new mongoose_1.Schema(vSchema, {
|
|
63
|
+
skipVersioning: true,
|
|
64
|
+
versionKey: false,
|
|
65
|
+
timestamps: true
|
|
66
|
+
});
|
|
67
|
+
exports.BillingLoggedInUsers['versionCollection'] = 'billing-logged-in-users.versions';
|
|
68
|
+
exports.BillingLoggedInUserVersions = index_1.ResolveIOServer.getMainDB().model(exports.BillingLoggedInUsers['versionCollection'], VersionSchema);
|
|
@@ -52,6 +52,9 @@ var support_tickets_1 = require("../publications/support-tickets");
|
|
|
52
52
|
var index_1 = require("../index");
|
|
53
53
|
var notifications_1 = require("../publications/notifications");
|
|
54
54
|
var common_1 = require("../util/common");
|
|
55
|
+
var billing_logged_in_users_collection_1 = require("../collections/billing-logged-in-users.collection");
|
|
56
|
+
var moment = require("moment");
|
|
57
|
+
var billing_logged_in_users_1 = require("../publications/billing-logged-in-users");
|
|
55
58
|
var SubscriptionManager = /** @class */ (function () {
|
|
56
59
|
function SubscriptionManager(mainServer, wss, serverConfig) {
|
|
57
60
|
var _this = this;
|
|
@@ -74,6 +77,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
74
77
|
method_calls_1.loadMethodCallsPublications(this);
|
|
75
78
|
method_responses_1.loadMethodResponsePublications(this);
|
|
76
79
|
support_tickets_1.loadSupportTicketPublications(this);
|
|
80
|
+
billing_logged_in_users_1.loadBillingLoggedInUsersPublications(this);
|
|
77
81
|
notifications_1.loadNotificationPublications(this);
|
|
78
82
|
this.tailOpLog();
|
|
79
83
|
this.runOpLogQueue();
|
|
@@ -115,20 +119,14 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
115
119
|
};
|
|
116
120
|
SubscriptionManager.prototype.loggedInLatency = function (ws) {
|
|
117
121
|
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
-
var
|
|
122
|
+
var _this = this;
|
|
119
123
|
return __generator(this, function (_a) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
this.unsubscribeAll(ws);
|
|
129
|
-
}
|
|
130
|
-
return [2 /*return*/];
|
|
131
|
-
}
|
|
124
|
+
logged_in_users_collection_1.LoggedInUsers.findOneAndUpdate({ id_ws: ws['id_socket'] }, { $set: { latency: ws['latency'] } }).exec(function (err, res) {
|
|
125
|
+
if (err) {
|
|
126
|
+
_this.unsubscribeAll(ws);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return [2 /*return*/];
|
|
132
130
|
});
|
|
133
131
|
});
|
|
134
132
|
};
|
|
@@ -139,7 +137,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
139
137
|
subscriptionData[_i - 3] = arguments[_i];
|
|
140
138
|
}
|
|
141
139
|
return __awaiter(this, void 0, void 0, function () {
|
|
142
|
-
var _a, that, pub, valObj, valKeys, rootKeys, i, sub, _b, newActiveSub;
|
|
140
|
+
var _a, that, pub, valObj, valKeys, rootKeys, i, sub, _b, newActiveSub, begDate, endDate, billUser;
|
|
143
141
|
return __generator(this, function (_c) {
|
|
144
142
|
switch (_c.label) {
|
|
145
143
|
case 0:
|
|
@@ -225,17 +223,48 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
225
223
|
}, { $setOnInsert: { _id: mongoose_1.Types.ObjectId().toHexString(), __v: 0 }, $set: newActiveSub }, { upsert: true }).exec();
|
|
226
224
|
_c.label = 4;
|
|
227
225
|
case 4:
|
|
228
|
-
if (publication === 'appversion')
|
|
229
|
-
|
|
226
|
+
if (!(publication === 'appversion')) return [3 /*break*/, 6];
|
|
227
|
+
logged_in_users_collection_1.LoggedInUsers.create({
|
|
228
|
+
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
229
|
+
__v: 0,
|
|
230
|
+
date: new Date(),
|
|
231
|
+
id_user: ws['id_user'],
|
|
232
|
+
user: ws['user'],
|
|
233
|
+
id_ws: ws['id_socket']
|
|
234
|
+
});
|
|
235
|
+
if (!(ws['user'] !== 'Admin')) return [3 /*break*/, 6];
|
|
236
|
+
begDate = moment().startOf('month');
|
|
237
|
+
endDate = moment().endOf('month');
|
|
238
|
+
return [4 /*yield*/, billing_logged_in_users_collection_1.BillingLoggedInUsers.findOne({
|
|
239
|
+
$and: [
|
|
240
|
+
{
|
|
241
|
+
client: index_1.ResolveIOServer.getClientName()
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
id_user: ws['id_user']
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
date: { $gte: begDate }
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
date: { $lte: endDate }
|
|
251
|
+
}
|
|
252
|
+
]
|
|
253
|
+
})];
|
|
254
|
+
case 5:
|
|
255
|
+
billUser = _c.sent();
|
|
256
|
+
if (!billUser) {
|
|
257
|
+
billing_logged_in_users_collection_1.BillingLoggedInUsers.create({
|
|
230
258
|
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
231
259
|
__v: 0,
|
|
232
|
-
date: new Date(),
|
|
233
260
|
id_user: ws['id_user'],
|
|
234
261
|
user: ws['user'],
|
|
235
|
-
|
|
262
|
+
date: new Date(),
|
|
263
|
+
client: index_1.ResolveIOServer.getClientName()
|
|
236
264
|
});
|
|
237
265
|
}
|
|
238
|
-
|
|
266
|
+
_c.label = 6;
|
|
267
|
+
case 6: return [2 /*return*/];
|
|
239
268
|
}
|
|
240
269
|
});
|
|
241
270
|
});
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadBillingLoggedInUsersPublications(subscriptionManager: any): void;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var simpl_schema_1 = require("simpl-schema");
|
|
4
|
+
var billing_logged_in_users_collection_1 = require("../collections/billing-logged-in-users.collection");
|
|
5
|
+
function loadBillingLoggedInUsersPublications(subscriptionManager) {
|
|
6
|
+
subscriptionManager.publications({
|
|
7
|
+
billingloggedinusers: {
|
|
8
|
+
function: function () {
|
|
9
|
+
return billing_logged_in_users_collection_1.BillingLoggedInUsers.find().sort({ date: -1 }).exec();
|
|
10
|
+
},
|
|
11
|
+
collections: ['billing-logged-in-users']
|
|
12
|
+
},
|
|
13
|
+
billingloggedinusersWithClientAndUserId: {
|
|
14
|
+
function: function (client, id_user) {
|
|
15
|
+
return billing_logged_in_users_collection_1.BillingLoggedInUsers.find({
|
|
16
|
+
$and: [
|
|
17
|
+
{ client: client },
|
|
18
|
+
{ id_user: id_user }
|
|
19
|
+
]
|
|
20
|
+
}).exec();
|
|
21
|
+
},
|
|
22
|
+
check: new simpl_schema_1.default({
|
|
23
|
+
client: {
|
|
24
|
+
type: String
|
|
25
|
+
},
|
|
26
|
+
id_user: {
|
|
27
|
+
type: String
|
|
28
|
+
}
|
|
29
|
+
}),
|
|
30
|
+
collections: ['billing-logged-in-users'],
|
|
31
|
+
fetchFunction: function (document, client, id_user) {
|
|
32
|
+
return document['id_user'] === id_user && document['client'] === client;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
billingloggedinusersWithClientAndDates: {
|
|
36
|
+
function: function (client, date_start, date_end) {
|
|
37
|
+
return billing_logged_in_users_collection_1.BillingLoggedInUsers.find({
|
|
38
|
+
$and: [
|
|
39
|
+
{ client: client },
|
|
40
|
+
{ date: { $gte: date_start } },
|
|
41
|
+
{ date: { $lte: date_end } }
|
|
42
|
+
]
|
|
43
|
+
}).exec();
|
|
44
|
+
},
|
|
45
|
+
check: new simpl_schema_1.default({
|
|
46
|
+
client: {
|
|
47
|
+
type: String
|
|
48
|
+
},
|
|
49
|
+
date_start: {
|
|
50
|
+
type: Date
|
|
51
|
+
},
|
|
52
|
+
date_end: {
|
|
53
|
+
type: Date
|
|
54
|
+
}
|
|
55
|
+
}),
|
|
56
|
+
collections: ['billing-logged-in-users'],
|
|
57
|
+
fetchFunction: function (document, date_start, date_end) {
|
|
58
|
+
return document['date'].getTime() >= date_start && document['date'].getTime() <= date_end;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
exports.loadBillingLoggedInUsersPublications = loadBillingLoggedInUsersPublications;
|