@resolveio/server-lib 6.1.4 → 6.1.5-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.
@@ -22,13 +22,6 @@ var schema = {
22
22
  type: Date,
23
23
  optional: true
24
24
  },
25
- readonly: {
26
- type: Boolean,
27
- optional: true
28
- },
29
- active: {
30
- type: Boolean
31
- },
32
25
  attempts: {
33
26
  type: Number,
34
27
  optional: true
@@ -65,53 +58,67 @@ var schema = {
65
58
  type: String
66
59
  },
67
60
  roles: {
61
+ type: Object
62
+ },
63
+ 'roles.super_admin': {
64
+ type: Boolean
65
+ },
66
+ 'roles.approvals': {
68
67
  type: Array
69
68
  },
70
- 'roles.$': {
69
+ 'roles.approvals.$': {
70
+ type: Object
71
+ },
72
+ 'roles.approvals.$.name': {
71
73
  type: String
72
74
  },
73
- phonenumber: {
74
- type: String,
75
- optional: true
75
+ 'roles.approvals.$.type': {
76
+ type: String
76
77
  },
77
- other: {
78
- type: Object,
79
- blackbox: true,
80
- optional: true
78
+ 'roles.approvals.$.accounting_code': {
79
+ type: String
81
80
  },
82
- assets: {
83
- type: Array,
84
- optional: true
81
+ 'roles.groups': {
82
+ type: Array
85
83
  },
86
- 'assets.$': {
84
+ 'roles.groups.$': {
87
85
  type: Object
88
86
  },
89
- 'assets.$.type': {
87
+ 'roles.groups.$.name': {
90
88
  type: String
91
89
  },
92
- 'assets.$.id_asset': {
93
- type: String
90
+ 'roles.groups.$.views': {
91
+ type: Array
94
92
  },
95
- 'assets.$.asset_number': {
93
+ 'roles.groups.$.views.$': {
96
94
  type: String
97
95
  },
98
- 'assets.$.ownership': {
99
- type: String
96
+ 'roles.groups.$.yard': {
97
+ type: String,
98
+ optional: true
99
+ },
100
+ 'roles.notifications': {
101
+ type: Array
100
102
  },
101
- 'assets.$.ownership_driver': {
103
+ 'roles.notifications.$': {
102
104
  type: String
103
105
  },
104
- 'assets.$.date_start': {
105
- type: Date
106
+ 'roles.miscs': {
107
+ type: Array
106
108
  },
107
- 'assets.$.date_end': {
108
- type: Date,
109
- optional: true
109
+ 'roles.miscs.$': {
110
+ type: String
110
111
  },
111
- id_function: {
112
+ active: Boolean,
113
+ phonenumber: {
112
114
  type: String,
113
115
  optional: true
114
116
  },
117
+ other: {
118
+ type: Object,
119
+ optional: true,
120
+ blackbox: true
121
+ },
115
122
  customers: {
116
123
  type: Array,
117
124
  optional: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/collections/user.collection.ts"],"names":[],"mappings":";;AAAA,qCAAwG;AACxG,+DAAiE;AACjE,6CAAwC;AACxC,kCAA2C;AAG3C,uEAA8E;AAE9E,IAAI,MAAM,GAAQ;IACjB,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;KACd;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,IAAI;KACd;IACD,MAAM,EAAE;QACP,IAAI,EAAE,OAAO;KACb;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,IAAI,EAAE;QACL,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;KACd;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,qBAAqB,EAAE;QACtB,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,0BAA0B,EAAE;QAC3B,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,yBAAyB,EAAE;QAC1B,IAAI,EAAE,MAAM;QACZ,QA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CAAC;AAEhD,MAAM,CAAC,GAAG,GAAG;IACZ,IAAI,EAAE,iBAAM,CAAC,KAAK,CAAC,KAAK;CACxB,CAAC;AAEF,IAAI,aAAa,GAAG,IAAI,iBAAM,CAAC,MAAM,EAAE;IACtC,cAAc,EAAE,IAAI;IACpB,UAAU,EAAE,KAAK;IACjB,UAAU,EAAE,IAAI;CAChB,CAAC,CAAC;AAEH,aAAK,CAAC,mBAAmB,CAAC,GAAG,gBAAgB,CAAC;AAEjC,QAAA,YAAY,GAA0B,uBAAe,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,aAAK,CAAC,mBAAmB,CAAC,EAAE,aAAa,CAAC,CAAC;AAEhI,qCAAqC;AACrC,IAAI,SAAS,GAAmB,EAAE,CAAC;AAEnC,IAAI,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,sCAAc,CAAC,SAAS,EAAE,aAAa,EAAE,EAAE,CAAC,CAAC,CAAC;AACnF,aAAK,CAAC,UAAU,CAAC,GAAG,qCAAa,CAAC,QAAQ,CAAC,CAAC","file":"user.collection.js","sourcesContent":["import { Schema, Model, PassportLocalDocument, PassportLocalModel, PassportLocalSchema} from 'mongoose';\nimport * as passportLocalMongoose from 'passport-local-mongoose';\nimport SimpleSchema from 'simpl-schema';\nimport { ResolveIOServer } from '../index';\nimport { UserModel } from '../models/user.model';\nimport { LookupTables } from '../models/report-builder.model';\nimport { buildRbSchema, buildRbLookups } from '../util/schema-report-builder';\n\nlet schema: any = {\n\t_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t__v: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tupdatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tcreatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\treadonly: {\n\t\ttype: Boolean,\n\t\toptional: true\n\t},\n\tactive: {\n\t\ttype: Boolean\n\t},\n\tattempts: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tlast: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tservices: {\n\t\ttype: Object,\n\t\toptional: true\n\t},\n\t'services.enrollment': {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t'services.forgot_password': {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t'services.reset_password': {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tusername: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\temail: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tfullname: {\n\t\ttype: String\n\t},\n\troles: {\n\t\ttype: Array\n\t},\n\t'roles.$': {\n\t\ttype: String\n\t},\n\tphonenumber: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tother: {\n\t\ttype: Object,\n\t\tblackbox: true,\n\t\toptional: true\n\t},\n\tassets: {\n\t\ttype: Array,\n\t\toptional: true\n\t},\n\t'assets.$': {\n\t\ttype: Object\n\t},\n\t'assets.$.type': {\n\t\ttype: String\n\t},\n\t'assets.$.id_asset': {\n\t\ttype: String\n\t},\n\t'assets.$.asset_number': {\n\t\ttype: String\n\t},\n\t'assets.$.ownership': {\n\t\ttype: String\n\t},\n\t'assets.$.ownership_driver': {\n\t\ttype: String\n\t},\n\t'assets.$.date_start': {\n\t\ttype: Date\n\t},\n\t'assets.$.date_end': {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tid_function: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tcustomers: {\n\t\ttype: Array,\n\t\toptional: true,\n\t},\n\t'customers.$': {\n\t\ttype: Object\n\t},\n\t'customers.$.id_customer': {\n\t\ttype: String\n\t},\n\t'customers.$.customer': {\n\t\ttype: String\n\t},\n\tid_customer: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tcustomer: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tcustomer_type: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tdepartments: {\n\t\ttype: Array,\n\t\toptional: true\n\t},\n\t'departments.$': {\n\t\ttype: Object\n\t},\n\t'departments.$.id_department': {\n\t\ttype: String\n\t},\n\t'departments.$.department': {\n\t\ttype: String\n\t}\n};\n\nconst DefaultSchema = <PassportLocalSchema>new Schema(schema, {\n\tskipVersioning: true,\n\tversionKey: false,\n\ttimestamps: true\n});\n\nDefaultSchema.plugin(passportLocalMongoose, {\n\tusernameUnique: true,\n\tlimitAttempts: true,\n\tmaxAttempts: 5,\n\tfindByUsername: (mongooseModel, queryParameters) => {\n\t\t// Add additional query parameter - AND condition - active: true\n\t\tqueryParameters.active = true;\n\t\treturn mongooseModel.findOne(queryParameters);\n\t}\n});\n\ninterface ResolveIOModel extends UserModel, PassportLocalDocument {}\nexport const Users: PassportLocalModel<ResolveIOModel> = ResolveIOServer.getMainDB().model('users', DefaultSchema);\n\nexport let ClientUsers: PassportLocalModel<ResolveIOModel> = null;\n\nif (ResolveIOServer.getSupportDB()) {\n\tClientUsers = ResolveIOServer.getSupportDB().model('client-users', DefaultSchema);\n}\n\nUsers['simplschema'] = new SimpleSchema(schema);\n\nschema._id = {\n\ttype: Schema.Types.Mixed\n};\n\nlet VersionSchema = new Schema(schema, {\n\tskipVersioning: true,\n\tversionKey: false,\n\ttimestamps: true\n});\n\nUsers['versionCollection'] = 'users.versions';\n\nexport const UserVersions: Model<ResolveIOModel> = ResolveIOServer.getMainDB().model(Users['versionCollection'], VersionSchema);\n\n//------------- Report Builder Schema\nlet rbLookups: LookupTables[] = [];\n\nlet rbSchema = Object.assign(schema, buildRbLookups(rbLookups, DefaultSchema, []));\nUsers['rbSchema'] = buildRbSchema(rbSchema);"]}
1
+ {"version":3,"sources":["../../src/collections/user.collection.ts"],"names":[],"mappings":";;AAAA,qCAAwG;AACxG,+DAAiE;AACjE,6CAAwC;AACxC,kCAA2C;AAG3C,uEAA8E;AAE9E,IAAI,MAAM,GAAQ;IACjB,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,GAAG,EAAE;QACJ,IAAI,EAAE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I,qCAAqC;AACrC,IAAI,SAAS,GAAmB,EAAE,CAAC;AAEnC,IAAI,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,sCAAc,CAAC,SAAS,EAAE,aAAa,EAAE,EAAE,CAAC,CAAC,CAAC;AACnF,aAAK,CAAC,UAAU,CAAC,GAAG,qCAAa,CAAC,QAAQ,CAAC,CAAC","file":"user.collection.js","sourcesContent":["import { Schema, Model, PassportLocalDocument, PassportLocalModel, PassportLocalSchema} from 'mongoose';\nimport * as passportLocalMongoose from 'passport-local-mongoose';\nimport SimpleSchema from 'simpl-schema';\nimport { ResolveIOServer } from '../index';\nimport { UserModel } from '../models/user.model';\nimport { LookupTables } from '../models/report-builder.model';\nimport { buildRbSchema, buildRbLookups } from '../util/schema-report-builder';\n\nlet schema: any = {\n\t_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t__v: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tupdatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tcreatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tattempts: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tlast: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tservices: {\n\t\ttype: Object,\n\t\toptional: true\n\t},\n\t'services.enrollment': {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t'services.forgot_password': {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t'services.reset_password': {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tusername: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\temail: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tfullname: {\n\t\ttype: String\n\t},\n\troles: {\n\t\ttype: Object\n\t},\n\t'roles.super_admin': {\n\t\ttype: Boolean\n\t},\n\t'roles.approvals': {\n\t\ttype: Array\n\t},\n\t'roles.approvals.$': {\n\t\ttype: Object\n\t},\n\t'roles.approvals.$.name': {\n\t\ttype: String\n\t},\n\t'roles.approvals.$.type': {\n\t\ttype: String\n\t},\n\t'roles.approvals.$.accounting_code': {\n\t\ttype: String\n\t},\n\t'roles.groups': {\n\t\ttype: Array\n\t},\n\t'roles.groups.$': {\n\t\ttype: Object\n\t},\n\t'roles.groups.$.name': {\n\t\ttype: String\n\t},\n\t'roles.groups.$.views': {\n\t\ttype: Array\n\t},\n\t'roles.groups.$.views.$': {\n\t\ttype: String\n\t},\n\t'roles.groups.$.yard': {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t'roles.notifications': {\n\t\ttype: Array\n\t},\n\t'roles.notifications.$': {\n\t\ttype: String\n\t},\n\t'roles.miscs': {\n\t\ttype: Array\n\t},\n\t'roles.miscs.$': {\n\t\ttype: String\n\t},\n\tactive: Boolean,\n\tphonenumber: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tother: {\n\t\ttype: Object,\n\t\toptional: true,\n\t\tblackbox: true\n\t},\n\tcustomers: {\n\t\ttype: Array,\n\t\toptional: true,\n\t},\n\t'customers.$': {\n\t\ttype: Object\n\t},\n\t'customers.$.id_customer': {\n\t\ttype: String\n\t},\n\t'customers.$.customer': {\n\t\ttype: String\n\t},\n\tid_customer: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tcustomer: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tcustomer_type: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tdepartments: {\n\t\ttype: Array,\n\t\toptional: true\n\t},\n\t'departments.$': {\n\t\ttype: Object\n\t},\n\t'departments.$.id_department': {\n\t\ttype: String\n\t},\n\t'departments.$.department': {\n\t\ttype: String\n\t}\n};\n\nconst DefaultSchema = <PassportLocalSchema>new Schema(schema, {\n\tskipVersioning: true,\n\tversionKey: false,\n\ttimestamps: true\n});\n\nDefaultSchema.plugin(passportLocalMongoose, {\n\tusernameUnique: true,\n\tlimitAttempts: true,\n\tmaxAttempts: 5,\n\tfindByUsername: (mongooseModel, queryParameters) => {\n\t\t// Add additional query parameter - AND condition - active: true\n\t\tqueryParameters.active = true;\n\t\treturn mongooseModel.findOne(queryParameters);\n\t}\n});\n\ninterface ResolveIOModel extends UserModel, PassportLocalDocument {}\nexport const Users: PassportLocalModel<ResolveIOModel> = ResolveIOServer.getMainDB().model('users', DefaultSchema);\n\nexport let ClientUsers: PassportLocalModel<ResolveIOModel> = null;\n\nif (ResolveIOServer.getSupportDB()) {\n\tClientUsers = ResolveIOServer.getSupportDB().model('client-users', DefaultSchema);\n}\n\nUsers['simplschema'] = new SimpleSchema(schema);\n\nschema._id = {\n\ttype: Schema.Types.Mixed\n};\n\nlet VersionSchema = new Schema(schema, {\n\tskipVersioning: true,\n\tversionKey: false,\n\ttimestamps: true\n});\n\nUsers['versionCollection'] = 'users.versions';\n\nexport const UserVersions: Model<ResolveIOModel> = ResolveIOServer.getMainDB().model(Users['versionCollection'], VersionSchema);\n\n//------------- Report Builder Schema\nlet rbLookups: LookupTables[] = [];\n\nlet rbSchema = Object.assign(schema, buildRbLookups(rbLookups, DefaultSchema, []));\nUsers['rbSchema'] = buildRbSchema(rbSchema);"]}
package/fixtures/init.js CHANGED
@@ -37,7 +37,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  var app_version_collection_1 = require("../collections/app-version.collection");
40
- var active_subscription_collection_1 = require("../collections/active-subscription.collection");
41
40
  var mongoose_1 = require("mongoose");
42
41
  function loadServerInit() {
43
42
  return __awaiter(this, void 0, void 0, function () {
@@ -53,9 +52,6 @@ function loadServerInit() {
53
52
  version: 1
54
53
  });
55
54
  }
56
- return [4 /*yield*/, active_subscription_collection_1.ActiveSubscriptions.deleteMany({}).exec()];
57
- case 2:
58
- _a.sent();
59
55
  return [2 /*return*/];
60
56
  }
61
57
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fixtures/init.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gFAAoE;AAEpE,gGAAoF;AACpF,qCAAiC;AAEjC,SAAsB,cAAc;;;;;wBAClB,qBAAM,oCAAW,CAAC,OAAO,EAAE,EAAA;;oBAAxC,UAAU,GAAG,SAA2B;oBAE5C,IAAI,CAAC,UAAU,EAAE;wBAChB,oCAAW,CAAC,MAAM,CAAC;4BAClB,GAAG,EAAE,gBAAK,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE;4BACnC,OAAO,EAAE,CAAC;yBACV,CAAC,CAAC;qBACH;oBAED,qBAAM,oDAAmB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,EAAA;;oBAA/C,SAA+C,CAAC;;;;;CAChD;AAXD,wCAWC","file":"init.js","sourcesContent":["import { AppVersions } from '../collections/app-version.collection';\nimport { LoggedInUsers } from '../collections/logged-in-users.collection';\nimport { ActiveSubscriptions } from '../collections/active-subscription.collection';\nimport { Types } from 'mongoose';\n\nexport async function loadServerInit() {\n\tlet appVersion = await AppVersions.findOne();\n\n\tif (!appVersion) {\n\t\tAppVersions.create({\n\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\tversion: 1\n\t\t});\n\t}\n\n\tawait ActiveSubscriptions.deleteMany({}).exec();\n}"]}
1
+ {"version":3,"sources":["../../src/fixtures/init.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gFAAoE;AACpE,qCAAiC;AAEjC,SAAsB,cAAc;;;;;wBAClB,qBAAM,oCAAW,CAAC,OAAO,EAAE,EAAA;;oBAAxC,UAAU,GAAG,SAA2B;oBAE5C,IAAI,CAAC,UAAU,EAAE;wBAChB,oCAAW,CAAC,MAAM,CAAC;4BAClB,GAAG,EAAE,gBAAK,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE;4BACnC,OAAO,EAAE,CAAC;yBACV,CAAC,CAAC;qBACH;;;;;CACD;AATD,wCASC","file":"init.js","sourcesContent":["import { AppVersions } from '../collections/app-version.collection';\nimport { Types } from 'mongoose';\n\nexport async function loadServerInit() {\n\tlet appVersion = await AppVersions.findOne();\n\n\tif (!appVersion) {\n\t\tAppVersions.create({\n\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\tversion: 1\n\t\t});\n\t}\n}"]}
@@ -50,7 +50,6 @@ var app_version_1 = require("../publications/app-version");
50
50
  var mongoose_1 = require("mongoose");
51
51
  var files_1 = require("../publications/files");
52
52
  var super_admin_1 = require("../publications/super-admin");
53
- var active_subscription_collection_1 = require("../collections/active-subscription.collection");
54
53
  var logged_in_users_collection_1 = require("../collections/logged-in-users.collection");
55
54
  var cron_jobs_1 = require("../publications/cron-jobs");
56
55
  var flags_1 = require("../publications/flags");
@@ -239,7 +238,7 @@ var SubscriptionManager = /** @class */ (function () {
239
238
  subscriptionData[_i - 4] = arguments[_i];
240
239
  }
241
240
  return __awaiter(this, void 0, void 0, function () {
242
- var that, pub, valObj, valKeys, rootKeys, i, sub, _a, newActiveSub, newLoggedInUser, begDate, endDate, billUser;
241
+ var that, pub, valObj, valKeys, rootKeys, i, sub, _a, newLoggedInUser, begDate, endDate, billUser;
243
242
  var _b;
244
243
  return __generator(this, function (_c) {
245
244
  switch (_c.label) {
@@ -312,22 +311,7 @@ var SubscriptionManager = /** @class */ (function () {
312
311
  _a.preSubscriptionData = _c.sent();
313
312
  _c.label = 3;
314
313
  case 3:
315
- newActiveSub = new active_subscription_collection_1.ActiveSubscriptions({
316
- date: new Date(),
317
- publication: publication,
318
- subData: JSON.stringify(subscriptionData),
319
- collections: pub.collections,
320
- clients: sub.clients
321
- });
322
- active_subscription_collection_1.ActiveSubscriptions.findOneAndUpdate({
323
- $and: [
324
- { publication: publication },
325
- { subData: JSON.stringify(subscriptionData) }
326
- ]
327
- }, { $setOnInsert: { _id: mongoose_1.Types.ObjectId().toHexString(), __v: 0 }, $set: newActiveSub }, { upsert: true }).exec();
328
- _c.label = 4;
329
- case 4:
330
- if (!(publication === 'appversion')) return [3 /*break*/, 6];
314
+ if (!(publication === 'appversion')) return [3 /*break*/, 5];
331
315
  newLoggedInUser = {
332
316
  _id: mongoose_1.Types.ObjectId().toHexString(),
333
317
  __v: 0,
@@ -338,7 +322,7 @@ var SubscriptionManager = /** @class */ (function () {
338
322
  };
339
323
  this._loggedInUsers.push(newLoggedInUser);
340
324
  logged_in_users_collection_1.LoggedInUsers.create(newLoggedInUser);
341
- if (!(ws['user'] !== 'Admin' && index_1.ResolveIOServer.getSupportDB())) return [3 /*break*/, 6];
325
+ if (!(ws['user'] !== 'Admin' && index_1.ResolveIOServer.getSupportDB())) return [3 /*break*/, 5];
342
326
  begDate = moment().startOf('month');
343
327
  endDate = moment().endOf('month');
344
328
  return [4 /*yield*/, billing_logged_in_users_collection_1.BillingLoggedInUsers.findOne({
@@ -357,7 +341,7 @@ var SubscriptionManager = /** @class */ (function () {
357
341
  }
358
342
  ]
359
343
  })];
360
- case 5:
344
+ case 4:
361
345
  billUser = _c.sent();
362
346
  if (!billUser) {
363
347
  billing_logged_in_users_collection_1.BillingLoggedInUsers.create({
@@ -369,8 +353,8 @@ var SubscriptionManager = /** @class */ (function () {
369
353
  client: index_1.ResolveIOServer.getClientName()
370
354
  });
371
355
  }
372
- _c.label = 6;
373
- case 6: return [2 /*return*/];
356
+ _c.label = 5;
357
+ case 5: return [2 /*return*/];
374
358
  }
375
359
  });
376
360
  });
@@ -382,46 +366,36 @@ var SubscriptionManager = /** @class */ (function () {
382
366
  subscriptionData[_i - 4] = arguments[_i];
383
367
  }
384
368
  return __awaiter(this, void 0, void 0, function () {
385
- var that, sub, i, activeSub;
369
+ var that, sub, i;
386
370
  return __generator(this, function (_a) {
387
- switch (_a.label) {
388
- case 0:
389
- that = this;
390
- if (!!that._publications[publication]) return [3 /*break*/, 1];
391
- console.log('No Publication: ' + publication);
392
- return [2 /*return*/];
393
- case 1:
394
- sub = that._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
395
- if (!sub) return [3 /*break*/, 3];
371
+ that = this;
372
+ // console.log('Before');
373
+ // console.dir(this._subscriptions.map(a => a.publication));
374
+ if (!that._publications[publication]) {
375
+ console.log('No Publication: ' + publication);
376
+ return [2 /*return*/];
377
+ }
378
+ else {
379
+ sub = that._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
380
+ if (sub) {
396
381
  for (i = sub.clients.length - 1; i >= 0; i--) {
397
382
  if (sub.clients[i].id_user === ws['id_user'] && sub.clients[i].messageId === messageId && sub.clients[i].id_socket === ws['id_socket']) {
398
383
  sub.clients.splice(i, 1);
399
384
  }
400
385
  }
401
- return [4 /*yield*/, active_subscription_collection_1.ActiveSubscriptions.findOne({
402
- $and: [
403
- { publication: publication },
404
- { subData: JSON.stringify(subscriptionData) }
405
- ]
406
- })];
407
- case 2:
408
- activeSub = _a.sent();
409
- if (activeSub) {
410
- active_subscription_collection_1.ActiveSubscriptions.updateOne({ _id: activeSub._id }, { $set: { clients: sub.clients } }).exec();
411
- }
412
- return [3 /*break*/, 4];
413
- case 3:
386
+ }
387
+ else {
414
388
  console.log(ws['user'] + ' - Did not find sub on unsubscribe - publication: ' + publication + ', subData: ' + JSON.stringify(subscriptionData, null, 2));
415
- _a.label = 4;
416
- case 4: return [2 /*return*/];
389
+ }
417
390
  }
391
+ return [2 /*return*/];
418
392
  });
419
393
  });
420
394
  };
421
395
  // Unsubscribe from publication
422
396
  SubscriptionManager.prototype.unsubscribeAll = function (ws) {
423
397
  return __awaiter(this, void 0, void 0, function () {
424
- var that, loggedInUser, userSubs, i, sub, j, activeSubs;
398
+ var that, loggedInUser, userSubs, i, sub, j;
425
399
  return __generator(this, function (_a) {
426
400
  switch (_a.label) {
427
401
  case 0:
@@ -444,22 +418,6 @@ var SubscriptionManager = /** @class */ (function () {
444
418
  }
445
419
  }
446
420
  }
447
- return [4 /*yield*/, active_subscription_collection_1.ActiveSubscriptions.find({ 'clients.id_socket': ws['id_socket'] })];
448
- case 2:
449
- activeSubs = _a.sent();
450
- activeSubs.forEach(function (sub) {
451
- for (var j = sub.clients.length - 1; j >= 0; j--) {
452
- if (sub.clients[j].id_socket === ws['id_socket']) {
453
- sub.clients.splice(j, 1);
454
- }
455
- }
456
- for (var j = sub.clients.length - 1; j >= 0; j--) {
457
- if (sub.clients[j].id_socket === ws['id_socket']) {
458
- sub.clients.splice(j, 1);
459
- }
460
- }
461
- active_subscription_collection_1.ActiveSubscriptions.updateOne({ _id: sub._id }, { $set: { clients: sub.clients } }).exec();
462
- });
463
421
  ws.terminate();
464
422
  return [2 /*return*/];
465
423
  }
@@ -630,7 +588,7 @@ var SubscriptionManager = /** @class */ (function () {
630
588
  return __generator(this, function (_a) {
631
589
  switch (_a.label) {
632
590
  case 0:
633
- if (!this._oplogQueue.length) return [3 /*break*/, 12];
591
+ if (!this._oplogQueue.length) return [3 /*break*/, 8];
634
592
  uniqueOplog_1 = common_1.deepCopy(this._oplogQueue);
635
593
  this._oplogQueue = [];
636
594
  uniquePubs = [];
@@ -703,159 +661,103 @@ var SubscriptionManager = /** @class */ (function () {
703
661
  return [3 /*break*/, 1];
704
662
  case 4:
705
663
  _loop_6 = function (i) {
706
- var oplog, _loop_7, j;
707
- return __generator(this, function (_a) {
708
- switch (_a.label) {
709
- case 0:
710
- oplog = uniqueOplog_1[i];
711
- _loop_7 = function (j) {
712
- var sub;
713
- var _a;
714
- return __generator(this, function (_b) {
715
- switch (_b.label) {
716
- case 0:
717
- sub = that._subscriptions[j];
718
- if (!sub) return [3 /*break*/, 16];
719
- if (!sub.collections.includes(oplog.collection)) return [3 /*break*/, 16];
720
- if (!sub.preSubscriptionData) return [3 /*break*/, 5];
721
- if (!that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) return [3 /*break*/, 5];
722
- if (!!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData) && JSON.stringify(oplog) === JSON.stringify(a.oplog); }).length) return [3 /*break*/, 4];
723
- if (!!sub.clients.length) return [3 /*break*/, 2];
664
+ var oplog = uniqueOplog_1[i];
665
+ var _loop_7 = function (j) {
666
+ var _a;
667
+ var sub = that._subscriptions[j];
668
+ if (sub) {
669
+ if (sub.collections.includes(oplog.collection)) {
670
+ if (sub.preSubscriptionData) {
671
+ if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
672
+ if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData) && JSON.stringify(oplog) === JSON.stringify(a.oplog); }).length) {
673
+ if (!sub.clients.length) {
724
674
  that._subscriptions.splice(j, 1);
725
- return [4 /*yield*/, active_subscription_collection_1.ActiveSubscriptions.deleteOne({
726
- $and: [
727
- { publication: sub.publication },
728
- { subData: JSON.stringify(sub.subscriptionData) }
729
- ]
730
- }).exec()];
731
- case 1:
732
- _b.sent();
733
- return [3 /*break*/, 3];
734
- case 2:
675
+ }
676
+ else {
735
677
  sub['oplog'] = oplog;
736
678
  uniquePubs.push(common_1.deepCopy(sub));
737
- _b.label = 3;
738
- case 3:
739
- if (this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
740
- this_3._nodeCache.del(this_3._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
741
- this_3._subCache.splice(this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
742
- }
743
- _b.label = 4;
744
- case 4: return [2 /*return*/, "continue"];
745
- case 5:
746
- if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 9];
747
- if (!!sub.clients.length) return [3 /*break*/, 7];
748
- that._subscriptions.splice(j, 1);
749
- return [4 /*yield*/, active_subscription_collection_1.ActiveSubscriptions.deleteOne({
750
- $and: [
751
- { publication: sub.publication },
752
- { subData: JSON.stringify(sub.subscriptionData) }
753
- ]
754
- }).exec()];
755
- case 6:
756
- _b.sent();
757
- if (this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
758
- this_3._nodeCache.del(this_3._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
759
- this_3._subCache.splice(this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
679
+ }
680
+ if (this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
681
+ this_3._nodeCache.del(this_3._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
682
+ this_3._subCache.splice(this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
683
+ }
684
+ }
685
+ return "continue";
686
+ }
687
+ }
688
+ if (that._publications[sub.publication].preFunction) {
689
+ if (!sub.clients.length) {
690
+ that._subscriptions.splice(j, 1);
691
+ if (this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
692
+ this_3._nodeCache.del(this_3._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
693
+ this_3._subCache.splice(this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
694
+ }
695
+ }
696
+ else {
697
+ if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData) && JSON.stringify(oplog) === JSON.stringify(a.oplog); }).length) {
698
+ sub['oplog'] = oplog;
699
+ uniquePubs.push(common_1.deepCopy(sub));
700
+ }
701
+ }
702
+ }
703
+ else {
704
+ if (that._publications[sub.publication].fetchFunction) {
705
+ if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, __spreadArrays([oplog.doc], sub.subscriptionData))) {
706
+ if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) {
707
+ if (!sub.clients.length) {
708
+ that._subscriptions.splice(j, 1);
709
+ if (this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
710
+ this_3._nodeCache.del(this_3._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
711
+ this_3._subCache.splice(this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
712
+ }
760
713
  }
761
- return [3 /*break*/, 8];
762
- case 7:
763
- if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData) && JSON.stringify(oplog) === JSON.stringify(a.oplog); }).length) {
714
+ else {
764
715
  sub['oplog'] = oplog;
765
716
  uniquePubs.push(common_1.deepCopy(sub));
766
717
  }
767
- _b.label = 8;
768
- case 8: return [3 /*break*/, 16];
769
- case 9:
770
- if (!that._publications[sub.publication].fetchFunction) return [3 /*break*/, 13];
771
- if (!(_a = that._publications[sub.publication]).fetchFunction.apply(_a, __spreadArrays([oplog.doc], sub.subscriptionData))) return [3 /*break*/, 12];
772
- if (!!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) return [3 /*break*/, 12];
773
- if (!!sub.clients.length) return [3 /*break*/, 11];
774
- that._subscriptions.splice(j, 1);
775
- return [4 /*yield*/, active_subscription_collection_1.ActiveSubscriptions.deleteOne({
776
- $and: [
777
- { publication: sub.publication },
778
- { subData: JSON.stringify(sub.subscriptionData) }
779
- ]
780
- }).exec()];
781
- case 10:
782
- _b.sent();
783
- if (this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
784
- this_3._nodeCache.del(this_3._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
785
- this_3._subCache.splice(this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
786
- }
787
- return [3 /*break*/, 12];
788
- case 11:
789
- sub['oplog'] = oplog;
790
- uniquePubs.push(common_1.deepCopy(sub));
791
- _b.label = 12;
792
- case 12: return [3 /*break*/, 16];
793
- case 13:
794
- if (!!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) return [3 /*break*/, 16];
795
- if (!!sub.clients.length) return [3 /*break*/, 15];
718
+ }
719
+ }
720
+ }
721
+ else {
722
+ if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) {
723
+ if (!sub.clients.length) {
796
724
  that._subscriptions.splice(j, 1);
797
- return [4 /*yield*/, active_subscription_collection_1.ActiveSubscriptions.deleteOne({
798
- $and: [
799
- { publication: sub.publication },
800
- { subData: JSON.stringify(sub.subscriptionData) }
801
- ]
802
- }).exec()];
803
- case 14:
804
- _b.sent();
805
725
  if (this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
806
726
  this_3._nodeCache.del(this_3._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
807
727
  this_3._subCache.splice(this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
808
728
  }
809
- return [3 /*break*/, 16];
810
- case 15:
729
+ }
730
+ else {
811
731
  sub['oplog'] = oplog;
812
732
  uniquePubs.push(common_1.deepCopy(sub));
813
- _b.label = 16;
814
- case 16: return [2 /*return*/];
733
+ }
815
734
  }
816
- });
817
- };
818
- j = that._subscriptions.length - 1;
819
- _a.label = 1;
820
- case 1:
821
- if (!(j >= 0)) return [3 /*break*/, 4];
822
- return [5 /*yield**/, _loop_7(j)];
823
- case 2:
824
- _a.sent();
825
- _a.label = 3;
826
- case 3:
827
- j--;
828
- return [3 /*break*/, 1];
829
- case 4: return [2 /*return*/];
735
+ }
736
+ }
737
+ }
830
738
  }
831
- });
739
+ };
740
+ for (var j = that._subscriptions.length - 1; j >= 0; j--) {
741
+ _loop_7(j);
742
+ }
832
743
  };
833
744
  this_3 = this;
834
- i = uniqueOplog_1.length - 1;
745
+ for (i = uniqueOplog_1.length - 1; i >= 0; i--) {
746
+ _loop_6(i);
747
+ }
748
+ i = 0;
835
749
  _a.label = 5;
836
750
  case 5:
837
- if (!(i >= 0)) return [3 /*break*/, 8];
838
- return [5 /*yield**/, _loop_6(i)];
751
+ if (!(i < uniquePubs.length)) return [3 /*break*/, 8];
752
+ pub = uniquePubs[i];
753
+ return [4 /*yield*/, this.checkPubsForChanges(pub['oplog'].collection, pub['oplog'].doc, pub['oplog'].type, pub)];
839
754
  case 6:
840
755
  _a.sent();
841
756
  _a.label = 7;
842
757
  case 7:
843
- i--;
844
- return [3 /*break*/, 5];
845
- case 8:
846
- i = 0;
847
- _a.label = 9;
848
- case 9:
849
- if (!(i < uniquePubs.length)) return [3 /*break*/, 12];
850
- pub = uniquePubs[i];
851
- return [4 /*yield*/, this.checkPubsForChanges(pub['oplog'].collection, pub['oplog'].doc, pub['oplog'].type, pub)];
852
- case 10:
853
- _a.sent();
854
- _a.label = 11;
855
- case 11:
856
758
  i++;
857
- return [3 /*break*/, 9];
858
- case 12: return [2 /*return*/];
759
+ return [3 /*break*/, 5];
760
+ case 8: return [2 /*return*/];
859
761
  }
860
762
  });
861
763
  }); }, 250);
@@ -907,26 +809,18 @@ var SubscriptionManager = /** @class */ (function () {
907
809
  case 5:
908
810
  aa++;
909
811
  return [3 /*break*/, 1];
910
- case 6: return [3 /*break*/, 11];
812
+ case 6: return [3 /*break*/, 10];
911
813
  case 7:
912
- if (!!sub.clients.length) return [3 /*break*/, 9];
814
+ if (!!sub.clients.length) return [3 /*break*/, 8];
913
815
  if (that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
914
816
  that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
915
817
  }
916
- return [4 /*yield*/, active_subscription_collection_1.ActiveSubscriptions.deleteOne({
917
- $and: [
918
- { publication: sub.publication },
919
- { subData: JSON.stringify(sub.subscriptionData) }
920
- ]
921
- }).exec()];
922
- case 8:
923
- _a.sent();
924
- return [3 /*break*/, 11];
925
- case 9: return [4 /*yield*/, that.sendPubData(sub, 'delete', collection)];
926
- case 10:
818
+ return [3 /*break*/, 10];
819
+ case 8: return [4 /*yield*/, that.sendPubData(sub, 'delete', collection)];
820
+ case 9:
927
821
  _a.sent();
928
- _a.label = 11;
929
- case 11: return [2 /*return*/];
822
+ _a.label = 10;
823
+ case 10: return [2 /*return*/];
930
824
  }
931
825
  });
932
826
  };