@resolveio/server-lib 9.2.19 → 9.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client-server-app.js +55 -1
- package/client-server-app.js.map +1 -1
- package/collections/app-status.collection.js +40 -1
- package/collections/app-status.collection.js.map +1 -1
- package/collections/app-version.collection.js +40 -1
- package/collections/app-version.collection.js.map +1 -1
- package/collections/counter.collection.js +43 -1
- package/collections/counter.collection.js.map +1 -1
- package/collections/cron-job-history.collection.js +71 -1
- package/collections/cron-job-history.collection.js.map +1 -1
- package/collections/cron-job.collection.js +74 -1
- package/collections/cron-job.collection.js.map +1 -1
- package/collections/email-history.collection.js +55 -1
- package/collections/email-history.collection.js.map +1 -1
- package/collections/email-verified.collection.js +50 -1
- package/collections/email-verified.collection.js.map +1 -1
- package/collections/file.collection.js +62 -1
- package/collections/file.collection.js.map +1 -1
- package/collections/flag.collection.js +44 -1
- package/collections/flag.collection.js.map +1 -1
- package/collections/log-method-latency.collection.js +53 -1
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +57 -1
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log.collection.js +72 -1
- package/collections/log.collection.js.map +1 -1
- package/collections/logged-in-users.collection.js +58 -1
- package/collections/logged-in-users.collection.js.map +1 -1
- package/collections/method-call.collection.js +51 -1
- package/collections/method-call.collection.js.map +1 -1
- package/collections/method-response.collection.js +55 -1
- package/collections/method-response.collection.js.map +1 -1
- package/collections/monitor-cpu.collection.js +57 -1
- package/collections/monitor-cpu.collection.js.map +1 -1
- package/collections/monitor-https-inbound.collection.js +66 -1
- package/collections/monitor-https-inbound.collection.js.map +1 -1
- package/collections/monitor-https-outbound.collection.js +74 -1
- package/collections/monitor-https-outbound.collection.js.map +1 -1
- package/collections/monitor-memory.collection.js +68 -1
- package/collections/monitor-memory.collection.js.map +1 -1
- package/collections/monitor-mongo.collection.js +62 -1
- package/collections/monitor-mongo.collection.js.map +1 -1
- package/collections/notification.collection.js +40 -1
- package/collections/notification.collection.js.map +1 -1
- package/collections/report-builder-dashboard-builder.collection.js +93 -1
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
- package/collections/report-builder-library.collection.js +76 -1
- package/collections/report-builder-library.collection.js.map +1 -1
- package/collections/report-builder-report.collection.js +138 -1
- package/collections/report-builder-report.collection.js.map +1 -1
- package/collections/user-group.collection.js +79 -1
- package/collections/user-group.collection.js.map +1 -1
- package/collections/user-guide.collection.js +46 -1
- package/collections/user-guide.collection.js.map +1 -1
- package/collections/user.collection.js +248 -1
- package/collections/user.collection.js.map +1 -1
- package/cron/cron.js +161 -1
- package/cron/cron.js.map +1 -1
- package/fixtures/cron-jobs.js +72 -1
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +62 -1
- package/fixtures/init.js.map +1 -1
- package/http/auth.js +697 -1
- package/http/auth.js.map +1 -1
- package/http/health.js +10 -1
- package/http/health.js.map +1 -1
- package/http/home.js +64 -1
- package/http/home.js.map +1 -1
- package/index.js +123 -1
- package/index.js.map +1 -1
- package/managers/cron.manager.js +205 -1
- package/managers/cron.manager.js.map +1 -1
- package/managers/method.manager.js +599 -1
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.js +1777 -1
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +334 -1
- package/managers/monitor.manager.js.map +1 -1
- package/managers/subscription.manager.js +867 -1
- package/managers/subscription.manager.js.map +1 -1
- package/managers/subscription.performance.js +100 -1
- package/managers/subscription.performance.js.map +1 -1
- package/methods/accounts.js +224 -1
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +449 -1
- package/methods/aws.js.map +1 -1
- package/methods/cloudconvert.js +214 -1
- package/methods/cloudconvert.js.map +1 -1
- package/methods/collections.js +526 -1
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +121 -1
- package/methods/counters.js.map +1 -1
- package/methods/cron-jobs.js +1284 -1
- package/methods/cron-jobs.js.map +1 -1
- package/methods/flags.js +8 -1
- package/methods/flags.js.map +1 -1
- package/methods/logs.js +370 -1
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +384 -1
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +685 -1
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +826 -1
- package/methods/report-builder.js.map +1 -1
- package/methods/support.js +263 -1
- package/methods/support.js.map +1 -1
- package/models/app-status.model.js +3 -1
- package/models/app-status.model.js.map +1 -1
- package/models/app-version.model.js +3 -1
- package/models/app-version.model.js.map +1 -1
- package/models/billing-logged-in-users.model.js +3 -1
- package/models/billing-logged-in-users.model.js.map +1 -1
- package/models/collection-document.model.js +3 -1
- package/models/collection-document.model.js.map +1 -1
- package/models/counter.model.js +3 -1
- package/models/counter.model.js.map +1 -1
- package/models/cron-job-history.model.js +3 -1
- package/models/cron-job-history.model.js.map +1 -1
- package/models/cron-job.model.js +3 -1
- package/models/cron-job.model.js.map +1 -1
- package/models/dialog.model.js +3 -1
- package/models/dialog.model.js.map +1 -1
- package/models/email-history.model.js +3 -1
- package/models/email-history.model.js.map +1 -1
- package/models/email-verified.model.js +3 -1
- package/models/email-verified.model.js.map +1 -1
- package/models/file.model.js +3 -1
- package/models/file.model.js.map +1 -1
- package/models/flag.model.js +3 -1
- package/models/flag.model.js.map +1 -1
- package/models/log-method-latency.model.js +3 -1
- package/models/log-method-latency.model.js.map +1 -1
- package/models/log-subscription.model.js +3 -1
- package/models/log-subscription.model.js.map +1 -1
- package/models/log.model.js +3 -1
- package/models/log.model.js.map +1 -1
- package/models/logged-in-users.model.js +3 -1
- package/models/logged-in-users.model.js.map +1 -1
- package/models/method-call.model.js +3 -1
- package/models/method-call.model.js.map +1 -1
- package/models/method-response.model.js +3 -1
- package/models/method-response.model.js.map +1 -1
- package/models/method.model.js +3 -1
- package/models/method.model.js.map +1 -1
- package/models/monitor-cpu.model.js +3 -1
- package/models/monitor-cpu.model.js.map +1 -1
- package/models/monitor-https-inbound.model.js +3 -1
- package/models/monitor-https-inbound.model.js.map +1 -1
- package/models/monitor-https-outbound.model.js +3 -1
- package/models/monitor-https-outbound.model.js.map +1 -1
- package/models/monitor-memory.model.js +3 -1
- package/models/monitor-memory.model.js.map +1 -1
- package/models/monitor-mongo.model.js +3 -1
- package/models/monitor-mongo.model.js.map +1 -1
- package/models/notification.model.js +3 -1
- package/models/notification.model.js.map +1 -1
- package/models/pagination.model.js +23 -1
- package/models/pagination.model.js.map +1 -1
- package/models/permission.model.js +3 -1
- package/models/permission.model.js.map +1 -1
- package/models/report-builder-dashboard-builder.model.js +3 -1
- package/models/report-builder-dashboard-builder.model.js.map +1 -1
- package/models/report-builder-library.model.js +3 -1
- package/models/report-builder-library.model.js.map +1 -1
- package/models/report-builder-report.model.js +3 -1
- package/models/report-builder-report.model.js.map +1 -1
- package/models/report-builder.model.js +3 -1
- package/models/report-builder.model.js.map +1 -1
- package/models/select-data-label.model.js +3 -1
- package/models/select-data-label.model.js.map +1 -1
- package/models/server-response.model.js +3 -1
- package/models/server-response.model.js.map +1 -1
- package/models/subscription.model.js +3 -1
- package/models/subscription.model.js.map +1 -1
- package/models/support-ticket.model.js +3 -1
- package/models/support-ticket.model.js.map +1 -1
- package/models/user-group.model.js +3 -1
- package/models/user-group.model.js.map +1 -1
- package/models/user-guide.model.js +3 -1
- package/models/user-guide.model.js.map +1 -1
- package/models/user.model.js +3 -1
- package/models/user.model.js.map +1 -1
- package/package.json +1 -2
- package/public_api.js +78 -1
- package/public_api.js.map +1 -1
- package/publications/app-status.js +16 -1
- package/publications/app-status.js.map +1 -1
- package/publications/app-version.js +16 -1
- package/publications/app-version.js.map +1 -1
- package/publications/cron-jobs.js +32 -1
- package/publications/cron-jobs.js.map +1 -1
- package/publications/files.js +36 -1
- package/publications/files.js.map +1 -1
- package/publications/flags.js +22 -1
- package/publications/flags.js.map +1 -1
- package/publications/logs.js +90 -1
- package/publications/logs.js.map +1 -1
- package/publications/method-calls.js +16 -1
- package/publications/method-calls.js.map +1 -1
- package/publications/method-responses.js +16 -1
- package/publications/method-responses.js.map +1 -1
- package/publications/notifications.js +16 -1
- package/publications/notifications.js.map +1 -1
- package/publications/report-builder-dashboard-builders.js +42 -1
- package/publications/report-builder-dashboard-builders.js.map +1 -1
- package/publications/report-builder-libraries.js +89 -1
- package/publications/report-builder-libraries.js.map +1 -1
- package/publications/report-builder-reports.js +50 -1
- package/publications/report-builder-reports.js.map +1 -1
- package/publications/super-admin.js +16 -1
- package/publications/super-admin.js.map +1 -1
- package/publications/user-groups.js +16 -1
- package/publications/user-groups.js.map +1 -1
- package/publications/user-guides.js +16 -1
- package/publications/user-guides.js.map +1 -1
- package/server-app.js +682 -1
- package/server-app.js.map +1 -1
- package/util/common.js +498 -1
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +452 -1
- package/util/schema-report-builder.js.map +1 -1
package/methods/collections.js
CHANGED
|
@@ -1,2 +1,527 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadCollectionMethods = void 0;
|
|
4
|
+
var common_1 = require("../util/common");
|
|
5
|
+
var simpl_schema_1 = require("simpl-schema");
|
|
6
|
+
var pagination_model_1 = require("../models/pagination.model");
|
|
7
|
+
var index_1 = require("../index");
|
|
8
|
+
var mongo_manager_1 = require("../managers/mongo.manager");
|
|
9
|
+
function loadCollectionMethods(methodManager) {
|
|
10
|
+
methodManager.methods({
|
|
11
|
+
collectionListAll: {
|
|
12
|
+
function: function () {
|
|
13
|
+
return new Promise(function (resolve, reject) {
|
|
14
|
+
resolve(index_1.ResolveIOServer.getMongoManager().collections().map(function (a) { return a.collectionName; }).sort(function (a, b) { return a.localeCompare(b); }));
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
collectionListRB: {
|
|
19
|
+
function: function () {
|
|
20
|
+
return new Promise(function (resolve, reject) {
|
|
21
|
+
resolve(index_1.ResolveIOServer.getMongoManager().collections().filter(function (a) { return a.useRB; }).map(function (a) { return a.collectionName; }).sort(function (a, b) { return a.localeCompare(b); }));
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
// Query database for any collection and query
|
|
26
|
+
findOne: {
|
|
27
|
+
check: new simpl_schema_1.default({
|
|
28
|
+
collection: {
|
|
29
|
+
type: String
|
|
30
|
+
},
|
|
31
|
+
query: {
|
|
32
|
+
type: Object,
|
|
33
|
+
blackbox: true
|
|
34
|
+
}
|
|
35
|
+
}),
|
|
36
|
+
function: function (collection, query) {
|
|
37
|
+
if (query === void 0) { query = {}; }
|
|
38
|
+
return new Promise(function (resolve, reject) {
|
|
39
|
+
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
40
|
+
reject('Invalid collection');
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).findOne(query).then(function (res) { return resolve(res); }, function (err) { return reject(err); });
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
find: {
|
|
49
|
+
check: new simpl_schema_1.default({
|
|
50
|
+
collection: {
|
|
51
|
+
type: String
|
|
52
|
+
},
|
|
53
|
+
query: {
|
|
54
|
+
type: Object,
|
|
55
|
+
blackbox: true
|
|
56
|
+
},
|
|
57
|
+
sort: {
|
|
58
|
+
type: Object,
|
|
59
|
+
blackbox: true,
|
|
60
|
+
optional: true
|
|
61
|
+
}
|
|
62
|
+
}),
|
|
63
|
+
function: function (collection, query, sortQuery) {
|
|
64
|
+
if (query === void 0) { query = {}; }
|
|
65
|
+
if (sortQuery === void 0) { sortQuery = {}; }
|
|
66
|
+
return new Promise(function (resolve, reject) {
|
|
67
|
+
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
68
|
+
reject('Invalid collection');
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).find(query, { sort: sortQuery }).then(function (res) { return resolve(res); }, function (err) { return reject(err); });
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
findWithOptions: {
|
|
77
|
+
check: new simpl_schema_1.default({
|
|
78
|
+
collection: {
|
|
79
|
+
type: String
|
|
80
|
+
},
|
|
81
|
+
query: {
|
|
82
|
+
type: Object,
|
|
83
|
+
blackbox: true
|
|
84
|
+
},
|
|
85
|
+
options: {
|
|
86
|
+
type: pagination_model_1.PaginationOptionsSchema
|
|
87
|
+
}
|
|
88
|
+
}),
|
|
89
|
+
function: function (collection, query, options) {
|
|
90
|
+
return new Promise(function (resolve, reject) {
|
|
91
|
+
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
92
|
+
reject('Invalid collection');
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
var optionsQuery = {};
|
|
96
|
+
if (options.fields && Object.keys(options.fields).length) {
|
|
97
|
+
optionsQuery['projection'] = options.fields;
|
|
98
|
+
}
|
|
99
|
+
if (options.sort && Object.keys(options.sort).length) {
|
|
100
|
+
optionsQuery['sort'] = options.sort;
|
|
101
|
+
}
|
|
102
|
+
if (options.limit) {
|
|
103
|
+
optionsQuery['limit'] = options.limit;
|
|
104
|
+
}
|
|
105
|
+
if (options.skip) {
|
|
106
|
+
optionsQuery['skip'] = options.skip;
|
|
107
|
+
}
|
|
108
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).find(query, optionsQuery).then(function (res) { return resolve(res); }, function (err) { return reject(err); });
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
// Insert 1 document
|
|
114
|
+
// @Inputs: collection, document
|
|
115
|
+
// @Outputs: res = _id of new document, err = not inserted
|
|
116
|
+
insertDocument: {
|
|
117
|
+
check: new simpl_schema_1.default({
|
|
118
|
+
collection: {
|
|
119
|
+
type: String
|
|
120
|
+
},
|
|
121
|
+
document: {
|
|
122
|
+
type: Object,
|
|
123
|
+
blackbox: true
|
|
124
|
+
}
|
|
125
|
+
}),
|
|
126
|
+
function: function (collection, document) {
|
|
127
|
+
return new Promise(function (resolve, reject) {
|
|
128
|
+
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
129
|
+
reject('Invalid collection');
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
var id_1 = mongo_manager_1.objectIdHexString();
|
|
133
|
+
document['_id'] = id_1;
|
|
134
|
+
document['__v'] = 0;
|
|
135
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).insertOne(document).then(function () { return resolve(id_1); }, function (err) { return reject(err); });
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
// Insert 1 document
|
|
141
|
+
// @Inputs: collection, document
|
|
142
|
+
// @Outputs: res = _id of new document, err = not inserted
|
|
143
|
+
insertManyDocuments: {
|
|
144
|
+
check: new simpl_schema_1.default({
|
|
145
|
+
collection: {
|
|
146
|
+
type: String
|
|
147
|
+
},
|
|
148
|
+
documents: {
|
|
149
|
+
type: Array
|
|
150
|
+
},
|
|
151
|
+
'documents.$': {
|
|
152
|
+
type: Object,
|
|
153
|
+
blackbox: true
|
|
154
|
+
}
|
|
155
|
+
}),
|
|
156
|
+
function: function (collection, documents) {
|
|
157
|
+
return new Promise(function (resolve, reject) {
|
|
158
|
+
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
159
|
+
reject('Invalid collection');
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
documents.forEach(function (document) {
|
|
163
|
+
document['_id'] = mongo_manager_1.objectIdHexString();
|
|
164
|
+
document['__v'] = 0;
|
|
165
|
+
});
|
|
166
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).insertMany(documents).then(function () { return resolve(documents.map(function (a) { return a['_id']; })); }, function (err) { return reject(err); });
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
// Replaces 1 document with new document (from _id)
|
|
172
|
+
// @Inputs: collection, document id
|
|
173
|
+
// @Outputs: res = 1 (updated 1), err = not updated/wrong version
|
|
174
|
+
// Search for doc, check version, if found then try and update
|
|
175
|
+
updateDocument: {
|
|
176
|
+
check: new simpl_schema_1.default({
|
|
177
|
+
collection: {
|
|
178
|
+
type: String
|
|
179
|
+
},
|
|
180
|
+
f_document: {
|
|
181
|
+
type: Object,
|
|
182
|
+
blackbox: true
|
|
183
|
+
}
|
|
184
|
+
}),
|
|
185
|
+
function: function (collection, f_document) {
|
|
186
|
+
return new Promise(function (resolve, reject) {
|
|
187
|
+
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
188
|
+
reject('Invalid collection');
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: f_document['_id'] }, f_document).then(function (res) { return resolve(res); }, function (err) { return reject(err); });
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
// Updates 1 document's props (from _id)
|
|
197
|
+
// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})
|
|
198
|
+
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
199
|
+
// Search for doc, check version, if found then try and update props
|
|
200
|
+
updateDocumentProps: {
|
|
201
|
+
check: new simpl_schema_1.default({
|
|
202
|
+
collection: {
|
|
203
|
+
type: String
|
|
204
|
+
},
|
|
205
|
+
doc_id: {
|
|
206
|
+
type: String
|
|
207
|
+
},
|
|
208
|
+
updateParams: {
|
|
209
|
+
type: Array
|
|
210
|
+
},
|
|
211
|
+
'updateParams.$': {
|
|
212
|
+
type: Object,
|
|
213
|
+
blackbox: true
|
|
214
|
+
},
|
|
215
|
+
doc__v: {
|
|
216
|
+
type: Number
|
|
217
|
+
}
|
|
218
|
+
}),
|
|
219
|
+
function: function (collection, doc_id, updateParams, doc__v) {
|
|
220
|
+
return new Promise(function (resolve, reject) {
|
|
221
|
+
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
222
|
+
reject('Invalid collection');
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).findOne({ _id: doc_id }).then(function (currDoc) {
|
|
226
|
+
if (currDoc) {
|
|
227
|
+
var modifiedDoc_1 = common_1.deepCopy(currDoc);
|
|
228
|
+
updateParams.forEach(function (data) {
|
|
229
|
+
modifiedDoc_1[data.prop] = data.data;
|
|
230
|
+
});
|
|
231
|
+
if (modifiedDoc_1.__v === doc__v) {
|
|
232
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: modifiedDoc_1._id }, modifiedDoc_1, {}, false, false, currDoc).then(function (res) {
|
|
233
|
+
resolve(res);
|
|
234
|
+
}, function (err) { return reject(err); });
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
console.log(new Date(), 'invalid version - ' + collection, currDoc.__v, doc__v);
|
|
238
|
+
if (index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) {
|
|
239
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({
|
|
240
|
+
_id: {
|
|
241
|
+
_id: currDoc._id,
|
|
242
|
+
__v: doc__v
|
|
243
|
+
}
|
|
244
|
+
}).then(function (oldDoc) {
|
|
245
|
+
var newCurrDocId = currDoc._id;
|
|
246
|
+
var newCurrDocV = currDoc.__v;
|
|
247
|
+
if (oldDoc) {
|
|
248
|
+
var updatedDoc = common_1.getMongoMergeUpdatedDoc(modifiedDoc_1, currDoc, oldDoc);
|
|
249
|
+
updatedDoc._id = newCurrDocId;
|
|
250
|
+
updatedDoc.__v = newCurrDocV;
|
|
251
|
+
currDoc._id = newCurrDocId;
|
|
252
|
+
currDoc.__v = newCurrDocV;
|
|
253
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc, {}, false, false, currDoc).then(function (res) {
|
|
254
|
+
resolve(res);
|
|
255
|
+
}, function (err) { return reject(err); });
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
reject('Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + doc__v);
|
|
259
|
+
}
|
|
260
|
+
}, function () { });
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
reject('Invalid Version And We Are NOT Using Versions On This Collection!');
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
reject('No Document');
|
|
269
|
+
}
|
|
270
|
+
}, function () { });
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
updateDocumentOffline: {
|
|
276
|
+
check: new simpl_schema_1.default({
|
|
277
|
+
collection: {
|
|
278
|
+
type: String
|
|
279
|
+
},
|
|
280
|
+
f_document: {
|
|
281
|
+
type: Object,
|
|
282
|
+
blackbox: true
|
|
283
|
+
},
|
|
284
|
+
f_oldDocument: {
|
|
285
|
+
type: Object,
|
|
286
|
+
blackbox: true
|
|
287
|
+
}
|
|
288
|
+
}),
|
|
289
|
+
function: function (collection, f_document, f_oldDocument) {
|
|
290
|
+
return new Promise(function (resolve, reject) {
|
|
291
|
+
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
292
|
+
reject('Invalid collection');
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).findOne({ _id: f_document['_id'] }).then(function (currDoc) {
|
|
296
|
+
if (currDoc) {
|
|
297
|
+
if (currDoc.__v === f_document['__v']) {
|
|
298
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: f_document['_id'] }, f_document, {}, false, false, currDoc).then(function (res) {
|
|
299
|
+
resolve(res);
|
|
300
|
+
}, function (err) { return reject(err); });
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
console.log('OFFLINE - invalid version - ' + collection, currDoc.__v, f_document['__v']);
|
|
304
|
+
var newCurrDocId_1 = currDoc._id;
|
|
305
|
+
var newCurrDocV_1 = currDoc.__v;
|
|
306
|
+
var oldDocV_1 = f_document['__v'];
|
|
307
|
+
if (f_oldDocument) {
|
|
308
|
+
var updatedDoc = common_1.getMongoMergeUpdatedDoc(f_document, currDoc, f_oldDocument);
|
|
309
|
+
updatedDoc._id = newCurrDocId_1;
|
|
310
|
+
updatedDoc.__v = newCurrDocV_1;
|
|
311
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId_1 }, updatedDoc, {}, false, false, currDoc).then(function (res) {
|
|
312
|
+
resolve(res);
|
|
313
|
+
}, function (err) { return reject(err); });
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
if (index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) {
|
|
317
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({
|
|
318
|
+
_id: {
|
|
319
|
+
_id: newCurrDocId_1,
|
|
320
|
+
__v: oldDocV_1
|
|
321
|
+
}
|
|
322
|
+
}).then(function (oldDoc) {
|
|
323
|
+
if (oldDoc) {
|
|
324
|
+
var updatedDoc = common_1.getMongoMergeUpdatedDoc(f_document, currDoc, oldDoc);
|
|
325
|
+
updatedDoc._id = newCurrDocId_1;
|
|
326
|
+
updatedDoc.__v = newCurrDocV_1;
|
|
327
|
+
currDoc._id = newCurrDocId_1;
|
|
328
|
+
currDoc.__v = newCurrDocV_1;
|
|
329
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId_1 }, updatedDoc, {}, false, false, currDoc).then(function (res) {
|
|
330
|
+
resolve(res);
|
|
331
|
+
}, function (err) { return reject(err); });
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
reject('OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV_1 + ', Trying to update with :' + oldDocV_1);
|
|
335
|
+
}
|
|
336
|
+
}, function () { });
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
reject('Invalid Version And We Are NOT Using Versions On This Collection!');
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
reject('No Document');
|
|
346
|
+
}
|
|
347
|
+
}, function () { });
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
// Updates 1 document's props (from _id)
|
|
353
|
+
// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})
|
|
354
|
+
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
355
|
+
// Search for doc, check version, if found then try and update props
|
|
356
|
+
updateDocumentPropsOffline: {
|
|
357
|
+
check: new simpl_schema_1.default({
|
|
358
|
+
collection: {
|
|
359
|
+
type: String
|
|
360
|
+
},
|
|
361
|
+
doc_id: {
|
|
362
|
+
type: String
|
|
363
|
+
},
|
|
364
|
+
updateParams: {
|
|
365
|
+
type: Array
|
|
366
|
+
},
|
|
367
|
+
'updateParams.$': {
|
|
368
|
+
type: Object,
|
|
369
|
+
blackbox: true
|
|
370
|
+
},
|
|
371
|
+
doc__v: {
|
|
372
|
+
type: Number
|
|
373
|
+
},
|
|
374
|
+
f_oldDocument: {
|
|
375
|
+
type: Object,
|
|
376
|
+
blackbox: true
|
|
377
|
+
}
|
|
378
|
+
}),
|
|
379
|
+
function: function (collection, doc_id, updateParams, doc__v, f_oldDocument) {
|
|
380
|
+
return new Promise(function (resolve, reject) {
|
|
381
|
+
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
382
|
+
reject('Invalid collection');
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).findOne({ _id: doc_id }, null, true).then(function (currDoc) {
|
|
386
|
+
if (currDoc) {
|
|
387
|
+
var modifiedDoc_2 = common_1.deepCopy(currDoc);
|
|
388
|
+
updateParams.forEach(function (data) {
|
|
389
|
+
modifiedDoc_2[data.prop] = data.data;
|
|
390
|
+
});
|
|
391
|
+
if (modifiedDoc_2.__v === doc__v) {
|
|
392
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: modifiedDoc_2._id }, modifiedDoc_2, {}, false, false, currDoc).then(function (res) {
|
|
393
|
+
resolve(res);
|
|
394
|
+
}, function (err) { return reject(err); });
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
console.log('OFFLINE - invalid version - ' + collection, currDoc.__v, doc__v);
|
|
398
|
+
var newCurrDocId_2 = currDoc._id;
|
|
399
|
+
var newCurrDocV_2 = currDoc.__v;
|
|
400
|
+
if (f_oldDocument) {
|
|
401
|
+
var updatedDoc = common_1.getMongoMergeUpdatedDoc(modifiedDoc_2, currDoc, f_oldDocument);
|
|
402
|
+
updatedDoc._id = newCurrDocId_2;
|
|
403
|
+
updatedDoc.__v = newCurrDocV_2;
|
|
404
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId_2 }, updatedDoc, {}, false, false, currDoc).then(function (res) {
|
|
405
|
+
resolve(res);
|
|
406
|
+
}, function (err) { return reject(err); });
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
if (index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) {
|
|
410
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({
|
|
411
|
+
_id: {
|
|
412
|
+
_id: currDoc._id,
|
|
413
|
+
__v: doc__v
|
|
414
|
+
}
|
|
415
|
+
}).then(function (oldDoc) {
|
|
416
|
+
if (oldDoc) {
|
|
417
|
+
var updatedDoc = common_1.getMongoMergeUpdatedDoc(modifiedDoc_2, currDoc, oldDoc);
|
|
418
|
+
updatedDoc._id = newCurrDocId_2;
|
|
419
|
+
updatedDoc.__v = newCurrDocV_2;
|
|
420
|
+
currDoc._id = newCurrDocId_2;
|
|
421
|
+
currDoc.__v = newCurrDocV_2;
|
|
422
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId_2 }, updatedDoc, {}, false, false, currDoc).then(function (res) {
|
|
423
|
+
resolve(res);
|
|
424
|
+
}, function (err) { return reject(err); });
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
reject('OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV_2 + ', Trying to update with :' + doc__v);
|
|
428
|
+
}
|
|
429
|
+
}, function () { });
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
reject('Invalid Version And We Are NOT Using Versions On This Collection!');
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
reject('No Document');
|
|
439
|
+
}
|
|
440
|
+
}, function () { });
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
// Removes 1 document (from _id)
|
|
446
|
+
// @Inputs: collection, document id
|
|
447
|
+
// @Outputs: res = 1 (deleted), res = 0 (not deleted), err = not deleted
|
|
448
|
+
// Search for doc, if found then try and remove
|
|
449
|
+
removeDocument: {
|
|
450
|
+
check: new simpl_schema_1.default({
|
|
451
|
+
collection: {
|
|
452
|
+
type: String
|
|
453
|
+
},
|
|
454
|
+
doc_id: {
|
|
455
|
+
type: String
|
|
456
|
+
}
|
|
457
|
+
}),
|
|
458
|
+
function: function (collection, doc_id) {
|
|
459
|
+
return new Promise(function (resolve, reject) {
|
|
460
|
+
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
461
|
+
reject('Invalid collection');
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).deleteOne({ _id: doc_id }).then(function (res) {
|
|
465
|
+
resolve(res);
|
|
466
|
+
}, function (err) {
|
|
467
|
+
reject(err);
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
removeDocumentWithQuery: {
|
|
474
|
+
check: new simpl_schema_1.default({
|
|
475
|
+
collection: {
|
|
476
|
+
type: String
|
|
477
|
+
},
|
|
478
|
+
query: {
|
|
479
|
+
type: Object,
|
|
480
|
+
blackbox: true
|
|
481
|
+
}
|
|
482
|
+
}),
|
|
483
|
+
function: function (collection, query) {
|
|
484
|
+
return new Promise(function (resolve, reject) {
|
|
485
|
+
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
486
|
+
reject('Invalid collection');
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).deleteOne(query).then(function (res) {
|
|
490
|
+
resolve(res);
|
|
491
|
+
}, function (err) {
|
|
492
|
+
reject(err);
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
},
|
|
498
|
+
removeDocumentsWithQuery: {
|
|
499
|
+
check: new simpl_schema_1.default({
|
|
500
|
+
collection: {
|
|
501
|
+
type: String
|
|
502
|
+
},
|
|
503
|
+
query: {
|
|
504
|
+
type: Object,
|
|
505
|
+
blackbox: true
|
|
506
|
+
}
|
|
507
|
+
}),
|
|
508
|
+
function: function (collection, query) {
|
|
509
|
+
return new Promise(function (resolve, reject) {
|
|
510
|
+
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
511
|
+
reject('Invalid collection');
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
index_1.ResolveIOServer.getMongoManager().collection(collection).deleteMany(query).then(function (res) {
|
|
515
|
+
resolve(res);
|
|
516
|
+
}, function (err) {
|
|
517
|
+
reject(err);
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
exports.loadCollectionMethods = loadCollectionMethods;
|
|
526
|
+
|
|
2
527
|
//# sourceMappingURL=collections.js.map
|