@resolveio/server-lib 6.4.23 → 7.0.1
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/counter.collection.d.ts +0 -2
- package/collections/counter.collection.js +0 -14
- package/collections/counter.collection.js.map +1 -1
- package/collections/file.collection.d.ts +0 -2
- package/collections/file.collection.js +0 -14
- package/collections/file.collection.js.map +1 -1
- package/collections/user.collection.d.ts +0 -1
- package/collections/user.collection.js +0 -4
- package/collections/user.collection.js.map +1 -1
- package/fixtures/cron-jobs.js +0 -17
- package/fixtures/cron-jobs.js.map +1 -1
- package/http/auth.js +176 -20
- package/http/auth.js.map +1 -1
- package/http/home.js +37 -0
- package/http/home.js.map +1 -1
- package/index.d.ts +1 -4
- package/index.js +22 -71
- package/index.js.map +1 -1
- package/managers/method.manager.d.ts +0 -1
- package/managers/method.manager.js +2 -28
- package/managers/method.manager.js.map +1 -1
- package/managers/subscription.manager.d.ts +0 -3
- package/managers/subscription.manager.js +19 -142
- package/managers/subscription.manager.js.map +1 -1
- package/methods/cron-jobs.js +0 -68
- package/methods/cron-jobs.js.map +1 -1
- package/methods/support.d.ts +2 -0
- package/methods/support.js +439 -0
- package/methods/support.js.map +1 -0
- package/package.json +1 -1
- package/publications/files.js +0 -31
- package/publications/files.js.map +1 -1
- package/server-app.d.ts +0 -4
- package/server-app.js +11 -71
- package/server-app.js.map +1 -1
- package/client-server-app.d.ts +0 -1
- package/client-server-app.js +0 -48
- package/client-server-app.js.map +0 -1
- package/collections/billing-logged-in-users.collection.d.ts +0 -7
- package/collections/billing-logged-in-users.collection.js +0 -75
- package/collections/billing-logged-in-users.collection.js.map +0 -1
- package/collections/support-ticket.collection.d.ts +0 -7
- package/collections/support-ticket.collection.js +0 -226
- package/collections/support-ticket.collection.js.map +0 -1
- package/managers/support.manager.d.ts +0 -22
- package/managers/support.manager.js +0 -329
- package/managers/support.manager.js.map +0 -1
- package/models/support-method.model.d.ts +0 -9
- package/models/support-method.model.js +0 -4
- package/models/support-method.model.js.map +0 -1
- package/publications/billing-logged-in-users.d.ts +0 -1
- package/publications/billing-logged-in-users.js +0 -65
- package/publications/billing-logged-in-users.js.map +0 -1
- package/publications/support-tickets.d.ts +0 -1
- package/publications/support-tickets.js +0 -203
- package/publications/support-tickets.js.map +0 -1
- package/support-methods/aws.d.ts +0 -2
- package/support-methods/aws.js +0 -279
- package/support-methods/aws.js.map +0 -1
- package/support-methods/collections.d.ts +0 -2
- package/support-methods/collections.js +0 -475
- package/support-methods/collections.js.map +0 -1
- package/support-methods/counters.d.ts +0 -2
- package/support-methods/counters.js +0 -192
- package/support-methods/counters.js.map +0 -1
- package/support-methods/support.d.ts +0 -2
- package/support-methods/support.js +0 -282
- package/support-methods/support.js.map +0 -1
|
@@ -1,475 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var mongoose_1 = require("mongoose");
|
|
4
|
-
var common_1 = require("../util/common");
|
|
5
|
-
var simpl_schema_1 = require("simpl-schema");
|
|
6
|
-
var log_collection_1 = require("../collections/log.collection");
|
|
7
|
-
var pagination_model_1 = require("../models/pagination.model");
|
|
8
|
-
var __1 = require("..");
|
|
9
|
-
function loadSupportCollectionMethods(supportManager) {
|
|
10
|
-
supportManager.supportMethods({
|
|
11
|
-
findOne: {
|
|
12
|
-
check: new simpl_schema_1.default({
|
|
13
|
-
collection: {
|
|
14
|
-
type: String
|
|
15
|
-
},
|
|
16
|
-
query: {
|
|
17
|
-
type: Object,
|
|
18
|
-
blackbox: true
|
|
19
|
-
}
|
|
20
|
-
}),
|
|
21
|
-
function: function (collection, query) {
|
|
22
|
-
return __1.ResolveIOServer.getSupportDB().model(collection).findOne(query).exec();
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
find: {
|
|
26
|
-
check: new simpl_schema_1.default({
|
|
27
|
-
collection: {
|
|
28
|
-
type: String
|
|
29
|
-
},
|
|
30
|
-
query: {
|
|
31
|
-
type: Object,
|
|
32
|
-
blackbox: true
|
|
33
|
-
},
|
|
34
|
-
sort: {
|
|
35
|
-
type: Object,
|
|
36
|
-
blackbox: true,
|
|
37
|
-
optional: true
|
|
38
|
-
}
|
|
39
|
-
}),
|
|
40
|
-
function: function (collection, query, sortQuery) {
|
|
41
|
-
if (sortQuery === void 0) { sortQuery = {}; }
|
|
42
|
-
return __1.ResolveIOServer.getSupportDB().model(collection).find(query).sort(sortQuery).exec();
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
findWithOptions: {
|
|
46
|
-
check: new simpl_schema_1.default({
|
|
47
|
-
collection: {
|
|
48
|
-
type: String
|
|
49
|
-
},
|
|
50
|
-
query: {
|
|
51
|
-
type: Object,
|
|
52
|
-
blackbox: true
|
|
53
|
-
},
|
|
54
|
-
options: {
|
|
55
|
-
type: pagination_model_1.PaginationOptionsSchema
|
|
56
|
-
}
|
|
57
|
-
}),
|
|
58
|
-
function: function (collection, query, options) {
|
|
59
|
-
return __1.ResolveIOServer.getSupportDB().model(collection).find(query).sort(options.sort).limit(options.limit).skip(options.skip).select(options.fields).exec();
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
// Insert 1 document
|
|
63
|
-
// @Inputs: collection, document
|
|
64
|
-
// @Outputs: res = _id of new document, err = not inserted
|
|
65
|
-
insertDocument: {
|
|
66
|
-
check: new simpl_schema_1.default({
|
|
67
|
-
collection: {
|
|
68
|
-
type: String
|
|
69
|
-
},
|
|
70
|
-
document: {
|
|
71
|
-
type: Object,
|
|
72
|
-
blackbox: true
|
|
73
|
-
}
|
|
74
|
-
}),
|
|
75
|
-
function: function (collection, document) {
|
|
76
|
-
var _this = this;
|
|
77
|
-
return new Promise(function (resolve, reject) {
|
|
78
|
-
var schemaErrors = null;
|
|
79
|
-
try {
|
|
80
|
-
__1.ResolveIOServer.getSupportDB().model(collection)['simplschema'].validate(document);
|
|
81
|
-
}
|
|
82
|
-
catch (errors) {
|
|
83
|
-
schemaErrors = errors;
|
|
84
|
-
supportManager.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insert - ' + collection, [schemaErrors, document]);
|
|
85
|
-
}
|
|
86
|
-
if (schemaErrors) {
|
|
87
|
-
console.log(schemaErrors);
|
|
88
|
-
reject('Schema Errors');
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
if (common_1.getBinarySize(JSON.stringify(document)) < 200000) {
|
|
92
|
-
log_collection_1.Logs.create({
|
|
93
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
94
|
-
date: new Date(),
|
|
95
|
-
type: 'info',
|
|
96
|
-
title: 'Insert Document',
|
|
97
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
98
|
-
payload: JSON.stringify(document, null, 2),
|
|
99
|
-
method: 'insertDocument',
|
|
100
|
-
user: _this.user,
|
|
101
|
-
messageId: ''
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
log_collection_1.Logs.create({
|
|
106
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
107
|
-
date: new Date(),
|
|
108
|
-
type: 'info',
|
|
109
|
-
title: 'Insert Document',
|
|
110
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
111
|
-
payload: 'Too Big',
|
|
112
|
-
method: 'insertDocument',
|
|
113
|
-
user: _this.user,
|
|
114
|
-
messageId: ''
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
var id_1 = mongoose_1.Types.ObjectId().toHexString();
|
|
118
|
-
document._id = id_1;
|
|
119
|
-
document.__v = 0;
|
|
120
|
-
__1.ResolveIOServer.getSupportDB().model(collection).create(document).then(function () { return resolve(id_1); }, function (err) { return reject(err); });
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
// Replaces 1 document with new document (from _id)
|
|
126
|
-
// @Inputs: collection, document id
|
|
127
|
-
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
128
|
-
// Search for doc, check version, if found then try and update
|
|
129
|
-
updateDocument: {
|
|
130
|
-
check: new simpl_schema_1.default({
|
|
131
|
-
collection: {
|
|
132
|
-
type: String
|
|
133
|
-
},
|
|
134
|
-
f_document: {
|
|
135
|
-
type: Object,
|
|
136
|
-
blackbox: true
|
|
137
|
-
}
|
|
138
|
-
}),
|
|
139
|
-
function: function (collection, f_document) {
|
|
140
|
-
var _this = this;
|
|
141
|
-
return new Promise(function (resolve, reject) {
|
|
142
|
-
__1.ResolveIOServer.getSupportDB().model(collection).findOne({ _id: f_document._id }).lean().exec(function (errDoc, currDoc) {
|
|
143
|
-
if (currDoc) {
|
|
144
|
-
if (currDoc.__v === f_document.__v) {
|
|
145
|
-
var versionDoc = common_1.deepCopy(currDoc);
|
|
146
|
-
versionDoc._id = {
|
|
147
|
-
_id: currDoc._id,
|
|
148
|
-
__v: currDoc.__v
|
|
149
|
-
};
|
|
150
|
-
var schemaErrors = null;
|
|
151
|
-
try {
|
|
152
|
-
__1.ResolveIOServer.getSupportDB().model(collection)['simplschema'].validate(f_document);
|
|
153
|
-
}
|
|
154
|
-
catch (errors) {
|
|
155
|
-
schemaErrors = errors;
|
|
156
|
-
supportManager.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on updateDocument - ' + collection, [schemaErrors, f_document]);
|
|
157
|
-
}
|
|
158
|
-
if (schemaErrors) {
|
|
159
|
-
console.log(schemaErrors);
|
|
160
|
-
reject('Schema Errors');
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
__1.ResolveIOServer.getSupportDB().model(__1.ResolveIOServer.getSupportDB().model(collection)['versionCollection']).create(versionDoc).then(function (doc) {
|
|
164
|
-
__1.ResolveIOServer.getSupportDB().model(__1.ResolveIOServer.getSupportDB().model(collection)['versionCollection']).deleteMany({
|
|
165
|
-
$and: [
|
|
166
|
-
{ '_id._id': currDoc._id },
|
|
167
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
168
|
-
]
|
|
169
|
-
}).exec();
|
|
170
|
-
}, function (err) {
|
|
171
|
-
console.log(err);
|
|
172
|
-
});
|
|
173
|
-
var updates = common_1.getMongoUpdates(currDoc, f_document, true);
|
|
174
|
-
if (updates) {
|
|
175
|
-
__1.ResolveIOServer.getSupportDB().model(collection).updateOne({ _id: f_document._id }, updates, { strict: false }).exec().then(function (res) {
|
|
176
|
-
resolve(res.nModified);
|
|
177
|
-
}, function (err) { return reject(err); });
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
resolve(1);
|
|
181
|
-
}
|
|
182
|
-
if (common_1.getBinarySize(JSON.stringify(f_document)) < 200000) {
|
|
183
|
-
log_collection_1.Logs.create({
|
|
184
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
185
|
-
date: new Date(),
|
|
186
|
-
type: 'info',
|
|
187
|
-
title: 'Update Document',
|
|
188
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
189
|
-
payload: JSON.stringify(f_document, null, 2),
|
|
190
|
-
method: 'updateDocument',
|
|
191
|
-
user: _this.user,
|
|
192
|
-
messageId: ''
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
log_collection_1.Logs.create({
|
|
197
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
198
|
-
date: new Date(),
|
|
199
|
-
type: 'info',
|
|
200
|
-
title: 'Update Document',
|
|
201
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
202
|
-
payload: 'Too Big',
|
|
203
|
-
method: 'updateDocument',
|
|
204
|
-
user: _this.user,
|
|
205
|
-
messageId: ''
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
console.log('invalid version - ' + collection, currDoc.__v, f_document.__v);
|
|
212
|
-
__1.ResolveIOServer.getSupportDB().model(__1.ResolveIOServer.getSupportDB().model(collection)['versionCollection']).findOne({
|
|
213
|
-
$and: [
|
|
214
|
-
{ '_id._id': currDoc._id },
|
|
215
|
-
{ '_id.__v': f_document.__v }
|
|
216
|
-
]
|
|
217
|
-
}).lean().exec(function (errOldDoc, oldDoc) {
|
|
218
|
-
var newCurrDocId = currDoc._id;
|
|
219
|
-
if (oldDoc) {
|
|
220
|
-
var versionDoc_1 = common_1.deepCopy(currDoc);
|
|
221
|
-
versionDoc_1._id = {
|
|
222
|
-
_id: currDoc._id,
|
|
223
|
-
__v: currDoc.__v
|
|
224
|
-
};
|
|
225
|
-
var updatedDoc = common_1.getMongoMergeUpdatedDoc(f_document, currDoc, oldDoc);
|
|
226
|
-
updatedDoc._id = newCurrDocId;
|
|
227
|
-
updatedDoc.__v++;
|
|
228
|
-
__1.ResolveIOServer.getSupportDB().model(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).exec().then(function (res) {
|
|
229
|
-
__1.ResolveIOServer.getSupportDB().model(__1.ResolveIOServer.getSupportDB().model(collection)['versionCollection']).create(versionDoc_1).then(function (doc) {
|
|
230
|
-
__1.ResolveIOServer.getSupportDB().model(__1.ResolveIOServer.getSupportDB().model(collection)['versionCollection']).deleteMany({
|
|
231
|
-
$and: [
|
|
232
|
-
{ '_id._id': versionDoc_1._id._id },
|
|
233
|
-
{ '_id.__v': { $lte: versionDoc_1._id.__v - 4 } }
|
|
234
|
-
]
|
|
235
|
-
}).exec();
|
|
236
|
-
resolve(res.nModified);
|
|
237
|
-
}, function (err) {
|
|
238
|
-
console.log(err);
|
|
239
|
-
});
|
|
240
|
-
}, function (err) { return reject(err); });
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
reject('Invalid Version And Could Not Find History - DB: ' + currDoc.__v + ', Trying to update with :' + f_document.__v);
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
reject('No Document');
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
},
|
|
255
|
-
// Updates 1 document's props (from _id)
|
|
256
|
-
// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})
|
|
257
|
-
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
258
|
-
// Search for doc, check version, if found then try and update props
|
|
259
|
-
updateDocumentProps: {
|
|
260
|
-
check: new simpl_schema_1.default({
|
|
261
|
-
collection: {
|
|
262
|
-
type: String
|
|
263
|
-
},
|
|
264
|
-
doc_id: {
|
|
265
|
-
type: String
|
|
266
|
-
},
|
|
267
|
-
updateParams: {
|
|
268
|
-
type: Array
|
|
269
|
-
},
|
|
270
|
-
'updateParams.$': {
|
|
271
|
-
type: Object,
|
|
272
|
-
blackbox: true
|
|
273
|
-
},
|
|
274
|
-
doc__v: {
|
|
275
|
-
type: Number
|
|
276
|
-
}
|
|
277
|
-
}),
|
|
278
|
-
function: function (collection, doc_id, updateParams, doc__v) {
|
|
279
|
-
var _this = this;
|
|
280
|
-
return new Promise(function (resolve, reject) {
|
|
281
|
-
__1.ResolveIOServer.getSupportDB().model(collection).findOne({ _id: doc_id }).lean().exec(function (errDoc, currDoc) {
|
|
282
|
-
if (currDoc) {
|
|
283
|
-
var modifiedDoc_1 = common_1.deepCopy(currDoc);
|
|
284
|
-
updateParams.forEach(function (data) {
|
|
285
|
-
modifiedDoc_1[data.prop] = data.data;
|
|
286
|
-
});
|
|
287
|
-
if (modifiedDoc_1.__v === doc__v) {
|
|
288
|
-
var versionDoc = common_1.deepCopy(currDoc);
|
|
289
|
-
versionDoc._id = {
|
|
290
|
-
_id: currDoc._id,
|
|
291
|
-
__v: currDoc.__v
|
|
292
|
-
};
|
|
293
|
-
var schemaErrors = null;
|
|
294
|
-
try {
|
|
295
|
-
__1.ResolveIOServer.getSupportDB().model(collection)['simplschema'].validate(modifiedDoc_1);
|
|
296
|
-
}
|
|
297
|
-
catch (errors) {
|
|
298
|
-
schemaErrors = errors;
|
|
299
|
-
supportManager.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on updateDocumentProps - ' + collection, [schemaErrors, modifiedDoc_1]);
|
|
300
|
-
}
|
|
301
|
-
if (schemaErrors) {
|
|
302
|
-
console.log(schemaErrors);
|
|
303
|
-
reject('Schema Errors');
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
__1.ResolveIOServer.getSupportDB().model(__1.ResolveIOServer.getSupportDB().model(collection)['versionCollection']).create(versionDoc).then(function (doc) {
|
|
307
|
-
__1.ResolveIOServer.getSupportDB().model(__1.ResolveIOServer.getSupportDB().model(collection)['versionCollection']).deleteMany({
|
|
308
|
-
$and: [
|
|
309
|
-
{ '_id._id': currDoc._id },
|
|
310
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
311
|
-
]
|
|
312
|
-
}).exec();
|
|
313
|
-
}, function (err) {
|
|
314
|
-
console.log(err);
|
|
315
|
-
});
|
|
316
|
-
var updates = common_1.getMongoUpdates(currDoc, modifiedDoc_1, true);
|
|
317
|
-
if (updates) {
|
|
318
|
-
__1.ResolveIOServer.getSupportDB().model(collection).updateOne({ _id: modifiedDoc_1._id }, updates, { strict: false }).exec().then(function (res) {
|
|
319
|
-
resolve(res.ok);
|
|
320
|
-
}, function (err) { return reject(err); });
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
resolve(1);
|
|
324
|
-
}
|
|
325
|
-
if (common_1.getBinarySize(JSON.stringify(updateParams)) < 200000) {
|
|
326
|
-
log_collection_1.Logs.create({
|
|
327
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
328
|
-
date: new Date(),
|
|
329
|
-
type: 'info',
|
|
330
|
-
title: 'Update Document Props',
|
|
331
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,
|
|
332
|
-
payload: JSON.stringify(updateParams, null, 2),
|
|
333
|
-
method: 'updateDocumentProps',
|
|
334
|
-
user: _this.user,
|
|
335
|
-
messageId: ''
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
log_collection_1.Logs.create({
|
|
340
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
341
|
-
date: new Date(),
|
|
342
|
-
type: 'info',
|
|
343
|
-
title: 'Update Document Props',
|
|
344
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,
|
|
345
|
-
payload: 'Too Big',
|
|
346
|
-
method: 'updateDocumentProps',
|
|
347
|
-
user: _this.user,
|
|
348
|
-
messageId: ''
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
console.log('invalid version - ' + collection, currDoc.__v, doc__v);
|
|
355
|
-
__1.ResolveIOServer.getSupportDB().model(__1.ResolveIOServer.getSupportDB().model(collection)['versionCollection']).findOne({
|
|
356
|
-
$and: [
|
|
357
|
-
{ '_id._id': currDoc._id },
|
|
358
|
-
{ '_id.__v': doc__v }
|
|
359
|
-
]
|
|
360
|
-
}).lean().exec(function (errOldDoc, oldDoc) {
|
|
361
|
-
var newCurrDocId = currDoc._id;
|
|
362
|
-
if (oldDoc) {
|
|
363
|
-
var versionDoc_2 = common_1.deepCopy(currDoc);
|
|
364
|
-
versionDoc_2._id = {
|
|
365
|
-
_id: currDoc._id,
|
|
366
|
-
__v: currDoc.__v
|
|
367
|
-
};
|
|
368
|
-
var updatedDoc = common_1.getMongoMergeUpdatedDoc(modifiedDoc_1, currDoc, oldDoc);
|
|
369
|
-
updatedDoc._id = newCurrDocId;
|
|
370
|
-
updatedDoc.__v++;
|
|
371
|
-
__1.ResolveIOServer.getSupportDB().model(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).exec().then(function (res) {
|
|
372
|
-
__1.ResolveIOServer.getSupportDB().model(__1.ResolveIOServer.getSupportDB().model(collection)['versionCollection']).create(versionDoc_2).then(function (doc) {
|
|
373
|
-
__1.ResolveIOServer.getSupportDB().model(__1.ResolveIOServer.getSupportDB().model(collection)['versionCollection']).deleteMany({
|
|
374
|
-
$and: [
|
|
375
|
-
{ '_id._id': versionDoc_2._id._id },
|
|
376
|
-
{ '_id.__v': { $lte: versionDoc_2._id.__v - 4 } }
|
|
377
|
-
]
|
|
378
|
-
}).exec();
|
|
379
|
-
}, function (err) {
|
|
380
|
-
console.log(err);
|
|
381
|
-
});
|
|
382
|
-
resolve(res.nModified);
|
|
383
|
-
}, function (err) { return reject(err); });
|
|
384
|
-
}
|
|
385
|
-
else {
|
|
386
|
-
reject('Invalid Version And Could Not Find History Props - DB: ' + currDoc.__v + ', Trying to update with :' + modifiedDoc_1.__v);
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
else {
|
|
392
|
-
reject('No Document');
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
},
|
|
398
|
-
// Removes 1 document (from _id)
|
|
399
|
-
// @Inputs: collection, document id
|
|
400
|
-
// @Outputs: res = 1 (deleted), res = 0 (not deleted), err = not deleted
|
|
401
|
-
// Search for doc, if found then try and remove
|
|
402
|
-
removeDocument: {
|
|
403
|
-
check: new simpl_schema_1.default({
|
|
404
|
-
collection: {
|
|
405
|
-
type: String
|
|
406
|
-
},
|
|
407
|
-
doc_id: {
|
|
408
|
-
type: String
|
|
409
|
-
}
|
|
410
|
-
}),
|
|
411
|
-
function: function (collection, doc_id) {
|
|
412
|
-
var _this = this;
|
|
413
|
-
return new Promise(function (resolve, reject) {
|
|
414
|
-
log_collection_1.Logs.create({
|
|
415
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
416
|
-
date: new Date(),
|
|
417
|
-
type: 'info',
|
|
418
|
-
title: 'Remove Document',
|
|
419
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
420
|
-
payload: JSON.stringify({ _id: doc_id }, null, 2),
|
|
421
|
-
method: 'removeDocument',
|
|
422
|
-
user: _this.user,
|
|
423
|
-
messageId: ''
|
|
424
|
-
});
|
|
425
|
-
__1.ResolveIOServer.getSupportDB().model(collection).deleteOne({ _id: doc_id }).exec(function (err, res) {
|
|
426
|
-
if (err) {
|
|
427
|
-
reject(err);
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
430
|
-
resolve(res.ok);
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
},
|
|
436
|
-
removeDocumentWithQuery: {
|
|
437
|
-
check: new simpl_schema_1.default({
|
|
438
|
-
collection: {
|
|
439
|
-
type: String
|
|
440
|
-
},
|
|
441
|
-
query: {
|
|
442
|
-
type: Object,
|
|
443
|
-
blackbox: true
|
|
444
|
-
}
|
|
445
|
-
}),
|
|
446
|
-
function: function (collection, query) {
|
|
447
|
-
var _this = this;
|
|
448
|
-
return new Promise(function (resolve, reject) {
|
|
449
|
-
log_collection_1.Logs.create({
|
|
450
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
451
|
-
date: new Date(),
|
|
452
|
-
type: 'info',
|
|
453
|
-
title: 'Remove Document (Query)',
|
|
454
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
455
|
-
payload: JSON.stringify({ _id: query }, null, 2),
|
|
456
|
-
method: 'removeDocumentWithQuery',
|
|
457
|
-
user: _this.user,
|
|
458
|
-
messageId: ''
|
|
459
|
-
});
|
|
460
|
-
__1.ResolveIOServer.getSupportDB().model(collection).deleteOne(query).exec(function (err, res) {
|
|
461
|
-
if (err) {
|
|
462
|
-
reject(err);
|
|
463
|
-
}
|
|
464
|
-
else {
|
|
465
|
-
resolve(res.ok);
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
exports.loadSupportCollectionMethods = loadSupportCollectionMethods;
|
|
474
|
-
|
|
475
|
-
//# sourceMappingURL=collections.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/support-methods/collections.ts"],"names":[],"mappings":";;AAAA,qCAA0C;AAC1C,yCAAmG;AACnG,6CAAwC;AACxC,gEAAqD;AACrD,+DAAwF;AAExF,wBAAqC;AAErC,SAAgB,4BAA4B,CAAC,cAA8B;IAC1E,cAAc,CAAC,cAAc,CAAC;QAC7B,OAAO,EAAE;YACR,KAAK,EAAE,IAAI,sBAAY,CAAC;gBACvB,UAAU,EAAE;oBACX,IAAI,EAAE,MAAM;iBACZ;gBACD,KAAK,EAAE;oBACN,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,IAAI;iBACd;aACD,CAAC;YACF,QAAQ,EAAE,UAAS,UAAkB,EAAE,KAAa;gBACnD,OAAO,mBAAe,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;YAC/E,CAAC;SACD;QACD,IAAI,EAAE;YACL,KAAK,EAAE,IAAI,sBAAY,CAAC;gBACvB,UAAU,EAAE;oBACX,IAAI,EAAE,MAAM;iBACZ;gBACD,KAAK,EAAE;oBACN,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,IAAI;iBACd;gBACD,IAAI,EAAE;oBACL,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,IAAI;oBACd,QAAQ,EAAE,IAAI;iBACd;aACD,CAAC;YACF,QAAQ,EAAE,UAAS,UAAkB,EAAE,KAAa,EAAE,SAAsB;gBAAtB,0BAAA,EAAA,cAAsB;gBAC3E,OAAO,mBAAe,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC;YAC5F,CAAC;SACD;QACD,eA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OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;oBAElC,qBAAI,CAAC,MAAM,CAAC;wBACX,GAAG,EAAE,gBAAK,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE;wBACnC,IAAI,EAAE,IAAI,IAAI,EAAE;wBAChB,IAAI,EAAE,MAAM;wBACZ,KAAK,EAAE,yBAAyB;wBAChC,OAAO,EAAE,QAAQ,GAAG,KAAI,CAAC,IAAI,GAAG,qBAAqB,GAAG,UAAU;wBAClE,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,KAAK,EAAC,EAAE,IAAI,EAAE,CAAC,CAAC;wBAC9C,MAAM,EAAE,yBAAyB;wBACjC,IAAI,EAAE,KAAI,CAAC,IAAI;wBACf,SAAS,EAAE,EAAE;qBACb,CAAC,CAAC;oBAEH,mBAAe,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,UAAC,GAAG,EAAE,GAAG;wBAC/E,IAAI,GAAG,EAAE;4BACR,MAAM,CAAC,GAAG,CAAC,CAAC;yBACZ;6BACI;4BACJ,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;yBAChB;oBACF,CAAC,CAAC,CAAC;gBACJ,CAAC,CAAC,CAAC;YACJ,CAAC;SACD;KACD,CAAC,CAAC;AACJ,CAAC;AA9eD,oEA8eC","file":"collections.js","sourcesContent":["import { Document, Types} from 'mongoose';\nimport { getMongoUpdates, deepCopy, getMongoMergeUpdatedDoc, getBinarySize } from '../util/common';\nimport SimpleSchema from 'simpl-schema';\nimport { Logs } from '../collections/log.collection';\nimport { PaginationOptionsSchema, PaginationOptions } from '../models/pagination.model';\nimport { SupportManager } from '../managers/support.manager';\nimport { ResolveIOServer } from '..';\n\nexport function loadSupportCollectionMethods(supportManager: SupportManager) {\n\tsupportManager.supportMethods({\n\t\tfindOne: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query: Object) {\n\t\t\t\treturn ResolveIOServer.getSupportDB().model(collection).findOne(query).exec();\n\t\t\t}\n\t\t},\n\t\tfind: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tsort: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query: Object, sortQuery: Object = {}) {\n\t\t\t\treturn ResolveIOServer.getSupportDB().model(collection).find(query).sort(sortQuery).exec();\n\t\t\t}\n\t\t},\n\t\tfindWithOptions: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\toptions: {\n\t\t\t\t\ttype: PaginationOptionsSchema\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query: Object, options: PaginationOptions) {\n\t\t\t\treturn ResolveIOServer.getSupportDB().model(collection).find(query).sort(options.sort).limit(options.limit).skip(options.skip).select(options.fields).exec();\n\t\t\t}\n\t\t},\n\t\t// Insert 1 document\n\t\t// @Inputs: collection, document\n\t\t// @Outputs: res = _id of new document, err = not inserted\n\t\tinsertDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdocument: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, document: Document) {\n\t\t\t\treturn new Promise((resolve, reject) => {\n\n\t\t\t\t\tlet schemaErrors = null;\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tResolveIOServer.getSupportDB().model(collection)['simplschema'].validate(document);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (errors) {\n\t\t\t\t\t\tschemaErrors = errors;\n\t\t\t\t\t\tsupportManager.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insert - ' + collection, [schemaErrors, document]);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (schemaErrors) {\n\t\t\t\t\t\tconsole.log(schemaErrors);\n\t\t\t\t\t\treject('Schema Errors');\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tif (getBinarySize(JSON.stringify(document)) < 200000) {\n\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\t\ttype: 'info',\n\t\t\t\t\t\t\t\ttitle: 'Insert Document',\n\t\t\t\t\t\t\t\tmessage: 'User: ' + this.user + ', Collection Type: ' + collection,\n\t\t\t\t\t\t\t\tpayload: JSON.stringify(document, null, 2),\n\t\t\t\t\t\t\t\tmethod: 'insertDocument',\n\t\t\t\t\t\t\t\tuser: this.user,\n\t\t\t\t\t\t\t\tmessageId: ''\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\t\ttype: 'info',\n\t\t\t\t\t\t\t\ttitle: 'Insert Document',\n\t\t\t\t\t\t\t\tmessage: 'User: ' + this.user + ', Collection Type: ' + collection,\n\t\t\t\t\t\t\t\tpayload: 'Too Big',\n\t\t\t\t\t\t\t\tmethod: 'insertDocument',\n\t\t\t\t\t\t\t\tuser: this.user,\n\t\t\t\t\t\t\t\tmessageId: ''\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet id = Types.ObjectId().toHexString();\n\t\t\t\t\t\tdocument._id = id;\n\t\t\t\t\t\tdocument.__v = 0;\n\t\t\t\t\t\tResolveIOServer.getSupportDB().model(collection).create(document).then(() => resolve(id), err => reject(err));\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\t// Replaces 1 document with new document (from _id)\n\t\t// @Inputs: collection, document id\n\t\t// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version\n\t\t// Search for doc, check version, if found then try and update\n\t\tupdateDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tf_document: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, f_document: Document) {\n\t\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\t\tResolveIOServer.getSupportDB().model(collection).findOne({_id: f_document._id}).lean().exec((errDoc, currDoc) => {\n\t\t\t\t\t\tif (currDoc) {\n\t\t\t\t\t\t\tif (currDoc.__v === f_document.__v) {\n\t\t\t\t\t\t\t\tlet versionDoc = deepCopy(currDoc);\n\n\t\t\t\t\t\t\t\tversionDoc._id = {\n\t\t\t\t\t\t\t\t\t_id: currDoc._id,\n\t\t\t\t\t\t\t\t\t__v: currDoc.__v\n\t\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\t\tlet schemaErrors = null;\n\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(collection)['simplschema'].validate(f_document);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcatch (errors) {\n\t\t\t\t\t\t\t\t\tschemaErrors = errors;\n\t\t\t\t\t\t\t\t\tsupportManager.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on updateDocument - ' + collection, [schemaErrors, f_document]);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tif (schemaErrors) {\n\t\t\t\t\t\t\t\t\tconsole.log(schemaErrors);\n\t\t\t\t\t\t\t\t\treject('Schema Errors');\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(ResolveIOServer.getSupportDB().model(collection)['versionCollection']).create(versionDoc).then(doc => {\n\t\t\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(ResolveIOServer.getSupportDB().model(collection)['versionCollection']).deleteMany({\n\t\t\t\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t\t\t\t{'_id._id': currDoc._id},\n\t\t\t\t\t\t\t\t\t\t\t\t{'_id.__v': {$lte: currDoc.__v - 4}}\n\t\t\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t\t}).exec();\n\t\t\t\t\t\t\t\t\t}, err => {\n\t\t\t\t\t\t\t\t\t\tconsole.log(err);\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\tlet updates = getMongoUpdates(currDoc, f_document, true);\n\n\t\t\t\t\t\t\t\t\tif (updates) {\n\t\t\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(collection).updateOne({_id: f_document._id}, updates, {strict: false}).exec().then(res => {\n\t\t\t\t\t\t\t\t\t\t\tresolve(res.nModified);\n\t\t\t\t\t\t\t\t\t\t}, err => reject(err));\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\tresolve(1);\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\tif (getBinarySize(JSON.stringify(f_document)) < 200000) {\n\t\t\t\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\t\t\t\t\ttype: 'info',\n\t\t\t\t\t\t\t\t\t\t\ttitle: 'Update Document',\n\t\t\t\t\t\t\t\t\t\t\tmessage: 'User: ' + this.user + ', Collection Type: ' + collection,\n\t\t\t\t\t\t\t\t\t\t\tpayload: JSON.stringify(f_document, null, 2),\n\t\t\t\t\t\t\t\t\t\t\tmethod: 'updateDocument',\n\t\t\t\t\t\t\t\t\t\t\tuser: this.user,\n\t\t\t\t\t\t\t\t\t\t\tmessageId: ''\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\t\t\t\t\ttype: 'info',\n\t\t\t\t\t\t\t\t\t\t\ttitle: 'Update Document',\n\t\t\t\t\t\t\t\t\t\t\tmessage: 'User: ' + this.user + ', Collection Type: ' + collection,\n\t\t\t\t\t\t\t\t\t\t\tpayload: 'Too Big',\n\t\t\t\t\t\t\t\t\t\t\tmethod: 'updateDocument',\n\t\t\t\t\t\t\t\t\t\t\tuser: this.user,\n\t\t\t\t\t\t\t\t\t\t\tmessageId: ''\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tconsole.log('invalid version - ' + collection, currDoc.__v, f_document.__v);\n\n\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(ResolveIOServer.getSupportDB().model(collection)['versionCollection']).findOne({\n\t\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t\t{'_id._id': currDoc._id},\n\t\t\t\t\t\t\t\t\t\t{'_id.__v': f_document.__v}\n\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t}).lean().exec((errOldDoc, oldDoc) => {\n\t\t\t\t\t\t\t\t\tlet newCurrDocId = currDoc._id;\n\n\t\t\t\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\t\t\t\tlet versionDoc = deepCopy(currDoc);\n\n\t\t\t\t\t\t\t\t\t\tversionDoc._id = {\n\t\t\t\t\t\t\t\t\t\t\t_id: currDoc._id,\n\t\t\t\t\t\t\t\t\t\t\t__v: currDoc.__v\n\t\t\t\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\t\t\t\tlet updatedDoc = getMongoMergeUpdatedDoc(f_document, currDoc, oldDoc);\n\t\t\t\t\t\t\t\t\t\tupdatedDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\t\tupdatedDoc.__v++;\n\t\n\n\t\t\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(collection).replaceOne({_id: newCurrDocId}, updatedDoc).exec().then(res => {\n\t\t\t\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(ResolveIOServer.getSupportDB().model(collection)['versionCollection']).create(versionDoc).then(doc => {\n\t\t\t\t\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(ResolveIOServer.getSupportDB().model(collection)['versionCollection']).deleteMany({\n\t\t\t\t\t\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{'_id._id': versionDoc._id._id},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{'_id.__v': {$lte: versionDoc._id.__v - 4}}\n\t\t\t\t\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t\t\t\t}).exec();\n\n\t\t\t\t\t\t\t\t\t\t\t\tresolve(res.nModified);\n\t\t\t\t\t\t\t\t\t\t\t}, err => {\n\t\t\t\t\t\t\t\t\t\t\t\tconsole.log(err);\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t}, err => reject(err));\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\treject('Invalid Version And Could Not Find History - DB: ' + currDoc.__v + ', Trying to update with :' + f_document.__v);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treject('No Document');\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\t// Updates 1 document's props (from _id)\n\t\t// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})\n\t\t// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version\n\t\t// Search for doc, check version, if found then try and update props\n\t\tupdateDocumentProps: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdoc_id: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tupdateParams: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'updateParams.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tdoc__v: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, doc_id: string, updateParams: any[], doc__v: number) {\n\t\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\t\tResolveIOServer.getSupportDB().model(collection).findOne({_id: doc_id}).lean().exec((errDoc, currDoc: Document) => {\n\t\t\t\t\t\tif (currDoc) {\n\t\t\t\t\t\t\tlet modifiedDoc = deepCopy(currDoc);\n\n\t\t\t\t\t\t\tupdateParams.forEach(data => {\n\t\t\t\t\t\t\t\tmodifiedDoc[data.prop] = data.data;\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (modifiedDoc.__v === doc__v) {\n\t\t\t\t\t\t\t\tlet versionDoc = deepCopy(currDoc);\n\t\n\t\t\t\t\t\t\t\tversionDoc._id = {\n\t\t\t\t\t\t\t\t\t_id: currDoc._id,\n\t\t\t\t\t\t\t\t\t__v: currDoc.__v\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\n\t\t\t\t\t\t\t\tlet schemaErrors = null;\n\t\t\t\t\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(collection)['simplschema'].validate(modifiedDoc);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcatch (errors) {\n\t\t\t\t\t\t\t\t\tschemaErrors = errors;\n\t\t\t\t\t\t\t\t\tsupportManager.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on updateDocumentProps - ' + collection, [schemaErrors, modifiedDoc]);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tif (schemaErrors) {\n\t\t\t\t\t\t\t\t\tconsole.log(schemaErrors);\n\t\t\t\t\t\t\t\t\treject('Schema Errors');\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(ResolveIOServer.getSupportDB().model(collection)['versionCollection']).create(versionDoc).then(doc => {\n\t\t\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(ResolveIOServer.getSupportDB().model(collection)['versionCollection']).deleteMany({\n\t\t\t\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t\t\t\t{'_id._id': currDoc._id},\n\t\t\t\t\t\t\t\t\t\t\t\t{'_id.__v': {$lte: currDoc.__v - 4}}\n\t\t\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t\t}).exec();\n\t\t\t\t\t\t\t\t\t}, err => {\n\t\t\t\t\t\t\t\t\t\tconsole.log(err);\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\tlet updates = getMongoUpdates(currDoc, modifiedDoc, true);\n\n\t\t\t\t\t\t\t\t\tif (updates) {\n\t\t\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(collection).updateOne({_id: modifiedDoc._id}, updates, {strict: false}).exec().then(res => {\n\t\t\t\t\t\t\t\t\t\t\tresolve(res.ok);\n\t\t\t\t\t\t\t\t\t\t}, err => reject(err));\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\tresolve(1);\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\tif (getBinarySize(JSON.stringify(updateParams)) < 200000) {\n\t\t\t\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\t\t\t\t\ttype: 'info',\n\t\t\t\t\t\t\t\t\t\t\ttitle: 'Update Document Props',\n\t\t\t\t\t\t\t\t\t\t\tmessage: 'User: ' + this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,\n\t\t\t\t\t\t\t\t\t\t\tpayload: JSON.stringify(updateParams, null, 2),\n\t\t\t\t\t\t\t\t\t\t\tmethod: 'updateDocumentProps',\n\t\t\t\t\t\t\t\t\t\t\tuser: this.user,\n\t\t\t\t\t\t\t\t\t\t\tmessageId: ''\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\t\t\t\t\t\ttype: 'info',\n\t\t\t\t\t\t\t\t\t\t\ttitle: 'Update Document Props',\n\t\t\t\t\t\t\t\t\t\t\tmessage: 'User: ' + this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,\n\t\t\t\t\t\t\t\t\t\t\tpayload: 'Too Big',\n\t\t\t\t\t\t\t\t\t\t\tmethod: 'updateDocumentProps',\n\t\t\t\t\t\t\t\t\t\t\tuser: this.user,\n\t\t\t\t\t\t\t\t\t\t\tmessageId: ''\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tconsole.log('invalid version - ' + collection, currDoc.__v, doc__v);\n\n\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(ResolveIOServer.getSupportDB().model(collection)['versionCollection']).findOne({\n\t\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t\t{'_id._id': currDoc._id},\n\t\t\t\t\t\t\t\t\t\t{'_id.__v': doc__v}\n\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t}).lean().exec((errOldDoc, oldDoc) => {\n\t\t\t\t\t\t\t\t\tlet newCurrDocId = currDoc._id;\n\n\t\t\t\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\t\t\t\tlet versionDoc = deepCopy(currDoc);\n\n\t\t\t\t\t\t\t\t\t\tversionDoc._id = {\n\t\t\t\t\t\t\t\t\t\t\t_id: currDoc._id,\n\t\t\t\t\t\t\t\t\t\t\t__v: currDoc.__v\n\t\t\t\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\t\t\t\tlet updatedDoc = getMongoMergeUpdatedDoc(modifiedDoc, currDoc, oldDoc);\n\t\t\t\t\t\t\t\t\t\tupdatedDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\t\tupdatedDoc.__v++;\n\t\n\t\t\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(collection).replaceOne({_id: newCurrDocId}, updatedDoc).exec().then(res => {\n\t\t\t\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(ResolveIOServer.getSupportDB().model(collection)['versionCollection']).create(versionDoc).then(doc => {\n\t\t\t\t\t\t\t\t\t\t\t\tResolveIOServer.getSupportDB().model(ResolveIOServer.getSupportDB().model(collection)['versionCollection']).deleteMany({\n\t\t\t\t\t\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{'_id._id': versionDoc._id._id},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{'_id.__v': {$lte: versionDoc._id.__v - 4}}\n\t\t\t\t\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t\t\t\t}).exec();\n\t\t\t\t\t\t\t\t\t\t\t}, err => {\n\t\t\t\t\t\t\t\t\t\t\t\tconsole.log(err);\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tresolve(res.nModified);\n\t\t\t\t\t\t\t\t\t\t}, err => reject(err));\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\treject('Invalid Version And Could Not Find History Props - DB: ' + currDoc.__v + ', Trying to update with :' + modifiedDoc.__v);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\treject('No Document');\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\t// Removes 1 document (from _id)\n\t\t// @Inputs: collection, document id\n\t\t// @Outputs: res = 1 (deleted), res = 0 (not deleted), err = not deleted\n\t\t// Search for doc, if found then try and remove\n\t\tremoveDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdoc_id: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, doc_id: string) {\n\t\t\t\treturn new Promise((resolve, reject) => {\n\n\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\ttype: 'info',\n\t\t\t\t\t\ttitle: 'Remove Document',\n\t\t\t\t\t\tmessage: 'User: ' + this.user + ', Collection Type: ' + collection,\n\t\t\t\t\t\tpayload: JSON.stringify({_id: doc_id}, null, 2),\n\t\t\t\t\t\tmethod: 'removeDocument',\n\t\t\t\t\t\tuser: this.user,\n\t\t\t\t\t\tmessageId: ''\n\t\t\t\t\t});\n\n\t\t\t\t\tResolveIOServer.getSupportDB().model(collection).deleteOne({_id: doc_id}).exec((err, res) => {\n\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\treject(err);\t\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tresolve(res.ok);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tremoveDocumentWithQuery: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query: Object) {\n\t\t\t\treturn new Promise((resolve, reject) => {\n\n\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\t\t\t\tdate: new Date(),\n\t\t\t\t\t\ttype: 'info',\n\t\t\t\t\t\ttitle: 'Remove Document (Query)',\n\t\t\t\t\t\tmessage: 'User: ' + this.user + ', Collection Type: ' + collection,\n\t\t\t\t\t\tpayload: JSON.stringify({_id: query}, null, 2),\n\t\t\t\t\t\tmethod: 'removeDocumentWithQuery',\n\t\t\t\t\t\tuser: this.user,\n\t\t\t\t\t\tmessageId: ''\n\t\t\t\t\t});\n\n\t\t\t\t\tResolveIOServer.getSupportDB().model(collection).deleteOne(query).exec((err, res) => {\n\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\treject(err);\t\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tresolve(res.ok);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n}"]}
|