@dhyasama/totem-models 11.145.0 → 12.0.0
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/helpers.js +23 -17
- package/index.js +3 -13
- package/lib/Account.js +32 -51
- package/lib/Activity.js +7 -14
- package/lib/ApiKey.js +68 -0
- package/lib/CalendarEvent.js +15 -19
- package/lib/CapTable.js +13 -16
- package/lib/Deal.js +116 -112
- package/lib/DiffbotArticle.js +3 -5
- package/lib/DiffbotOrganization.js +3 -5
- package/lib/Document.js +14 -17
- package/lib/Event.js +5 -7
- package/lib/EventAttendee.js +5 -11
- package/lib/Financials.js +32 -62
- package/lib/FinancialsAnalysis.js +9 -19
- package/lib/Flag.js +12 -15
- package/lib/Folder.js +4 -7
- package/lib/Fund.js +10 -13
- package/lib/Interaction.js +19 -29
- package/lib/Investment.js +13 -28
- package/lib/LimitedPartner.js +28 -72
- package/lib/LimitedPartnerCampaign.js +7 -10
- package/lib/LimitedPartnerCommunication.js +14 -17
- package/lib/LimitedPartnerContactGroup.js +6 -13
- package/lib/LimitedPartnerReportGenerator.js +2 -5
- package/lib/List.js +11 -17
- package/lib/Meeting.js +9 -12
- package/lib/Message.js +17 -20
- package/lib/MessageRecipient.js +3 -3
- package/lib/News.js +4 -6
- package/lib/Note.js +12 -15
- package/lib/Organization.js +62 -122
- package/lib/Person.js +29 -46
- package/lib/Rate.js +3 -6
- package/lib/Round.js +31 -65
- package/lib/Snapshot.js +2 -4
- package/lib/Sync.js +2 -5
- package/lib/Webhook.js +1 -4
- package/package.json +9 -7
- package/scripts/migrate-all-customers.js +1 -6
- package/scripts/migrate-financials-schema.js +2 -7
- package/scripts/run_mongoose8_smoke.js +334 -0
- package/test/CapTable.js +10 -15
- package/test/Deal.js +50 -0
- package/test/Financials.js +4 -6
- package/test/Investment.js +4 -6
- package/test/LimitedPartner.js +1 -1
- package/test/Person.js +13 -0
- package/test/Round.js +26 -39
- package/test/databaseHelpers.js +25 -19
- package/test/utilities.js +33 -0
package/helpers.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
const _ = require('underscore');
|
|
4
4
|
const mongoose = require('mongoose');
|
|
5
5
|
const rangeCheck = require('range_check');
|
|
6
|
-
const request = require('request');
|
|
7
6
|
const utilities = require('@dhyasama/totem-utilities');
|
|
8
7
|
|
|
9
8
|
const cleanOrg = module.exports.cleanOrg = function cleanOrg(doc, customerId) {
|
|
@@ -81,22 +80,29 @@ const getGeolocation = module.exports.getGeolocation = function getGeolocation(i
|
|
|
81
80
|
|
|
82
81
|
if (!rangeCheck.validIp(ip)) { return cb(null, {}); }
|
|
83
82
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
fetch('https://freegeoip.net/json/' + ip)
|
|
84
|
+
.then(function(response) {
|
|
85
|
+
return response.text().then(function(body) {
|
|
86
|
+
return {
|
|
87
|
+
body: body,
|
|
88
|
+
status: response.status
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
})
|
|
92
|
+
.then(function(result) {
|
|
93
|
+
if (result.status !== 200) {
|
|
94
|
+
return cb(new Error('non-200 status code from geoip (' + result.status + ')'), null);
|
|
95
|
+
}
|
|
96
|
+
else if (!utilities.isValidJson(result.body)) {
|
|
97
|
+
return cb(new Error('invalid json from geoip'), null);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
return cb(null, JSON.parse(result.body));
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
.catch(function(error) {
|
|
87
104
|
return cb(error, null);
|
|
88
|
-
}
|
|
89
|
-
else if (response && response.statusCode !== 200) {
|
|
90
|
-
return cb(new Error('non-200 status code from geoip (' + response.statusCode + ')'), null);
|
|
91
|
-
}
|
|
92
|
-
else if (!utilities.isValidJson(body)) {
|
|
93
|
-
return cb(new Error('invalid json from geoip'), null);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
return cb(null, JSON.parse(body));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
});
|
|
105
|
+
});
|
|
100
106
|
|
|
101
107
|
};
|
|
102
108
|
|
|
@@ -140,4 +146,4 @@ const sortPeopleSources = module.exports.sortPeopleSources = function sortPeople
|
|
|
140
146
|
|
|
141
147
|
return items;
|
|
142
148
|
|
|
143
|
-
};
|
|
149
|
+
};
|
package/index.js
CHANGED
|
@@ -4,23 +4,12 @@ var bootstrap = function(mongoose, config) {
|
|
|
4
4
|
|
|
5
5
|
var env = process.env.NODE_ENV || 'development';
|
|
6
6
|
|
|
7
|
-
// Make Mongoose use `findOneAndUpdate()`. Note that this option is `true`
|
|
8
|
-
// by default, you need to set it to false.
|
|
9
|
-
mongoose.set('useFindAndModify', false);
|
|
10
|
-
|
|
11
|
-
mongoose.set('useNewUrlParser', true);
|
|
12
|
-
mongoose.set('useUnifiedTopology', true);
|
|
13
|
-
mongoose.set('useCreateIndex', true);
|
|
14
|
-
|
|
15
7
|
// TODO: Turn this off for now; It will be nice when we can go through all code to safely utilize it;
|
|
16
8
|
//https://mongoosejs.com/docs/migrating_to_5.html#id-getter
|
|
17
|
-
mongoose.set(
|
|
9
|
+
mongoose.set("objectIdGetter", false);
|
|
18
10
|
|
|
19
11
|
// turn on debug if in development and not explicitly turned off
|
|
20
|
-
mongoose.set(
|
|
21
|
-
|
|
22
|
-
// use bluebird promises globally within mongoose
|
|
23
|
-
mongoose.Promise = require('bluebird');
|
|
12
|
+
mongoose.set("debug", (!config.suppressDebugLog && env == "development"));//mongoose.set('debug',true);
|
|
24
13
|
|
|
25
14
|
// todo - find a solution to load without worrying about order
|
|
26
15
|
|
|
@@ -59,6 +48,7 @@ var bootstrap = function(mongoose, config) {
|
|
|
59
48
|
// none of these need to be loaded before anything
|
|
60
49
|
require('./lib/Account.js')(mongoose, config);
|
|
61
50
|
require('./lib/Activity.js')(mongoose, config);
|
|
51
|
+
require('./lib/ApiKey.js')(mongoose, config);
|
|
62
52
|
require('./lib/CalendarEvent.js')(mongoose, config);
|
|
63
53
|
require('./lib/CapTable.js')(mongoose, config);
|
|
64
54
|
require('./lib/DiffbotArticle')(mongoose, config);
|
package/lib/Account.js
CHANGED
|
@@ -104,18 +104,16 @@ module.exports = function(mongoose, config) {
|
|
|
104
104
|
|
|
105
105
|
let query = { email: email.toLowerCase() };
|
|
106
106
|
|
|
107
|
-
if (options.current || options.customerId) {
|
|
107
|
+
if (options.current !== undefined || options.customerId !== undefined) {
|
|
108
108
|
|
|
109
|
-
if (options.current !== undefined) query.current = options.current;
|
|
110
|
-
if (options.customerId !== undefined) query.org = options.
|
|
109
|
+
if (options.current !== undefined) { query.current = options.current; }
|
|
110
|
+
if (options.customerId !== undefined) { query.org = options.customerId; }
|
|
111
111
|
|
|
112
112
|
self
|
|
113
113
|
.findOne(query)
|
|
114
114
|
.populate('person')
|
|
115
|
-
.exec(function(
|
|
116
|
-
|
|
117
|
-
if (err) { return cb(err); }
|
|
118
|
-
else if (!account) { return cb(null, null); }
|
|
115
|
+
.exec().then(function(account) {
|
|
116
|
+
if (!account) { return cb(null, null); }
|
|
119
117
|
|
|
120
118
|
if (account.populated('person')) {
|
|
121
119
|
|
|
@@ -126,7 +124,7 @@ module.exports = function(mongoose, config) {
|
|
|
126
124
|
|
|
127
125
|
return cb(null, account);
|
|
128
126
|
|
|
129
|
-
});
|
|
127
|
+
}).catch(function(err) { cb(err); });
|
|
130
128
|
|
|
131
129
|
}
|
|
132
130
|
|
|
@@ -134,8 +132,11 @@ module.exports = function(mongoose, config) {
|
|
|
134
132
|
|
|
135
133
|
self
|
|
136
134
|
.find(query)
|
|
137
|
-
.populate(
|
|
138
|
-
|
|
135
|
+
.populate({
|
|
136
|
+
path: 'org',
|
|
137
|
+
select: 'name'
|
|
138
|
+
})
|
|
139
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
139
140
|
|
|
140
141
|
}
|
|
141
142
|
|
|
@@ -151,10 +152,8 @@ module.exports = function(mongoose, config) {
|
|
|
151
152
|
self
|
|
152
153
|
.find({ 'email': { $in : emails }})
|
|
153
154
|
.populate('person')
|
|
154
|
-
.exec(function(
|
|
155
|
-
|
|
156
|
-
if (err) { return cb(err); }
|
|
157
|
-
else if (!accounts) { return cb(null, null); }
|
|
155
|
+
.exec().then(function(accounts) {
|
|
156
|
+
if (!accounts) { return cb(null, null); }
|
|
158
157
|
|
|
159
158
|
_.each(accounts, function(account) {
|
|
160
159
|
|
|
@@ -169,7 +168,7 @@ module.exports = function(mongoose, config) {
|
|
|
169
168
|
|
|
170
169
|
return cb(null, accounts);
|
|
171
170
|
|
|
172
|
-
});
|
|
171
|
+
}).catch(function(err) { cb(err); });
|
|
173
172
|
|
|
174
173
|
};
|
|
175
174
|
|
|
@@ -186,12 +185,8 @@ module.exports = function(mongoose, config) {
|
|
|
186
185
|
query.populate('person');
|
|
187
186
|
query.populate('org');
|
|
188
187
|
|
|
189
|
-
query.exec(function
|
|
190
|
-
|
|
191
|
-
if (err) {
|
|
192
|
-
return cb(err, null);
|
|
193
|
-
}
|
|
194
|
-
else if (account && account.populated('person') && account.populated('org')) {
|
|
188
|
+
query.exec().then(function(account) {
|
|
189
|
+
if (account && account.populated('person') && account.populated('org')) {
|
|
195
190
|
|
|
196
191
|
// Scrub customer info before returning
|
|
197
192
|
|
|
@@ -217,7 +212,7 @@ module.exports = function(mongoose, config) {
|
|
|
217
212
|
return cb(new Error('Unknown error'), null);
|
|
218
213
|
}
|
|
219
214
|
|
|
220
|
-
});
|
|
215
|
+
}).catch(function(err) { cb(err); });
|
|
221
216
|
|
|
222
217
|
};
|
|
223
218
|
|
|
@@ -233,7 +228,7 @@ module.exports = function(mongoose, config) {
|
|
|
233
228
|
|
|
234
229
|
self
|
|
235
230
|
.find({ 'org': customerId })
|
|
236
|
-
.exec(cb);
|
|
231
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
237
232
|
|
|
238
233
|
};
|
|
239
234
|
|
|
@@ -246,18 +241,11 @@ module.exports = function(mongoose, config) {
|
|
|
246
241
|
|
|
247
242
|
const self = this;
|
|
248
243
|
|
|
249
|
-
self.updateMany({ email: email }, { $set: { current: false } }, function(
|
|
250
|
-
|
|
251
|
-
if (err) { return cb(err, null); }
|
|
244
|
+
self.updateMany({ email: email }, { $set: { current: false } }).then(function(res) {self.updateOne({ email: email, org: customerId }, { $set: { current: true } }).then(function(res) {cb(null, res);
|
|
252
245
|
|
|
253
|
-
|
|
246
|
+
}).catch(function(err) { cb(err); });
|
|
254
247
|
|
|
255
|
-
|
|
256
|
-
cb(null, res);
|
|
257
|
-
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
});
|
|
248
|
+
}).catch(function(err) { cb(err); });
|
|
261
249
|
|
|
262
250
|
};
|
|
263
251
|
|
|
@@ -270,12 +258,9 @@ module.exports = function(mongoose, config) {
|
|
|
270
258
|
|
|
271
259
|
const self = this;
|
|
272
260
|
|
|
273
|
-
self.updateOne({ email: email }, { $set: { org: customerId } }
|
|
274
|
-
|
|
275
|
-
if (err) { return cb(err, null); }
|
|
276
|
-
cb(null, res);
|
|
261
|
+
self.updateOne({ email: email }, { $set: { org: customerId } }).then(function(res) {cb(null, res);
|
|
277
262
|
|
|
278
|
-
});
|
|
263
|
+
}).catch(function(err) { cb(err); });
|
|
279
264
|
|
|
280
265
|
};
|
|
281
266
|
|
|
@@ -287,7 +272,7 @@ module.exports = function(mongoose, config) {
|
|
|
287
272
|
|
|
288
273
|
self
|
|
289
274
|
.find({ 'active': true, 'role': 'admin' })
|
|
290
|
-
.exec(cb);
|
|
275
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
291
276
|
|
|
292
277
|
};
|
|
293
278
|
|
|
@@ -303,7 +288,7 @@ module.exports = function(mongoose, config) {
|
|
|
303
288
|
queryObj['org'] = options.CUSTOMER_ID;
|
|
304
289
|
}
|
|
305
290
|
|
|
306
|
-
self.find(queryObj).exec(cb);
|
|
291
|
+
self.find(queryObj).exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
307
292
|
|
|
308
293
|
};
|
|
309
294
|
|
|
@@ -324,7 +309,7 @@ module.exports = function(mongoose, config) {
|
|
|
324
309
|
.find({'active': true})
|
|
325
310
|
.populate('person')
|
|
326
311
|
.sort({'person.name.last': 1})
|
|
327
|
-
.exec(cb);
|
|
312
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
328
313
|
|
|
329
314
|
};
|
|
330
315
|
|
|
@@ -341,7 +326,7 @@ module.exports = function(mongoose, config) {
|
|
|
341
326
|
self
|
|
342
327
|
.find({'active': true})
|
|
343
328
|
.select('active email auth')
|
|
344
|
-
.exec(cb);
|
|
329
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
345
330
|
|
|
346
331
|
};
|
|
347
332
|
|
|
@@ -365,7 +350,7 @@ module.exports = function(mongoose, config) {
|
|
|
365
350
|
'auth.strategy': 'google',
|
|
366
351
|
'auth.google.refreshToken': { $ne: null }
|
|
367
352
|
})
|
|
368
|
-
.exec(cb);
|
|
353
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
369
354
|
|
|
370
355
|
};
|
|
371
356
|
|
|
@@ -389,7 +374,7 @@ module.exports = function(mongoose, config) {
|
|
|
389
374
|
'auth.strategy': 'microsoft',
|
|
390
375
|
'auth.microsoft.refreshToken': { $ne: null }
|
|
391
376
|
})
|
|
392
|
-
.exec(cb);
|
|
377
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
393
378
|
|
|
394
379
|
};
|
|
395
380
|
|
|
@@ -401,7 +386,7 @@ module.exports = function(mongoose, config) {
|
|
|
401
386
|
if (!id) { return cb(new Error('id is required'), null); }
|
|
402
387
|
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
403
388
|
|
|
404
|
-
self.
|
|
389
|
+
self.findByIdAndDelete(id).then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
405
390
|
|
|
406
391
|
};
|
|
407
392
|
|
|
@@ -409,16 +394,12 @@ module.exports = function(mongoose, config) {
|
|
|
409
394
|
|
|
410
395
|
// No population so no need to scrub
|
|
411
396
|
|
|
412
|
-
account.save(cb);
|
|
397
|
+
account.save().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
413
398
|
|
|
414
399
|
};
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
Account.set('usePushEach', true);
|
|
418
400
|
Account.set('autoIndex', false);
|
|
419
|
-
Account.set('usePushEach', true);
|
|
420
401
|
Account.on('index', function(err) { console.log('error building account indexes: ' + err); });
|
|
421
402
|
|
|
422
403
|
mongoose.model('Account', Account);
|
|
423
404
|
|
|
424
|
-
};
|
|
405
|
+
};
|
package/lib/Activity.js
CHANGED
|
@@ -50,11 +50,7 @@ module.exports = function(mongoose, config) {
|
|
|
50
50
|
|
|
51
51
|
username = username.toLowerCase();
|
|
52
52
|
|
|
53
|
-
self.findOne({ 'username': username }
|
|
54
|
-
|
|
55
|
-
if (err) return callback(err, null);
|
|
56
|
-
|
|
57
|
-
if (!activity) {
|
|
53
|
+
self.findOne({ 'username': username }).then(function(activity) {if (!activity) {
|
|
58
54
|
const A = mongoose.model('Activity');
|
|
59
55
|
activity = new A();
|
|
60
56
|
activity.username = username;
|
|
@@ -75,20 +71,20 @@ module.exports = function(mongoose, config) {
|
|
|
75
71
|
|
|
76
72
|
if (activity) {
|
|
77
73
|
activity.items.unshift(item);
|
|
78
|
-
activity.save(function(
|
|
79
|
-
return callback(
|
|
80
|
-
});
|
|
74
|
+
activity.save().then(function(result) {
|
|
75
|
+
return callback(null, item);
|
|
76
|
+
}).catch(function(err) { callback(err); });
|
|
81
77
|
}
|
|
82
78
|
else {
|
|
83
79
|
return callback(null, null);
|
|
84
80
|
}
|
|
85
81
|
|
|
86
|
-
});
|
|
82
|
+
}).catch(function(err) { callback(err); });
|
|
87
83
|
|
|
88
84
|
};
|
|
89
85
|
|
|
90
86
|
Activity.statics.forMessage = function(username, messageId, cb) {
|
|
91
|
-
this.find({ 'username': username.toLowerCase(), 'items.document.messageId': messageId }, cb);
|
|
87
|
+
this.find({ 'username': username.toLowerCase(), 'items.document.messageId': messageId }).then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
92
88
|
};
|
|
93
89
|
|
|
94
90
|
Activity.statics.list = function(username, maxItems, cb) {
|
|
@@ -97,13 +93,10 @@ module.exports = function(mongoose, config) {
|
|
|
97
93
|
|
|
98
94
|
if (maxItems && maxItems >= 1) { query = query.slice('items', maxItems); }
|
|
99
95
|
|
|
100
|
-
query.exec(cb);
|
|
96
|
+
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
101
97
|
|
|
102
98
|
};
|
|
103
|
-
|
|
104
|
-
Activity.set('usePushEach', true);
|
|
105
99
|
Activity.set('autoIndex', false);
|
|
106
|
-
Activity.set('usePushEach', true);
|
|
107
100
|
Activity.on('index', function(err) { console.log('error building activity indexes: ' + err); });
|
|
108
101
|
|
|
109
102
|
mongoose.model('Activity', Activity);
|
package/lib/ApiKey.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = function(mongoose, config) {
|
|
4
|
+
|
|
5
|
+
var Schema = mongoose.Schema;
|
|
6
|
+
|
|
7
|
+
var ApiKey = new Schema({
|
|
8
|
+
account: { type: Schema.ObjectId, ref: 'Account', required: true },
|
|
9
|
+
customer: { type: Schema.ObjectId, ref: 'Organization', required: true },
|
|
10
|
+
email: { type: String, required: true },
|
|
11
|
+
scopes: { type: [String], default: ['read'] },
|
|
12
|
+
tokenHash: { type: String, required: true },
|
|
13
|
+
lastUsedOn: { type: Date },
|
|
14
|
+
createdOn: { type: Date, default: Date.now },
|
|
15
|
+
active: { type: Boolean, default: true }
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
ApiKey.index({ customer: 1, account: 1 });
|
|
19
|
+
ApiKey.index({ tokenHash: 1 });
|
|
20
|
+
|
|
21
|
+
ApiKey.statics.getByTokenHash = function(hash, cb) {
|
|
22
|
+
|
|
23
|
+
var self = this;
|
|
24
|
+
|
|
25
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
26
|
+
if (!hash) { return cb(new Error('hash is required'), null); }
|
|
27
|
+
|
|
28
|
+
self
|
|
29
|
+
.findOne({ tokenHash: hash })
|
|
30
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
31
|
+
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
ApiKey.statics.getByAccount = function(accountId, customerId, cb) {
|
|
35
|
+
|
|
36
|
+
var self = this;
|
|
37
|
+
|
|
38
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
39
|
+
if (!accountId) { return cb(new Error('accountId is required'), null); }
|
|
40
|
+
if (!customerId) { return cb(new Error('customerId is required'), null); }
|
|
41
|
+
|
|
42
|
+
self
|
|
43
|
+
.find({ account: accountId, customer: customerId, active: true })
|
|
44
|
+
.sort({ createdOn: -1 })
|
|
45
|
+
.select('scopes createdOn lastUsedOn')
|
|
46
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
47
|
+
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
ApiKey.statics.revoke = function(tokenId, accountId, customerId, cb) {
|
|
51
|
+
|
|
52
|
+
var self = this;
|
|
53
|
+
|
|
54
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
55
|
+
if (!tokenId) { return cb(new Error('tokenId is required'), null); }
|
|
56
|
+
|
|
57
|
+
self.findOneAndUpdate(
|
|
58
|
+
{ _id: tokenId, account: accountId, customer: customerId },
|
|
59
|
+
{ active: false },
|
|
60
|
+
{ new: true }).then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
61
|
+
|
|
62
|
+
};
|
|
63
|
+
ApiKey.set('autoIndex', false);
|
|
64
|
+
ApiKey.on('index', function(err) { console.log('error building ApiKey indexes: ' + err); });
|
|
65
|
+
|
|
66
|
+
mongoose.model('ApiKey', ApiKey);
|
|
67
|
+
|
|
68
|
+
};
|
package/lib/CalendarEvent.js
CHANGED
|
@@ -57,33 +57,33 @@ module.exports = function(mongoose, config) {
|
|
|
57
57
|
var self = this;
|
|
58
58
|
|
|
59
59
|
self
|
|
60
|
-
.
|
|
61
|
-
.exec(cb);
|
|
60
|
+
.findByIdAndDelete(calendarEventId)
|
|
61
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
62
62
|
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
CalendarEvent.statics.findByAccountId = function (accountId, cb) {
|
|
66
66
|
this
|
|
67
67
|
.find({ account: accountId })
|
|
68
|
-
.exec(cb);
|
|
68
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
CalendarEvent.statics.findByCreatedRange = function (since, until, cb) {
|
|
72
72
|
this
|
|
73
73
|
.find({ createdOn: { $gt: since, $lt: until } })
|
|
74
|
-
.exec(cb);
|
|
74
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
CalendarEvent.statics.findByCreatedSince = function (since, cb) {
|
|
78
78
|
this
|
|
79
79
|
.find({ createdOn: { $gt: since } })
|
|
80
|
-
.exec(cb);
|
|
80
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
CalendarEvent.statics.findByEmail = function (email, cb) {
|
|
84
84
|
this
|
|
85
85
|
.find({ email: email })
|
|
86
|
-
.exec(cb);
|
|
86
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
CalendarEvent.statics.findByEmailForRange = function (email, startsAfter, startsBefore, cb) {
|
|
@@ -91,48 +91,48 @@ module.exports = function(mongoose, config) {
|
|
|
91
91
|
var self = this;
|
|
92
92
|
var query = self.find({ email: email });
|
|
93
93
|
query.where({ start: { $gte: startsAfter, $lte: startsBefore }});
|
|
94
|
-
query.exec(cb);
|
|
94
|
+
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
95
95
|
|
|
96
96
|
};
|
|
97
97
|
|
|
98
98
|
CalendarEvent.statics.findByEventId = function (eventId, cb) {
|
|
99
99
|
this
|
|
100
100
|
.findOne({ 'eventId': eventId })
|
|
101
|
-
.exec(cb);
|
|
101
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
102
102
|
};
|
|
103
103
|
|
|
104
104
|
CalendarEvent.statics.findUnprocessedForAccount = function (id, cb) {
|
|
105
105
|
this
|
|
106
106
|
.find({ account: id, processed: false })
|
|
107
107
|
.populate('account', 'email customer')
|
|
108
|
-
.exec(cb);
|
|
108
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
CalendarEvent.statics.findByUsername = function (username, cb) {
|
|
112
112
|
this
|
|
113
113
|
.find({ 'account.username': username })
|
|
114
|
-
.exec(cb);
|
|
114
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
115
115
|
};
|
|
116
116
|
|
|
117
117
|
CalendarEvent.statics.getById = function (id, cb) {
|
|
118
118
|
this
|
|
119
119
|
.findOne({ '_id': id })
|
|
120
120
|
.populate('account', 'email customer')
|
|
121
|
-
.exec(cb);
|
|
121
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
122
122
|
};
|
|
123
123
|
|
|
124
124
|
CalendarEvent.statics.getNewest = function (email, cb) {
|
|
125
125
|
this
|
|
126
126
|
.findOne({email: email})
|
|
127
127
|
.sort({createdOn: -1})
|
|
128
|
-
.exec(cb);
|
|
128
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
129
129
|
};
|
|
130
130
|
|
|
131
131
|
CalendarEvent.statics.getNewestProcessed = function (email, cb) {
|
|
132
132
|
this
|
|
133
133
|
.findOne({ email: email, processed: true })
|
|
134
134
|
.sort({ createdOn: -1 })
|
|
135
|
-
.exec(cb);
|
|
135
|
+
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
136
136
|
};
|
|
137
137
|
|
|
138
138
|
CalendarEvent.statics.markAsProcessed = function markAsProcessed(id, cb) {
|
|
@@ -142,7 +142,7 @@ module.exports = function(mongoose, config) {
|
|
|
142
142
|
var update = { $set: { processed: true } };
|
|
143
143
|
var options = { 'upsert': false, 'new': true };
|
|
144
144
|
|
|
145
|
-
self.findOneAndUpdate(filter, update, options, cb);
|
|
145
|
+
self.findOneAndUpdate(filter, update, options).then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
146
146
|
|
|
147
147
|
};
|
|
148
148
|
|
|
@@ -172,14 +172,10 @@ module.exports = function(mongoose, config) {
|
|
|
172
172
|
raw: calendarEvent.raw
|
|
173
173
|
};
|
|
174
174
|
|
|
175
|
-
self.findOneAndUpdate(query, update, options, cb);
|
|
175
|
+
self.findOneAndUpdate(query, update, options).then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
176
176
|
|
|
177
177
|
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
CalendarEvent.set('usePushEach', true);
|
|
181
178
|
CalendarEvent.set('autoIndex', false);
|
|
182
|
-
CalendarEvent.set('usePushEach', true);
|
|
183
179
|
CalendarEvent.on('index', function(err) { console.log('error building calendar event indexes: ' + err); });
|
|
184
180
|
|
|
185
181
|
mongoose.model('CalendarEvent', CalendarEvent);
|
package/lib/CapTable.js
CHANGED
|
@@ -165,7 +165,7 @@ module.exports = function(mongoose, config) {
|
|
|
165
165
|
query.populate('stakeholders.person', 'name avatarUrl title');
|
|
166
166
|
query.sort({ asOfDate: -1 });
|
|
167
167
|
|
|
168
|
-
query.exec(cb);
|
|
168
|
+
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
169
169
|
|
|
170
170
|
};
|
|
171
171
|
|
|
@@ -178,7 +178,7 @@ module.exports = function(mongoose, config) {
|
|
|
178
178
|
if (!mongoose.Types.ObjectId.isValid(customerid)) { return cb(new Error('customerid is not a valid ObjectId'), null); }
|
|
179
179
|
if (!options) { return cb(new Error('options is required'), null); }
|
|
180
180
|
|
|
181
|
-
self.deleteMany({ customer: customerid, 'entered.by': { $ne: 'carta-parser' } }, cb);
|
|
181
|
+
self.deleteMany({ customer: customerid, 'entered.by': { $ne: 'carta-parser' } }).then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
182
182
|
|
|
183
183
|
};
|
|
184
184
|
|
|
@@ -217,7 +217,7 @@ module.exports = function(mongoose, config) {
|
|
|
217
217
|
query.populate('stakeholders.person', 'name avatarUrl title')
|
|
218
218
|
query.sort({ asOfDate: -1 });
|
|
219
219
|
|
|
220
|
-
query.exec(cb);
|
|
220
|
+
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
221
221
|
|
|
222
222
|
};
|
|
223
223
|
|
|
@@ -251,7 +251,7 @@ module.exports = function(mongoose, config) {
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
query.populate('organization', 'name logoUrl')
|
|
254
|
-
query.exec(cb);
|
|
254
|
+
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
255
255
|
|
|
256
256
|
};
|
|
257
257
|
|
|
@@ -284,7 +284,7 @@ module.exports = function(mongoose, config) {
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
query.populate('organization', 'name logoUrl')
|
|
287
|
-
query.exec(cb);
|
|
287
|
+
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
288
288
|
|
|
289
289
|
};
|
|
290
290
|
|
|
@@ -318,7 +318,7 @@ module.exports = function(mongoose, config) {
|
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
query.populate('organization', 'name logoUrl')
|
|
321
|
-
query.exec(cb);
|
|
321
|
+
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
322
322
|
|
|
323
323
|
};
|
|
324
324
|
|
|
@@ -352,7 +352,7 @@ module.exports = function(mongoose, config) {
|
|
|
352
352
|
}
|
|
353
353
|
|
|
354
354
|
query.populate('organization', 'name logoUrl')
|
|
355
|
-
query.exec(cb);
|
|
355
|
+
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
356
356
|
|
|
357
357
|
};
|
|
358
358
|
|
|
@@ -378,7 +378,7 @@ module.exports = function(mongoose, config) {
|
|
|
378
378
|
|
|
379
379
|
query.populate('organization', 'name logoUrl');
|
|
380
380
|
query.sort({ 'name': -1 });
|
|
381
|
-
query.exec(cb);
|
|
381
|
+
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
382
382
|
|
|
383
383
|
};
|
|
384
384
|
|
|
@@ -420,7 +420,7 @@ module.exports = function(mongoose, config) {
|
|
|
420
420
|
{
|
|
421
421
|
equals: {
|
|
422
422
|
path: 'customer',
|
|
423
|
-
value: mongoose.Types.ObjectId(options.CUSTOMER_ID)
|
|
423
|
+
value: new mongoose.Types.ObjectId(options.CUSTOMER_ID)
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
426
|
],
|
|
@@ -462,7 +462,7 @@ module.exports = function(mongoose, config) {
|
|
|
462
462
|
highlights: { $meta: "searchHighlights" }
|
|
463
463
|
}
|
|
464
464
|
}
|
|
465
|
-
]).exec(cb);
|
|
465
|
+
]).exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
466
466
|
|
|
467
467
|
};
|
|
468
468
|
|
|
@@ -470,13 +470,13 @@ module.exports = function(mongoose, config) {
|
|
|
470
470
|
|
|
471
471
|
if (!capTable) { return cb(new Error('cap table is required'), null); }
|
|
472
472
|
|
|
473
|
-
capTable.save(cb);
|
|
473
|
+
capTable.save().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
474
474
|
|
|
475
475
|
};
|
|
476
476
|
|
|
477
477
|
CapTable.statics.delete = function(id, cb) {
|
|
478
478
|
var self = this;
|
|
479
|
-
self.
|
|
479
|
+
self.findByIdAndDelete(id).then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
480
480
|
};
|
|
481
481
|
|
|
482
482
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
@@ -487,10 +487,7 @@ module.exports = function(mongoose, config) {
|
|
|
487
487
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
488
488
|
// CONFIG
|
|
489
489
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
490
|
-
|
|
491
|
-
CapTable.set('usePushEach', true);
|
|
492
490
|
CapTable.set('toJSON', { virtuals: true });
|
|
493
|
-
CapTable.set('usePushEach', true);
|
|
494
491
|
CapTable.set('autoIndex', false);
|
|
495
492
|
|
|
496
493
|
CapTable.index({ organization: 1, customer: 1, asOfDate: -1 });
|
|
@@ -498,4 +495,4 @@ module.exports = function(mongoose, config) {
|
|
|
498
495
|
|
|
499
496
|
mongoose.model('CapTable', CapTable);
|
|
500
497
|
|
|
501
|
-
};
|
|
498
|
+
};
|