@resolveio/server-lib 1.0.0-rc19 → 1.0.0-rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/collections/active-subscription.collection.js +1 -68
- package/collections/app-status.collection.js +1 -43
- package/collections/app-version.collection.js +1 -56
- package/collections/counter.collection.js +1 -73
- package/collections/cron-job-history.collection.js +1 -86
- package/collections/cron-job.collection.js +1 -89
- package/collections/file.collection.js +1 -73
- package/collections/flag.collection.js +1 -47
- package/collections/log.collection.js +1 -64
- package/collections/logged-in-users.collection.js +1 -70
- package/collections/method-call.collection.js +1 -44
- package/collections/method-response.collection.js +1 -48
- package/collections/queue-flag.collection.js +1 -41
- package/collections/queue-method.collection.js +1 -116
- package/collections/queue-response.collection.js +1 -78
- package/collections/support-ticket.collection.js +1 -146
- package/collections/user.collection.js +1 -108
- package/cron/cron.js +1 -160
- package/fixtures/cron-jobs.js +1 -72
- package/fixtures/init.js +1 -73
- package/http/auth.js +1 -472
- package/http/health.js +1 -8
- package/index.js +1 -123
- package/managers/cron.manager.js +1 -193
- package/managers/method.manager.js +1 -513
- package/managers/queue-method.manager.js +1 -239
- package/managers/subscription.manager.js +1 -700
- package/managers/support.manager.js +1 -208
- package/methods/accounts.js +1 -253
- package/methods/aws.js +1 -323
- package/methods/cloudconvert.js +1 -37
- package/methods/collections.js +1 -738
- package/methods/counters.js +1 -404
- package/methods/cron-jobs.js +1 -63
- package/methods/flags.js +1 -6
- package/methods/logs.js +1 -29
- package/methods/pdf.js +1 -303
- package/models/active-subscription.model.js +1 -2
- package/models/app-status.model.js +1 -2
- package/models/app-version.model.js +1 -2
- package/models/collection-document.model.js +1 -2
- package/models/counter.model.js +1 -2
- package/models/cron-job-history.model.js +1 -2
- package/models/cron-job.model.js +1 -2
- package/models/dialog.model.js +1 -2
- package/models/file.model.js +1 -2
- package/models/flag.model.js +1 -2
- package/models/log.model.js +1 -2
- package/models/logged-in-users.model.js +1 -2
- package/models/method-call.model.js +1 -2
- package/models/method-response.model.js +1 -2
- package/models/method.model.js +1 -2
- package/models/pagination.model.js +1 -20
- package/models/permission.model.js +1 -2
- package/models/queue-method.model.js +1 -2
- package/models/queue-response.model.js +1 -2
- package/models/select-data-label.model.js +1 -2
- package/models/server-response.model.js +1 -2
- package/models/subscription.model.js +1 -2
- package/models/support-method.model.js +1 -2
- package/models/support-ticket.model.js +1 -2
- package/models/user.model.js +1 -2
- package/package.json +2 -5
- package/publications/app-status.js +1 -14
- package/publications/app-version.js +1 -14
- package/publications/cron-jobs.js +1 -14
- package/publications/files.js +1 -71
- package/publications/flags.js +1 -23
- package/publications/logs.js +1 -26
- package/publications/method-calls.js +1 -14
- package/publications/method-responses.js +1 -14
- package/publications/super-admin.js +1 -21
- package/publications/support-tickets.js +1 -118
- package/server-app.js +1 -640
- package/support-methods/aws.js +1 -276
- package/support-methods/collections.js +1 -471
- package/support-methods/counters.js +1 -189
- package/support-methods/support.js +1 -19
- package/util/common.js +1 -334
- package/collections/active-subscription.collection.d.ts +0 -8
- package/collections/app-status.collection.d.ts +0 -8
- package/collections/app-version.collection.d.ts +0 -8
- package/collections/counter.collection.d.ts +0 -10
- package/collections/cron-job-history.collection.d.ts +0 -8
- package/collections/cron-job.collection.d.ts +0 -8
- package/collections/file.collection.d.ts +0 -10
- package/collections/flag.collection.d.ts +0 -8
- package/collections/log.collection.d.ts +0 -8
- package/collections/logged-in-users.collection.d.ts +0 -8
- package/collections/method-call.collection.d.ts +0 -7
- package/collections/method-response.collection.d.ts +0 -7
- package/collections/queue-flag.collection.d.ts +0 -8
- package/collections/queue-method.collection.d.ts +0 -8
- package/collections/queue-response.collection.d.ts +0 -8
- package/collections/support-ticket.collection.d.ts +0 -8
- package/collections/user.collection.d.ts +0 -9
- package/cron/cron.d.ts +0 -6
- package/fixtures/cron-jobs.d.ts +0 -2
- package/fixtures/init.d.ts +0 -2
- package/http/auth.d.ts +0 -3
- package/http/health.d.ts +0 -2
- package/index.d.ts +0 -15
- package/managers/cron.manager.d.ts +0 -17
- package/managers/method.manager.d.ts +0 -27
- package/managers/queue-method.manager.d.ts +0 -14
- package/managers/subscription.manager.d.ts +0 -27
- package/managers/support.manager.d.ts +0 -18
- package/methods/accounts.d.ts +0 -3
- package/methods/aws.d.ts +0 -3
- package/methods/cloudconvert.d.ts +0 -3
- package/methods/collections.d.ts +0 -3
- package/methods/counters.d.ts +0 -3
- package/methods/cron-jobs.d.ts +0 -3
- package/methods/flags.d.ts +0 -3
- package/methods/logs.d.ts +0 -3
- package/methods/pdf.d.ts +0 -3
- package/models/active-subscription.model.d.ts +0 -14
- package/models/app-status.model.d.ts +0 -5
- package/models/app-version.model.d.ts +0 -5
- package/models/collection-document.model.d.ts +0 -7
- package/models/counter.model.d.ts +0 -6
- package/models/cron-job-history.model.d.ts +0 -13
- package/models/cron-job.model.d.ts +0 -14
- package/models/dialog.model.d.ts +0 -24
- package/models/file.model.d.ts +0 -10
- package/models/flag.model.d.ts +0 -6
- package/models/log.model.d.ts +0 -12
- package/models/logged-in-users.model.d.ts +0 -10
- package/models/method-call.model.d.ts +0 -8
- package/models/method-response.model.d.ts +0 -9
- package/models/method.model.d.ts +0 -11
- package/models/pagination.model.d.ts +0 -12
- package/models/permission.model.d.ts +0 -13
- package/models/queue-method.model.d.ts +0 -10
- package/models/queue-response.model.d.ts +0 -11
- package/models/select-data-label.model.d.ts +0 -10
- package/models/server-response.model.d.ts +0 -6
- package/models/subscription.model.d.ts +0 -31
- package/models/support-method.model.d.ts +0 -10
- package/models/support-ticket.model.d.ts +0 -40
- package/models/user.model.d.ts +0 -15
- package/publications/app-status.d.ts +0 -3
- package/publications/app-version.d.ts +0 -3
- package/publications/cron-jobs.d.ts +0 -3
- package/publications/files.d.ts +0 -3
- package/publications/flags.d.ts +0 -3
- package/publications/logs.d.ts +0 -3
- package/publications/method-calls.d.ts +0 -3
- package/publications/method-responses.d.ts +0 -3
- package/publications/super-admin.d.ts +0 -3
- package/publications/support-tickets.d.ts +0 -2
- package/server-app.d.ts +0 -33
- package/support-methods/aws.d.ts +0 -3
- package/support-methods/collections.d.ts +0 -3
- package/support-methods/counters.d.ts +0 -3
- package/support-methods/support.d.ts +0 -3
- package/util/common.d.ts +0 -15
|
@@ -1,471 +1 @@
|
|
|
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: document,
|
|
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: f_document,
|
|
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
|
-
});
|
|
238
|
-
}, function (err) { return reject(err); });
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
reject('Invalid Version And Could Not Find History - DB: ' + currDoc.__v + ', Trying to update with :' + f_document.__v);
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
reject(errDoc);
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
// Updates 1 document's props (from _id)
|
|
254
|
-
// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})
|
|
255
|
-
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
256
|
-
// Search for doc, check version, if found then try and update props
|
|
257
|
-
updateDocumentProps: {
|
|
258
|
-
check: new simpl_schema_1.default({
|
|
259
|
-
collection: {
|
|
260
|
-
type: String
|
|
261
|
-
},
|
|
262
|
-
doc_id: {
|
|
263
|
-
type: String
|
|
264
|
-
},
|
|
265
|
-
updateParams: {
|
|
266
|
-
type: Array
|
|
267
|
-
},
|
|
268
|
-
'updateParams.$': {
|
|
269
|
-
type: Object,
|
|
270
|
-
blackbox: true
|
|
271
|
-
},
|
|
272
|
-
doc__v: {
|
|
273
|
-
type: Number
|
|
274
|
-
}
|
|
275
|
-
}),
|
|
276
|
-
function: function (collection, doc_id, updateParams, doc__v) {
|
|
277
|
-
var _this = this;
|
|
278
|
-
return new Promise(function (resolve, reject) {
|
|
279
|
-
__1.ResolveIOServer.getSupportDB().model(collection).findOne({ _id: doc_id }).lean().exec(function (errDoc, currDoc) {
|
|
280
|
-
if (currDoc) {
|
|
281
|
-
var modifiedDoc_1 = common_1.deepCopy(currDoc);
|
|
282
|
-
updateParams.forEach(function (data) {
|
|
283
|
-
modifiedDoc_1[data.prop] = data.data;
|
|
284
|
-
});
|
|
285
|
-
if (modifiedDoc_1.__v === doc__v) {
|
|
286
|
-
var versionDoc = common_1.deepCopy(currDoc);
|
|
287
|
-
versionDoc._id = {
|
|
288
|
-
_id: currDoc._id,
|
|
289
|
-
__v: currDoc.__v
|
|
290
|
-
};
|
|
291
|
-
var schemaErrors = null;
|
|
292
|
-
try {
|
|
293
|
-
__1.ResolveIOServer.getSupportDB().model(collection)['simplschema'].validate(modifiedDoc_1);
|
|
294
|
-
}
|
|
295
|
-
catch (errors) {
|
|
296
|
-
schemaErrors = errors;
|
|
297
|
-
supportManager.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on updateDocumentProps - ' + collection, [schemaErrors, modifiedDoc_1]);
|
|
298
|
-
}
|
|
299
|
-
if (schemaErrors) {
|
|
300
|
-
console.log(schemaErrors);
|
|
301
|
-
reject('Schema Errors');
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
__1.ResolveIOServer.getSupportDB().model(__1.ResolveIOServer.getSupportDB().model(collection)['versionCollection']).create(versionDoc).then(function (doc) {
|
|
305
|
-
__1.ResolveIOServer.getSupportDB().model(__1.ResolveIOServer.getSupportDB().model(collection)['versionCollection']).deleteMany({
|
|
306
|
-
$and: [
|
|
307
|
-
{ '_id._id': currDoc._id },
|
|
308
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
309
|
-
]
|
|
310
|
-
}).exec();
|
|
311
|
-
}, function (err) {
|
|
312
|
-
console.log(err);
|
|
313
|
-
});
|
|
314
|
-
var updates = common_1.getMongoUpdates(currDoc, modifiedDoc_1, true);
|
|
315
|
-
if (updates) {
|
|
316
|
-
__1.ResolveIOServer.getSupportDB().model(collection).updateOne({ _id: modifiedDoc_1._id }, updates, { strict: false }).exec().then(function (res) {
|
|
317
|
-
resolve(res.ok);
|
|
318
|
-
}, function (err) { return reject(err); });
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
resolve(1);
|
|
322
|
-
}
|
|
323
|
-
if (common_1.getBinarySize(JSON.stringify(updateParams)) < 200000) {
|
|
324
|
-
log_collection_1.Logs.create({
|
|
325
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
326
|
-
date: new Date(),
|
|
327
|
-
type: 'info',
|
|
328
|
-
title: 'Update Document Props',
|
|
329
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,
|
|
330
|
-
payload: updateParams,
|
|
331
|
-
method: 'updateDocumentProps',
|
|
332
|
-
user: _this.user,
|
|
333
|
-
messageId: ''
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
log_collection_1.Logs.create({
|
|
338
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
339
|
-
date: new Date(),
|
|
340
|
-
type: 'info',
|
|
341
|
-
title: 'Update Document Props',
|
|
342
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,
|
|
343
|
-
payload: 'Too Big',
|
|
344
|
-
method: 'updateDocumentProps',
|
|
345
|
-
user: _this.user,
|
|
346
|
-
messageId: ''
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
else {
|
|
352
|
-
console.log('invalid version - ' + collection, currDoc.__v, doc__v);
|
|
353
|
-
__1.ResolveIOServer.getSupportDB().model(__1.ResolveIOServer.getSupportDB().model(collection)['versionCollection']).findOne({
|
|
354
|
-
$and: [
|
|
355
|
-
{ '_id._id': currDoc._id },
|
|
356
|
-
{ '_id.__v': doc__v }
|
|
357
|
-
]
|
|
358
|
-
}).lean().exec(function (errOldDoc, oldDoc) {
|
|
359
|
-
var newCurrDocId = currDoc._id;
|
|
360
|
-
if (oldDoc) {
|
|
361
|
-
var versionDoc_2 = common_1.deepCopy(currDoc);
|
|
362
|
-
versionDoc_2._id = {
|
|
363
|
-
_id: currDoc._id,
|
|
364
|
-
__v: currDoc.__v
|
|
365
|
-
};
|
|
366
|
-
var updatedDoc = common_1.getMongoMergeUpdatedDoc(modifiedDoc_1, currDoc, oldDoc);
|
|
367
|
-
updatedDoc._id = newCurrDocId;
|
|
368
|
-
updatedDoc.__v++;
|
|
369
|
-
__1.ResolveIOServer.getSupportDB().model(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).exec().then(function (res) {
|
|
370
|
-
__1.ResolveIOServer.getSupportDB().model(__1.ResolveIOServer.getSupportDB().model(collection)['versionCollection']).create(versionDoc_2).then(function (doc) {
|
|
371
|
-
__1.ResolveIOServer.getSupportDB().model(__1.ResolveIOServer.getSupportDB().model(collection)['versionCollection']).deleteMany({
|
|
372
|
-
$and: [
|
|
373
|
-
{ '_id._id': versionDoc_2._id._id },
|
|
374
|
-
{ '_id.__v': { $lte: versionDoc_2._id.__v - 4 } }
|
|
375
|
-
]
|
|
376
|
-
}).exec();
|
|
377
|
-
}, function (err) {
|
|
378
|
-
console.log(err);
|
|
379
|
-
});
|
|
380
|
-
resolve(res.nModified);
|
|
381
|
-
}, function (err) { return reject(err); });
|
|
382
|
-
}
|
|
383
|
-
else {
|
|
384
|
-
reject('Invalid Version And Could Not Find History Props - DB: ' + currDoc.__v + ', Trying to update with :' + modifiedDoc_1.__v);
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
reject(errDoc);
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
},
|
|
396
|
-
// Removes 1 document (from _id)
|
|
397
|
-
// @Inputs: collection, document id
|
|
398
|
-
// @Outputs: res = 1 (deleted), res = 0 (not deleted), err = not deleted
|
|
399
|
-
// Search for doc, if found then try and remove
|
|
400
|
-
removeDocument: {
|
|
401
|
-
check: new simpl_schema_1.default({
|
|
402
|
-
collection: {
|
|
403
|
-
type: String
|
|
404
|
-
},
|
|
405
|
-
doc_id: {
|
|
406
|
-
type: String
|
|
407
|
-
}
|
|
408
|
-
}),
|
|
409
|
-
function: function (collection, doc_id) {
|
|
410
|
-
var _this = this;
|
|
411
|
-
return new Promise(function (resolve, reject) {
|
|
412
|
-
log_collection_1.Logs.create({
|
|
413
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
414
|
-
date: new Date(),
|
|
415
|
-
type: 'info',
|
|
416
|
-
title: 'Remove Document',
|
|
417
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
418
|
-
payload: { _id: doc_id },
|
|
419
|
-
method: 'removeDocument',
|
|
420
|
-
user: _this.user,
|
|
421
|
-
messageId: ''
|
|
422
|
-
});
|
|
423
|
-
__1.ResolveIOServer.getSupportDB().model(collection).deleteOne({ _id: doc_id }).exec(function (err, res) {
|
|
424
|
-
if (err) {
|
|
425
|
-
reject(err);
|
|
426
|
-
}
|
|
427
|
-
else {
|
|
428
|
-
resolve(res.ok);
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
},
|
|
434
|
-
removeDocumentWithQuery: {
|
|
435
|
-
check: new simpl_schema_1.default({
|
|
436
|
-
collection: {
|
|
437
|
-
type: String
|
|
438
|
-
},
|
|
439
|
-
query: {
|
|
440
|
-
type: Object,
|
|
441
|
-
blackbox: true
|
|
442
|
-
}
|
|
443
|
-
}),
|
|
444
|
-
function: function (collection, query) {
|
|
445
|
-
var _this = this;
|
|
446
|
-
return new Promise(function (resolve, reject) {
|
|
447
|
-
log_collection_1.Logs.create({
|
|
448
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
449
|
-
date: new Date(),
|
|
450
|
-
type: 'info',
|
|
451
|
-
title: 'Remove Document (Query)',
|
|
452
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
453
|
-
payload: { _id: query },
|
|
454
|
-
method: 'removeDocumentWithQuery',
|
|
455
|
-
user: _this.user,
|
|
456
|
-
messageId: ''
|
|
457
|
-
});
|
|
458
|
-
__1.ResolveIOServer.getSupportDB().model(collection).deleteOne(query).exec(function (err, res) {
|
|
459
|
-
if (err) {
|
|
460
|
-
reject(err);
|
|
461
|
-
}
|
|
462
|
-
else {
|
|
463
|
-
resolve(res.ok);
|
|
464
|
-
}
|
|
465
|
-
});
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
exports.loadSupportCollectionMethods = loadSupportCollectionMethods;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var mongoose_1=require("mongoose"),common_1=require("../util/common"),simpl_schema_1=require("simpl-schema"),log_collection_1=require("../collections/log.collection"),pagination_model_1=require("../models/pagination.model"),__1=require("..");function loadSupportCollectionMethods(p){p.supportMethods({findOne:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0}}),function:function(e,t){return __1.default.getSupportDB().model(e).findOne(t).exec()}},find:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0},sort:{type:Object,blackbox:!0,optional:!0}}),function:function(e,t,o){return void 0===o&&(o={}),__1.default.getSupportDB().model(e).find(t).sort(o).exec()}},findWithOptions:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0},options:{type:pagination_model_1.PaginationOptionsSchema}}),function:function(e,t,o){return __1.default.getSupportDB().model(e).find(t).sort(o.sort).limit(o.limit).skip(o.skip).select(o.fields).exec()}},insertDocument:{check:new simpl_schema_1.default({collection:{type:String},document:{type:Object,blackbox:!0}}),function:function(i,d){var l=this;return new Promise(function(e,t){var o=null;try{__1.default.getSupportDB().model(i).simplschema.validate(d)}catch(e){o=e,p.getMainServer().getMethodManager().callMethodInternal("insertErrorLog","Schema Failed on insert - "+i,[o,d])}if(o)console.log(o),t("Schema Errors");else{common_1.getBinarySize(JSON.stringify(d))<2e5?log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"info",title:"Insert Document",message:"User: "+l.user+", Collection Type: "+i,payload:d,method:"insertDocument",user:l.user,messageId:""}):log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"info",title:"Insert Document",message:"User: "+l.user+", Collection Type: "+i,payload:"Too Big",method:"insertDocument",user:l.user,messageId:""});var n=mongoose_1.Types.ObjectId().toHexString();d._id=n,d.__v=0,__1.default.getSupportDB().model(i).create(d).then(function(){return e(n)},function(e){return t(e)})}})}},updateDocument:{check:new simpl_schema_1.default({collection:{type:String},f_document:{type:Object,blackbox:!0}}),function:function(_,c){var i=this;return new Promise(function(l,r){__1.default.getSupportDB().model(_).findOne({_id:c._id}).lean().exec(function(e,d){if(d)if(d.__v===c.__v){var t=common_1.deepCopy(d);t._id={_id:d._id,__v:d.__v};var o=null;try{__1.default.getSupportDB().model(_).simplschema.validate(c)}catch(e){o=e,p.getMainServer().getMethodManager().callMethodInternal("insertErrorLog","Schema Failed on updateDocument - "+_,[o,c])}if(o)console.log(o),r("Schema Errors");else{__1.default.getSupportDB().model(__1.default.getSupportDB().model(_).versionCollection).create(t).then(function(e){__1.default.getSupportDB().model(__1.default.getSupportDB().model(_).versionCollection).deleteMany({$and:[{"_id._id":d._id},{"_id.__v":{$lte:d.__v-4}}]}).exec()},function(e){console.log(e)});var n=common_1.getMongoUpdates(d,c,!0);n?__1.default.getSupportDB().model(_).updateOne({_id:c._id},n,{strict:!1}).exec().then(function(e){l(e.nModified)},function(e){return r(e)}):l(1),common_1.getBinarySize(JSON.stringify(c))<2e5?log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"info",title:"Update Document",message:"User: "+i.user+", Collection Type: "+_,payload:c,method:"updateDocument",user:i.user,messageId:""}):log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"info",title:"Update Document",message:"User: "+i.user+", Collection Type: "+_,payload:"Too Big",method:"updateDocument",user:i.user,messageId:""})}}else console.log("invalid version - "+_,d.__v,c.__v),__1.default.getSupportDB().model(__1.default.getSupportDB().model(_).versionCollection).findOne({$and:[{"_id._id":d._id},{"_id.__v":c.__v}]}).lean().exec(function(e,t){var o=d._id;if(t){var n=common_1.deepCopy(d);n._id={_id:d._id,__v:d.__v};var i=common_1.getMongoMergeUpdatedDoc(c,d,t);i._id=o,i.__v++,__1.default.getSupportDB().model(_).replaceOne({_id:o},i).exec().then(function(t){__1.default.getSupportDB().model(__1.default.getSupportDB().model(_).versionCollection).create(n).then(function(e){__1.default.getSupportDB().model(__1.default.getSupportDB().model(_).versionCollection).deleteMany({$and:[{"_id._id":n._id._id},{"_id.__v":{$lte:n._id.__v-4}}]}).exec(),l(t.nModified)})},function(e){return r(e)})}else r("Invalid Version And Could Not Find History - DB: "+d.__v+", Trying to update with :"+c.__v)});else r(e)})})}},updateDocumentProps:{check:new simpl_schema_1.default({collection:{type:String},doc_id:{type:String},updateParams:{type:Array},"updateParams.$":{type:Object,blackbox:!0},doc__v:{type:Number}}),function:function(c,i,a,u){var s=this;return new Promise(function(r,_){__1.default.getSupportDB().model(c).findOne({_id:i}).lean().exec(function(e,d){if(d){var l=common_1.deepCopy(d);if(a.forEach(function(e){l[e.prop]=e.data}),l.__v===u){var t=common_1.deepCopy(d);t._id={_id:d._id,__v:d.__v};var o=null;try{__1.default.getSupportDB().model(c).simplschema.validate(l)}catch(e){o=e,p.getMainServer().getMethodManager().callMethodInternal("insertErrorLog","Schema Failed on updateDocumentProps - "+c,[o,l])}if(o)console.log(o),_("Schema Errors");else{__1.default.getSupportDB().model(__1.default.getSupportDB().model(c).versionCollection).create(t).then(function(e){__1.default.getSupportDB().model(__1.default.getSupportDB().model(c).versionCollection).deleteMany({$and:[{"_id._id":d._id},{"_id.__v":{$lte:d.__v-4}}]}).exec()},function(e){console.log(e)});var n=common_1.getMongoUpdates(d,l,!0);n?__1.default.getSupportDB().model(c).updateOne({_id:l._id},n,{strict:!1}).exec().then(function(e){r(e.ok)},function(e){return _(e)}):r(1),common_1.getBinarySize(JSON.stringify(a))<2e5?log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"info",title:"Update Document Props",message:"User: "+s.user+", Collection Type: "+c+", Id: "+i+", Version: "+u,payload:a,method:"updateDocumentProps",user:s.user,messageId:""}):log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"info",title:"Update Document Props",message:"User: "+s.user+", Collection Type: "+c+", Id: "+i+", Version: "+u,payload:"Too Big",method:"updateDocumentProps",user:s.user,messageId:""})}}else console.log("invalid version - "+c,d.__v,u),__1.default.getSupportDB().model(__1.default.getSupportDB().model(c).versionCollection).findOne({$and:[{"_id._id":d._id},{"_id.__v":u}]}).lean().exec(function(e,t){var o=d._id;if(t){var n=common_1.deepCopy(d);n._id={_id:d._id,__v:d.__v};var i=common_1.getMongoMergeUpdatedDoc(l,d,t);i._id=o,i.__v++,__1.default.getSupportDB().model(c).replaceOne({_id:o},i).exec().then(function(e){__1.default.getSupportDB().model(__1.default.getSupportDB().model(c).versionCollection).create(n).then(function(e){__1.default.getSupportDB().model(__1.default.getSupportDB().model(c).versionCollection).deleteMany({$and:[{"_id._id":n._id._id},{"_id.__v":{$lte:n._id.__v-4}}]}).exec()},function(e){console.log(e)}),r(e.nModified)},function(e){return _(e)})}else _("Invalid Version And Could Not Find History Props - DB: "+d.__v+", Trying to update with :"+l.__v)})}else _(e)})})}},removeDocument:{check:new simpl_schema_1.default({collection:{type:String},doc_id:{type:String}}),function:function(e,t){var i=this;return new Promise(function(o,n){log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"info",title:"Remove Document",message:"User: "+i.user+", Collection Type: "+e,payload:{_id:t},method:"removeDocument",user:i.user,messageId:""}),__1.default.getSupportDB().model(e).deleteOne({_id:t}).exec(function(e,t){e?n(e):o(t.ok)})})}},removeDocumentWithQuery:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0}}),function:function(e,t){var i=this;return new Promise(function(o,n){log_collection_1.Logs.create({_id:mongoose_1.Types.ObjectId().toHexString(),date:new Date,type:"info",title:"Remove Document (Query)",message:"User: "+i.user+", Collection Type: "+e,payload:{_id:t},method:"removeDocumentWithQuery",user:i.user,messageId:""}),__1.default.getSupportDB().model(e).deleteOne(t).exec(function(e,t){e?n(e):o(t.ok)})})}}})}exports.loadSupportCollectionMethods=loadSupportCollectionMethods;
|