@resolveio/server-lib 2.1.4 → 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.
@@ -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);
@@ -21,13 +21,6 @@ var schema = {
21
21
  type: Date,
22
22
  optional: true
23
23
  },
24
- readonly: {
25
- type: Boolean,
26
- optional: true
27
- },
28
- active: {
29
- type: Boolean
30
- },
31
24
  attempts: {
32
25
  type: Number,
33
26
  optional: true
@@ -64,60 +57,78 @@ var schema = {
64
57
  type: String
65
58
  },
66
59
  roles: {
60
+ type: Object
61
+ },
62
+ 'roles.super_admin': {
63
+ type: Boolean
64
+ },
65
+ 'roles.approvals': {
67
66
  type: Array
68
67
  },
69
- 'roles.$': {
68
+ 'roles.approvals.$': {
69
+ type: Object
70
+ },
71
+ 'roles.approvals.$.name': {
70
72
  type: String
71
73
  },
72
- phonenumber: {
73
- type: String,
74
- optional: true
74
+ 'roles.approvals.$.type': {
75
+ type: String
75
76
  },
76
- other: {
77
- type: Object,
78
- blackbox: true,
79
- optional: true
77
+ 'roles.approvals.$.accounting_code': {
78
+ type: String
80
79
  },
81
- assets: {
82
- type: Array,
83
- optional: true
80
+ 'roles.groups': {
81
+ type: Array
84
82
  },
85
- 'assets.$': {
83
+ 'roles.groups.$': {
86
84
  type: Object
87
85
  },
88
- 'assets.$.type': {
86
+ 'roles.groups.$.name': {
89
87
  type: String
90
88
  },
91
- 'assets.$.id_asset': {
92
- type: String
89
+ 'roles.groups.$.views': {
90
+ type: Array
93
91
  },
94
- 'assets.$.asset_number': {
92
+ 'roles.groups.$.views.$': {
95
93
  type: String
96
94
  },
97
- 'assets.$.ownership': {
98
- type: String
95
+ 'roles.groups.$.yard': {
96
+ type: String,
97
+ optional: true
99
98
  },
100
- 'assets.$.ownership_driver': {
99
+ 'roles.notifications': {
100
+ type: Array
101
+ },
102
+ 'roles.notifications.$': {
101
103
  type: String
102
104
  },
103
- 'assets.$.date_start': {
104
- type: Date
105
+ 'roles.miscs': {
106
+ type: Array
105
107
  },
106
- 'assets.$.date_end': {
107
- type: Date,
108
- optional: true
108
+ 'roles.miscs.$': {
109
+ type: String
109
110
  },
110
- id_function: {
111
+ active: Boolean,
112
+ id_customer: {
111
113
  type: String,
112
114
  optional: true
113
115
  },
114
116
  customer: {
115
117
  type: String,
116
- optional: true,
118
+ optional: true
117
119
  },
118
- id_customer: {
120
+ customer_type: {
121
+ type: String,
122
+ optional: true
123
+ },
124
+ phonenumber: {
119
125
  type: String,
126
+ optional: true
127
+ },
128
+ other: {
129
+ type: Object,
120
130
  optional: true,
131
+ blackbox: true
121
132
  }
122
133
  };
123
134
  var DefaultSchema = new mongoose_1.Schema(schema, {
package/fixtures/init.js CHANGED
@@ -37,8 +37,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  var app_version_collection_1 = require("../collections/app-version.collection");
39
39
  var logged_in_users_collection_1 = require("../collections/logged-in-users.collection");
40
- var active_subscription_collection_1 = require("../collections/active-subscription.collection");
41
40
  var mongoose_1 = require("mongoose");
41
+ var active_subscription_collection_1 = require("../collections/active-subscription.collection");
42
42
  function loadServerInit() {
43
43
  return __awaiter(this, void 0, void 0, function () {
44
44
  var appVersion;
@@ -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 loggedInUser;
122
+ var _this = this;
119
123
  return __generator(this, function (_a) {
120
- switch (_a.label) {
121
- case 0: return [4 /*yield*/, logged_in_users_collection_1.LoggedInUsers.findOne({ id_ws: ws['id_socket'] })];
122
- case 1:
123
- loggedInUser = _a.sent();
124
- if (loggedInUser) {
125
- logged_in_users_collection_1.LoggedInUsers.updateOne({ _id: loggedInUser._id }, { $set: { latency: ws['latency'] } }).exec();
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
- logged_in_users_collection_1.LoggedInUsers.create({
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
- id_ws: ws['id_socket']
262
+ date: new Date(),
263
+ client: index_1.ResolveIOServer.getClientName()
236
264
  });
237
265
  }
238
- return [2 /*return*/];
266
+ _c.label = 6;
267
+ case 6: return [2 /*return*/];
239
268
  }
240
269
  });
241
270
  });
@@ -0,0 +1,7 @@
1
+ import { CollectionDocument } from './collection-document.model';
2
+ export interface BillingLoggedInUserModel extends CollectionDocument {
3
+ date: Date;
4
+ id_user: string;
5
+ user: string;
6
+ client: string;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,14 +1,31 @@
1
1
  import { CollectionDocument } from './collection-document.model';
2
2
  export interface UserModel extends CollectionDocument {
3
- attempts: number;
4
- last: Date;
5
- services?: any;
6
3
  fullname: string;
4
+ roles: UserRoleModel;
7
5
  username?: string;
8
6
  email?: string;
9
- roles?: string[];
10
7
  active?: boolean;
11
- readonly?: boolean;
8
+ services?: any;
9
+ id_customer?: string;
10
+ customer?: string;
11
+ customer_type?: string;
12
12
  phonenumber?: string;
13
13
  other?: object;
14
14
  }
15
+ export interface UserRoleModel {
16
+ super_admin: boolean;
17
+ approvals: UserRoleApprovalModel[];
18
+ groups: UserRoleGroupModel[];
19
+ notifications: string[];
20
+ miscs: string[];
21
+ }
22
+ export interface UserRoleApprovalModel {
23
+ accounting_code: string;
24
+ type: string;
25
+ name: string;
26
+ }
27
+ export interface UserRoleGroupModel {
28
+ name: string;
29
+ views: string[];
30
+ yard?: string;
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "2.1.4",
3
+ "version": "2.2.0-newrole",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {
@@ -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;