@resolveio/server-lib 9.0.10 → 9.0.12
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/user.collection.js +2 -1
- package/collections/user.collection.js.map +1 -1
- package/managers/mongo.manager.d.ts +1 -1
- package/managers/mongo.manager.js +4 -4
- package/managers/mongo.manager.js.map +1 -1
- package/methods/accounts.js +2 -29
- package/methods/accounts.js.map +1 -1
- package/methods/collections.js +694 -626
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +16 -2
- package/methods/counters.js.map +1 -1
- package/methods/report-builder.js +132 -127
- package/methods/report-builder.js.map +1 -1
- package/models/user.model.d.ts +4 -4
- package/models/user.model.js.map +1 -1
- package/package.json +1 -1
package/methods/collections.js
CHANGED
|
@@ -22,7 +22,15 @@ function loadCollectionMethods(methodManager) {
|
|
|
22
22
|
}
|
|
23
23
|
}),
|
|
24
24
|
function: function (collection, query) {
|
|
25
|
-
|
|
25
|
+
if (query === void 0) { query = {}; }
|
|
26
|
+
return new Promise(function (resolve, reject) {
|
|
27
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)) {
|
|
28
|
+
reject('Invalid collection');
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).findOne(query).then(function (res) { return resolve(res); }, function (err) { return reject(err); });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
26
34
|
}
|
|
27
35
|
},
|
|
28
36
|
find: {
|
|
@@ -42,8 +50,16 @@ function loadCollectionMethods(methodManager) {
|
|
|
42
50
|
}
|
|
43
51
|
}),
|
|
44
52
|
function: function (collection, query, sortQuery) {
|
|
53
|
+
if (query === void 0) { query = {}; }
|
|
45
54
|
if (sortQuery === void 0) { sortQuery = {}; }
|
|
46
|
-
return
|
|
55
|
+
return new Promise(function (resolve, reject) {
|
|
56
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)) {
|
|
57
|
+
reject('Invalid collection');
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).find(query, { sort: sortQuery }).then(function (res) { return resolve(res); }, function (err) { return reject(err); });
|
|
61
|
+
}
|
|
62
|
+
});
|
|
47
63
|
}
|
|
48
64
|
},
|
|
49
65
|
findWithOptions: {
|
|
@@ -61,7 +77,14 @@ function loadCollectionMethods(methodManager) {
|
|
|
61
77
|
}
|
|
62
78
|
}),
|
|
63
79
|
function: function (collection, query, options) {
|
|
64
|
-
return
|
|
80
|
+
return new Promise(function (resolve, reject) {
|
|
81
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)) {
|
|
82
|
+
reject('Invalid collection');
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).find(query, { projection: options.fields, sort: options.sort, limit: options.limit, skip: options.skip }).then(function (res) { return resolve(res); }, function (err) { return reject(err); });
|
|
86
|
+
}
|
|
87
|
+
});
|
|
65
88
|
}
|
|
66
89
|
},
|
|
67
90
|
// Insert 1 document
|
|
@@ -80,51 +103,56 @@ function loadCollectionMethods(methodManager) {
|
|
|
80
103
|
function: function (collection, document) {
|
|
81
104
|
var _this = this;
|
|
82
105
|
return new Promise(function (resolve, reject) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)['simplschema'].validate(document);
|
|
86
|
-
}
|
|
87
|
-
catch (errors) {
|
|
88
|
-
schemaErrors = errors;
|
|
89
|
-
_this.callMethodInternal('insertErrorLog', 'Schema Failed on insert - ' + collection, [schemaErrors, document]);
|
|
90
|
-
}
|
|
91
|
-
if (schemaErrors) {
|
|
92
|
-
console.log(schemaErrors);
|
|
93
|
-
reject('Schema Errors');
|
|
106
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)) {
|
|
107
|
+
reject('Invalid collection');
|
|
94
108
|
}
|
|
95
109
|
else {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
route: ''
|
|
108
|
-
});
|
|
110
|
+
var schemaErrors = null;
|
|
111
|
+
try {
|
|
112
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)['simplschema'].validate(document);
|
|
113
|
+
}
|
|
114
|
+
catch (errors) {
|
|
115
|
+
schemaErrors = errors;
|
|
116
|
+
_this.callMethodInternal('insertErrorLog', 'Schema Failed on insert - ' + collection, [schemaErrors, document]);
|
|
117
|
+
}
|
|
118
|
+
if (schemaErrors) {
|
|
119
|
+
console.log(schemaErrors);
|
|
120
|
+
reject('Schema Errors');
|
|
109
121
|
}
|
|
110
122
|
else {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
if (common_1.getBinarySize(JSON.stringify(document)) < 200000) {
|
|
124
|
+
log_collection_1.Logs.create({
|
|
125
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
126
|
+
date: new Date(),
|
|
127
|
+
type: 'info',
|
|
128
|
+
title: 'Insert Document',
|
|
129
|
+
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
130
|
+
payload: JSON.stringify(document, null, 2),
|
|
131
|
+
method: 'insertDocument',
|
|
132
|
+
user: _this.user,
|
|
133
|
+
messageId: '',
|
|
134
|
+
route: ''
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
log_collection_1.Logs.create({
|
|
139
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
140
|
+
date: new Date(),
|
|
141
|
+
type: 'info',
|
|
142
|
+
title: 'Insert Document',
|
|
143
|
+
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
144
|
+
payload: 'Too Big',
|
|
145
|
+
method: 'insertDocument',
|
|
146
|
+
user: _this.user,
|
|
147
|
+
messageId: '',
|
|
148
|
+
route: ''
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
var id_1 = mongo_manager_1.objectIdHexString();
|
|
152
|
+
document['_id'] = id_1;
|
|
153
|
+
document['__v'] = 0;
|
|
154
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).insertOne(document).then(function () { return resolve(id_1); }, function (err) { return reject(err); });
|
|
123
155
|
}
|
|
124
|
-
var id_1 = mongo_manager_1.objectIdHexString();
|
|
125
|
-
document['_id'] = id_1;
|
|
126
|
-
document['__v'] = 0;
|
|
127
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).insertOne(document).then(function () { return resolve(id_1); }, function (err) { return reject(err); });
|
|
128
156
|
}
|
|
129
157
|
});
|
|
130
158
|
}
|
|
@@ -148,151 +176,36 @@ function loadCollectionMethods(methodManager) {
|
|
|
148
176
|
function: function (collection, documents) {
|
|
149
177
|
var _this = this;
|
|
150
178
|
return new Promise(function (res, rej) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
var document_1 = documents[i];
|
|
154
|
-
promises.push(new Promise(function (resolve, reject) {
|
|
155
|
-
var schemaErrors = null;
|
|
156
|
-
try {
|
|
157
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)['simplschema'].validate(document_1);
|
|
158
|
-
}
|
|
159
|
-
catch (errors) {
|
|
160
|
-
schemaErrors = errors;
|
|
161
|
-
_this.callMethodInternal('insertErrorLog', 'Schema Failed on insert - ' + collection, [schemaErrors, document_1]);
|
|
162
|
-
}
|
|
163
|
-
if (schemaErrors) {
|
|
164
|
-
console.log(schemaErrors);
|
|
165
|
-
reject('Schema Errors');
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
if (common_1.getBinarySize(JSON.stringify(document_1)) < 200000) {
|
|
169
|
-
log_collection_1.Logs.create({
|
|
170
|
-
_id: mongo_manager_1.objectIdHexString(),
|
|
171
|
-
date: new Date(),
|
|
172
|
-
type: 'info',
|
|
173
|
-
title: 'Insert Document',
|
|
174
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
175
|
-
payload: JSON.stringify(document_1, null, 2),
|
|
176
|
-
method: 'insertDocument',
|
|
177
|
-
user: _this.user,
|
|
178
|
-
messageId: '',
|
|
179
|
-
route: ''
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
log_collection_1.Logs.create({
|
|
184
|
-
_id: mongo_manager_1.objectIdHexString(),
|
|
185
|
-
date: new Date(),
|
|
186
|
-
type: 'info',
|
|
187
|
-
title: 'Insert Document',
|
|
188
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
189
|
-
payload: 'Too Big',
|
|
190
|
-
method: 'insertDocument',
|
|
191
|
-
user: _this.user,
|
|
192
|
-
messageId: '',
|
|
193
|
-
route: ''
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
var id_2 = mongo_manager_1.objectIdHexString();
|
|
197
|
-
document_1['_id'] = id_2;
|
|
198
|
-
document_1['__v'] = 0;
|
|
199
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).insertOne(document_1).then(function () { return resolve(id_2); }, function (err) { return reject(err); });
|
|
200
|
-
}
|
|
201
|
-
}));
|
|
202
|
-
};
|
|
203
|
-
for (var i = 0; i < documents.length; i++) {
|
|
204
|
-
_loop_1(i);
|
|
179
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)) {
|
|
180
|
+
rej('Invalid collection');
|
|
205
181
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
// @Inputs: collection, document id
|
|
212
|
-
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
213
|
-
// Search for doc, check version, if found then try and update
|
|
214
|
-
updateDocument: {
|
|
215
|
-
check: new simpl_schema_1.default({
|
|
216
|
-
collection: {
|
|
217
|
-
type: String
|
|
218
|
-
},
|
|
219
|
-
f_document: {
|
|
220
|
-
type: Object,
|
|
221
|
-
blackbox: true
|
|
222
|
-
}
|
|
223
|
-
}),
|
|
224
|
-
function: function (collection, f_document) {
|
|
225
|
-
var _this = this;
|
|
226
|
-
return new Promise(function (resolve, reject) {
|
|
227
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).findOne({ _id: f_document['_id'] }).then(function (currDoc) {
|
|
228
|
-
if (currDoc) {
|
|
229
|
-
if (currDoc.__v === f_document['__v']) {
|
|
230
|
-
var versionDoc = common_1.deepCopy(currDoc);
|
|
231
|
-
versionDoc._id = {
|
|
232
|
-
_id: currDoc._id,
|
|
233
|
-
__v: currDoc.__v
|
|
234
|
-
};
|
|
182
|
+
else {
|
|
183
|
+
var promises = [];
|
|
184
|
+
var _loop_1 = function (i) {
|
|
185
|
+
var document_1 = documents[i];
|
|
186
|
+
promises.push(new Promise(function (resolve, reject) {
|
|
235
187
|
var schemaErrors = null;
|
|
236
188
|
try {
|
|
237
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)['simplschema'].validate(
|
|
189
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)['simplschema'].validate(document_1);
|
|
238
190
|
}
|
|
239
191
|
catch (errors) {
|
|
240
192
|
schemaErrors = errors;
|
|
241
|
-
_this.callMethodInternal('insertErrorLog', 'Schema Failed on
|
|
193
|
+
_this.callMethodInternal('insertErrorLog', 'Schema Failed on insert - ' + collection, [schemaErrors, document_1]);
|
|
242
194
|
}
|
|
243
195
|
if (schemaErrors) {
|
|
244
196
|
console.log(schemaErrors);
|
|
245
197
|
reject('Schema Errors');
|
|
246
198
|
}
|
|
247
199
|
else {
|
|
248
|
-
|
|
249
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').create(versionDoc).then(function (doc) {
|
|
250
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
251
|
-
$and: [
|
|
252
|
-
{ '_id._id': currDoc._id },
|
|
253
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
254
|
-
]
|
|
255
|
-
}).then(function () {
|
|
256
|
-
if (updates_1) {
|
|
257
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: f_document['_id'] }, updates_1).then(function (res) {
|
|
258
|
-
resolve(res.result.nModified);
|
|
259
|
-
}, function (err) { return reject(err); });
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
resolve(1);
|
|
263
|
-
}
|
|
264
|
-
}, function (err) {
|
|
265
|
-
console.log(err);
|
|
266
|
-
});
|
|
267
|
-
}, function (err) {
|
|
268
|
-
console.log(err);
|
|
269
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
270
|
-
$and: [
|
|
271
|
-
{ '_id._id': currDoc._id },
|
|
272
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
273
|
-
]
|
|
274
|
-
}).then(function () {
|
|
275
|
-
if (updates_1) {
|
|
276
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: f_document['_id'] }, updates_1).then(function (res) {
|
|
277
|
-
resolve(res.result.nModified);
|
|
278
|
-
}, function (err) { return reject(err); });
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
resolve(1);
|
|
282
|
-
}
|
|
283
|
-
}, function (err) {
|
|
284
|
-
console.log(err);
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
if (common_1.getBinarySize(JSON.stringify(f_document)) < 200000) {
|
|
200
|
+
if (common_1.getBinarySize(JSON.stringify(document_1)) < 200000) {
|
|
288
201
|
log_collection_1.Logs.create({
|
|
289
202
|
_id: mongo_manager_1.objectIdHexString(),
|
|
290
203
|
date: new Date(),
|
|
291
204
|
type: 'info',
|
|
292
|
-
title: '
|
|
205
|
+
title: 'Insert Document',
|
|
293
206
|
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
294
|
-
payload: JSON.stringify(
|
|
295
|
-
method: '
|
|
207
|
+
payload: JSON.stringify(document_1, null, 2),
|
|
208
|
+
method: 'insertDocument',
|
|
296
209
|
user: _this.user,
|
|
297
210
|
messageId: '',
|
|
298
211
|
route: ''
|
|
@@ -303,65 +216,190 @@ function loadCollectionMethods(methodManager) {
|
|
|
303
216
|
_id: mongo_manager_1.objectIdHexString(),
|
|
304
217
|
date: new Date(),
|
|
305
218
|
type: 'info',
|
|
306
|
-
title: '
|
|
219
|
+
title: 'Insert Document',
|
|
307
220
|
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
308
221
|
payload: 'Too Big',
|
|
309
|
-
method: '
|
|
222
|
+
method: 'insertDocument',
|
|
310
223
|
user: _this.user,
|
|
311
224
|
messageId: '',
|
|
312
225
|
route: ''
|
|
313
226
|
});
|
|
314
227
|
}
|
|
228
|
+
var id_2 = mongo_manager_1.objectIdHexString();
|
|
229
|
+
document_1['_id'] = id_2;
|
|
230
|
+
document_1['__v'] = 0;
|
|
231
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).insertOne(document_1).then(function () { return resolve(id_2); }, function (err) { return reject(err); });
|
|
315
232
|
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
233
|
+
}));
|
|
234
|
+
};
|
|
235
|
+
for (var i = 0; i < documents.length; i++) {
|
|
236
|
+
_loop_1(i);
|
|
237
|
+
}
|
|
238
|
+
Promise.all(promises).then(function (vals) { return res(vals); }, function (err) { return rej(err); });
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
// Replaces 1 document with new document (from _id)
|
|
244
|
+
// @Inputs: collection, document id
|
|
245
|
+
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
246
|
+
// Search for doc, check version, if found then try and update
|
|
247
|
+
updateDocument: {
|
|
248
|
+
check: new simpl_schema_1.default({
|
|
249
|
+
collection: {
|
|
250
|
+
type: String
|
|
251
|
+
},
|
|
252
|
+
f_document: {
|
|
253
|
+
type: Object,
|
|
254
|
+
blackbox: true
|
|
255
|
+
}
|
|
256
|
+
}),
|
|
257
|
+
function: function (collection, f_document) {
|
|
258
|
+
var _this = this;
|
|
259
|
+
return new Promise(function (resolve, reject) {
|
|
260
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)) {
|
|
261
|
+
reject('Invalid collection');
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).findOne({ _id: f_document['_id'] }).then(function (currDoc) {
|
|
265
|
+
if (currDoc) {
|
|
266
|
+
if (currDoc.__v === f_document['__v']) {
|
|
267
|
+
var versionDoc = common_1.deepCopy(currDoc);
|
|
268
|
+
versionDoc._id = {
|
|
269
|
+
_id: currDoc._id,
|
|
270
|
+
__v: currDoc.__v
|
|
271
|
+
};
|
|
272
|
+
var schemaErrors = null;
|
|
273
|
+
try {
|
|
274
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)['simplschema'].validate(f_document);
|
|
275
|
+
}
|
|
276
|
+
catch (errors) {
|
|
277
|
+
schemaErrors = errors;
|
|
278
|
+
_this.callMethodInternal('insertErrorLog', 'Schema Failed on updateDocument - ' + collection, [schemaErrors, f_document]);
|
|
279
|
+
}
|
|
280
|
+
if (schemaErrors) {
|
|
281
|
+
console.log(schemaErrors);
|
|
282
|
+
reject('Schema Errors');
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
var updates_1 = common_1.getMongoUpdates(currDoc, f_document, true);
|
|
286
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').create(versionDoc).then(function (doc) {
|
|
287
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
288
|
+
$and: [
|
|
289
|
+
{ '_id._id': currDoc._id },
|
|
290
|
+
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
291
|
+
]
|
|
292
|
+
}).then(function () {
|
|
293
|
+
if (updates_1) {
|
|
294
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: f_document['_id'] }, updates_1).then(function (res) {
|
|
295
|
+
resolve(res.result.nModified);
|
|
296
|
+
}, function (err) { return reject(err); });
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
resolve(1);
|
|
300
|
+
}
|
|
348
301
|
}, function (err) {
|
|
349
302
|
console.log(err);
|
|
350
303
|
});
|
|
351
|
-
}, function (err) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
304
|
+
}, function (err) {
|
|
305
|
+
console.log(err);
|
|
306
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
307
|
+
$and: [
|
|
308
|
+
{ '_id._id': currDoc._id },
|
|
309
|
+
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
310
|
+
]
|
|
311
|
+
}).then(function () {
|
|
312
|
+
if (updates_1) {
|
|
313
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: f_document['_id'] }, updates_1).then(function (res) {
|
|
314
|
+
resolve(res.result.nModified);
|
|
315
|
+
}, function (err) { return reject(err); });
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
resolve(1);
|
|
319
|
+
}
|
|
320
|
+
}, function (err) {
|
|
321
|
+
console.log(err);
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
if (common_1.getBinarySize(JSON.stringify(f_document)) < 200000) {
|
|
325
|
+
log_collection_1.Logs.create({
|
|
326
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
327
|
+
date: new Date(),
|
|
328
|
+
type: 'info',
|
|
329
|
+
title: 'Update Document',
|
|
330
|
+
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
331
|
+
payload: JSON.stringify(f_document, null, 2),
|
|
332
|
+
method: 'updateDocument',
|
|
333
|
+
user: _this.user,
|
|
334
|
+
messageId: '',
|
|
335
|
+
route: ''
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
log_collection_1.Logs.create({
|
|
340
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
341
|
+
date: new Date(),
|
|
342
|
+
type: 'info',
|
|
343
|
+
title: 'Update Document',
|
|
344
|
+
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
345
|
+
payload: 'Too Big',
|
|
346
|
+
method: 'updateDocument',
|
|
347
|
+
user: _this.user,
|
|
348
|
+
messageId: '',
|
|
349
|
+
route: ''
|
|
350
|
+
});
|
|
351
|
+
}
|
|
355
352
|
}
|
|
356
|
-
}
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
console.log('invalid version - ' + collection, currDoc.__v, f_document['__v']);
|
|
356
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').findOne({
|
|
357
|
+
$and: [
|
|
358
|
+
{ '_id._id': currDoc._id },
|
|
359
|
+
{ '_id.__v': f_document['__v'] }
|
|
360
|
+
]
|
|
361
|
+
}).then(function (oldDoc) {
|
|
362
|
+
var newCurrDocId = currDoc._id;
|
|
363
|
+
if (oldDoc) {
|
|
364
|
+
var versionDoc_1 = common_1.deepCopy(currDoc);
|
|
365
|
+
versionDoc_1._id = {
|
|
366
|
+
_id: currDoc._id,
|
|
367
|
+
__v: currDoc.__v
|
|
368
|
+
};
|
|
369
|
+
var updatedDoc = common_1.getMongoMergeUpdatedDoc(f_document, currDoc, oldDoc);
|
|
370
|
+
updatedDoc._id = newCurrDocId;
|
|
371
|
+
updatedDoc.__v++;
|
|
372
|
+
updatedDoc.updatedAt = new Date();
|
|
373
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).then(function (res) {
|
|
374
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').create(versionDoc_1).then(function (doc) {
|
|
375
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
376
|
+
$and: [
|
|
377
|
+
{ '_id._id': versionDoc_1._id._id },
|
|
378
|
+
{ '_id.__v': { $lte: versionDoc_1._id.__v - 4 } }
|
|
379
|
+
]
|
|
380
|
+
}).then(function () {
|
|
381
|
+
resolve(res.result.nModified);
|
|
382
|
+
}, function (err) {
|
|
383
|
+
console.log(err);
|
|
384
|
+
});
|
|
385
|
+
}, function (err) {
|
|
386
|
+
console.log(err);
|
|
387
|
+
});
|
|
388
|
+
}, function (err) { return reject(err); });
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
reject('Invalid Version And Could Not Find History - DB: ' + currDoc.__v + ', Trying to update with :' + f_document['__v']);
|
|
392
|
+
}
|
|
393
|
+
}, function (errOldDoc) { });
|
|
394
|
+
}
|
|
357
395
|
}
|
|
358
|
-
|
|
359
|
-
|
|
396
|
+
else {
|
|
397
|
+
reject('No Document');
|
|
398
|
+
}
|
|
399
|
+
}, function (errDoc) {
|
|
360
400
|
reject('No Document');
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
reject('No Document');
|
|
364
|
-
});
|
|
401
|
+
});
|
|
402
|
+
}
|
|
365
403
|
});
|
|
366
404
|
}
|
|
367
405
|
},
|
|
@@ -391,146 +429,151 @@ function loadCollectionMethods(methodManager) {
|
|
|
391
429
|
function: function (collection, doc_id, updateParams, doc__v) {
|
|
392
430
|
var _this = this;
|
|
393
431
|
return new Promise(function (resolve, reject) {
|
|
394
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
422
|
-
$and: [
|
|
423
|
-
{ '_id._id': currDoc._id },
|
|
424
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
425
|
-
]
|
|
426
|
-
}).then(function () {
|
|
427
|
-
if (updates_2) {
|
|
428
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: modifiedDoc_1._id }, updates_2).then(function (res) {
|
|
429
|
-
resolve(res.result.ok);
|
|
430
|
-
}, function (err) { return reject(err); });
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
433
|
-
resolve(1);
|
|
434
|
-
}
|
|
435
|
-
}, function (err) {
|
|
436
|
-
console.log(err);
|
|
437
|
-
});
|
|
438
|
-
}, function (err) {
|
|
439
|
-
console.log(err);
|
|
440
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
441
|
-
$and: [
|
|
442
|
-
{ '_id._id': currDoc._id },
|
|
443
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
444
|
-
]
|
|
445
|
-
}).then(function () {
|
|
446
|
-
if (updates_2) {
|
|
447
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: modifiedDoc_1._id }, updates_2).then(function (res) {
|
|
448
|
-
resolve(res.result.n);
|
|
449
|
-
}, function (err) { return reject(err); });
|
|
450
|
-
}
|
|
451
|
-
else {
|
|
452
|
-
resolve(1);
|
|
453
|
-
}
|
|
454
|
-
}, function (err) {
|
|
455
|
-
console.log(err);
|
|
456
|
-
});
|
|
457
|
-
});
|
|
458
|
-
if (common_1.getBinarySize(JSON.stringify(updateParams)) < 200000) {
|
|
459
|
-
log_collection_1.Logs.create({
|
|
460
|
-
_id: mongo_manager_1.objectIdHexString(),
|
|
461
|
-
date: new Date(),
|
|
462
|
-
type: 'info',
|
|
463
|
-
title: 'Update Document Props',
|
|
464
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,
|
|
465
|
-
payload: JSON.stringify(updateParams, null, 2),
|
|
466
|
-
method: 'updateDocumentProps',
|
|
467
|
-
user: _this.user,
|
|
468
|
-
messageId: '',
|
|
469
|
-
route: ''
|
|
470
|
-
});
|
|
432
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)) {
|
|
433
|
+
reject('Invalid collection');
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).findOne({ _id: doc_id }).then(function (currDoc) {
|
|
437
|
+
if (currDoc) {
|
|
438
|
+
var modifiedDoc_1 = common_1.deepCopy(currDoc);
|
|
439
|
+
updateParams.forEach(function (data) {
|
|
440
|
+
modifiedDoc_1[data.prop] = data.data;
|
|
441
|
+
});
|
|
442
|
+
if (modifiedDoc_1.__v === doc__v) {
|
|
443
|
+
var versionDoc = common_1.deepCopy(currDoc);
|
|
444
|
+
versionDoc._id = {
|
|
445
|
+
_id: currDoc._id,
|
|
446
|
+
__v: currDoc.__v
|
|
447
|
+
};
|
|
448
|
+
var schemaErrors = null;
|
|
449
|
+
try {
|
|
450
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)['simplschema'].validate(modifiedDoc_1);
|
|
451
|
+
}
|
|
452
|
+
catch (errors) {
|
|
453
|
+
schemaErrors = errors;
|
|
454
|
+
_this.callMethodInternal('insertErrorLog', 'Schema Failed on updateDocumentProps - ' + collection, [schemaErrors, modifiedDoc_1]);
|
|
455
|
+
}
|
|
456
|
+
if (schemaErrors) {
|
|
457
|
+
console.log(schemaErrors);
|
|
458
|
+
reject('Schema Errors');
|
|
471
459
|
}
|
|
472
460
|
else {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
461
|
+
var updates_2 = common_1.getMongoUpdates(currDoc, modifiedDoc_1, true);
|
|
462
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').create(versionDoc).then(function (doc) {
|
|
463
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
464
|
+
$and: [
|
|
465
|
+
{ '_id._id': currDoc._id },
|
|
466
|
+
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
467
|
+
]
|
|
468
|
+
}).then(function () {
|
|
469
|
+
if (updates_2) {
|
|
470
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: modifiedDoc_1._id }, updates_2).then(function (res) {
|
|
471
|
+
resolve(res.result.ok);
|
|
472
|
+
}, function (err) { return reject(err); });
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
resolve(1);
|
|
476
|
+
}
|
|
477
|
+
}, function (err) {
|
|
478
|
+
console.log(err);
|
|
479
|
+
});
|
|
480
|
+
}, function (err) {
|
|
481
|
+
console.log(err);
|
|
482
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
483
|
+
$and: [
|
|
484
|
+
{ '_id._id': currDoc._id },
|
|
485
|
+
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
486
|
+
]
|
|
487
|
+
}).then(function () {
|
|
488
|
+
if (updates_2) {
|
|
489
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: modifiedDoc_1._id }, updates_2).then(function (res) {
|
|
490
|
+
resolve(res.result.n);
|
|
491
|
+
}, function (err) { return reject(err); });
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
resolve(1);
|
|
495
|
+
}
|
|
496
|
+
}, function (err) {
|
|
497
|
+
console.log(err);
|
|
498
|
+
});
|
|
484
499
|
});
|
|
500
|
+
if (common_1.getBinarySize(JSON.stringify(updateParams)) < 200000) {
|
|
501
|
+
log_collection_1.Logs.create({
|
|
502
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
503
|
+
date: new Date(),
|
|
504
|
+
type: 'info',
|
|
505
|
+
title: 'Update Document Props',
|
|
506
|
+
message: 'User: ' + _this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,
|
|
507
|
+
payload: JSON.stringify(updateParams, null, 2),
|
|
508
|
+
method: 'updateDocumentProps',
|
|
509
|
+
user: _this.user,
|
|
510
|
+
messageId: '',
|
|
511
|
+
route: ''
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
log_collection_1.Logs.create({
|
|
516
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
517
|
+
date: new Date(),
|
|
518
|
+
type: 'info',
|
|
519
|
+
title: 'Update Document Props',
|
|
520
|
+
message: 'User: ' + _this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,
|
|
521
|
+
payload: 'Too Big',
|
|
522
|
+
method: 'updateDocumentProps',
|
|
523
|
+
user: _this.user,
|
|
524
|
+
messageId: '',
|
|
525
|
+
route: ''
|
|
526
|
+
});
|
|
527
|
+
}
|
|
485
528
|
}
|
|
486
529
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
530
|
+
else {
|
|
531
|
+
console.log(new Date(), 'invalid version - ' + collection, currDoc.__v, doc__v);
|
|
532
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').findOne({
|
|
533
|
+
$and: [
|
|
534
|
+
{ '_id._id': currDoc._id },
|
|
535
|
+
{ '_id.__v': doc__v }
|
|
536
|
+
]
|
|
537
|
+
}).then(function (oldDoc) {
|
|
538
|
+
var newCurrDocId = currDoc._id;
|
|
539
|
+
if (oldDoc) {
|
|
540
|
+
var versionDoc_2 = common_1.deepCopy(currDoc);
|
|
541
|
+
versionDoc_2._id = {
|
|
542
|
+
_id: currDoc._id,
|
|
543
|
+
__v: currDoc.__v
|
|
544
|
+
};
|
|
545
|
+
var updatedDoc = common_1.getMongoMergeUpdatedDoc(modifiedDoc_1, currDoc, oldDoc);
|
|
546
|
+
updatedDoc._id = newCurrDocId;
|
|
547
|
+
updatedDoc.__v++;
|
|
548
|
+
updatedDoc.updatedAt = new Date();
|
|
549
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).then(function (res) {
|
|
550
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').create(versionDoc_2).then(function (doc) {
|
|
551
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
552
|
+
$and: [
|
|
553
|
+
{ '_id._id': versionDoc_2._id._id },
|
|
554
|
+
{ '_id.__v': { $lte: versionDoc_2._id.__v - 4 } }
|
|
555
|
+
]
|
|
556
|
+
}).then(function () {
|
|
557
|
+
resolve(res.result.nModified);
|
|
558
|
+
}, function (err) {
|
|
559
|
+
console.log(err);
|
|
560
|
+
});
|
|
516
561
|
}, function (err) {
|
|
517
562
|
console.log(err);
|
|
518
563
|
});
|
|
519
|
-
}, function (err) {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
}
|
|
527
|
-
}, function () { });
|
|
564
|
+
}, function (err) { return reject(err); });
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
reject('Invalid Version And Could Not Find History Props - DB: ' + currDoc.__v + ', Trying to update with :' + doc__v);
|
|
568
|
+
}
|
|
569
|
+
}, function () { });
|
|
570
|
+
}
|
|
528
571
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}
|
|
533
|
-
}
|
|
572
|
+
else {
|
|
573
|
+
reject('No Document');
|
|
574
|
+
}
|
|
575
|
+
}, function () { });
|
|
576
|
+
}
|
|
534
577
|
});
|
|
535
578
|
}
|
|
536
579
|
},
|
|
@@ -551,135 +594,140 @@ function loadCollectionMethods(methodManager) {
|
|
|
551
594
|
function: function (collection, f_document, f_oldDocument) {
|
|
552
595
|
var _this = this;
|
|
553
596
|
return new Promise(function (resolve, reject) {
|
|
554
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
try {
|
|
564
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)['simplschema'].validate(f_document);
|
|
565
|
-
}
|
|
566
|
-
catch (errors) {
|
|
567
|
-
schemaErrors = errors;
|
|
568
|
-
_this.callMethodInternal('insertErrorLog', 'Schema Failed on updateDocument - ' + collection, [schemaErrors, f_document]);
|
|
569
|
-
}
|
|
570
|
-
if (schemaErrors) {
|
|
571
|
-
console.log(schemaErrors);
|
|
572
|
-
reject('Schema Errors');
|
|
573
|
-
}
|
|
574
|
-
else {
|
|
575
|
-
var updates_3 = common_1.getMongoUpdates(currDoc, f_document, true);
|
|
576
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').create(versionDoc).then(function (doc) {
|
|
577
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
578
|
-
$and: [
|
|
579
|
-
{ '_id._id': currDoc._id },
|
|
580
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
581
|
-
]
|
|
582
|
-
}).then(function () {
|
|
583
|
-
if (updates_3) {
|
|
584
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: f_document['_id'] }, updates_3).then(function (res) {
|
|
585
|
-
resolve(res.result.nModified);
|
|
586
|
-
}, function (err) { return reject(err); });
|
|
587
|
-
}
|
|
588
|
-
else {
|
|
589
|
-
resolve(1);
|
|
590
|
-
}
|
|
591
|
-
}, function (err) {
|
|
592
|
-
console.log(err);
|
|
593
|
-
});
|
|
594
|
-
}, function (err) {
|
|
595
|
-
console.log(err);
|
|
596
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
597
|
-
$and: [
|
|
598
|
-
{ '_id._id': currDoc._id },
|
|
599
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
600
|
-
]
|
|
601
|
-
}).then(function () {
|
|
602
|
-
if (updates_3) {
|
|
603
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: f_document['_id'] }, updates_3).then(function (res) {
|
|
604
|
-
resolve(res.result.nModified);
|
|
605
|
-
}, function (err) { return reject(err); });
|
|
606
|
-
}
|
|
607
|
-
else {
|
|
608
|
-
resolve(1);
|
|
609
|
-
}
|
|
610
|
-
}, function (err) {
|
|
611
|
-
console.log(err);
|
|
612
|
-
});
|
|
613
|
-
});
|
|
614
|
-
if (common_1.getBinarySize(JSON.stringify(f_document)) < 200000) {
|
|
615
|
-
log_collection_1.Logs.create({
|
|
616
|
-
_id: mongo_manager_1.objectIdHexString(),
|
|
617
|
-
date: new Date(),
|
|
618
|
-
type: 'info',
|
|
619
|
-
title: 'Update Document',
|
|
620
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
621
|
-
payload: JSON.stringify(f_document, null, 2),
|
|
622
|
-
method: 'updateDocumentOffline',
|
|
623
|
-
user: _this.user,
|
|
624
|
-
messageId: '',
|
|
625
|
-
route: ''
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
else {
|
|
629
|
-
log_collection_1.Logs.create({
|
|
630
|
-
_id: mongo_manager_1.objectIdHexString(),
|
|
631
|
-
date: new Date(),
|
|
632
|
-
type: 'info',
|
|
633
|
-
title: 'Update Document',
|
|
634
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
635
|
-
payload: 'Too Big',
|
|
636
|
-
method: 'updateDocumentOffline',
|
|
637
|
-
user: _this.user,
|
|
638
|
-
messageId: '',
|
|
639
|
-
route: ''
|
|
640
|
-
});
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
else {
|
|
645
|
-
console.log('OFFLINE - invalid version - ' + collection, currDoc.__v, f_document['__v']);
|
|
646
|
-
var newCurrDocId = currDoc._id;
|
|
647
|
-
if (f_oldDocument) {
|
|
648
|
-
var versionDoc_3 = common_1.deepCopy(currDoc);
|
|
649
|
-
versionDoc_3._id = {
|
|
597
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)) {
|
|
598
|
+
reject('Invalid collection');
|
|
599
|
+
}
|
|
600
|
+
else {
|
|
601
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).findOne({ _id: f_document['_id'] }).then(function (currDoc) {
|
|
602
|
+
if (currDoc) {
|
|
603
|
+
if (currDoc.__v === f_document['__v']) {
|
|
604
|
+
var versionDoc = common_1.deepCopy(currDoc);
|
|
605
|
+
versionDoc._id = {
|
|
650
606
|
_id: currDoc._id,
|
|
651
607
|
__v: currDoc.__v
|
|
652
608
|
};
|
|
653
|
-
var
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
609
|
+
var schemaErrors = null;
|
|
610
|
+
try {
|
|
611
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)['simplschema'].validate(f_document);
|
|
612
|
+
}
|
|
613
|
+
catch (errors) {
|
|
614
|
+
schemaErrors = errors;
|
|
615
|
+
_this.callMethodInternal('insertErrorLog', 'Schema Failed on updateDocument - ' + collection, [schemaErrors, f_document]);
|
|
616
|
+
}
|
|
617
|
+
if (schemaErrors) {
|
|
618
|
+
console.log(schemaErrors);
|
|
619
|
+
reject('Schema Errors');
|
|
620
|
+
}
|
|
621
|
+
else {
|
|
622
|
+
var updates_3 = common_1.getMongoUpdates(currDoc, f_document, true);
|
|
623
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').create(versionDoc).then(function (doc) {
|
|
659
624
|
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
660
625
|
$and: [
|
|
661
|
-
{ '_id._id':
|
|
662
|
-
{ '_id.__v': { $lte:
|
|
626
|
+
{ '_id._id': currDoc._id },
|
|
627
|
+
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
663
628
|
]
|
|
664
629
|
}).then(function () {
|
|
665
|
-
|
|
630
|
+
if (updates_3) {
|
|
631
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: f_document['_id'] }, updates_3).then(function (res) {
|
|
632
|
+
resolve(res.result.nModified);
|
|
633
|
+
}, function (err) { return reject(err); });
|
|
634
|
+
}
|
|
635
|
+
else {
|
|
636
|
+
resolve(1);
|
|
637
|
+
}
|
|
666
638
|
}, function (err) {
|
|
667
639
|
console.log(err);
|
|
668
640
|
});
|
|
669
641
|
}, function (err) {
|
|
670
642
|
console.log(err);
|
|
643
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
644
|
+
$and: [
|
|
645
|
+
{ '_id._id': currDoc._id },
|
|
646
|
+
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
647
|
+
]
|
|
648
|
+
}).then(function () {
|
|
649
|
+
if (updates_3) {
|
|
650
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: f_document['_id'] }, updates_3).then(function (res) {
|
|
651
|
+
resolve(res.result.nModified);
|
|
652
|
+
}, function (err) { return reject(err); });
|
|
653
|
+
}
|
|
654
|
+
else {
|
|
655
|
+
resolve(1);
|
|
656
|
+
}
|
|
657
|
+
}, function (err) {
|
|
658
|
+
console.log(err);
|
|
659
|
+
});
|
|
671
660
|
});
|
|
672
|
-
|
|
661
|
+
if (common_1.getBinarySize(JSON.stringify(f_document)) < 200000) {
|
|
662
|
+
log_collection_1.Logs.create({
|
|
663
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
664
|
+
date: new Date(),
|
|
665
|
+
type: 'info',
|
|
666
|
+
title: 'Update Document',
|
|
667
|
+
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
668
|
+
payload: JSON.stringify(f_document, null, 2),
|
|
669
|
+
method: 'updateDocumentOffline',
|
|
670
|
+
user: _this.user,
|
|
671
|
+
messageId: '',
|
|
672
|
+
route: ''
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
else {
|
|
676
|
+
log_collection_1.Logs.create({
|
|
677
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
678
|
+
date: new Date(),
|
|
679
|
+
type: 'info',
|
|
680
|
+
title: 'Update Document',
|
|
681
|
+
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
682
|
+
payload: 'Too Big',
|
|
683
|
+
method: 'updateDocumentOffline',
|
|
684
|
+
user: _this.user,
|
|
685
|
+
messageId: '',
|
|
686
|
+
route: ''
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
}
|
|
673
690
|
}
|
|
674
691
|
else {
|
|
675
|
-
|
|
692
|
+
console.log('OFFLINE - invalid version - ' + collection, currDoc.__v, f_document['__v']);
|
|
693
|
+
var newCurrDocId = currDoc._id;
|
|
694
|
+
if (f_oldDocument) {
|
|
695
|
+
var versionDoc_3 = common_1.deepCopy(currDoc);
|
|
696
|
+
versionDoc_3._id = {
|
|
697
|
+
_id: currDoc._id,
|
|
698
|
+
__v: currDoc.__v
|
|
699
|
+
};
|
|
700
|
+
var updatedDoc = common_1.getMongoMergeUpdatedDoc(f_document, currDoc, f_oldDocument);
|
|
701
|
+
updatedDoc._id = newCurrDocId;
|
|
702
|
+
updatedDoc.__v++;
|
|
703
|
+
updatedDoc.updatedAt = new Date();
|
|
704
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).then(function (res) {
|
|
705
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').create(versionDoc_3).then(function (doc) {
|
|
706
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
707
|
+
$and: [
|
|
708
|
+
{ '_id._id': versionDoc_3._id._id },
|
|
709
|
+
{ '_id.__v': { $lte: versionDoc_3._id.__v - 4 } }
|
|
710
|
+
]
|
|
711
|
+
}).then(function () {
|
|
712
|
+
resolve(res.result.nModified);
|
|
713
|
+
}, function (err) {
|
|
714
|
+
console.log(err);
|
|
715
|
+
});
|
|
716
|
+
}, function (err) {
|
|
717
|
+
console.log(err);
|
|
718
|
+
});
|
|
719
|
+
}, function (err) { return reject(err); });
|
|
720
|
+
}
|
|
721
|
+
else {
|
|
722
|
+
reject('OFFLINE - Invalid Version And Could Not Find History - DB: ' + currDoc.__v + ', Trying to update with :' + f_document['__v']);
|
|
723
|
+
}
|
|
676
724
|
}
|
|
677
725
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
}
|
|
682
|
-
}
|
|
726
|
+
else {
|
|
727
|
+
reject('No Document');
|
|
728
|
+
}
|
|
729
|
+
}, function () { });
|
|
730
|
+
}
|
|
683
731
|
});
|
|
684
732
|
}
|
|
685
733
|
},
|
|
@@ -713,139 +761,144 @@ function loadCollectionMethods(methodManager) {
|
|
|
713
761
|
function: function (collection, doc_id, updateParams, doc__v, f_oldDocument) {
|
|
714
762
|
var _this = this;
|
|
715
763
|
return new Promise(function (resolve, reject) {
|
|
716
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
try {
|
|
730
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)['simplschema'].validate(modifiedDoc_2);
|
|
731
|
-
}
|
|
732
|
-
catch (errors) {
|
|
733
|
-
schemaErrors = errors;
|
|
734
|
-
_this.callMethodInternal('insertErrorLog', 'Schema Failed on updateDocumentProps - ' + collection, [schemaErrors, modifiedDoc_2]);
|
|
735
|
-
}
|
|
736
|
-
if (schemaErrors) {
|
|
737
|
-
console.log(schemaErrors);
|
|
738
|
-
reject('Schema Errors');
|
|
739
|
-
}
|
|
740
|
-
else {
|
|
741
|
-
var updates_4 = common_1.getMongoUpdates(currDoc, modifiedDoc_2, true);
|
|
742
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').create(versionDoc).then(function (doc) {
|
|
743
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
744
|
-
$and: [
|
|
745
|
-
{ '_id._id': currDoc._id },
|
|
746
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
747
|
-
]
|
|
748
|
-
}).then(function () {
|
|
749
|
-
if (updates_4) {
|
|
750
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: modifiedDoc_2._id }, updates_4).then(function (res) {
|
|
751
|
-
resolve(res.result.ok);
|
|
752
|
-
}, function (err) { return reject(err); });
|
|
753
|
-
}
|
|
754
|
-
else {
|
|
755
|
-
resolve(1);
|
|
756
|
-
}
|
|
757
|
-
}, function (err) {
|
|
758
|
-
console.log(err);
|
|
759
|
-
});
|
|
760
|
-
}, function (err) {
|
|
761
|
-
console.log(err);
|
|
762
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
763
|
-
$and: [
|
|
764
|
-
{ '_id._id': currDoc._id },
|
|
765
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
766
|
-
]
|
|
767
|
-
}).then(function () {
|
|
768
|
-
if (updates_4) {
|
|
769
|
-
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: modifiedDoc_2._id }, updates_4).then(function (res) {
|
|
770
|
-
resolve(res.result.ok);
|
|
771
|
-
}, function (err) { return reject(err); });
|
|
772
|
-
}
|
|
773
|
-
else {
|
|
774
|
-
resolve(1);
|
|
775
|
-
}
|
|
776
|
-
}, function (err) {
|
|
777
|
-
console.log(err);
|
|
778
|
-
});
|
|
779
|
-
});
|
|
780
|
-
if (common_1.getBinarySize(JSON.stringify(updateParams)) < 200000) {
|
|
781
|
-
log_collection_1.Logs.create({
|
|
782
|
-
_id: mongo_manager_1.objectIdHexString(),
|
|
783
|
-
date: new Date(),
|
|
784
|
-
type: 'info',
|
|
785
|
-
title: 'Update Document Props',
|
|
786
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,
|
|
787
|
-
payload: JSON.stringify(updateParams, null, 2),
|
|
788
|
-
method: 'updateDocumentPropsOffline',
|
|
789
|
-
user: _this.user,
|
|
790
|
-
messageId: '',
|
|
791
|
-
route: ''
|
|
792
|
-
});
|
|
793
|
-
}
|
|
794
|
-
else {
|
|
795
|
-
log_collection_1.Logs.create({
|
|
796
|
-
_id: mongo_manager_1.objectIdHexString(),
|
|
797
|
-
date: new Date(),
|
|
798
|
-
type: 'info',
|
|
799
|
-
title: 'Update Document Props',
|
|
800
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,
|
|
801
|
-
payload: 'Too Big',
|
|
802
|
-
method: 'updateDocumentPropsOffline',
|
|
803
|
-
user: _this.user,
|
|
804
|
-
messageId: '',
|
|
805
|
-
route: ''
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
else {
|
|
811
|
-
console.log('OFFLINE - invalid version - ' + collection, currDoc.__v, doc__v);
|
|
812
|
-
var newCurrDocId = currDoc._id;
|
|
813
|
-
if (f_oldDocument) {
|
|
814
|
-
var versionDoc_4 = common_1.deepCopy(currDoc);
|
|
815
|
-
versionDoc_4._id = {
|
|
764
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)) {
|
|
765
|
+
reject('Invalid collection');
|
|
766
|
+
}
|
|
767
|
+
else {
|
|
768
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).findOne({ _id: doc_id }).then(function (currDoc) {
|
|
769
|
+
if (currDoc) {
|
|
770
|
+
var modifiedDoc_2 = common_1.deepCopy(currDoc);
|
|
771
|
+
updateParams.forEach(function (data) {
|
|
772
|
+
modifiedDoc_2[data.prop] = data.data;
|
|
773
|
+
});
|
|
774
|
+
if (modifiedDoc_2.__v === doc__v) {
|
|
775
|
+
var versionDoc = common_1.deepCopy(currDoc);
|
|
776
|
+
versionDoc._id = {
|
|
816
777
|
_id: currDoc._id,
|
|
817
778
|
__v: currDoc.__v
|
|
818
779
|
};
|
|
819
|
-
var
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
780
|
+
var schemaErrors = null;
|
|
781
|
+
try {
|
|
782
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)['simplschema'].validate(modifiedDoc_2);
|
|
783
|
+
}
|
|
784
|
+
catch (errors) {
|
|
785
|
+
schemaErrors = errors;
|
|
786
|
+
_this.callMethodInternal('insertErrorLog', 'Schema Failed on updateDocumentProps - ' + collection, [schemaErrors, modifiedDoc_2]);
|
|
787
|
+
}
|
|
788
|
+
if (schemaErrors) {
|
|
789
|
+
console.log(schemaErrors);
|
|
790
|
+
reject('Schema Errors');
|
|
791
|
+
}
|
|
792
|
+
else {
|
|
793
|
+
var updates_4 = common_1.getMongoUpdates(currDoc, modifiedDoc_2, true);
|
|
794
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').create(versionDoc).then(function (doc) {
|
|
825
795
|
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
826
796
|
$and: [
|
|
827
|
-
{ '_id._id':
|
|
828
|
-
{ '_id.__v': { $lte:
|
|
797
|
+
{ '_id._id': currDoc._id },
|
|
798
|
+
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
829
799
|
]
|
|
830
800
|
}).then(function () {
|
|
831
|
-
|
|
801
|
+
if (updates_4) {
|
|
802
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: modifiedDoc_2._id }, updates_4).then(function (res) {
|
|
803
|
+
resolve(res.result.ok);
|
|
804
|
+
}, function (err) { return reject(err); });
|
|
805
|
+
}
|
|
806
|
+
else {
|
|
807
|
+
resolve(1);
|
|
808
|
+
}
|
|
832
809
|
}, function (err) {
|
|
833
810
|
console.log(err);
|
|
834
811
|
});
|
|
835
812
|
}, function (err) {
|
|
836
813
|
console.log(err);
|
|
814
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
815
|
+
$and: [
|
|
816
|
+
{ '_id._id': currDoc._id },
|
|
817
|
+
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
818
|
+
]
|
|
819
|
+
}).then(function () {
|
|
820
|
+
if (updates_4) {
|
|
821
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).updateOne({ _id: modifiedDoc_2._id }, updates_4).then(function (res) {
|
|
822
|
+
resolve(res.result.ok);
|
|
823
|
+
}, function (err) { return reject(err); });
|
|
824
|
+
}
|
|
825
|
+
else {
|
|
826
|
+
resolve(1);
|
|
827
|
+
}
|
|
828
|
+
}, function (err) {
|
|
829
|
+
console.log(err);
|
|
830
|
+
});
|
|
837
831
|
});
|
|
838
|
-
|
|
832
|
+
if (common_1.getBinarySize(JSON.stringify(updateParams)) < 200000) {
|
|
833
|
+
log_collection_1.Logs.create({
|
|
834
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
835
|
+
date: new Date(),
|
|
836
|
+
type: 'info',
|
|
837
|
+
title: 'Update Document Props',
|
|
838
|
+
message: 'User: ' + _this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,
|
|
839
|
+
payload: JSON.stringify(updateParams, null, 2),
|
|
840
|
+
method: 'updateDocumentPropsOffline',
|
|
841
|
+
user: _this.user,
|
|
842
|
+
messageId: '',
|
|
843
|
+
route: ''
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
else {
|
|
847
|
+
log_collection_1.Logs.create({
|
|
848
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
849
|
+
date: new Date(),
|
|
850
|
+
type: 'info',
|
|
851
|
+
title: 'Update Document Props',
|
|
852
|
+
message: 'User: ' + _this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,
|
|
853
|
+
payload: 'Too Big',
|
|
854
|
+
method: 'updateDocumentPropsOffline',
|
|
855
|
+
user: _this.user,
|
|
856
|
+
messageId: '',
|
|
857
|
+
route: ''
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
}
|
|
839
861
|
}
|
|
840
862
|
else {
|
|
841
|
-
|
|
863
|
+
console.log('OFFLINE - invalid version - ' + collection, currDoc.__v, doc__v);
|
|
864
|
+
var newCurrDocId = currDoc._id;
|
|
865
|
+
if (f_oldDocument) {
|
|
866
|
+
var versionDoc_4 = common_1.deepCopy(currDoc);
|
|
867
|
+
versionDoc_4._id = {
|
|
868
|
+
_id: currDoc._id,
|
|
869
|
+
__v: currDoc.__v
|
|
870
|
+
};
|
|
871
|
+
var updatedDoc = common_1.getMongoMergeUpdatedDoc(modifiedDoc_2, currDoc, f_oldDocument);
|
|
872
|
+
updatedDoc._id = newCurrDocId;
|
|
873
|
+
updatedDoc.__v++;
|
|
874
|
+
updatedDoc.updatedAt = new Date();
|
|
875
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).then(function (res) {
|
|
876
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').create(versionDoc_4).then(function (doc) {
|
|
877
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection + '.versions').deleteMany({
|
|
878
|
+
$and: [
|
|
879
|
+
{ '_id._id': versionDoc_4._id._id },
|
|
880
|
+
{ '_id.__v': { $lte: versionDoc_4._id.__v - 4 } }
|
|
881
|
+
]
|
|
882
|
+
}).then(function () {
|
|
883
|
+
resolve(res.result.nModified);
|
|
884
|
+
}, function (err) {
|
|
885
|
+
console.log(err);
|
|
886
|
+
});
|
|
887
|
+
}, function (err) {
|
|
888
|
+
console.log(err);
|
|
889
|
+
});
|
|
890
|
+
}, function (err) { return reject(err); });
|
|
891
|
+
}
|
|
892
|
+
else {
|
|
893
|
+
reject('OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + currDoc.__v + ', Trying to update with :' + modifiedDoc_2.__v);
|
|
894
|
+
}
|
|
842
895
|
}
|
|
843
896
|
}
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
}
|
|
848
|
-
}
|
|
897
|
+
else {
|
|
898
|
+
reject('No Document');
|
|
899
|
+
}
|
|
900
|
+
}, function () { });
|
|
901
|
+
}
|
|
849
902
|
});
|
|
850
903
|
}
|
|
851
904
|
},
|
|
@@ -865,23 +918,28 @@ function loadCollectionMethods(methodManager) {
|
|
|
865
918
|
function: function (collection, doc_id) {
|
|
866
919
|
var _this = this;
|
|
867
920
|
return new Promise(function (resolve, reject) {
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
921
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)) {
|
|
922
|
+
reject('Invalid collection');
|
|
923
|
+
}
|
|
924
|
+
else {
|
|
925
|
+
log_collection_1.Logs.create({
|
|
926
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
927
|
+
date: new Date(),
|
|
928
|
+
type: 'info',
|
|
929
|
+
title: 'Remove Document',
|
|
930
|
+
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
931
|
+
payload: JSON.stringify({ _id: doc_id }, null, 2),
|
|
932
|
+
method: 'removeDocument',
|
|
933
|
+
user: _this.user,
|
|
934
|
+
messageId: '',
|
|
935
|
+
route: ''
|
|
936
|
+
});
|
|
937
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).deleteOne({ _id: doc_id }).then(function (res) {
|
|
938
|
+
resolve(res.result.ok);
|
|
939
|
+
}, function (err) {
|
|
940
|
+
reject(err);
|
|
941
|
+
});
|
|
942
|
+
}
|
|
885
943
|
});
|
|
886
944
|
}
|
|
887
945
|
},
|
|
@@ -898,23 +956,28 @@ function loadCollectionMethods(methodManager) {
|
|
|
898
956
|
function: function (collection, query) {
|
|
899
957
|
var _this = this;
|
|
900
958
|
return new Promise(function (resolve, reject) {
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
959
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)) {
|
|
960
|
+
reject('Invalid collection');
|
|
961
|
+
}
|
|
962
|
+
else {
|
|
963
|
+
log_collection_1.Logs.create({
|
|
964
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
965
|
+
date: new Date(),
|
|
966
|
+
type: 'info',
|
|
967
|
+
title: 'Remove Document (Query)',
|
|
968
|
+
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
969
|
+
payload: JSON.stringify({ _id: query }, null, 2),
|
|
970
|
+
method: 'removeDocumentWithQuery',
|
|
971
|
+
user: _this.user,
|
|
972
|
+
messageId: '',
|
|
973
|
+
route: ''
|
|
974
|
+
});
|
|
975
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).deleteOne(query).then(function (res) {
|
|
976
|
+
resolve(res.result.ok);
|
|
977
|
+
}, function (err) {
|
|
978
|
+
reject(err);
|
|
979
|
+
});
|
|
980
|
+
}
|
|
918
981
|
});
|
|
919
982
|
}
|
|
920
983
|
},
|
|
@@ -931,23 +994,28 @@ function loadCollectionMethods(methodManager) {
|
|
|
931
994
|
function: function (collection, query) {
|
|
932
995
|
var _this = this;
|
|
933
996
|
return new Promise(function (resolve, reject) {
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
997
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection)) {
|
|
998
|
+
reject('Invalid collection');
|
|
999
|
+
}
|
|
1000
|
+
else {
|
|
1001
|
+
log_collection_1.Logs.create({
|
|
1002
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
1003
|
+
date: new Date(),
|
|
1004
|
+
type: 'info',
|
|
1005
|
+
title: 'Remove Documents (Query)',
|
|
1006
|
+
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
1007
|
+
payload: JSON.stringify({ _id: query }, null, 2),
|
|
1008
|
+
method: 'removeDocumentsWithQuery',
|
|
1009
|
+
user: _this.user,
|
|
1010
|
+
messageId: '',
|
|
1011
|
+
route: ''
|
|
1012
|
+
});
|
|
1013
|
+
index_1.ResolveIOServer.getMainServer().getMongoServer().collection(collection).deleteMany(query).then(function (res) {
|
|
1014
|
+
resolve(res.result.ok);
|
|
1015
|
+
}, function (err) {
|
|
1016
|
+
reject(err);
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
951
1019
|
});
|
|
952
1020
|
}
|
|
953
1021
|
}
|