@resolveio/server-lib 9.0.32 → 9.0.34
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/client-server-app.js +7 -48
- package/client-server-app.js.map +1 -1
- package/collections/app-status.collection.js +8 -11
- package/collections/app-status.collection.js.map +1 -1
- package/collections/app-version.collection.js +8 -11
- package/collections/app-version.collection.js.map +1 -1
- package/collections/counter.collection.js +8 -11
- package/collections/counter.collection.js.map +1 -1
- package/collections/cron-job-history.collection.js +9 -12
- package/collections/cron-job-history.collection.js.map +1 -1
- package/collections/cron-job.collection.js +8 -11
- package/collections/cron-job.collection.js.map +1 -1
- package/collections/email-history.collection.js +8 -11
- package/collections/email-history.collection.js.map +1 -1
- package/collections/email-verified.collection.js +9 -12
- package/collections/email-verified.collection.js.map +1 -1
- package/collections/file.collection.js +8 -11
- package/collections/file.collection.js.map +1 -1
- package/collections/flag.collection.js +8 -11
- package/collections/flag.collection.js.map +1 -1
- package/collections/log-method-latency.collection.js +11 -14
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +13 -16
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log.collection.js +16 -19
- package/collections/log.collection.js.map +1 -1
- package/collections/logged-in-users.collection.js +9 -12
- package/collections/logged-in-users.collection.js.map +1 -1
- package/collections/method-call.collection.js +10 -13
- package/collections/method-call.collection.js.map +1 -1
- package/collections/method-response.collection.js +10 -13
- package/collections/method-response.collection.js.map +1 -1
- package/collections/monitor-cpu.collection.js +13 -16
- package/collections/monitor-cpu.collection.js.map +1 -1
- package/collections/monitor-https-inbound.collection.js +13 -16
- package/collections/monitor-https-inbound.collection.js.map +1 -1
- package/collections/monitor-https-outbound.collection.js +15 -18
- package/collections/monitor-https-outbound.collection.js.map +1 -1
- package/collections/monitor-memory.collection.js +12 -15
- package/collections/monitor-memory.collection.js.map +1 -1
- package/collections/monitor-mongo.collection.js +12 -15
- package/collections/monitor-mongo.collection.js.map +1 -1
- package/collections/notification.collection.js +8 -11
- package/collections/notification.collection.js.map +1 -1
- package/collections/queue-flag.collection.js +9 -12
- package/collections/queue-flag.collection.js.map +1 -1
- package/collections/queue-method.collection.js +9 -12
- package/collections/queue-method.collection.js.map +1 -1
- package/collections/queue-response.collection.js +9 -12
- package/collections/queue-response.collection.js.map +1 -1
- package/collections/report-builder-dashboard-builder.collection.js +10 -13
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
- package/collections/report-builder-library.collection.js +11 -14
- package/collections/report-builder-library.collection.js.map +1 -1
- package/collections/report-builder-report.collection.js +11 -14
- package/collections/report-builder-report.collection.js.map +1 -1
- package/collections/user-group.collection.js +11 -14
- package/collections/user-group.collection.js.map +1 -1
- package/collections/user-guide.collection.js +8 -11
- package/collections/user-guide.collection.js.map +1 -1
- package/collections/user.collection.js +12 -15
- package/collections/user.collection.js.map +1 -1
- package/cron/cron.js +25 -25
- package/cron/cron.js.map +1 -1
- package/fixtures/cron-jobs.js +30 -80
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +9 -59
- package/fixtures/init.js.map +1 -1
- package/http/auth.js +344 -460
- package/http/auth.js.map +1 -1
- package/http/health.js +1 -5
- package/http/health.js.map +1 -1
- package/http/home.js +7 -11
- package/http/home.js.map +1 -1
- package/index.js +36 -98
- package/index.js.map +1 -1
- package/managers/cron.manager.js +78 -157
- package/managers/cron.manager.js.map +1 -1
- package/managers/method.manager.js +323 -303
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.d.ts +14 -14
- package/managers/mongo.manager.js +794 -865
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +171 -254
- package/managers/monitor.manager.js.map +1 -1
- package/managers/queue-method.manager.js +69 -166
- package/managers/queue-method.manager.js.map +1 -1
- package/managers/subscription.manager.js +515 -708
- package/managers/subscription.manager.js.map +1 -1
- package/methods/accounts.js +111 -183
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +156 -262
- package/methods/aws.js.map +1 -1
- package/methods/cloudconvert.js +100 -180
- package/methods/cloudconvert.js.map +1 -1
- package/methods/collections.js +114 -530
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +29 -79
- package/methods/counters.js.map +1 -1
- package/methods/cron-jobs.js +819 -884
- package/methods/cron-jobs.js.map +1 -1
- package/methods/flags.js +1 -5
- package/methods/flags.js.map +1 -1
- package/methods/logs.js +258 -313
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +289 -348
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +341 -340
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +565 -657
- package/methods/report-builder.js.map +1 -1
- package/methods/support.js +67 -185
- package/methods/support.js.map +1 -1
- package/models/app-status.model.js +1 -2
- package/models/app-version.model.js +1 -2
- package/models/billing-logged-in-users.model.js +1 -2
- package/models/collection-document.model.js +1 -2
- package/models/counter.model.js +1 -2
- package/models/cron-job-history.model.js +1 -2
- package/models/cron-job.model.js +1 -2
- package/models/dialog.model.js +1 -2
- package/models/email-history.model.js +1 -2
- package/models/email-verified.model.js +1 -2
- package/models/file.model.js +1 -2
- package/models/flag.model.js +1 -2
- package/models/log-method-latency.model.js +1 -2
- package/models/log-subscription.model.js +1 -2
- package/models/log.model.js +1 -2
- package/models/logged-in-users.model.js +1 -2
- package/models/method-call.model.js +1 -2
- package/models/method-response.model.js +1 -2
- package/models/method.model.js +1 -2
- package/models/monitor-cpu.model.js +1 -2
- package/models/monitor-https-inbound.model.js +1 -2
- package/models/monitor-https-outbound.model.js +1 -2
- package/models/monitor-memory.model.js +1 -2
- package/models/monitor-mongo.model.js +1 -2
- package/models/notification.model.js +1 -2
- package/models/pagination.model.js +2 -5
- package/models/pagination.model.js.map +1 -1
- package/models/permission.model.js +1 -2
- package/models/queue-method.model.js +1 -2
- package/models/queue-response.model.js +1 -2
- package/models/report-builder-dashboard-builder.model.js +1 -2
- package/models/report-builder-library.model.js +1 -2
- package/models/report-builder-report.model.js +1 -2
- package/models/report-builder.model.js +1 -2
- package/models/select-data-label.model.js +1 -2
- package/models/server-response.model.js +1 -2
- package/models/subscription.model.js +1 -2
- package/models/support-ticket.model.js +1 -2
- package/models/user-group.model.js +1 -2
- package/models/user-guide.model.js +1 -2
- package/models/user.model.js +1 -2
- package/package.json +1 -1
- package/public_api.js +70 -82
- package/public_api.js.map +1 -1
- package/publications/app-status.js +4 -8
- package/publications/app-status.js.map +1 -1
- package/publications/app-version.js +4 -8
- package/publications/app-version.js.map +1 -1
- package/publications/cron-jobs.js +9 -13
- package/publications/cron-jobs.js.map +1 -1
- package/publications/files.js +11 -15
- package/publications/files.js.map +1 -1
- package/publications/flags.js +7 -11
- package/publications/flags.js.map +1 -1
- package/publications/logs.js +31 -35
- package/publications/logs.js.map +1 -1
- package/publications/method-calls.js +4 -8
- package/publications/method-calls.js.map +1 -1
- package/publications/method-responses.js +4 -8
- package/publications/method-responses.js.map +1 -1
- package/publications/notifications.js +4 -8
- package/publications/notifications.js.map +1 -1
- package/publications/report-builder-dashboard-builders.js +8 -12
- package/publications/report-builder-dashboard-builders.js.map +1 -1
- package/publications/report-builder-libraries.js +16 -66
- package/publications/report-builder-libraries.js.map +1 -1
- package/publications/report-builder-reports.js +17 -21
- package/publications/report-builder-reports.js.map +1 -1
- package/publications/super-admin.js +3 -7
- package/publications/super-admin.js.map +1 -1
- package/publications/user-groups.js +4 -8
- package/publications/user-groups.js.map +1 -1
- package/publications/user-guides.js +4 -8
- package/publications/user-guides.js.map +1 -1
- package/server-app.js +393 -534
- package/server-app.js.map +1 -1
- package/util/common.js +55 -92
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +76 -134
- package/util/schema-report-builder.js.map +1 -1
package/methods/collections.js
CHANGED
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var index_1 = require("../index");
|
|
8
|
-
var mongo_manager_1 = require("../managers/mongo.manager");
|
|
9
|
-
function loadCollectionMethods(methodManager) {
|
|
1
|
+
import { deepCopy, getMongoMergeUpdatedDoc } from '../util/common';
|
|
2
|
+
import SimpleSchema from 'simpl-schema';
|
|
3
|
+
import { PaginationOptionsSchema } from '../models/pagination.model';
|
|
4
|
+
import { ResolveIOServer } from '../index';
|
|
5
|
+
import { objectIdHexString } from '../managers/mongo.manager';
|
|
6
|
+
export function loadCollectionMethods(methodManager) {
|
|
10
7
|
methodManager.methods({
|
|
11
8
|
collectionListAll: {
|
|
12
9
|
skipQueue: true,
|
|
13
10
|
function: function () {
|
|
14
|
-
return new Promise(
|
|
15
|
-
resolve(
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
resolve(ResolveIOServer.getMongoManager().collections().map(a => a.collectionName).sort((a, b) => a.localeCompare(b)));
|
|
16
13
|
});
|
|
17
14
|
}
|
|
18
15
|
},
|
|
19
16
|
collectionListRB: {
|
|
20
17
|
skipQueue: true,
|
|
21
18
|
function: function () {
|
|
22
|
-
return new Promise(
|
|
23
|
-
resolve(
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
resolve(ResolveIOServer.getMongoManager().collections().filter(a => a.useRB).map(a => a.collectionName).sort((a, b) => a.localeCompare(b)));
|
|
24
21
|
});
|
|
25
22
|
}
|
|
26
23
|
},
|
|
27
24
|
// Query database for any collection and query
|
|
28
25
|
findOne: {
|
|
29
26
|
skipQueue: true,
|
|
30
|
-
check: new
|
|
27
|
+
check: new SimpleSchema({
|
|
31
28
|
collection: {
|
|
32
29
|
type: String
|
|
33
30
|
},
|
|
@@ -36,21 +33,20 @@ function loadCollectionMethods(methodManager) {
|
|
|
36
33
|
blackbox: true
|
|
37
34
|
}
|
|
38
35
|
}),
|
|
39
|
-
function: function (collection, query) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
36
|
+
function: function (collection, query = {}) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
if (!ResolveIOServer.getMongoManager().collection(collection)) {
|
|
43
39
|
reject('Invalid collection');
|
|
44
40
|
}
|
|
45
41
|
else {
|
|
46
|
-
|
|
42
|
+
ResolveIOServer.getMongoManager().collection(collection).findOne(query).then(res => resolve(res), err => reject(err));
|
|
47
43
|
}
|
|
48
44
|
});
|
|
49
45
|
}
|
|
50
46
|
},
|
|
51
47
|
find: {
|
|
52
48
|
skipQueue: true,
|
|
53
|
-
check: new
|
|
49
|
+
check: new SimpleSchema({
|
|
54
50
|
collection: {
|
|
55
51
|
type: String
|
|
56
52
|
},
|
|
@@ -64,22 +60,20 @@ function loadCollectionMethods(methodManager) {
|
|
|
64
60
|
optional: true
|
|
65
61
|
}
|
|
66
62
|
}),
|
|
67
|
-
function: function (collection, query, sortQuery) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return new Promise(function (resolve, reject) {
|
|
71
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
63
|
+
function: function (collection, query = {}, sortQuery = {}) {
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
if (!ResolveIOServer.getMongoManager().collection(collection)) {
|
|
72
66
|
reject('Invalid collection');
|
|
73
67
|
}
|
|
74
68
|
else {
|
|
75
|
-
|
|
69
|
+
ResolveIOServer.getMongoManager().collection(collection).find(query, { sort: sortQuery }).then(res => resolve(res), err => reject(err));
|
|
76
70
|
}
|
|
77
71
|
});
|
|
78
72
|
}
|
|
79
73
|
},
|
|
80
74
|
findWithOptions: {
|
|
81
75
|
skipQueue: true,
|
|
82
|
-
check: new
|
|
76
|
+
check: new SimpleSchema({
|
|
83
77
|
collection: {
|
|
84
78
|
type: String
|
|
85
79
|
},
|
|
@@ -88,16 +82,16 @@ function loadCollectionMethods(methodManager) {
|
|
|
88
82
|
blackbox: true
|
|
89
83
|
},
|
|
90
84
|
options: {
|
|
91
|
-
type:
|
|
85
|
+
type: PaginationOptionsSchema
|
|
92
86
|
}
|
|
93
87
|
}),
|
|
94
88
|
function: function (collection, query, options) {
|
|
95
|
-
return new Promise(
|
|
96
|
-
if (!
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
if (!ResolveIOServer.getMongoManager().collection(collection)) {
|
|
97
91
|
reject('Invalid collection');
|
|
98
92
|
}
|
|
99
93
|
else {
|
|
100
|
-
|
|
94
|
+
let optionsQuery = {};
|
|
101
95
|
if (options.fields && Object.keys(options.fields).length) {
|
|
102
96
|
optionsQuery['projection'] = options.fields;
|
|
103
97
|
}
|
|
@@ -110,7 +104,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
110
104
|
if (options.skip) {
|
|
111
105
|
optionsQuery['skip'] = options.skip;
|
|
112
106
|
}
|
|
113
|
-
|
|
107
|
+
ResolveIOServer.getMongoManager().collection(collection).find(query, optionsQuery).then(res => resolve(res), err => reject(err));
|
|
114
108
|
}
|
|
115
109
|
});
|
|
116
110
|
}
|
|
@@ -119,7 +113,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
119
113
|
// @Inputs: collection, document
|
|
120
114
|
// @Outputs: res = _id of new document, err = not inserted
|
|
121
115
|
insertDocument: {
|
|
122
|
-
check: new
|
|
116
|
+
check: new SimpleSchema({
|
|
123
117
|
collection: {
|
|
124
118
|
type: String
|
|
125
119
|
},
|
|
@@ -129,30 +123,15 @@ function loadCollectionMethods(methodManager) {
|
|
|
129
123
|
}
|
|
130
124
|
}),
|
|
131
125
|
function: function (collection, document) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
if (!ResolveIOServer.getMongoManager().collection(collection)) {
|
|
135
128
|
reject('Invalid collection');
|
|
136
129
|
}
|
|
137
130
|
else {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
catch (errors) {
|
|
143
|
-
schemaErrors = errors;
|
|
144
|
-
_this.callMethodInternal('insertErrorLog', 'Schema Failed on insert - ' + collection, [schemaErrors, document]);
|
|
145
|
-
}
|
|
146
|
-
if (schemaErrors) {
|
|
147
|
-
console.log(schemaErrors);
|
|
148
|
-
reject('Schema Errors');
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
var id_1 = mongo_manager_1.objectIdHexString();
|
|
152
|
-
document['_id'] = id_1;
|
|
153
|
-
document['__v'] = 0;
|
|
154
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).insertOne(document).then(function () { return resolve(id_1); }, function (err) { return reject(err); });
|
|
155
|
-
}
|
|
131
|
+
let id = objectIdHexString();
|
|
132
|
+
document['_id'] = id;
|
|
133
|
+
document['__v'] = 0;
|
|
134
|
+
ResolveIOServer.getMongoManager().collection(collection).insertOne(document).then(() => resolve(id), err => reject(err));
|
|
156
135
|
}
|
|
157
136
|
});
|
|
158
137
|
}
|
|
@@ -161,7 +140,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
161
140
|
// @Inputs: collection, document
|
|
162
141
|
// @Outputs: res = _id of new document, err = not inserted
|
|
163
142
|
insertManyDocuments: {
|
|
164
|
-
check: new
|
|
143
|
+
check: new SimpleSchema({
|
|
165
144
|
collection: {
|
|
166
145
|
type: String
|
|
167
146
|
},
|
|
@@ -174,50 +153,26 @@ function loadCollectionMethods(methodManager) {
|
|
|
174
153
|
}
|
|
175
154
|
}),
|
|
176
155
|
function: function (collection, documents) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
rej('Invalid collection');
|
|
156
|
+
return new Promise((resolve, reject) => {
|
|
157
|
+
if (!ResolveIOServer.getMongoManager().collection(collection)) {
|
|
158
|
+
reject('Invalid collection');
|
|
181
159
|
}
|
|
182
160
|
else {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
try {
|
|
189
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection)['simplschema'].validate(document_1);
|
|
190
|
-
}
|
|
191
|
-
catch (errors) {
|
|
192
|
-
schemaErrors = errors;
|
|
193
|
-
_this.callMethodInternal('insertErrorLog', 'Schema Failed on insert - ' + collection, [schemaErrors, document_1]);
|
|
194
|
-
}
|
|
195
|
-
if (schemaErrors) {
|
|
196
|
-
console.log(schemaErrors);
|
|
197
|
-
reject('Schema Errors');
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
var id_2 = mongo_manager_1.objectIdHexString();
|
|
201
|
-
document_1['_id'] = id_2;
|
|
202
|
-
document_1['__v'] = 0;
|
|
203
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).insertOne(document_1).then(function () { return resolve(id_2); }, function (err) { return reject(err); });
|
|
204
|
-
}
|
|
205
|
-
}));
|
|
206
|
-
};
|
|
207
|
-
for (var i = 0; i < documents.length; i++) {
|
|
208
|
-
_loop_1(i);
|
|
209
|
-
}
|
|
210
|
-
Promise.all(promises).then(function (vals) { return res(vals); }, function (err) { return rej(err); });
|
|
161
|
+
documents.forEach(document => {
|
|
162
|
+
document['_id'] = objectIdHexString();
|
|
163
|
+
document['__v'] = 0;
|
|
164
|
+
});
|
|
165
|
+
ResolveIOServer.getMongoManager().collection(collection).insertMany(documents).then(() => resolve(documents.map(a => a['_id'])), err => reject(err));
|
|
211
166
|
}
|
|
212
167
|
});
|
|
213
168
|
}
|
|
214
169
|
},
|
|
215
170
|
// Replaces 1 document with new document (from _id)
|
|
216
171
|
// @Inputs: collection, document id
|
|
217
|
-
// @Outputs: res = 1 (updated 1),
|
|
172
|
+
// @Outputs: res = 1 (updated 1), err = not updated/wrong version
|
|
218
173
|
// Search for doc, check version, if found then try and update
|
|
219
174
|
updateDocument: {
|
|
220
|
-
check: new
|
|
175
|
+
check: new SimpleSchema({
|
|
221
176
|
collection: {
|
|
222
177
|
type: String
|
|
223
178
|
},
|
|
@@ -227,130 +182,12 @@ function loadCollectionMethods(methodManager) {
|
|
|
227
182
|
}
|
|
228
183
|
}),
|
|
229
184
|
function: function (collection, f_document) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
185
|
+
return new Promise((resolve, reject) => {
|
|
186
|
+
if (!ResolveIOServer.getMongoManager().collection(collection)) {
|
|
233
187
|
reject('Invalid collection');
|
|
234
188
|
}
|
|
235
189
|
else {
|
|
236
|
-
|
|
237
|
-
if (currDoc) {
|
|
238
|
-
if (currDoc.__v === f_document['__v']) {
|
|
239
|
-
var versionDoc = common_1.deepCopy(currDoc);
|
|
240
|
-
versionDoc._id = {
|
|
241
|
-
_id: currDoc._id,
|
|
242
|
-
__v: currDoc.__v
|
|
243
|
-
};
|
|
244
|
-
var schemaErrors = null;
|
|
245
|
-
try {
|
|
246
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection)['simplschema'].validate(f_document);
|
|
247
|
-
}
|
|
248
|
-
catch (errors) {
|
|
249
|
-
schemaErrors = errors;
|
|
250
|
-
_this.callMethodInternal('insertErrorLog', 'Schema Failed on updateDocument - ' + collection, [schemaErrors, f_document]);
|
|
251
|
-
}
|
|
252
|
-
if (schemaErrors) {
|
|
253
|
-
console.log(schemaErrors);
|
|
254
|
-
reject('Schema Errors');
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
var updates_1 = common_1.getMongoUpdates(currDoc, f_document, true);
|
|
258
|
-
if (index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) {
|
|
259
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').create(versionDoc).then(function (doc) {
|
|
260
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').deleteMany({
|
|
261
|
-
$and: [
|
|
262
|
-
{ '_id._id': currDoc._id },
|
|
263
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
264
|
-
]
|
|
265
|
-
}).then(function () {
|
|
266
|
-
if (updates_1) {
|
|
267
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).updateOne({ _id: f_document['_id'] }, updates_1).then(function (res) {
|
|
268
|
-
resolve(res);
|
|
269
|
-
}, function (err) { return reject(err); });
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
resolve(1);
|
|
273
|
-
}
|
|
274
|
-
}, function (err) { return reject(err); });
|
|
275
|
-
}, function (err) {
|
|
276
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').deleteMany({
|
|
277
|
-
$and: [
|
|
278
|
-
{ '_id._id': currDoc._id },
|
|
279
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
280
|
-
]
|
|
281
|
-
}).then(function () {
|
|
282
|
-
if (updates_1) {
|
|
283
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).updateOne({ _id: f_document['_id'] }, updates_1).then(function (res) {
|
|
284
|
-
resolve(res);
|
|
285
|
-
}, function (err) { return reject(err); });
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
resolve(1);
|
|
289
|
-
}
|
|
290
|
-
}, function (err) { return reject(err); });
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
if (updates_1) {
|
|
295
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).updateOne({ _id: f_document['_id'] }, updates_1).then(function (res) {
|
|
296
|
-
resolve(res);
|
|
297
|
-
}, function (err) { return reject(err); });
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
resolve(1);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
console.log('invalid version - ' + collection, currDoc.__v, f_document['__v']);
|
|
307
|
-
if (index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) {
|
|
308
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({
|
|
309
|
-
$and: [
|
|
310
|
-
{ '_id._id': currDoc._id },
|
|
311
|
-
{ '_id.__v': f_document['__v'] }
|
|
312
|
-
]
|
|
313
|
-
}).then(function (oldDoc) {
|
|
314
|
-
var newCurrDocId = currDoc._id;
|
|
315
|
-
if (oldDoc) {
|
|
316
|
-
var versionDoc_1 = common_1.deepCopy(currDoc);
|
|
317
|
-
versionDoc_1._id = {
|
|
318
|
-
_id: currDoc._id,
|
|
319
|
-
__v: currDoc.__v
|
|
320
|
-
};
|
|
321
|
-
var updatedDoc = common_1.getMongoMergeUpdatedDoc(f_document, currDoc, oldDoc);
|
|
322
|
-
updatedDoc._id = newCurrDocId;
|
|
323
|
-
updatedDoc.__v++;
|
|
324
|
-
updatedDoc.updatedAt = new Date();
|
|
325
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).then(function (res) {
|
|
326
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').create(versionDoc_1).then(function (doc) {
|
|
327
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').deleteMany({
|
|
328
|
-
$and: [
|
|
329
|
-
{ '_id._id': versionDoc_1._id._id },
|
|
330
|
-
{ '_id.__v': { $lte: versionDoc_1._id.__v - 4 } }
|
|
331
|
-
]
|
|
332
|
-
}).then(function () {
|
|
333
|
-
resolve(res);
|
|
334
|
-
}, function (err) { return reject(err); });
|
|
335
|
-
}, function (err) { return reject(err); });
|
|
336
|
-
}, function (err) { return reject(err); });
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
reject('Invalid Version And Could Not Find History - DB: ' + currDoc.__v + ', Trying to update with :' + f_document['__v']);
|
|
340
|
-
}
|
|
341
|
-
}, function (err) { return reject(err); });
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
reject('Invalid Version And We Are NOT Using Versions On This Collection!');
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
reject('No Document');
|
|
350
|
-
}
|
|
351
|
-
}, function (errDoc) {
|
|
352
|
-
reject('No Document');
|
|
353
|
-
});
|
|
190
|
+
ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: f_document['_id'] }, f_document).then(res => resolve(res), err => reject(err));
|
|
354
191
|
}
|
|
355
192
|
});
|
|
356
193
|
}
|
|
@@ -360,7 +197,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
360
197
|
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
361
198
|
// Search for doc, check version, if found then try and update props
|
|
362
199
|
updateDocumentProps: {
|
|
363
|
-
check: new
|
|
200
|
+
check: new SimpleSchema({
|
|
364
201
|
collection: {
|
|
365
202
|
type: String
|
|
366
203
|
},
|
|
@@ -379,127 +216,43 @@ function loadCollectionMethods(methodManager) {
|
|
|
379
216
|
}
|
|
380
217
|
}),
|
|
381
218
|
function: function (collection, doc_id, updateParams, doc__v) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
219
|
+
return new Promise((resolve, reject) => {
|
|
220
|
+
if (!ResolveIOServer.getMongoManager().collection(collection)) {
|
|
385
221
|
reject('Invalid collection');
|
|
386
222
|
}
|
|
387
223
|
else {
|
|
388
|
-
|
|
224
|
+
ResolveIOServer.getMongoManager().collection(collection).findOne({ _id: doc_id }).then(currDoc => {
|
|
389
225
|
if (currDoc) {
|
|
390
|
-
|
|
391
|
-
updateParams.forEach(
|
|
392
|
-
|
|
226
|
+
let modifiedDoc = deepCopy(currDoc);
|
|
227
|
+
updateParams.forEach(data => {
|
|
228
|
+
modifiedDoc[data.prop] = data.data;
|
|
393
229
|
});
|
|
394
|
-
if (
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
__v: currDoc.__v
|
|
399
|
-
};
|
|
400
|
-
var schemaErrors = null;
|
|
401
|
-
try {
|
|
402
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection)['simplschema'].validate(modifiedDoc_1);
|
|
403
|
-
}
|
|
404
|
-
catch (errors) {
|
|
405
|
-
schemaErrors = errors;
|
|
406
|
-
_this.callMethodInternal('insertErrorLog', 'Schema Failed on updateDocumentProps - ' + collection, [schemaErrors, modifiedDoc_1]);
|
|
407
|
-
}
|
|
408
|
-
if (schemaErrors) {
|
|
409
|
-
console.log(schemaErrors);
|
|
410
|
-
reject('Schema Errors');
|
|
411
|
-
}
|
|
412
|
-
else {
|
|
413
|
-
var updates_2 = common_1.getMongoUpdates(currDoc, modifiedDoc_1, true);
|
|
414
|
-
if (index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) {
|
|
415
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').create(versionDoc).then(function (doc) {
|
|
416
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').deleteMany({
|
|
417
|
-
$and: [
|
|
418
|
-
{ '_id._id': currDoc._id },
|
|
419
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
420
|
-
]
|
|
421
|
-
}).then(function () {
|
|
422
|
-
if (updates_2) {
|
|
423
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).updateOne({ _id: modifiedDoc_1._id }, updates_2).then(function (res) {
|
|
424
|
-
resolve(res);
|
|
425
|
-
}, function (err) { return reject(err); });
|
|
426
|
-
}
|
|
427
|
-
else {
|
|
428
|
-
resolve(1);
|
|
429
|
-
}
|
|
430
|
-
}, function (err) { return reject(err); });
|
|
431
|
-
}, function (err) {
|
|
432
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').deleteMany({
|
|
433
|
-
$and: [
|
|
434
|
-
{ '_id._id': currDoc._id },
|
|
435
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
436
|
-
]
|
|
437
|
-
}).then(function () {
|
|
438
|
-
if (updates_2) {
|
|
439
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).updateOne({ _id: modifiedDoc_1._id }, updates_2).then(function (res) {
|
|
440
|
-
resolve(res);
|
|
441
|
-
}, function (err) { return reject(err); });
|
|
442
|
-
}
|
|
443
|
-
else {
|
|
444
|
-
resolve(1);
|
|
445
|
-
}
|
|
446
|
-
}, function (err) { return reject(err); });
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
else {
|
|
450
|
-
if (updates_2) {
|
|
451
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).updateOne({ _id: modifiedDoc_1._id }, updates_2).then(function (res) {
|
|
452
|
-
resolve(res);
|
|
453
|
-
}, function (err) { return reject(err); });
|
|
454
|
-
}
|
|
455
|
-
else {
|
|
456
|
-
resolve(1);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
230
|
+
if (modifiedDoc.__v === doc__v) {
|
|
231
|
+
ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: modifiedDoc._id }, modifiedDoc, {}, false, true).then(res => {
|
|
232
|
+
resolve(res);
|
|
233
|
+
}, err => reject(err));
|
|
460
234
|
}
|
|
461
235
|
else {
|
|
462
236
|
console.log(new Date(), 'invalid version - ' + collection, currDoc.__v, doc__v);
|
|
463
|
-
if (
|
|
464
|
-
|
|
237
|
+
if (ResolveIOServer.getMongoManager().collection(collection + '.versions')) {
|
|
238
|
+
ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({
|
|
465
239
|
$and: [
|
|
466
240
|
{ '_id._id': currDoc._id },
|
|
467
241
|
{ '_id.__v': doc__v }
|
|
468
242
|
]
|
|
469
|
-
}).then(
|
|
470
|
-
|
|
243
|
+
}).then(oldDoc => {
|
|
244
|
+
let newCurrDocId = currDoc._id;
|
|
471
245
|
if (oldDoc) {
|
|
472
|
-
|
|
473
|
-
versionDoc_2._id = {
|
|
474
|
-
_id: currDoc._id,
|
|
475
|
-
__v: currDoc.__v
|
|
476
|
-
};
|
|
477
|
-
var updatedDoc = common_1.getMongoMergeUpdatedDoc(modifiedDoc_1, currDoc, oldDoc);
|
|
246
|
+
let updatedDoc = getMongoMergeUpdatedDoc(modifiedDoc, currDoc, oldDoc);
|
|
478
247
|
updatedDoc._id = newCurrDocId;
|
|
479
|
-
updatedDoc.
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
if (index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) {
|
|
483
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').create(versionDoc_2).then(function (doc) {
|
|
484
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').deleteMany({
|
|
485
|
-
$and: [
|
|
486
|
-
{ '_id._id': versionDoc_2._id._id },
|
|
487
|
-
{ '_id.__v': { $lte: versionDoc_2._id.__v - 4 } }
|
|
488
|
-
]
|
|
489
|
-
}).then(function () {
|
|
490
|
-
resolve(res);
|
|
491
|
-
}, function (err) { return reject(err); });
|
|
492
|
-
}, function (err) { return reject(err); });
|
|
493
|
-
}
|
|
494
|
-
else {
|
|
495
|
-
resolve(res);
|
|
496
|
-
}
|
|
497
|
-
}, function (err) { return reject(err); });
|
|
248
|
+
ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc, {}, false, true).then(res => {
|
|
249
|
+
resolve(res);
|
|
250
|
+
}, err => reject(err));
|
|
498
251
|
}
|
|
499
252
|
else {
|
|
500
253
|
reject('Invalid Version And Could Not Find History Props - DB: ' + currDoc.__v + ', Trying to update with :' + doc__v);
|
|
501
254
|
}
|
|
502
|
-
},
|
|
255
|
+
}, () => { });
|
|
503
256
|
}
|
|
504
257
|
else {
|
|
505
258
|
reject('Invalid Version And We Are NOT Using Versions On This Collection!');
|
|
@@ -509,13 +262,13 @@ function loadCollectionMethods(methodManager) {
|
|
|
509
262
|
else {
|
|
510
263
|
reject('No Document');
|
|
511
264
|
}
|
|
512
|
-
},
|
|
265
|
+
}, () => { });
|
|
513
266
|
}
|
|
514
267
|
});
|
|
515
268
|
}
|
|
516
269
|
},
|
|
517
270
|
updateDocumentOffline: {
|
|
518
|
-
check: new
|
|
271
|
+
check: new SimpleSchema({
|
|
519
272
|
collection: {
|
|
520
273
|
type: String
|
|
521
274
|
},
|
|
@@ -529,111 +282,27 @@ function loadCollectionMethods(methodManager) {
|
|
|
529
282
|
}
|
|
530
283
|
}),
|
|
531
284
|
function: function (collection, f_document, f_oldDocument) {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
285
|
+
return new Promise((resolve, reject) => {
|
|
286
|
+
if (!ResolveIOServer.getMongoManager().collection(collection)) {
|
|
535
287
|
reject('Invalid collection');
|
|
536
288
|
}
|
|
537
289
|
else {
|
|
538
|
-
|
|
290
|
+
ResolveIOServer.getMongoManager().collection(collection).findOne({ _id: f_document['_id'] }).then(currDoc => {
|
|
539
291
|
if (currDoc) {
|
|
540
292
|
if (currDoc.__v === f_document['__v']) {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
__v: currDoc.__v
|
|
545
|
-
};
|
|
546
|
-
var schemaErrors = null;
|
|
547
|
-
try {
|
|
548
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection)['simplschema'].validate(f_document);
|
|
549
|
-
}
|
|
550
|
-
catch (errors) {
|
|
551
|
-
schemaErrors = errors;
|
|
552
|
-
_this.callMethodInternal('insertErrorLog', 'Schema Failed on updateDocument - ' + collection, [schemaErrors, f_document]);
|
|
553
|
-
}
|
|
554
|
-
if (schemaErrors) {
|
|
555
|
-
console.log(schemaErrors);
|
|
556
|
-
reject('Schema Errors');
|
|
557
|
-
}
|
|
558
|
-
else {
|
|
559
|
-
var updates_3 = common_1.getMongoUpdates(currDoc, f_document, true);
|
|
560
|
-
if (index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) {
|
|
561
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').create(versionDoc).then(function (doc) {
|
|
562
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').deleteMany({
|
|
563
|
-
$and: [
|
|
564
|
-
{ '_id._id': currDoc._id },
|
|
565
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
566
|
-
]
|
|
567
|
-
}).then(function () {
|
|
568
|
-
if (updates_3) {
|
|
569
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).updateOne({ _id: f_document['_id'] }, updates_3).then(function (res) {
|
|
570
|
-
resolve(res);
|
|
571
|
-
}, function (err) { return reject(err); });
|
|
572
|
-
}
|
|
573
|
-
else {
|
|
574
|
-
resolve(1);
|
|
575
|
-
}
|
|
576
|
-
}, function (err) { return reject(err); });
|
|
577
|
-
}, function (err) {
|
|
578
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').deleteMany({
|
|
579
|
-
$and: [
|
|
580
|
-
{ '_id._id': currDoc._id },
|
|
581
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
582
|
-
]
|
|
583
|
-
}).then(function () {
|
|
584
|
-
if (updates_3) {
|
|
585
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).updateOne({ _id: f_document['_id'] }, updates_3).then(function (res) {
|
|
586
|
-
resolve(res);
|
|
587
|
-
}, function (err) { return reject(err); });
|
|
588
|
-
}
|
|
589
|
-
else {
|
|
590
|
-
resolve(1);
|
|
591
|
-
}
|
|
592
|
-
}, function (err) { return reject(err); });
|
|
593
|
-
});
|
|
594
|
-
}
|
|
595
|
-
else {
|
|
596
|
-
if (updates_3) {
|
|
597
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).updateOne({ _id: f_document['_id'] }, updates_3).then(function (res) {
|
|
598
|
-
resolve(res);
|
|
599
|
-
}, function (err) { return reject(err); });
|
|
600
|
-
}
|
|
601
|
-
else {
|
|
602
|
-
resolve(1);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
}
|
|
293
|
+
ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: f_document['_id'] }, f_document, {}, false, true).then(res => {
|
|
294
|
+
resolve(res);
|
|
295
|
+
}, err => reject(err));
|
|
606
296
|
}
|
|
607
297
|
else {
|
|
608
298
|
console.log('OFFLINE - invalid version - ' + collection, currDoc.__v, f_document['__v']);
|
|
609
|
-
|
|
299
|
+
let newCurrDocId = currDoc._id;
|
|
610
300
|
if (f_oldDocument) {
|
|
611
|
-
|
|
612
|
-
versionDoc_3._id = {
|
|
613
|
-
_id: currDoc._id,
|
|
614
|
-
__v: currDoc.__v
|
|
615
|
-
};
|
|
616
|
-
var updatedDoc = common_1.getMongoMergeUpdatedDoc(f_document, currDoc, f_oldDocument);
|
|
301
|
+
let updatedDoc = getMongoMergeUpdatedDoc(f_document, currDoc, f_oldDocument);
|
|
617
302
|
updatedDoc._id = newCurrDocId;
|
|
618
|
-
updatedDoc.
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
if (index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) {
|
|
622
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').create(versionDoc_3).then(function (doc) {
|
|
623
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').deleteMany({
|
|
624
|
-
$and: [
|
|
625
|
-
{ '_id._id': versionDoc_3._id._id },
|
|
626
|
-
{ '_id.__v': { $lte: versionDoc_3._id.__v - 4 } }
|
|
627
|
-
]
|
|
628
|
-
}).then(function () {
|
|
629
|
-
resolve(res);
|
|
630
|
-
}, function (err) { return reject(err); });
|
|
631
|
-
}, function (err) { return reject(err); });
|
|
632
|
-
}
|
|
633
|
-
else {
|
|
634
|
-
resolve(res);
|
|
635
|
-
}
|
|
636
|
-
}, function (err) { return reject(err); });
|
|
303
|
+
ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc, {}, false, true).then(res => {
|
|
304
|
+
resolve(res);
|
|
305
|
+
}, err => reject(err));
|
|
637
306
|
}
|
|
638
307
|
else {
|
|
639
308
|
reject('OFFLINE - Invalid Version And Could Not Find History - DB: ' + currDoc.__v + ', Trying to update with :' + f_document['__v']);
|
|
@@ -643,7 +312,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
643
312
|
else {
|
|
644
313
|
reject('No Document');
|
|
645
314
|
}
|
|
646
|
-
},
|
|
315
|
+
}, () => { });
|
|
647
316
|
}
|
|
648
317
|
});
|
|
649
318
|
}
|
|
@@ -653,7 +322,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
653
322
|
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
654
323
|
// Search for doc, check version, if found then try and update props
|
|
655
324
|
updateDocumentPropsOffline: {
|
|
656
|
-
check: new
|
|
325
|
+
check: new SimpleSchema({
|
|
657
326
|
collection: {
|
|
658
327
|
type: String
|
|
659
328
|
},
|
|
@@ -676,125 +345,41 @@ function loadCollectionMethods(methodManager) {
|
|
|
676
345
|
}
|
|
677
346
|
}),
|
|
678
347
|
function: function (collection, doc_id, updateParams, doc__v, f_oldDocument) {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
348
|
+
return new Promise((resolve, reject) => {
|
|
349
|
+
if (!ResolveIOServer.getMongoManager().collection(collection)) {
|
|
682
350
|
reject('Invalid collection');
|
|
683
351
|
}
|
|
684
352
|
else {
|
|
685
|
-
|
|
353
|
+
ResolveIOServer.getMongoManager().collection(collection).findOne({ _id: doc_id }).then(currDoc => {
|
|
686
354
|
if (currDoc) {
|
|
687
|
-
|
|
688
|
-
updateParams.forEach(
|
|
689
|
-
|
|
355
|
+
let modifiedDoc = deepCopy(currDoc);
|
|
356
|
+
updateParams.forEach(data => {
|
|
357
|
+
modifiedDoc[data.prop] = data.data;
|
|
690
358
|
});
|
|
691
|
-
if (
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
__v: currDoc.__v
|
|
696
|
-
};
|
|
697
|
-
var schemaErrors = null;
|
|
698
|
-
try {
|
|
699
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection)['simplschema'].validate(modifiedDoc_2);
|
|
700
|
-
}
|
|
701
|
-
catch (errors) {
|
|
702
|
-
schemaErrors = errors;
|
|
703
|
-
_this.callMethodInternal('insertErrorLog', 'Schema Failed on updateDocumentProps - ' + collection, [schemaErrors, modifiedDoc_2]);
|
|
704
|
-
}
|
|
705
|
-
if (schemaErrors) {
|
|
706
|
-
console.log(schemaErrors);
|
|
707
|
-
reject('Schema Errors');
|
|
708
|
-
}
|
|
709
|
-
else {
|
|
710
|
-
var updates_4 = common_1.getMongoUpdates(currDoc, modifiedDoc_2, true);
|
|
711
|
-
if (index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) {
|
|
712
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').create(versionDoc).then(function (doc) {
|
|
713
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').deleteMany({
|
|
714
|
-
$and: [
|
|
715
|
-
{ '_id._id': currDoc._id },
|
|
716
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
717
|
-
]
|
|
718
|
-
}).then(function () {
|
|
719
|
-
if (updates_4) {
|
|
720
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).updateOne({ _id: modifiedDoc_2._id }, updates_4).then(function (res) {
|
|
721
|
-
resolve(res);
|
|
722
|
-
}, function (err) { return reject(err); });
|
|
723
|
-
}
|
|
724
|
-
else {
|
|
725
|
-
resolve(1);
|
|
726
|
-
}
|
|
727
|
-
}, function (err) { return reject(err); });
|
|
728
|
-
}, function (err) {
|
|
729
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').deleteMany({
|
|
730
|
-
$and: [
|
|
731
|
-
{ '_id._id': currDoc._id },
|
|
732
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
733
|
-
]
|
|
734
|
-
}).then(function () {
|
|
735
|
-
if (updates_4) {
|
|
736
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).updateOne({ _id: modifiedDoc_2._id }, updates_4).then(function (res) {
|
|
737
|
-
resolve(res);
|
|
738
|
-
}, function (err) { return reject(err); });
|
|
739
|
-
}
|
|
740
|
-
else {
|
|
741
|
-
resolve(1);
|
|
742
|
-
}
|
|
743
|
-
}, function (err) { return reject(err); });
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
else {
|
|
747
|
-
if (updates_4) {
|
|
748
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).updateOne({ _id: modifiedDoc_2._id }, updates_4).then(function (res) {
|
|
749
|
-
resolve(res);
|
|
750
|
-
}, function (err) { return reject(err); });
|
|
751
|
-
}
|
|
752
|
-
else {
|
|
753
|
-
resolve(1);
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
}
|
|
359
|
+
if (modifiedDoc.__v === doc__v) {
|
|
360
|
+
ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: modifiedDoc._id }, modifiedDoc, {}, false, true).then(res => {
|
|
361
|
+
resolve(res);
|
|
362
|
+
}, err => reject(err));
|
|
757
363
|
}
|
|
758
364
|
else {
|
|
759
365
|
console.log('OFFLINE - invalid version - ' + collection, currDoc.__v, doc__v);
|
|
760
|
-
|
|
366
|
+
let newCurrDocId = currDoc._id;
|
|
761
367
|
if (f_oldDocument) {
|
|
762
|
-
|
|
763
|
-
versionDoc_4._id = {
|
|
764
|
-
_id: currDoc._id,
|
|
765
|
-
__v: currDoc.__v
|
|
766
|
-
};
|
|
767
|
-
var updatedDoc = common_1.getMongoMergeUpdatedDoc(modifiedDoc_2, currDoc, f_oldDocument);
|
|
368
|
+
let updatedDoc = getMongoMergeUpdatedDoc(modifiedDoc, currDoc, f_oldDocument);
|
|
768
369
|
updatedDoc._id = newCurrDocId;
|
|
769
|
-
updatedDoc.
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
if (index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) {
|
|
773
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').create(versionDoc_4).then(function (doc) {
|
|
774
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').deleteMany({
|
|
775
|
-
$and: [
|
|
776
|
-
{ '_id._id': versionDoc_4._id._id },
|
|
777
|
-
{ '_id.__v': { $lte: versionDoc_4._id.__v - 4 } }
|
|
778
|
-
]
|
|
779
|
-
}).then(function () {
|
|
780
|
-
resolve(res);
|
|
781
|
-
}, function (err) { return reject(err); });
|
|
782
|
-
}, function (err) { return reject(err); });
|
|
783
|
-
}
|
|
784
|
-
else {
|
|
785
|
-
resolve(res);
|
|
786
|
-
}
|
|
787
|
-
}, function (err) { return reject(err); });
|
|
370
|
+
ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).then(res => {
|
|
371
|
+
resolve(res);
|
|
372
|
+
}, err => reject(err));
|
|
788
373
|
}
|
|
789
374
|
else {
|
|
790
|
-
reject('OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + currDoc.__v + ', Trying to update with :' +
|
|
375
|
+
reject('OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + currDoc.__v + ', Trying to update with :' + modifiedDoc.__v);
|
|
791
376
|
}
|
|
792
377
|
}
|
|
793
378
|
}
|
|
794
379
|
else {
|
|
795
380
|
reject('No Document');
|
|
796
381
|
}
|
|
797
|
-
},
|
|
382
|
+
}, () => { });
|
|
798
383
|
}
|
|
799
384
|
});
|
|
800
385
|
}
|
|
@@ -804,7 +389,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
804
389
|
// @Outputs: res = 1 (deleted), res = 0 (not deleted), err = not deleted
|
|
805
390
|
// Search for doc, if found then try and remove
|
|
806
391
|
removeDocument: {
|
|
807
|
-
check: new
|
|
392
|
+
check: new SimpleSchema({
|
|
808
393
|
collection: {
|
|
809
394
|
type: String
|
|
810
395
|
},
|
|
@@ -813,14 +398,14 @@ function loadCollectionMethods(methodManager) {
|
|
|
813
398
|
}
|
|
814
399
|
}),
|
|
815
400
|
function: function (collection, doc_id) {
|
|
816
|
-
return new Promise(
|
|
817
|
-
if (!
|
|
401
|
+
return new Promise((resolve, reject) => {
|
|
402
|
+
if (!ResolveIOServer.getMongoManager().collection(collection)) {
|
|
818
403
|
reject('Invalid collection');
|
|
819
404
|
}
|
|
820
405
|
else {
|
|
821
|
-
|
|
406
|
+
ResolveIOServer.getMongoManager().collection(collection).deleteOne({ _id: doc_id }).then(res => {
|
|
822
407
|
resolve(res);
|
|
823
|
-
},
|
|
408
|
+
}, err => {
|
|
824
409
|
reject(err);
|
|
825
410
|
});
|
|
826
411
|
}
|
|
@@ -828,7 +413,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
828
413
|
}
|
|
829
414
|
},
|
|
830
415
|
removeDocumentWithQuery: {
|
|
831
|
-
check: new
|
|
416
|
+
check: new SimpleSchema({
|
|
832
417
|
collection: {
|
|
833
418
|
type: String
|
|
834
419
|
},
|
|
@@ -838,14 +423,14 @@ function loadCollectionMethods(methodManager) {
|
|
|
838
423
|
}
|
|
839
424
|
}),
|
|
840
425
|
function: function (collection, query) {
|
|
841
|
-
return new Promise(
|
|
842
|
-
if (!
|
|
426
|
+
return new Promise((resolve, reject) => {
|
|
427
|
+
if (!ResolveIOServer.getMongoManager().collection(collection)) {
|
|
843
428
|
reject('Invalid collection');
|
|
844
429
|
}
|
|
845
430
|
else {
|
|
846
|
-
|
|
431
|
+
ResolveIOServer.getMongoManager().collection(collection).deleteOne(query).then(res => {
|
|
847
432
|
resolve(res);
|
|
848
|
-
},
|
|
433
|
+
}, err => {
|
|
849
434
|
reject(err);
|
|
850
435
|
});
|
|
851
436
|
}
|
|
@@ -853,7 +438,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
853
438
|
}
|
|
854
439
|
},
|
|
855
440
|
removeDocumentsWithQuery: {
|
|
856
|
-
check: new
|
|
441
|
+
check: new SimpleSchema({
|
|
857
442
|
collection: {
|
|
858
443
|
type: String
|
|
859
444
|
},
|
|
@@ -863,14 +448,14 @@ function loadCollectionMethods(methodManager) {
|
|
|
863
448
|
}
|
|
864
449
|
}),
|
|
865
450
|
function: function (collection, query) {
|
|
866
|
-
return new Promise(
|
|
867
|
-
if (!
|
|
451
|
+
return new Promise((resolve, reject) => {
|
|
452
|
+
if (!ResolveIOServer.getMongoManager().collection(collection)) {
|
|
868
453
|
reject('Invalid collection');
|
|
869
454
|
}
|
|
870
455
|
else {
|
|
871
|
-
|
|
456
|
+
ResolveIOServer.getMongoManager().collection(collection).deleteMany(query).then(res => {
|
|
872
457
|
resolve(res);
|
|
873
|
-
},
|
|
458
|
+
}, err => {
|
|
874
459
|
reject(err);
|
|
875
460
|
});
|
|
876
461
|
}
|
|
@@ -879,6 +464,5 @@ function loadCollectionMethods(methodManager) {
|
|
|
879
464
|
}
|
|
880
465
|
});
|
|
881
466
|
}
|
|
882
|
-
exports.loadCollectionMethods = loadCollectionMethods;
|
|
883
467
|
|
|
884
468
|
//# sourceMappingURL=collections.js.map
|