@resolveio/server-lib 3.2.10 → 3.2.11
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/package.json +26 -26
- package/collections/active-subscription.collection.d.ts +0 -7
- package/collections/active-subscription.collection.js +0 -68
- package/collections/app-status.collection.d.ts +0 -7
- package/collections/app-status.collection.js +0 -43
- package/collections/app-version.collection.d.ts +0 -7
- package/collections/app-version.collection.js +0 -56
- package/collections/billing-logged-in-users.collection.d.ts +0 -7
- package/collections/billing-logged-in-users.collection.js +0 -73
- package/collections/counter.collection.d.ts +0 -9
- package/collections/counter.collection.js +0 -73
- package/collections/cron-job-history.collection.d.ts +0 -7
- package/collections/cron-job-history.collection.js +0 -86
- package/collections/cron-job.collection.d.ts +0 -7
- package/collections/cron-job.collection.js +0 -89
- package/collections/file.collection.d.ts +0 -9
- package/collections/file.collection.js +0 -73
- package/collections/flag.collection.d.ts +0 -7
- package/collections/flag.collection.js +0 -47
- package/collections/log.collection.d.ts +0 -7
- package/collections/log.collection.js +0 -65
- package/collections/logged-in-users.collection.d.ts +0 -7
- package/collections/logged-in-users.collection.js +0 -70
- package/collections/method-call.collection.d.ts +0 -6
- package/collections/method-call.collection.js +0 -44
- package/collections/method-response.collection.d.ts +0 -6
- package/collections/method-response.collection.js +0 -48
- package/collections/notification.collection.d.ts +0 -7
- package/collections/notification.collection.js +0 -43
- package/collections/queue-flag.collection.d.ts +0 -7
- package/collections/queue-flag.collection.js +0 -41
- package/collections/queue-method.collection.d.ts +0 -7
- package/collections/queue-method.collection.js +0 -119
- package/collections/queue-response.collection.d.ts +0 -7
- package/collections/queue-response.collection.js +0 -74
- package/collections/support-ticket.collection.d.ts +0 -7
- package/collections/support-ticket.collection.js +0 -200
- package/collections/user.collection.d.ts +0 -9
- package/collections/user.collection.js +0 -153
- package/cron/cron.d.ts +0 -5
- package/cron/cron.js +0 -160
- package/fixtures/cron-jobs.d.ts +0 -1
- package/fixtures/cron-jobs.js +0 -90
- package/fixtures/init.d.ts +0 -1
- package/fixtures/init.js +0 -67
- package/http/auth.d.ts +0 -2
- package/http/auth.js +0 -468
- package/http/health.d.ts +0 -1
- package/http/health.js +0 -8
- package/index.d.ts +0 -16
- package/index.js +0 -125
- package/managers/cron.manager.d.ts +0 -16
- package/managers/cron.manager.js +0 -202
- package/managers/database.manager.d.ts +0 -6
- package/managers/database.manager.js +0 -12
- package/managers/method.manager.d.ts +0 -28
- package/managers/method.manager.js +0 -584
- package/managers/queue-method.manager.d.ts +0 -13
- package/managers/queue-method.manager.js +0 -240
- package/managers/subscription.manager.d.ts +0 -28
- package/managers/subscription.manager.js +0 -803
- package/managers/support.manager.d.ts +0 -22
- package/managers/support.manager.js +0 -320
- package/methods/accounts.d.ts +0 -2
- package/methods/accounts.js +0 -253
- package/methods/aws.d.ts +0 -2
- package/methods/aws.js +0 -387
- package/methods/cloudconvert.d.ts +0 -2
- package/methods/cloudconvert.js +0 -37
- package/methods/collections.d.ts +0 -2
- package/methods/collections.js +0 -750
- package/methods/counters.d.ts +0 -2
- package/methods/counters.js +0 -107
- package/methods/cron-jobs.d.ts +0 -2
- package/methods/cron-jobs.js +0 -132
- package/methods/flags.d.ts +0 -2
- package/methods/flags.js +0 -6
- package/methods/logs.d.ts +0 -2
- package/methods/logs.js +0 -29
- package/methods/pdf.d.ts +0 -2
- package/methods/pdf.js +0 -303
- package/models/active-subscription.model.d.ts +0 -13
- package/models/active-subscription.model.js +0 -2
- package/models/app-status.model.d.ts +0 -4
- package/models/app-status.model.js +0 -2
- package/models/app-version.model.d.ts +0 -4
- package/models/app-version.model.js +0 -2
- package/models/billing-logged-in-users.model.d.ts +0 -7
- package/models/billing-logged-in-users.model.js +0 -2
- package/models/collection-document.model.d.ts +0 -6
- package/models/collection-document.model.js +0 -2
- package/models/counter.model.d.ts +0 -5
- package/models/counter.model.js +0 -2
- package/models/cron-job-history.model.d.ts +0 -12
- package/models/cron-job-history.model.js +0 -2
- package/models/cron-job.model.d.ts +0 -13
- package/models/cron-job.model.js +0 -2
- package/models/dialog.model.d.ts +0 -23
- package/models/dialog.model.js +0 -2
- package/models/file.model.d.ts +0 -9
- package/models/file.model.js +0 -2
- package/models/flag.model.d.ts +0 -5
- package/models/flag.model.js +0 -2
- package/models/log.model.d.ts +0 -11
- package/models/log.model.js +0 -2
- package/models/logged-in-users.model.d.ts +0 -9
- package/models/logged-in-users.model.js +0 -2
- package/models/method-call.model.d.ts +0 -7
- package/models/method-call.model.js +0 -2
- package/models/method-response.model.d.ts +0 -8
- package/models/method-response.model.js +0 -2
- package/models/method.model.d.ts +0 -10
- package/models/method.model.js +0 -2
- package/models/notification.model.d.ts +0 -4
- package/models/notification.model.js +0 -2
- package/models/pagination.model.d.ts +0 -11
- package/models/pagination.model.js +0 -20
- package/models/permission.model.d.ts +0 -12
- package/models/permission.model.js +0 -2
- package/models/queue-method.model.d.ts +0 -10
- package/models/queue-method.model.js +0 -2
- package/models/queue-response.model.d.ts +0 -10
- package/models/queue-response.model.js +0 -2
- package/models/select-data-label.model.d.ts +0 -9
- package/models/select-data-label.model.js +0 -2
- package/models/server-response.model.d.ts +0 -5
- package/models/server-response.model.js +0 -2
- package/models/subscription.model.d.ts +0 -30
- package/models/subscription.model.js +0 -2
- package/models/support-method.model.d.ts +0 -9
- package/models/support-method.model.js +0 -2
- package/models/support-ticket.model.d.ts +0 -61
- package/models/support-ticket.model.js +0 -2
- package/models/user.model.d.ts +0 -14
- package/models/user.model.js +0 -2
- package/private/email-templates/enrollment.html +0 -12
- package/private/email-templates/forgot-password.html +0 -12
- package/private/email-templates/support-ticket-deleted.html +0 -40
- package/private/email-templates/support-ticket-modified.html +0 -71
- package/private/email-templates/support-ticket.html +0 -71
- package/private/images/ResolveIO.png +0 -0
- package/publications/app-status.d.ts +0 -2
- package/publications/app-status.js +0 -14
- package/publications/app-version.d.ts +0 -2
- package/publications/app-version.js +0 -14
- package/publications/billing-logged-in-users.d.ts +0 -1
- package/publications/billing-logged-in-users.js +0 -63
- package/publications/cron-jobs.d.ts +0 -2
- package/publications/cron-jobs.js +0 -14
- package/publications/files.d.ts +0 -2
- package/publications/files.js +0 -71
- package/publications/flags.d.ts +0 -2
- package/publications/flags.js +0 -23
- package/publications/logs.d.ts +0 -2
- package/publications/logs.js +0 -26
- package/publications/method-calls.d.ts +0 -2
- package/publications/method-calls.js +0 -14
- package/publications/method-responses.d.ts +0 -2
- package/publications/method-responses.js +0 -14
- package/publications/notifications.d.ts +0 -2
- package/publications/notifications.js +0 -14
- package/publications/super-admin.d.ts +0 -2
- package/publications/super-admin.js +0 -21
- package/publications/support-tickets.d.ts +0 -1
- package/publications/support-tickets.js +0 -200
- package/server-app.d.ts +0 -35
- package/server-app.js +0 -636
- package/support-methods/aws.d.ts +0 -2
- package/support-methods/aws.js +0 -276
- package/support-methods/collections.d.ts +0 -2
- package/support-methods/collections.js +0 -471
- package/support-methods/counters.d.ts +0 -2
- package/support-methods/counters.js +0 -189
- package/support-methods/support.d.ts +0 -2
- package/support-methods/support.js +0 -236
- package/util/common.d.ts +0 -14
- package/util/common.js +0 -341
package/methods/collections.js
DELETED
|
@@ -1,750 +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 pagination_model_1 = require("../models/pagination.model");
|
|
7
|
-
var log_collection_1 = require("../collections/log.collection");
|
|
8
|
-
var index_1 = require("../index");
|
|
9
|
-
function loadCollectionMethods(methodManager) {
|
|
10
|
-
methodManager.methods({
|
|
11
|
-
// Query database for any collection and query
|
|
12
|
-
findOne: {
|
|
13
|
-
skipQueue: true,
|
|
14
|
-
check: new simpl_schema_1.default({
|
|
15
|
-
collection: {
|
|
16
|
-
type: String
|
|
17
|
-
},
|
|
18
|
-
query: {
|
|
19
|
-
type: Object,
|
|
20
|
-
blackbox: true
|
|
21
|
-
}
|
|
22
|
-
}),
|
|
23
|
-
function: function (collection, query) {
|
|
24
|
-
return index_1.ResolveIOServer.getMainDB().model(collection).findOne(query).exec();
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
find: {
|
|
28
|
-
skipQueue: true,
|
|
29
|
-
check: new simpl_schema_1.default({
|
|
30
|
-
collection: {
|
|
31
|
-
type: String
|
|
32
|
-
},
|
|
33
|
-
query: {
|
|
34
|
-
type: Object,
|
|
35
|
-
blackbox: true
|
|
36
|
-
},
|
|
37
|
-
sort: {
|
|
38
|
-
type: Object,
|
|
39
|
-
blackbox: true,
|
|
40
|
-
optional: true
|
|
41
|
-
}
|
|
42
|
-
}),
|
|
43
|
-
function: function (collection, query, sortQuery) {
|
|
44
|
-
if (sortQuery === void 0) { sortQuery = {}; }
|
|
45
|
-
return index_1.ResolveIOServer.getMainDB().model(collection).find(query).sort(sortQuery).exec();
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
findWithOptions: {
|
|
49
|
-
skipQueue: true,
|
|
50
|
-
check: new simpl_schema_1.default({
|
|
51
|
-
collection: {
|
|
52
|
-
type: String
|
|
53
|
-
},
|
|
54
|
-
query: {
|
|
55
|
-
type: Object,
|
|
56
|
-
blackbox: true
|
|
57
|
-
},
|
|
58
|
-
options: {
|
|
59
|
-
type: pagination_model_1.PaginationOptionsSchema
|
|
60
|
-
}
|
|
61
|
-
}),
|
|
62
|
-
function: function (collection, query, options) {
|
|
63
|
-
return index_1.ResolveIOServer.getMainDB().model(collection).find(query).sort(options.sort).limit(options.limit).skip(options.skip).select(options.fields).exec();
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
// Insert 1 document
|
|
67
|
-
// @Inputs: collection, document
|
|
68
|
-
// @Outputs: res = _id of new document, err = not inserted
|
|
69
|
-
insertDocument: {
|
|
70
|
-
check: new simpl_schema_1.default({
|
|
71
|
-
collection: {
|
|
72
|
-
type: String
|
|
73
|
-
},
|
|
74
|
-
document: {
|
|
75
|
-
type: Object,
|
|
76
|
-
blackbox: true
|
|
77
|
-
}
|
|
78
|
-
}),
|
|
79
|
-
function: function (collection, document) {
|
|
80
|
-
var _this = this;
|
|
81
|
-
return new Promise(function (resolve, reject) {
|
|
82
|
-
var schemaErrors = null;
|
|
83
|
-
try {
|
|
84
|
-
index_1.ResolveIOServer.getMainDB().model(collection)['simplschema'].validate(document);
|
|
85
|
-
}
|
|
86
|
-
catch (errors) {
|
|
87
|
-
schemaErrors = errors;
|
|
88
|
-
_this.callMethodInternal.call(_this, 'insertErrorLog', 'Schema Failed on insert - ' + collection, [schemaErrors, document]);
|
|
89
|
-
}
|
|
90
|
-
if (schemaErrors) {
|
|
91
|
-
console.log(schemaErrors);
|
|
92
|
-
reject('Schema Errors');
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
if (common_1.getBinarySize(JSON.stringify(document)) < 200000) {
|
|
96
|
-
log_collection_1.Logs.create({
|
|
97
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
98
|
-
date: new Date(),
|
|
99
|
-
type: 'info',
|
|
100
|
-
title: 'Insert Document',
|
|
101
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
102
|
-
payload: JSON.stringify(document),
|
|
103
|
-
method: 'insertDocument',
|
|
104
|
-
user: _this.user,
|
|
105
|
-
messageId: ''
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
log_collection_1.Logs.create({
|
|
110
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
111
|
-
date: new Date(),
|
|
112
|
-
type: 'info',
|
|
113
|
-
title: 'Insert Document',
|
|
114
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
115
|
-
payload: 'Too Big',
|
|
116
|
-
method: 'insertDocument',
|
|
117
|
-
user: _this.user,
|
|
118
|
-
messageId: ''
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
var id_1 = mongoose_1.Types.ObjectId().toHexString();
|
|
122
|
-
document['_id'] = id_1;
|
|
123
|
-
document['__v'] = 0;
|
|
124
|
-
index_1.ResolveIOServer.getMainDB().model(collection).create(document).then(function () { return resolve(id_1); }, function (err) { return reject(err); });
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
// Replaces 1 document with new document (from _id)
|
|
130
|
-
// @Inputs: collection, document id
|
|
131
|
-
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
132
|
-
// Search for doc, check version, if found then try and update
|
|
133
|
-
updateDocument: {
|
|
134
|
-
check: new simpl_schema_1.default({
|
|
135
|
-
collection: {
|
|
136
|
-
type: String
|
|
137
|
-
},
|
|
138
|
-
f_document: {
|
|
139
|
-
type: Object,
|
|
140
|
-
blackbox: true
|
|
141
|
-
}
|
|
142
|
-
}),
|
|
143
|
-
function: function (collection, f_document) {
|
|
144
|
-
var _this = this;
|
|
145
|
-
return new Promise(function (resolve, reject) {
|
|
146
|
-
index_1.ResolveIOServer.getMainDB().model(collection).findOne({ _id: f_document['_id'] }).lean().exec(function (errDoc, currDoc) {
|
|
147
|
-
if (currDoc) {
|
|
148
|
-
if (currDoc.__v === f_document['__v']) {
|
|
149
|
-
var versionDoc = common_1.deepCopy(currDoc);
|
|
150
|
-
versionDoc._id = {
|
|
151
|
-
_id: currDoc._id,
|
|
152
|
-
__v: currDoc.__v
|
|
153
|
-
};
|
|
154
|
-
var schemaErrors = null;
|
|
155
|
-
try {
|
|
156
|
-
index_1.ResolveIOServer.getMainDB().model(collection)['simplschema'].validate(f_document);
|
|
157
|
-
}
|
|
158
|
-
catch (errors) {
|
|
159
|
-
schemaErrors = errors;
|
|
160
|
-
_this.callMethodInternal.call(_this, 'insertErrorLog', 'Schema Failed on updateDocument - ' + collection, [schemaErrors, f_document]);
|
|
161
|
-
}
|
|
162
|
-
if (schemaErrors) {
|
|
163
|
-
console.log(schemaErrors);
|
|
164
|
-
reject('Schema Errors');
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
var updates_1 = common_1.getMongoUpdates(currDoc, f_document, true);
|
|
168
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc).then(function (doc) {
|
|
169
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
170
|
-
$and: [
|
|
171
|
-
{ '_id._id': currDoc._id },
|
|
172
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
173
|
-
]
|
|
174
|
-
}).exec().then(function () {
|
|
175
|
-
if (updates_1) {
|
|
176
|
-
index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: f_document['_id'] }, updates_1, { strict: false }).exec().then(function (res) {
|
|
177
|
-
resolve(res.nModified);
|
|
178
|
-
}, function (err) { return reject(err); });
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
resolve(1);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}, function (err) {
|
|
185
|
-
console.log(err);
|
|
186
|
-
});
|
|
187
|
-
if (common_1.getBinarySize(JSON.stringify(f_document)) < 200000) {
|
|
188
|
-
log_collection_1.Logs.create({
|
|
189
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
190
|
-
date: new Date(),
|
|
191
|
-
type: 'info',
|
|
192
|
-
title: 'Update Document',
|
|
193
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
194
|
-
payload: JSON.stringify(f_document),
|
|
195
|
-
method: 'updateDocument',
|
|
196
|
-
user: _this.user,
|
|
197
|
-
messageId: ''
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
log_collection_1.Logs.create({
|
|
202
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
203
|
-
date: new Date(),
|
|
204
|
-
type: 'info',
|
|
205
|
-
title: 'Update Document',
|
|
206
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
207
|
-
payload: 'Too Big',
|
|
208
|
-
method: 'updateDocument',
|
|
209
|
-
user: _this.user,
|
|
210
|
-
messageId: ''
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
console.log('invalid version - ' + collection, currDoc.__v, f_document['__v']);
|
|
217
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).findOne({
|
|
218
|
-
$and: [
|
|
219
|
-
{ '_id._id': currDoc._id },
|
|
220
|
-
{ '_id.__v': f_document['__v'] }
|
|
221
|
-
]
|
|
222
|
-
}).lean().exec(function (errOldDoc, oldDoc) {
|
|
223
|
-
var newCurrDocId = currDoc._id;
|
|
224
|
-
if (oldDoc) {
|
|
225
|
-
var versionDoc_1 = common_1.deepCopy(currDoc);
|
|
226
|
-
versionDoc_1._id = {
|
|
227
|
-
_id: currDoc._id,
|
|
228
|
-
__v: currDoc.__v
|
|
229
|
-
};
|
|
230
|
-
var updatedDoc = common_1.getMongoMergeUpdatedDoc(f_document, currDoc, oldDoc);
|
|
231
|
-
updatedDoc._id = newCurrDocId;
|
|
232
|
-
updatedDoc.__v++;
|
|
233
|
-
updatedDoc.updatedAt = new Date();
|
|
234
|
-
index_1.ResolveIOServer.getMainDB().model(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).exec().then(function (res) {
|
|
235
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc_1).then(function (doc) {
|
|
236
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
237
|
-
$and: [
|
|
238
|
-
{ '_id._id': versionDoc_1._id._id },
|
|
239
|
-
{ '_id.__v': { $lte: versionDoc_1._id.__v - 4 } }
|
|
240
|
-
]
|
|
241
|
-
}).exec().then(function () {
|
|
242
|
-
resolve(res.nModified);
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
}, function (err) { return reject(err); });
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
reject('Invalid Version And Could Not Find History - DB: ' + currDoc.__v + ', Trying to update with :' + f_document['__v']);
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
reject(errDoc);
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
},
|
|
260
|
-
// Updates 1 document's props (from _id)
|
|
261
|
-
// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})
|
|
262
|
-
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
263
|
-
// Search for doc, check version, if found then try and update props
|
|
264
|
-
updateDocumentProps: {
|
|
265
|
-
check: new simpl_schema_1.default({
|
|
266
|
-
collection: {
|
|
267
|
-
type: String
|
|
268
|
-
},
|
|
269
|
-
doc_id: {
|
|
270
|
-
type: String
|
|
271
|
-
},
|
|
272
|
-
updateParams: {
|
|
273
|
-
type: Array
|
|
274
|
-
},
|
|
275
|
-
'updateParams.$': {
|
|
276
|
-
type: Object,
|
|
277
|
-
blackbox: true
|
|
278
|
-
},
|
|
279
|
-
doc__v: {
|
|
280
|
-
type: Number
|
|
281
|
-
}
|
|
282
|
-
}),
|
|
283
|
-
function: function (collection, doc_id, updateParams, doc__v) {
|
|
284
|
-
var _this = this;
|
|
285
|
-
return new Promise(function (resolve, reject) {
|
|
286
|
-
index_1.ResolveIOServer.getMainDB().model(collection).findOne({ _id: doc_id }).lean().exec(function (errDoc, currDoc) {
|
|
287
|
-
if (currDoc) {
|
|
288
|
-
var modifiedDoc_1 = common_1.deepCopy(currDoc);
|
|
289
|
-
updateParams.forEach(function (data) {
|
|
290
|
-
modifiedDoc_1[data.prop] = data.data;
|
|
291
|
-
});
|
|
292
|
-
if (modifiedDoc_1.__v === doc__v) {
|
|
293
|
-
var versionDoc = common_1.deepCopy(currDoc);
|
|
294
|
-
versionDoc._id = {
|
|
295
|
-
_id: currDoc._id,
|
|
296
|
-
__v: currDoc.__v
|
|
297
|
-
};
|
|
298
|
-
var schemaErrors = null;
|
|
299
|
-
try {
|
|
300
|
-
index_1.ResolveIOServer.getMainDB().model(collection)['simplschema'].validate(modifiedDoc_1);
|
|
301
|
-
}
|
|
302
|
-
catch (errors) {
|
|
303
|
-
schemaErrors = errors;
|
|
304
|
-
_this.callMethodInternal.call(_this, 'insertErrorLog', 'Schema Failed on updateDocumentProps - ' + collection, [schemaErrors, modifiedDoc_1]);
|
|
305
|
-
}
|
|
306
|
-
if (schemaErrors) {
|
|
307
|
-
console.log(schemaErrors);
|
|
308
|
-
reject('Schema Errors');
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
var updates_2 = common_1.getMongoUpdates(currDoc, modifiedDoc_1, true);
|
|
312
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc).then(function (doc) {
|
|
313
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
314
|
-
$and: [
|
|
315
|
-
{ '_id._id': currDoc._id },
|
|
316
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
317
|
-
]
|
|
318
|
-
}).exec().then(function () {
|
|
319
|
-
if (updates_2) {
|
|
320
|
-
index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: modifiedDoc_1._id }, updates_2, { strict: false }).exec().then(function (res) {
|
|
321
|
-
resolve(res.ok);
|
|
322
|
-
}, function (err) { return reject(err); });
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
resolve(1);
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
}, function (err) {
|
|
329
|
-
console.log(err);
|
|
330
|
-
});
|
|
331
|
-
if (common_1.getBinarySize(JSON.stringify(updateParams)) < 200000) {
|
|
332
|
-
log_collection_1.Logs.create({
|
|
333
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
334
|
-
date: new Date(),
|
|
335
|
-
type: 'info',
|
|
336
|
-
title: 'Update Document Props',
|
|
337
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,
|
|
338
|
-
payload: JSON.stringify(updateParams),
|
|
339
|
-
method: 'updateDocumentProps',
|
|
340
|
-
user: _this.user,
|
|
341
|
-
messageId: ''
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
log_collection_1.Logs.create({
|
|
346
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
347
|
-
date: new Date(),
|
|
348
|
-
type: 'info',
|
|
349
|
-
title: 'Update Document Props',
|
|
350
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,
|
|
351
|
-
payload: 'Too Big',
|
|
352
|
-
method: 'updateDocumentProps',
|
|
353
|
-
user: _this.user,
|
|
354
|
-
messageId: ''
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
console.log(new Date(), 'invalid version - ' + collection, currDoc.__v, doc__v);
|
|
361
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).findOne({
|
|
362
|
-
$and: [
|
|
363
|
-
{ '_id._id': currDoc._id },
|
|
364
|
-
{ '_id.__v': doc__v }
|
|
365
|
-
]
|
|
366
|
-
}).lean().exec(function (errOldDoc, oldDoc) {
|
|
367
|
-
var newCurrDocId = currDoc._id;
|
|
368
|
-
if (oldDoc) {
|
|
369
|
-
var versionDoc_2 = common_1.deepCopy(currDoc);
|
|
370
|
-
versionDoc_2._id = {
|
|
371
|
-
_id: currDoc._id,
|
|
372
|
-
__v: currDoc.__v
|
|
373
|
-
};
|
|
374
|
-
var updatedDoc = common_1.getMongoMergeUpdatedDoc(modifiedDoc_1, currDoc, oldDoc);
|
|
375
|
-
updatedDoc._id = newCurrDocId;
|
|
376
|
-
updatedDoc.__v++;
|
|
377
|
-
updatedDoc.updatedAt = new Date();
|
|
378
|
-
index_1.ResolveIOServer.getMainDB().model(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).exec().then(function (res) {
|
|
379
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc_2).then(function (doc) {
|
|
380
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
381
|
-
$and: [
|
|
382
|
-
{ '_id._id': versionDoc_2._id._id },
|
|
383
|
-
{ '_id.__v': { $lte: versionDoc_2._id.__v - 4 } }
|
|
384
|
-
]
|
|
385
|
-
}).exec().then(function () {
|
|
386
|
-
resolve(res.nModified);
|
|
387
|
-
});
|
|
388
|
-
}, function (err) {
|
|
389
|
-
console.log(err);
|
|
390
|
-
});
|
|
391
|
-
}, function (err) { return reject(err); });
|
|
392
|
-
}
|
|
393
|
-
else {
|
|
394
|
-
reject('Invalid Version And Could Not Find History Props - DB: ' + currDoc.__v + ', Trying to update with :' + doc__v);
|
|
395
|
-
}
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
400
|
-
reject(errDoc);
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
},
|
|
406
|
-
updateDocumentOffline: {
|
|
407
|
-
check: new simpl_schema_1.default({
|
|
408
|
-
collection: {
|
|
409
|
-
type: String
|
|
410
|
-
},
|
|
411
|
-
f_document: {
|
|
412
|
-
type: Object,
|
|
413
|
-
blackbox: true
|
|
414
|
-
},
|
|
415
|
-
f_oldDocument: {
|
|
416
|
-
type: Object,
|
|
417
|
-
blackbox: true
|
|
418
|
-
}
|
|
419
|
-
}),
|
|
420
|
-
function: function (collection, f_document, f_oldDocument) {
|
|
421
|
-
var _this = this;
|
|
422
|
-
return new Promise(function (resolve, reject) {
|
|
423
|
-
index_1.ResolveIOServer.getMainDB().model(collection).findOne({ _id: f_document['_id'] }).lean().exec(function (errDoc, currDoc) {
|
|
424
|
-
if (currDoc) {
|
|
425
|
-
if (currDoc.__v === f_document['__v']) {
|
|
426
|
-
var versionDoc = common_1.deepCopy(currDoc);
|
|
427
|
-
versionDoc._id = {
|
|
428
|
-
_id: currDoc._id,
|
|
429
|
-
__v: currDoc.__v
|
|
430
|
-
};
|
|
431
|
-
var schemaErrors = null;
|
|
432
|
-
try {
|
|
433
|
-
index_1.ResolveIOServer.getMainDB().model(collection)['simplschema'].validate(f_document);
|
|
434
|
-
}
|
|
435
|
-
catch (errors) {
|
|
436
|
-
schemaErrors = errors;
|
|
437
|
-
_this.callMethodInternal.call(_this, 'insertErrorLog', 'Schema Failed on updateDocument - ' + collection, [schemaErrors, f_document]);
|
|
438
|
-
}
|
|
439
|
-
if (schemaErrors) {
|
|
440
|
-
console.log(schemaErrors);
|
|
441
|
-
reject('Schema Errors');
|
|
442
|
-
}
|
|
443
|
-
else {
|
|
444
|
-
var updates_3 = common_1.getMongoUpdates(currDoc, f_document, true);
|
|
445
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc).then(function (doc) {
|
|
446
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
447
|
-
$and: [
|
|
448
|
-
{ '_id._id': currDoc._id },
|
|
449
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
450
|
-
]
|
|
451
|
-
}).exec().then(function () {
|
|
452
|
-
if (updates_3) {
|
|
453
|
-
index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: f_document['_id'] }, updates_3, { strict: false }).exec().then(function (res) {
|
|
454
|
-
resolve(res.nModified);
|
|
455
|
-
}, function (err) { return reject(err); });
|
|
456
|
-
}
|
|
457
|
-
else {
|
|
458
|
-
resolve(1);
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
}, function (err) {
|
|
462
|
-
console.log(err);
|
|
463
|
-
});
|
|
464
|
-
if (common_1.getBinarySize(JSON.stringify(f_document)) < 200000) {
|
|
465
|
-
log_collection_1.Logs.create({
|
|
466
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
467
|
-
date: new Date(),
|
|
468
|
-
type: 'info',
|
|
469
|
-
title: 'Update Document',
|
|
470
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
471
|
-
payload: JSON.stringify(f_document),
|
|
472
|
-
method: 'updateDocumentOffline',
|
|
473
|
-
user: _this.user,
|
|
474
|
-
messageId: ''
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
478
|
-
log_collection_1.Logs.create({
|
|
479
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
480
|
-
date: new Date(),
|
|
481
|
-
type: 'info',
|
|
482
|
-
title: 'Update Document',
|
|
483
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
484
|
-
payload: 'Too Big',
|
|
485
|
-
method: 'updateDocumentOffline',
|
|
486
|
-
user: _this.user,
|
|
487
|
-
messageId: ''
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
else {
|
|
493
|
-
console.log('OFFLINE - invalid version - ' + collection, currDoc.__v, f_document['__v']);
|
|
494
|
-
var newCurrDocId = currDoc._id;
|
|
495
|
-
if (f_oldDocument) {
|
|
496
|
-
var versionDoc_3 = common_1.deepCopy(currDoc);
|
|
497
|
-
versionDoc_3._id = {
|
|
498
|
-
_id: currDoc._id,
|
|
499
|
-
__v: currDoc.__v
|
|
500
|
-
};
|
|
501
|
-
var updatedDoc = common_1.getMongoMergeUpdatedDoc(f_document, currDoc, f_oldDocument);
|
|
502
|
-
updatedDoc._id = newCurrDocId;
|
|
503
|
-
updatedDoc.__v++;
|
|
504
|
-
updatedDoc.updatedAt = new Date();
|
|
505
|
-
index_1.ResolveIOServer.getMainDB().model(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).exec().then(function (res) {
|
|
506
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc_3).then(function (doc) {
|
|
507
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
508
|
-
$and: [
|
|
509
|
-
{ '_id._id': versionDoc_3._id._id },
|
|
510
|
-
{ '_id.__v': { $lte: versionDoc_3._id.__v - 4 } }
|
|
511
|
-
]
|
|
512
|
-
}).exec().then(function () {
|
|
513
|
-
resolve(res.nModified);
|
|
514
|
-
});
|
|
515
|
-
}, function (err) {
|
|
516
|
-
console.log(err);
|
|
517
|
-
});
|
|
518
|
-
}, function (err) { return reject(err); });
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
reject('OFFLINE - Invalid Version And Could Not Find History - DB: ' + currDoc.__v + ', Trying to update with :' + f_document['__v']);
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
else {
|
|
526
|
-
reject(errDoc);
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
},
|
|
532
|
-
// Updates 1 document's props (from _id)
|
|
533
|
-
// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})
|
|
534
|
-
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
535
|
-
// Search for doc, check version, if found then try and update props
|
|
536
|
-
updateDocumentPropsOffline: {
|
|
537
|
-
check: new simpl_schema_1.default({
|
|
538
|
-
collection: {
|
|
539
|
-
type: String
|
|
540
|
-
},
|
|
541
|
-
doc_id: {
|
|
542
|
-
type: String
|
|
543
|
-
},
|
|
544
|
-
updateParams: {
|
|
545
|
-
type: Array
|
|
546
|
-
},
|
|
547
|
-
'updateParams.$': {
|
|
548
|
-
type: Object,
|
|
549
|
-
blackbox: true
|
|
550
|
-
},
|
|
551
|
-
doc__v: {
|
|
552
|
-
type: Number
|
|
553
|
-
},
|
|
554
|
-
f_oldDocument: {
|
|
555
|
-
type: Object,
|
|
556
|
-
blackbox: true
|
|
557
|
-
}
|
|
558
|
-
}),
|
|
559
|
-
function: function (collection, doc_id, updateParams, doc__v, f_oldDocument) {
|
|
560
|
-
var _this = this;
|
|
561
|
-
return new Promise(function (resolve, reject) {
|
|
562
|
-
index_1.ResolveIOServer.getMainDB().model(collection).findOne({ _id: doc_id }).lean().exec(function (errDoc, currDoc) {
|
|
563
|
-
if (currDoc) {
|
|
564
|
-
var modifiedDoc_2 = common_1.deepCopy(currDoc);
|
|
565
|
-
updateParams.forEach(function (data) {
|
|
566
|
-
modifiedDoc_2[data.prop] = data.data;
|
|
567
|
-
});
|
|
568
|
-
if (modifiedDoc_2.__v === doc__v) {
|
|
569
|
-
var versionDoc = common_1.deepCopy(currDoc);
|
|
570
|
-
versionDoc._id = {
|
|
571
|
-
_id: currDoc._id,
|
|
572
|
-
__v: currDoc.__v
|
|
573
|
-
};
|
|
574
|
-
var schemaErrors = null;
|
|
575
|
-
try {
|
|
576
|
-
index_1.ResolveIOServer.getMainDB().model(collection)['simplschema'].validate(modifiedDoc_2);
|
|
577
|
-
}
|
|
578
|
-
catch (errors) {
|
|
579
|
-
schemaErrors = errors;
|
|
580
|
-
_this.callMethodInternal.call(_this, 'insertErrorLog', 'Schema Failed on updateDocumentProps - ' + collection, [schemaErrors, modifiedDoc_2]);
|
|
581
|
-
}
|
|
582
|
-
if (schemaErrors) {
|
|
583
|
-
console.log(schemaErrors);
|
|
584
|
-
reject('Schema Errors');
|
|
585
|
-
}
|
|
586
|
-
else {
|
|
587
|
-
var updates_4 = common_1.getMongoUpdates(currDoc, modifiedDoc_2, true);
|
|
588
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc).then(function (doc) {
|
|
589
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
590
|
-
$and: [
|
|
591
|
-
{ '_id._id': currDoc._id },
|
|
592
|
-
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
593
|
-
]
|
|
594
|
-
}).exec().then(function () {
|
|
595
|
-
if (updates_4) {
|
|
596
|
-
index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: modifiedDoc_2._id }, updates_4, { strict: false }).exec().then(function (res) {
|
|
597
|
-
resolve(res.ok);
|
|
598
|
-
}, function (err) { return reject(err); });
|
|
599
|
-
}
|
|
600
|
-
else {
|
|
601
|
-
resolve(1);
|
|
602
|
-
}
|
|
603
|
-
});
|
|
604
|
-
}, function (err) {
|
|
605
|
-
console.log(err);
|
|
606
|
-
});
|
|
607
|
-
if (common_1.getBinarySize(JSON.stringify(updateParams)) < 200000) {
|
|
608
|
-
log_collection_1.Logs.create({
|
|
609
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
610
|
-
date: new Date(),
|
|
611
|
-
type: 'info',
|
|
612
|
-
title: 'Update Document Props',
|
|
613
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,
|
|
614
|
-
payload: JSON.stringify(updateParams),
|
|
615
|
-
method: 'updateDocumentPropsOffline',
|
|
616
|
-
user: _this.user,
|
|
617
|
-
messageId: ''
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
else {
|
|
621
|
-
log_collection_1.Logs.create({
|
|
622
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
623
|
-
date: new Date(),
|
|
624
|
-
type: 'info',
|
|
625
|
-
title: 'Update Document Props',
|
|
626
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection + ', Id: ' + doc_id + ', ' + 'Version: ' + doc__v,
|
|
627
|
-
payload: 'Too Big',
|
|
628
|
-
method: 'updateDocumentPropsOffline',
|
|
629
|
-
user: _this.user,
|
|
630
|
-
messageId: ''
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
else {
|
|
636
|
-
console.log('OFFLINE - invalid version - ' + collection, currDoc.__v, doc__v);
|
|
637
|
-
var newCurrDocId = currDoc._id;
|
|
638
|
-
if (f_oldDocument) {
|
|
639
|
-
var versionDoc_4 = common_1.deepCopy(currDoc);
|
|
640
|
-
versionDoc_4._id = {
|
|
641
|
-
_id: currDoc._id,
|
|
642
|
-
__v: currDoc.__v
|
|
643
|
-
};
|
|
644
|
-
var updatedDoc = common_1.getMongoMergeUpdatedDoc(modifiedDoc_2, currDoc, f_oldDocument);
|
|
645
|
-
updatedDoc._id = newCurrDocId;
|
|
646
|
-
updatedDoc.__v++;
|
|
647
|
-
updatedDoc.updatedAt = new Date();
|
|
648
|
-
index_1.ResolveIOServer.getMainDB().model(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).exec().then(function (res) {
|
|
649
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc_4).then(function (doc) {
|
|
650
|
-
index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
|
|
651
|
-
$and: [
|
|
652
|
-
{ '_id._id': versionDoc_4._id._id },
|
|
653
|
-
{ '_id.__v': { $lte: versionDoc_4._id.__v - 4 } }
|
|
654
|
-
]
|
|
655
|
-
}).exec().then(function () {
|
|
656
|
-
resolve(res.nModified);
|
|
657
|
-
});
|
|
658
|
-
}, function (err) {
|
|
659
|
-
console.log(err);
|
|
660
|
-
});
|
|
661
|
-
}, function (err) { return reject(err); });
|
|
662
|
-
}
|
|
663
|
-
else {
|
|
664
|
-
reject('OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + currDoc.__v + ', Trying to update with :' + modifiedDoc_2.__v);
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
else {
|
|
669
|
-
reject(errDoc);
|
|
670
|
-
}
|
|
671
|
-
});
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
},
|
|
675
|
-
// Removes 1 document (from _id)
|
|
676
|
-
// @Inputs: collection, document id
|
|
677
|
-
// @Outputs: res = 1 (deleted), res = 0 (not deleted), err = not deleted
|
|
678
|
-
// Search for doc, if found then try and remove
|
|
679
|
-
removeDocument: {
|
|
680
|
-
check: new simpl_schema_1.default({
|
|
681
|
-
collection: {
|
|
682
|
-
type: String
|
|
683
|
-
},
|
|
684
|
-
doc_id: {
|
|
685
|
-
type: String
|
|
686
|
-
}
|
|
687
|
-
}),
|
|
688
|
-
function: function (collection, doc_id) {
|
|
689
|
-
var _this = this;
|
|
690
|
-
return new Promise(function (resolve, reject) {
|
|
691
|
-
log_collection_1.Logs.create({
|
|
692
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
693
|
-
date: new Date(),
|
|
694
|
-
type: 'info',
|
|
695
|
-
title: 'Remove Document',
|
|
696
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
697
|
-
payload: JSON.stringify({ _id: doc_id }),
|
|
698
|
-
method: 'removeDocument',
|
|
699
|
-
user: _this.user,
|
|
700
|
-
messageId: ''
|
|
701
|
-
});
|
|
702
|
-
index_1.ResolveIOServer.getMainDB().model(collection).deleteOne({ _id: doc_id }).exec(function (err, res) {
|
|
703
|
-
if (err) {
|
|
704
|
-
reject(err);
|
|
705
|
-
}
|
|
706
|
-
else {
|
|
707
|
-
resolve(res.ok);
|
|
708
|
-
}
|
|
709
|
-
});
|
|
710
|
-
});
|
|
711
|
-
}
|
|
712
|
-
},
|
|
713
|
-
removeDocumentWithQuery: {
|
|
714
|
-
check: new simpl_schema_1.default({
|
|
715
|
-
collection: {
|
|
716
|
-
type: String
|
|
717
|
-
},
|
|
718
|
-
query: {
|
|
719
|
-
type: Object,
|
|
720
|
-
blackbox: true
|
|
721
|
-
}
|
|
722
|
-
}),
|
|
723
|
-
function: function (collection, query) {
|
|
724
|
-
var _this = this;
|
|
725
|
-
return new Promise(function (resolve, reject) {
|
|
726
|
-
log_collection_1.Logs.create({
|
|
727
|
-
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
728
|
-
date: new Date(),
|
|
729
|
-
type: 'info',
|
|
730
|
-
title: 'Remove Document (Query)',
|
|
731
|
-
message: 'User: ' + _this.user + ', Collection Type: ' + collection,
|
|
732
|
-
payload: JSON.stringify({ _id: query }),
|
|
733
|
-
method: 'removeDocumentWithQuery',
|
|
734
|
-
user: _this.user,
|
|
735
|
-
messageId: ''
|
|
736
|
-
});
|
|
737
|
-
index_1.ResolveIOServer.getMainDB().model(collection).deleteOne(query).exec(function (err, res) {
|
|
738
|
-
if (err) {
|
|
739
|
-
reject(err);
|
|
740
|
-
}
|
|
741
|
-
else {
|
|
742
|
-
resolve(res.ok);
|
|
743
|
-
}
|
|
744
|
-
});
|
|
745
|
-
});
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
});
|
|
749
|
-
}
|
|
750
|
-
exports.loadCollectionMethods = loadCollectionMethods;
|