@resolveio/server-lib 1.0.0-rc8 → 1.0.0
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/active-subscription.collection.js +2 -2
- package/collections/app-status.collection.js +2 -2
- package/collections/app-version.collection.js +2 -2
- package/collections/counter.collection.js +8 -8
- package/collections/cron-job-history.collection.js +2 -2
- package/collections/cron-job.collection.js +2 -2
- package/collections/file.collection.js +8 -8
- package/collections/flag.collection.js +2 -2
- package/collections/log.collection.js +2 -2
- package/collections/logged-in-users.collection.js +2 -2
- package/collections/method-call.collection.js +1 -1
- package/collections/method-response.collection.js +1 -1
- package/collections/queue-flag.collection.js +2 -2
- package/collections/queue-method.collection.js +2 -2
- package/collections/queue-response.collection.js +2 -2
- package/collections/support-ticket.collection.js +5 -5
- package/collections/user.collection.js +2 -2
- package/http/auth.d.ts +1 -1
- package/http/auth.js +3 -3
- package/index.d.ts +6 -44
- package/index.js +61 -60
- package/managers/method.manager.d.ts +3 -2
- package/managers/method.manager.js +50 -19
- package/managers/subscription.manager.js +8 -8
- package/managers/support.manager.d.ts +1 -1
- package/managers/support.manager.js +1 -1
- package/methods/accounts.js +2 -2
- package/methods/aws.js +23 -1
- package/methods/collections.js +41 -41
- package/methods/counters.js +2 -299
- package/methods/logs.js +1 -1
- package/models/notification.model.d.ts +5 -0
- package/models/notification.model.js +2 -0
- package/package.json +2 -2
- package/publications/support-tickets.js +2 -2
- package/server-app.d.ts +3 -2
- package/server-app.js +46 -3
- package/support-methods/collections.js +25 -25
- package/support-methods/counters.js +3 -3
|
@@ -20,13 +20,14 @@ var mongoose_1 = require("mongoose");
|
|
|
20
20
|
var common_1 = require("../util/common");
|
|
21
21
|
var log_collection_1 = require("../collections/log.collection");
|
|
22
22
|
var MethodManager = /** @class */ (function () {
|
|
23
|
-
function MethodManager(mainServer, serverConfig) {
|
|
23
|
+
function MethodManager(mainServer, serverConfig, clientDir) {
|
|
24
24
|
var _this = this;
|
|
25
25
|
this._methods = {};
|
|
26
26
|
this._sendQueue = [];
|
|
27
27
|
this._runningQueue = false;
|
|
28
28
|
this._mainServer = mainServer;
|
|
29
29
|
this.serverConfig = serverConfig;
|
|
30
|
+
this.clientDir = clientDir;
|
|
30
31
|
// Fixtures
|
|
31
32
|
init_1.loadServerInit();
|
|
32
33
|
cron_jobs_1.loadServerCronJobs();
|
|
@@ -262,7 +263,7 @@ var MethodManager = /** @class */ (function () {
|
|
|
262
263
|
}
|
|
263
264
|
}
|
|
264
265
|
}
|
|
265
|
-
(_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, { id_user: '', user: '', id_ws: '' })].concat(methodData));
|
|
266
|
+
(_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: '', user: '', id_ws: '' })].concat(methodData));
|
|
266
267
|
};
|
|
267
268
|
MethodManager.prototype.callMethodQueue = function (update) {
|
|
268
269
|
// console.log('Call Method Queue', update);
|
|
@@ -330,7 +331,7 @@ var MethodManager = /** @class */ (function () {
|
|
|
330
331
|
}
|
|
331
332
|
}
|
|
332
333
|
// console.log('Run Method', update.method);
|
|
333
|
-
(_a = that._methods[update.method].function).call.apply(_a, [Object.assign({}, that, { id_user: update.id_user, user: update.user, id_ws: update.id_ws })].concat(update.method_data)).then(function (res) {
|
|
334
|
+
(_a = that._methods[update.method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: update.id_user, user: update.user, id_ws: update.id_ws })].concat(update.method_data)).then(function (res) {
|
|
334
335
|
var serverRes = {
|
|
335
336
|
messageId: update.messageId,
|
|
336
337
|
hasError: false,
|
|
@@ -414,7 +415,7 @@ var MethodManager = /** @class */ (function () {
|
|
|
414
415
|
}
|
|
415
416
|
}
|
|
416
417
|
}
|
|
417
|
-
(_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] })].concat(methodData)).then(function (res) {
|
|
418
|
+
(_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] })].concat(methodData)).then(function (res) {
|
|
418
419
|
var serverRes = {
|
|
419
420
|
messageId: messageId,
|
|
420
421
|
hasError: false,
|
|
@@ -452,7 +453,7 @@ var MethodManager = /** @class */ (function () {
|
|
|
452
453
|
return;
|
|
453
454
|
}
|
|
454
455
|
}
|
|
455
|
-
var promise = (_a = that._methods[method].function).call.apply(_a, [that].concat(methodData));
|
|
456
|
+
var promise = (_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype)].concat(methodData));
|
|
456
457
|
if (methodData[methodData.length - 1] && typeof (methodData[methodData.length - 1]) === 'function') {
|
|
457
458
|
promise.then(function (res) { return methodData[methodData.length - 1](null, res); }, function (err) { return methodData[methodData.length - 1](err, null); });
|
|
458
459
|
}
|
|
@@ -485,27 +486,57 @@ var MethodManager = /** @class */ (function () {
|
|
|
485
486
|
return this._aws;
|
|
486
487
|
};
|
|
487
488
|
MethodManager.prototype.readFile = function (fileName) {
|
|
489
|
+
var _this = this;
|
|
488
490
|
return new Promise(function (resolve, reject) {
|
|
489
|
-
fs.
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
491
|
+
if (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {
|
|
492
|
+
fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'utf-8', function (err, res) {
|
|
493
|
+
if (err) {
|
|
494
|
+
reject(err);
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
resolve(res);
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
if (fs.existsSync(path.join(_this.clientDir, ('./private/' + fileName)))) {
|
|
503
|
+
fs.readFile(path.join(_this.clientDir, ('./private/' + fileName)), 'utf-8', function (err, res) {
|
|
504
|
+
if (err) {
|
|
505
|
+
reject(err);
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
resolve(res);
|
|
509
|
+
}
|
|
510
|
+
});
|
|
495
511
|
}
|
|
496
|
-
}
|
|
512
|
+
}
|
|
497
513
|
});
|
|
498
514
|
};
|
|
499
515
|
MethodManager.prototype.readImage = function (fileName) {
|
|
516
|
+
var _this = this;
|
|
500
517
|
return new Promise(function (resolve, reject) {
|
|
501
|
-
fs.
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
518
|
+
if (fs.existsSync(path.join(__dirname, ('../private/' + fileName)))) {
|
|
519
|
+
fs.readFile(path.join(__dirname, ('../private/' + fileName)), 'base64', function (err, res) {
|
|
520
|
+
if (err) {
|
|
521
|
+
reject(err);
|
|
522
|
+
}
|
|
523
|
+
else {
|
|
524
|
+
resolve(res);
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
if (fs.existsSync(path.join(_this.clientDir, ('./private/' + fileName)))) {
|
|
530
|
+
fs.readFile(path.join(_this.clientDir, ('./private/' + fileName)), 'base64', function (err, res) {
|
|
531
|
+
if (err) {
|
|
532
|
+
reject(err);
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
resolve(res);
|
|
536
|
+
}
|
|
537
|
+
});
|
|
507
538
|
}
|
|
508
|
-
}
|
|
539
|
+
}
|
|
509
540
|
});
|
|
510
541
|
};
|
|
511
542
|
return MethodManager;
|
|
@@ -72,7 +72,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
72
72
|
method_responses_1.loadMethodResponsePublications(this);
|
|
73
73
|
support_tickets_1.loadSupportTicketPublications(this);
|
|
74
74
|
this.tailOpLog();
|
|
75
|
-
if (index_1.
|
|
75
|
+
if (index_1.ResolveIOServer.getSupportDB()) {
|
|
76
76
|
this.tailOpLogSupport();
|
|
77
77
|
}
|
|
78
78
|
setInterval(function () {
|
|
@@ -471,13 +471,13 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
471
471
|
case 0:
|
|
472
472
|
schemaErrors = null;
|
|
473
473
|
try {
|
|
474
|
-
index_1.
|
|
474
|
+
index_1.ResolveIOServer.getMainDB().model(collection)['simplschema'].validate(document);
|
|
475
475
|
}
|
|
476
476
|
catch (errors) {
|
|
477
477
|
schemaErrors = errors;
|
|
478
478
|
}
|
|
479
479
|
if (!schemaErrors) return [3 /*break*/, 2];
|
|
480
|
-
return [4 /*yield*/, index_1.
|
|
480
|
+
return [4 /*yield*/, index_1.ResolveIOServer.getMainDB().model(collection).findById(document['_id'])];
|
|
481
481
|
case 1:
|
|
482
482
|
document = _c.sent();
|
|
483
483
|
_c.label = 2;
|
|
@@ -539,13 +539,13 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
539
539
|
case 0:
|
|
540
540
|
schemaErrors = null;
|
|
541
541
|
try {
|
|
542
|
-
index_1.
|
|
542
|
+
index_1.ResolveIOServer.getSupportDB().model(collection)['simplschema'].validate(document);
|
|
543
543
|
}
|
|
544
544
|
catch (errors) {
|
|
545
545
|
schemaErrors = errors;
|
|
546
546
|
}
|
|
547
547
|
if (!schemaErrors) return [3 /*break*/, 2];
|
|
548
|
-
return [4 /*yield*/, index_1.
|
|
548
|
+
return [4 /*yield*/, index_1.ResolveIOServer.getSupportDB().model(collection).findById(document['_id'])];
|
|
549
549
|
case 1:
|
|
550
550
|
document = _f.sent();
|
|
551
551
|
_f.label = 2;
|
|
@@ -614,7 +614,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
614
614
|
return __generator(this, function (_c) {
|
|
615
615
|
that = this;
|
|
616
616
|
if (!that._publications[subscription.publication].ws_specific) { // Same pub for all users
|
|
617
|
-
(_a = that._publications[subscription.publication].function).call.apply(_a, [that].concat(subscription.subscriptionData)).then(function (res) {
|
|
617
|
+
(_a = that._publications[subscription.publication].function).call.apply(_a, [Object.assign({}, that, SubscriptionManager.prototype)].concat(subscription.subscriptionData)).then(function (res) {
|
|
618
618
|
var serverRes = {
|
|
619
619
|
messageId: messageId,
|
|
620
620
|
hasError: false,
|
|
@@ -631,7 +631,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
631
631
|
});
|
|
632
632
|
}
|
|
633
633
|
else { // Pub is different for each user (Look at users publication) [MUCH SLOWER, RE-RUNS FOR EACH USER]
|
|
634
|
-
(_b = that._publications[subscription.publication].function).call.apply(_b, [that, ws['id_user']].concat(subscription.subscriptionData)).then(function (res) {
|
|
634
|
+
(_b = that._publications[subscription.publication].function).call.apply(_b, [Object.assign({}, that, SubscriptionManager.prototype), ws['id_user']].concat(subscription.subscriptionData)).then(function (res) {
|
|
635
635
|
var serverRes = {
|
|
636
636
|
messageId: messageId,
|
|
637
637
|
hasError: false,
|
|
@@ -658,7 +658,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
658
658
|
var _this = this;
|
|
659
659
|
return __generator(this, function (_b) {
|
|
660
660
|
that = this;
|
|
661
|
-
(_a = that._publications[subscription.publication].function).call.apply(_a, [that].concat(subscription.subscriptionData)).then(function (res) {
|
|
661
|
+
(_a = that._publications[subscription.publication].function).call.apply(_a, [Object.assign({}, that, SubscriptionManager.prototype)].concat(subscription.subscriptionData)).then(function (res) {
|
|
662
662
|
subscription.clients.forEach(function (client) {
|
|
663
663
|
that._wss.clients.forEach(function (ws) {
|
|
664
664
|
if (ws['id_socket'] === client.id_socket) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SupportMethodModel } from '../models/support-method.model';
|
|
2
|
-
import
|
|
2
|
+
import ResolveIOMainServer from '../server-app';
|
|
3
3
|
export declare class SupportManager {
|
|
4
4
|
private _mainServer;
|
|
5
5
|
_supportMethods: SupportMethodModel;
|
|
@@ -164,7 +164,7 @@ var SupportManager = /** @class */ (function () {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
(_a = that._supportMethods[supportMethod].function).call.apply(_a, [Object.assign({}, that, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] })].concat(methodData)).then(function (res) {
|
|
167
|
+
(_a = that._supportMethods[supportMethod].function).call.apply(_a, [Object.assign({}, that, SupportManager.prototype, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] })].concat(methodData)).then(function (res) {
|
|
168
168
|
var serverRes = {
|
|
169
169
|
messageId: messageId,
|
|
170
170
|
hasError: false,
|
package/methods/accounts.js
CHANGED
|
@@ -191,7 +191,7 @@ function loadAccountMethods(methodManager) {
|
|
|
191
191
|
handlebars.registerHelper('equals', function (a, b) {
|
|
192
192
|
return a === b;
|
|
193
193
|
});
|
|
194
|
-
_this.sendEmail(user.email, 'ResolveIO (' + index_1.
|
|
194
|
+
_this.sendEmail(user.email, 'ResolveIO (' + index_1.ResolveIOServer.getClientName() + ') - Enrollment Email', '', template(emailData));
|
|
195
195
|
resolve(true);
|
|
196
196
|
}, function (errEmail) { return reject(errEmail); });
|
|
197
197
|
}));
|
|
@@ -230,7 +230,7 @@ function loadAccountMethods(methodManager) {
|
|
|
230
230
|
handlebars.registerHelper('equals', function (a, b) {
|
|
231
231
|
return a === b;
|
|
232
232
|
});
|
|
233
|
-
_this.sendEmail(user.email, 'ResolveIO (' + index_1.
|
|
233
|
+
_this.sendEmail(user.email, 'ResolveIO (' + index_1.ResolveIOServer.getClientName() + ') - Forgot Password', '', template(emailData_1));
|
|
234
234
|
resolve(true);
|
|
235
235
|
}, function (errEmail) { return reject(errEmail); });
|
|
236
236
|
});
|
package/methods/aws.js
CHANGED
|
@@ -39,6 +39,7 @@ var file_collection_1 = require("../collections/file.collection");
|
|
|
39
39
|
var mongoose_1 = require("mongoose");
|
|
40
40
|
var simpl_schema_1 = require("simpl-schema");
|
|
41
41
|
var index_1 = require("../index");
|
|
42
|
+
var request = require('request').defaults({ encoding: null });
|
|
42
43
|
var pdfCnt = 1000000;
|
|
43
44
|
function loadAWSMethods(methodManager) {
|
|
44
45
|
methodManager.methods({
|
|
@@ -276,6 +277,27 @@ function loadAWSMethods(methodManager) {
|
|
|
276
277
|
});
|
|
277
278
|
}
|
|
278
279
|
},
|
|
280
|
+
getDataURIfromURL: {
|
|
281
|
+
skipQueue: true,
|
|
282
|
+
check: new simpl_schema_1.default({
|
|
283
|
+
url: {
|
|
284
|
+
type: String
|
|
285
|
+
}
|
|
286
|
+
}),
|
|
287
|
+
function: function (url) {
|
|
288
|
+
return new Promise(function (resolve, reject) {
|
|
289
|
+
request.get(url, function (error, response, body) {
|
|
290
|
+
if (!error && response.statusCode === 200) {
|
|
291
|
+
var data = 'data:' + response.headers['content-type'] + ';base64,' + new Buffer(body).toString('base64');
|
|
292
|
+
resolve(data);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
reject(error);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
},
|
|
279
301
|
emailFile: {
|
|
280
302
|
skipQueue: true,
|
|
281
303
|
check: new simpl_schema_1.default({
|
|
@@ -302,7 +324,7 @@ function loadAWSMethods(methodManager) {
|
|
|
302
324
|
}
|
|
303
325
|
that.callMethodInternal.call(that, 'getSignedUrl', file.key, 900, function (errPDF, resPDF) {
|
|
304
326
|
if (resPDF) {
|
|
305
|
-
that.sendEmail(email, index_1.
|
|
327
|
+
that.sendEmail(email, index_1.ResolveIOServer.getClientName() + ' File - ' + file.name, 'Attached is the file requested for email.', '', [{
|
|
306
328
|
filename: file.name,
|
|
307
329
|
path: resPDF
|
|
308
330
|
}]);
|
package/methods/collections.js
CHANGED
|
@@ -21,7 +21,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
21
21
|
}
|
|
22
22
|
}),
|
|
23
23
|
function: function (collection, query) {
|
|
24
|
-
return index_1.
|
|
24
|
+
return index_1.ResolveIOServer.getMainDB().model(collection).findOne(query).exec();
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
find: {
|
|
@@ -42,7 +42,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
42
42
|
}),
|
|
43
43
|
function: function (collection, query, sortQuery) {
|
|
44
44
|
if (sortQuery === void 0) { sortQuery = {}; }
|
|
45
|
-
return index_1.
|
|
45
|
+
return index_1.ResolveIOServer.getMainDB().model(collection).find(query).sort(sortQuery).exec();
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
findWithOptions: {
|
|
@@ -60,7 +60,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
60
60
|
}
|
|
61
61
|
}),
|
|
62
62
|
function: function (collection, query, options) {
|
|
63
|
-
return index_1.
|
|
63
|
+
return index_1.ResolveIOServer.getMainDB().model(collection).find(query).sort(options.sort).limit(options.limit).skip(options.skip).select(options.fields).exec();
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
// Insert 1 document
|
|
@@ -81,7 +81,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
81
81
|
return new Promise(function (resolve, reject) {
|
|
82
82
|
var schemaErrors = null;
|
|
83
83
|
try {
|
|
84
|
-
index_1.
|
|
84
|
+
index_1.ResolveIOServer.getMainDB().model(collection)['simplschema'].validate(document);
|
|
85
85
|
}
|
|
86
86
|
catch (errors) {
|
|
87
87
|
schemaErrors = errors;
|
|
@@ -121,7 +121,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
121
121
|
var id_1 = mongoose_1.Types.ObjectId().toHexString();
|
|
122
122
|
document['_id'] = id_1;
|
|
123
123
|
document['__v'] = 0;
|
|
124
|
-
index_1.
|
|
124
|
+
index_1.ResolveIOServer.getMainDB().model(collection).create(document).then(function () { return resolve(id_1); }, function (err) { return reject(err); });
|
|
125
125
|
}
|
|
126
126
|
});
|
|
127
127
|
}
|
|
@@ -143,7 +143,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
143
143
|
function: function (collection, f_document) {
|
|
144
144
|
var _this = this;
|
|
145
145
|
return new Promise(function (resolve, reject) {
|
|
146
|
-
index_1.
|
|
146
|
+
index_1.ResolveIOServer.getMainDB().model(collection).findOne({ _id: f_document['_id'] }).lean().exec(function (errDoc, currDoc) {
|
|
147
147
|
if (currDoc) {
|
|
148
148
|
if (currDoc.__v === f_document['__v']) {
|
|
149
149
|
var versionDoc = common_1.deepCopy(currDoc);
|
|
@@ -153,7 +153,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
153
153
|
};
|
|
154
154
|
var schemaErrors = null;
|
|
155
155
|
try {
|
|
156
|
-
index_1.
|
|
156
|
+
index_1.ResolveIOServer.getMainDB().model(collection)['simplschema'].validate(f_document);
|
|
157
157
|
}
|
|
158
158
|
catch (errors) {
|
|
159
159
|
schemaErrors = errors;
|
|
@@ -164,8 +164,8 @@ function loadCollectionMethods(methodManager) {
|
|
|
164
164
|
reject('Schema Errors');
|
|
165
165
|
}
|
|
166
166
|
else {
|
|
167
|
-
index_1.
|
|
168
|
-
index_1.
|
|
167
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc).then(function (doc) {
|
|
168
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
169
169
|
$and: [
|
|
170
170
|
{ '_id._id': currDoc._id },
|
|
171
171
|
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
@@ -176,7 +176,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
176
176
|
});
|
|
177
177
|
var updates = common_1.getMongoUpdates(currDoc, f_document, true);
|
|
178
178
|
if (updates) {
|
|
179
|
-
index_1.
|
|
179
|
+
index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: f_document['_id'] }, updates, { strict: false }).exec().then(function (res) {
|
|
180
180
|
resolve(res.nModified);
|
|
181
181
|
}, function (err) { return reject(err); });
|
|
182
182
|
}
|
|
@@ -213,7 +213,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
213
213
|
}
|
|
214
214
|
else {
|
|
215
215
|
console.log('invalid version - ' + collection, currDoc.__v, f_document['__v']);
|
|
216
|
-
index_1.
|
|
216
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).findOne({
|
|
217
217
|
$and: [
|
|
218
218
|
{ '_id._id': currDoc._id },
|
|
219
219
|
{ '_id.__v': f_document['__v'] }
|
|
@@ -229,9 +229,9 @@ function loadCollectionMethods(methodManager) {
|
|
|
229
229
|
var updatedDoc = common_1.getMongoMergeUpdatedDoc(f_document, currDoc, oldDoc);
|
|
230
230
|
updatedDoc._id = newCurrDocId;
|
|
231
231
|
updatedDoc.__v++;
|
|
232
|
-
index_1.
|
|
233
|
-
index_1.
|
|
234
|
-
index_1.
|
|
232
|
+
index_1.ResolveIOServer.getMainDB().model(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).exec().then(function (res) {
|
|
233
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc_1).then(function (doc) {
|
|
234
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
235
235
|
$and: [
|
|
236
236
|
{ '_id._id': versionDoc_1._id._id },
|
|
237
237
|
{ '_id.__v': { $lte: versionDoc_1._id.__v - 4 } }
|
|
@@ -280,7 +280,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
280
280
|
function: function (collection, doc_id, updateParams, doc__v) {
|
|
281
281
|
var _this = this;
|
|
282
282
|
return new Promise(function (resolve, reject) {
|
|
283
|
-
index_1.
|
|
283
|
+
index_1.ResolveIOServer.getMainDB().model(collection).findOne({ _id: doc_id }).lean().exec(function (errDoc, currDoc) {
|
|
284
284
|
if (currDoc) {
|
|
285
285
|
var modifiedDoc_1 = common_1.deepCopy(currDoc);
|
|
286
286
|
updateParams.forEach(function (data) {
|
|
@@ -294,7 +294,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
294
294
|
};
|
|
295
295
|
var schemaErrors = null;
|
|
296
296
|
try {
|
|
297
|
-
index_1.
|
|
297
|
+
index_1.ResolveIOServer.getMainDB().model(collection)['simplschema'].validate(modifiedDoc_1);
|
|
298
298
|
}
|
|
299
299
|
catch (errors) {
|
|
300
300
|
schemaErrors = errors;
|
|
@@ -305,8 +305,8 @@ function loadCollectionMethods(methodManager) {
|
|
|
305
305
|
reject('Schema Errors');
|
|
306
306
|
}
|
|
307
307
|
else {
|
|
308
|
-
index_1.
|
|
309
|
-
index_1.
|
|
308
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc).then(function (doc) {
|
|
309
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
310
310
|
$and: [
|
|
311
311
|
{ '_id._id': currDoc._id },
|
|
312
312
|
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
@@ -317,7 +317,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
317
317
|
});
|
|
318
318
|
var updates = common_1.getMongoUpdates(currDoc, modifiedDoc_1, true);
|
|
319
319
|
if (updates) {
|
|
320
|
-
index_1.
|
|
320
|
+
index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: modifiedDoc_1._id }, updates, { strict: false }).exec().then(function (res) {
|
|
321
321
|
resolve(res.ok);
|
|
322
322
|
}, function (err) { return reject(err); });
|
|
323
323
|
}
|
|
@@ -354,7 +354,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
354
354
|
}
|
|
355
355
|
else {
|
|
356
356
|
console.log('invalid version - ' + collection, currDoc.__v, doc__v);
|
|
357
|
-
index_1.
|
|
357
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).findOne({
|
|
358
358
|
$and: [
|
|
359
359
|
{ '_id._id': currDoc._id },
|
|
360
360
|
{ '_id.__v': doc__v }
|
|
@@ -370,9 +370,9 @@ function loadCollectionMethods(methodManager) {
|
|
|
370
370
|
var updatedDoc = common_1.getMongoMergeUpdatedDoc(modifiedDoc_1, currDoc, oldDoc);
|
|
371
371
|
updatedDoc._id = newCurrDocId;
|
|
372
372
|
updatedDoc.__v++;
|
|
373
|
-
index_1.
|
|
374
|
-
index_1.
|
|
375
|
-
index_1.
|
|
373
|
+
index_1.ResolveIOServer.getMainDB().model(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).exec().then(function (res) {
|
|
374
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc_2).then(function (doc) {
|
|
375
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
376
376
|
$and: [
|
|
377
377
|
{ '_id._id': versionDoc_2._id._id },
|
|
378
378
|
{ '_id.__v': { $lte: versionDoc_2._id.__v - 4 } }
|
|
@@ -414,7 +414,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
414
414
|
function: function (collection, f_document, f_oldDocument) {
|
|
415
415
|
var _this = this;
|
|
416
416
|
return new Promise(function (resolve, reject) {
|
|
417
|
-
index_1.
|
|
417
|
+
index_1.ResolveIOServer.getMainDB().model(collection).findOne({ _id: f_document['_id'] }).lean().exec(function (errDoc, currDoc) {
|
|
418
418
|
if (currDoc) {
|
|
419
419
|
if (currDoc.__v === f_document['__v']) {
|
|
420
420
|
var versionDoc = common_1.deepCopy(currDoc);
|
|
@@ -424,7 +424,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
424
424
|
};
|
|
425
425
|
var schemaErrors = null;
|
|
426
426
|
try {
|
|
427
|
-
index_1.
|
|
427
|
+
index_1.ResolveIOServer.getMainDB().model(collection)['simplschema'].validate(f_document);
|
|
428
428
|
}
|
|
429
429
|
catch (errors) {
|
|
430
430
|
schemaErrors = errors;
|
|
@@ -435,8 +435,8 @@ function loadCollectionMethods(methodManager) {
|
|
|
435
435
|
reject('Schema Errors');
|
|
436
436
|
}
|
|
437
437
|
else {
|
|
438
|
-
index_1.
|
|
439
|
-
index_1.
|
|
438
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc).then(function (doc) {
|
|
439
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
440
440
|
$and: [
|
|
441
441
|
{ '_id._id': currDoc._id },
|
|
442
442
|
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
@@ -447,7 +447,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
447
447
|
});
|
|
448
448
|
var updates = common_1.getMongoUpdates(currDoc, f_document, true);
|
|
449
449
|
if (updates) {
|
|
450
|
-
index_1.
|
|
450
|
+
index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: f_document['_id'] }, updates, { strict: false }).exec().then(function (res) {
|
|
451
451
|
resolve(res.nModified);
|
|
452
452
|
}, function (err) { return reject(err); });
|
|
453
453
|
}
|
|
@@ -494,9 +494,9 @@ function loadCollectionMethods(methodManager) {
|
|
|
494
494
|
var updatedDoc = common_1.getMongoMergeUpdatedDoc(f_document, currDoc, f_oldDocument);
|
|
495
495
|
updatedDoc._id = newCurrDocId;
|
|
496
496
|
updatedDoc.__v++;
|
|
497
|
-
index_1.
|
|
498
|
-
index_1.
|
|
499
|
-
index_1.
|
|
497
|
+
index_1.ResolveIOServer.getMainDB().model(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).exec().then(function (res) {
|
|
498
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc_3).then(function (doc) {
|
|
499
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
500
500
|
$and: [
|
|
501
501
|
{ '_id._id': versionDoc_3._id._id },
|
|
502
502
|
{ '_id.__v': { $lte: versionDoc_3._id.__v - 4 } }
|
|
@@ -550,7 +550,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
550
550
|
function: function (collection, doc_id, updateParams, doc__v, f_oldDocument) {
|
|
551
551
|
var _this = this;
|
|
552
552
|
return new Promise(function (resolve, reject) {
|
|
553
|
-
index_1.
|
|
553
|
+
index_1.ResolveIOServer.getMainDB().model(collection).findOne({ _id: doc_id }).lean().exec(function (errDoc, currDoc) {
|
|
554
554
|
if (currDoc) {
|
|
555
555
|
var modifiedDoc_2 = common_1.deepCopy(currDoc);
|
|
556
556
|
updateParams.forEach(function (data) {
|
|
@@ -564,7 +564,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
564
564
|
};
|
|
565
565
|
var schemaErrors = null;
|
|
566
566
|
try {
|
|
567
|
-
index_1.
|
|
567
|
+
index_1.ResolveIOServer.getMainDB().model(collection)['simplschema'].validate(modifiedDoc_2);
|
|
568
568
|
}
|
|
569
569
|
catch (errors) {
|
|
570
570
|
schemaErrors = errors;
|
|
@@ -575,8 +575,8 @@ function loadCollectionMethods(methodManager) {
|
|
|
575
575
|
reject('Schema Errors');
|
|
576
576
|
}
|
|
577
577
|
else {
|
|
578
|
-
index_1.
|
|
579
|
-
index_1.
|
|
578
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc).then(function (doc) {
|
|
579
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
580
580
|
$and: [
|
|
581
581
|
{ '_id._id': currDoc._id },
|
|
582
582
|
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
@@ -587,7 +587,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
587
587
|
});
|
|
588
588
|
var updates = common_1.getMongoUpdates(currDoc, modifiedDoc_2, true);
|
|
589
589
|
if (updates) {
|
|
590
|
-
index_1.
|
|
590
|
+
index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: modifiedDoc_2._id }, updates, { strict: false }).exec().then(function (res) {
|
|
591
591
|
resolve(res.ok);
|
|
592
592
|
}, function (err) { return reject(err); });
|
|
593
593
|
}
|
|
@@ -634,9 +634,9 @@ function loadCollectionMethods(methodManager) {
|
|
|
634
634
|
var updatedDoc = common_1.getMongoMergeUpdatedDoc(modifiedDoc_2, currDoc, f_oldDocument);
|
|
635
635
|
updatedDoc._id = newCurrDocId;
|
|
636
636
|
updatedDoc.__v++;
|
|
637
|
-
index_1.
|
|
638
|
-
index_1.
|
|
639
|
-
index_1.
|
|
637
|
+
index_1.ResolveIOServer.getMainDB().model(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).exec().then(function (res) {
|
|
638
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc_4).then(function (doc) {
|
|
639
|
+
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
640
640
|
$and: [
|
|
641
641
|
{ '_id._id': versionDoc_4._id._id },
|
|
642
642
|
{ '_id.__v': { $lte: versionDoc_4._id.__v - 4 } }
|
|
@@ -687,7 +687,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
687
687
|
user: _this.user,
|
|
688
688
|
messageId: ''
|
|
689
689
|
});
|
|
690
|
-
index_1.
|
|
690
|
+
index_1.ResolveIOServer.getMainDB().model(collection).deleteOne({ _id: doc_id }).exec(function (err, res) {
|
|
691
691
|
if (err) {
|
|
692
692
|
reject(err);
|
|
693
693
|
}
|
|
@@ -722,7 +722,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
722
722
|
user: _this.user,
|
|
723
723
|
messageId: ''
|
|
724
724
|
});
|
|
725
|
-
index_1.
|
|
725
|
+
index_1.ResolveIOServer.getMainDB().model(collection).deleteOne(query).exec(function (err, res) {
|
|
726
726
|
if (err) {
|
|
727
727
|
reject(err);
|
|
728
728
|
}
|