@dhyasama/totem-models 7.57.0 → 8.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/.npmignore +14 -0
- package/helpers.js +89 -0
- package/index.js +0 -1
- package/lib/Account.js +125 -79
- package/lib/Activity.js +0 -2
- package/lib/CalendarEvent.js +1 -7
- package/lib/CapTable.js +0 -1
- package/lib/Deal.js +215 -151
- package/lib/Document.js +57 -56
- package/lib/Financials.js +115 -172
- package/lib/Flag.js +37 -14
- package/lib/Fund.js +6 -33
- package/lib/Interaction.js +79 -32
- package/lib/Investment.js +4 -10
- package/lib/LimitedPartner.js +303 -634
- package/lib/List.js +105 -147
- package/lib/Message.js +100 -51
- package/lib/News.js +1 -53
- package/lib/Note.js +60 -66
- package/lib/Organization.js +470 -645
- package/lib/Person.js +342 -650
- package/lib/Round.js +191 -134
- package/lib/Snapshot.js +3 -5
- package/lib/Webhook.js +1 -4
- package/package-lock.json +1927 -0
- package/package.json +2 -3
- package/test/Account.js +53 -38
- package/test/Deal.js +14 -30
- package/test/Document.js +51 -50
- package/test/Financials.js +5 -3
- package/test/Flag.js +18 -14
- package/test/Interaction.js +1 -31
- package/test/Investment.js +2 -3
- package/test/LimitedPartner.js +399 -554
- package/test/List.js +24 -29
- package/test/Message.js +7 -46
- package/test/News.js +12 -29
- package/test/Note.js +23 -22
- package/test/Organization.js +33 -307
- package/test/Person.js +6 -253
- package/test/Round.js +11 -11
- package/lib/Sync.js +0 -48
package/.npmignore
ADDED
package/helpers.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _ = require('underscore');
|
|
4
|
+
const mongoose = require('mongoose');
|
|
5
|
+
|
|
6
|
+
const cleanOrg = module.exports.cleanOrg = function cleanOrg(doc, customerId) {
|
|
7
|
+
|
|
8
|
+
if (!doc) { return; }
|
|
9
|
+
if (!doc._id) { return; }
|
|
10
|
+
if (!customerId) { return; }
|
|
11
|
+
if (!mongoose.Types.ObjectId.isValid(customerId)) { return; }
|
|
12
|
+
|
|
13
|
+
// remove customer details if not viewing self
|
|
14
|
+
if (doc._id.toString() !== customerId.toString()) { doc.customer = {}; }
|
|
15
|
+
|
|
16
|
+
doc.lps = _.reject(doc.lps, function(item) { return !item.customer || item.customer.toString() !== customerId.toString(); });
|
|
17
|
+
doc.filters = _.reject(doc.filters, function(item) { return !item.customer || item.customer.toString() !== customerId.toString(); });
|
|
18
|
+
doc.valuations = _.reject(doc.valuations, function(item) { return !item.customer || item.customer.toString() !== customerId.toString(); });
|
|
19
|
+
doc.iLevel = _.reject(doc.iLevel, function(item) { return !item.customer || item.customer.toString() !== customerId.toString(); });
|
|
20
|
+
doc.chairs = _.reject(doc.chairs, function(item) { return !item.customer || item.customer.toString() !== customerId.toString(); });
|
|
21
|
+
doc.operating.acquired.private = _.find(doc.operating.acquired.private, function(item) { return !item.customer || item.customer.toString() === customerId.toString(); });
|
|
22
|
+
doc.operating.closed.private = _.find(doc.operating.closed.private, function(item) { return !item.customer || item.customer.toString() === customerId.toString(); });
|
|
23
|
+
|
|
24
|
+
return doc;
|
|
25
|
+
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const cleanPerson = module.exports.cleanPerson = function cleanPerson(doc, customerId) {
|
|
29
|
+
|
|
30
|
+
if (!doc) { return; }
|
|
31
|
+
if (!doc._id) { return; }
|
|
32
|
+
if (!customerId) { return; }
|
|
33
|
+
if (!mongoose.Types.ObjectId.isValid(customerId)) { return; }
|
|
34
|
+
|
|
35
|
+
doc.sources = _.reject(doc.sources, function(source) {
|
|
36
|
+
let sourceCustomerId = mongoose.Types.ObjectId.isValid(source.customer) ? source.customer : source.customer._id;
|
|
37
|
+
return sourceCustomerId.toString() !== customerId.toString();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return doc;
|
|
41
|
+
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const getDefaultOptions = module.exports.getDefaultOptions = function getDefaultOptions(options) {
|
|
45
|
+
|
|
46
|
+
const DEFAULT_OPTIONS = { isWorkerProcess: false, role: 'none' };
|
|
47
|
+
|
|
48
|
+
return _.defaults(options || {}, DEFAULT_OPTIONS);
|
|
49
|
+
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const getPeopleSources = module.exports.getPeopleSources = function getPeopleSources(people) {
|
|
53
|
+
|
|
54
|
+
if (!people) { return []; }
|
|
55
|
+
if (!Array.isArray(people)) { return []; }
|
|
56
|
+
|
|
57
|
+
let result = _.compact(_.pluck(people, 'sources'));
|
|
58
|
+
if (result.length === 0) { return []; }
|
|
59
|
+
|
|
60
|
+
result = _.flatten(result);
|
|
61
|
+
result = _.compact(result);
|
|
62
|
+
|
|
63
|
+
if (result.length === 0) { return []; }
|
|
64
|
+
if (mongoose.Types.ObjectId.isValid(result[0].person)) { return []; } // not populated
|
|
65
|
+
|
|
66
|
+
result = _.uniq(result, function(item) {
|
|
67
|
+
if (!item || !item.person) { return ''; }
|
|
68
|
+
else return item.person._id ? item.person._id.toString() : '';
|
|
69
|
+
});
|
|
70
|
+
result = _.compact(result);
|
|
71
|
+
result = _.reject(result, function(item) { return !item.person; });
|
|
72
|
+
|
|
73
|
+
return result;
|
|
74
|
+
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const sortPeopleSources = module.exports.sortPeopleSources = function sortPeopleSources(items, customerId) {
|
|
78
|
+
|
|
79
|
+
items = _.sortBy(items, function(item) {
|
|
80
|
+
return item.interactionsCount(customerId);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
items.reverse();
|
|
84
|
+
|
|
85
|
+
items = _.sortBy(items, 'name.full');
|
|
86
|
+
|
|
87
|
+
return items;
|
|
88
|
+
|
|
89
|
+
};
|
package/index.js
CHANGED
|
@@ -64,7 +64,6 @@ var bootstrap = function(mongoose, config) {
|
|
|
64
64
|
require('./lib/Message.js')(mongoose, config);
|
|
65
65
|
require('./lib/News.js')(mongoose, config);
|
|
66
66
|
require('./lib/Snapshot.js')(mongoose, config);
|
|
67
|
-
require('./lib/Sync.js')(mongoose, config);
|
|
68
67
|
require('./lib/Webhook.js')(mongoose, config);
|
|
69
68
|
|
|
70
69
|
};
|
package/lib/Account.js
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
module.exports = function(mongoose, config) {
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
let
|
|
6
6
|
|
|
7
7
|
Schema = mongoose.Schema,
|
|
8
|
-
_ = require('underscore')
|
|
8
|
+
_ = require('underscore'),
|
|
9
|
+
helpers = require('../helpers');
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
let Account = new Schema({
|
|
11
12
|
|
|
12
13
|
username: { type: String, required: true, unique: true },
|
|
13
14
|
email: { type: String, required: true, unique: true },
|
|
@@ -72,66 +73,130 @@ module.exports = function(mongoose, config) {
|
|
|
72
73
|
|
|
73
74
|
Account.statics.findByEmail = function(email, cb) {
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
let self = this;
|
|
77
|
+
|
|
78
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
79
|
+
if (!email) { return cb(new Error('email is required'), null); }
|
|
76
80
|
|
|
77
81
|
self
|
|
78
|
-
.findOne({ 'email':
|
|
82
|
+
.findOne({ 'email': email.toLowerCase()})
|
|
79
83
|
.populate('person')
|
|
80
|
-
.exec(
|
|
81
|
-
|
|
84
|
+
.exec(function(err, account) {
|
|
85
|
+
|
|
86
|
+
if (err) { return cb(err); }
|
|
87
|
+
else if (!account) { return cb(null, null); }
|
|
88
|
+
|
|
89
|
+
if (account.populated('person')) {
|
|
90
|
+
|
|
91
|
+
if (account.org) { helpers.cleanPerson(account.person, account.org); }
|
|
92
|
+
else { account.person.sources = []; }
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return cb(null, account);
|
|
82
97
|
|
|
83
|
-
Account.statics.findByUsername = function(username, cb) {
|
|
84
|
-
this
|
|
85
|
-
.findOne({ 'username': new RegExp(username, 'i') })
|
|
86
|
-
.populate('person')
|
|
87
|
-
.exec(function (err, account) {
|
|
88
|
-
cb(err, account);
|
|
89
98
|
});
|
|
90
99
|
};
|
|
91
100
|
|
|
92
101
|
Account.statics.getById = function (id, cb) {
|
|
93
102
|
|
|
94
|
-
this
|
|
95
|
-
.findById(id)
|
|
96
|
-
.populate('person org')
|
|
97
|
-
.exec(function (err, account) {
|
|
98
|
-
if (err) {
|
|
99
|
-
return cb(err, null);
|
|
100
|
-
}
|
|
101
|
-
else if (account && account.person) {
|
|
102
|
-
account.deepPopulate('person.lps.lp', function (err, result) {
|
|
103
|
-
return cb(err, account);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
else if (!account) {
|
|
107
|
-
return cb(new Error('No account with id ' + id.toString()), null);
|
|
108
|
-
}
|
|
109
|
-
else if (account && !account.person) {
|
|
110
|
-
return cb(new Error('Missing person reference on account with id ' + id.toString()), null);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
return cb(new Error('Unknown error'), null);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
103
|
+
const self = this;
|
|
116
104
|
|
|
117
|
-
|
|
105
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
106
|
+
if (!id) { throw new Error('id is required'); }
|
|
107
|
+
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
108
|
+
|
|
109
|
+
let query = self.findById(id);
|
|
110
|
+
|
|
111
|
+
query.populate('person');
|
|
112
|
+
query.populate('org');
|
|
113
|
+
|
|
114
|
+
query.exec(function (err, account) {
|
|
115
|
+
|
|
116
|
+
if (err) {
|
|
117
|
+
return cb(err, null);
|
|
118
|
+
}
|
|
119
|
+
else if (account && account.populated('person') && account.populated('org')) {
|
|
120
|
+
|
|
121
|
+
// Scrub customer info before returning
|
|
122
|
+
|
|
123
|
+
let customerId = account.populated('org');
|
|
124
|
+
|
|
125
|
+
if (account.populated('org')) { helpers.cleanOrg(account.org, customerId); }
|
|
126
|
+
|
|
127
|
+
if (account.populated('person')) { helpers.cleanPerson(account.person, customerId); }
|
|
128
|
+
|
|
129
|
+
return cb(null, account);
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
else if (!account) {
|
|
133
|
+
return cb(new Error('No account with id ' + id.toString()), null);
|
|
134
|
+
}
|
|
135
|
+
else if (account && !account.person) {
|
|
136
|
+
return cb(new Error('Missing person reference on account with id ' + id.toString()), null);
|
|
137
|
+
}
|
|
138
|
+
else if (account && !account.org) {
|
|
139
|
+
return cb(new Error('Missing org reference on account with id ' + id.toString()), null);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
return cb(new Error('Unknown error'), null);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
});
|
|
118
146
|
|
|
119
|
-
Account.statics.getByPersonIds = function (ids, cb) {
|
|
120
|
-
this
|
|
121
|
-
.find({ 'person': { $in : ids } })
|
|
122
|
-
.populate('person', 'name')
|
|
123
|
-
.exec(cb);
|
|
124
147
|
};
|
|
125
148
|
|
|
126
149
|
Account.statics.getForCustomer = function (customerId, cb) {
|
|
127
|
-
|
|
150
|
+
|
|
151
|
+
// No population so no need to scrub
|
|
152
|
+
|
|
153
|
+
const self = this;
|
|
154
|
+
|
|
155
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
156
|
+
if (!customerId) { return cb(new Error('customerId is required'), null); }
|
|
157
|
+
if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
|
|
158
|
+
|
|
159
|
+
self
|
|
128
160
|
.find({ 'org': customerId })
|
|
129
161
|
.exec(cb);
|
|
162
|
+
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
Account.statics.listAllAccounts = function (options, cb) {
|
|
166
|
+
|
|
167
|
+
// This is only for worker
|
|
168
|
+
// Since it's only worker, no need to scrub results
|
|
169
|
+
|
|
170
|
+
const self = this;
|
|
171
|
+
|
|
172
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
173
|
+
|
|
174
|
+
options = helpers.getDefaultOptions(options);
|
|
175
|
+
|
|
176
|
+
if (!options.isWorkerProcess) { return cb(null, []); }
|
|
177
|
+
|
|
178
|
+
self
|
|
179
|
+
.find({'active': true})
|
|
180
|
+
.populate('person')
|
|
181
|
+
.sort({'person.name.last': 1})
|
|
182
|
+
.exec(cb);
|
|
183
|
+
|
|
130
184
|
};
|
|
131
185
|
|
|
132
|
-
Account.statics.listGoogleAccounts = function(cb) {
|
|
186
|
+
Account.statics.listGoogleAccounts = function(options, cb) {
|
|
187
|
+
|
|
188
|
+
// This is only for worker
|
|
189
|
+
// Since it's only worker, no need to scrub results
|
|
190
|
+
|
|
191
|
+
const self = this;
|
|
192
|
+
|
|
193
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
133
194
|
|
|
134
|
-
|
|
195
|
+
options = helpers.getDefaultOptions(options);
|
|
196
|
+
|
|
197
|
+
if (!options.isWorkerProcess) { return cb(null, []); }
|
|
198
|
+
|
|
199
|
+
self
|
|
135
200
|
.find({
|
|
136
201
|
'active': true,
|
|
137
202
|
'calendar.active': true,
|
|
@@ -142,9 +207,20 @@ module.exports = function(mongoose, config) {
|
|
|
142
207
|
|
|
143
208
|
};
|
|
144
209
|
|
|
145
|
-
Account.statics.listMicrosoftAccounts = function(cb) {
|
|
210
|
+
Account.statics.listMicrosoftAccounts = function(options, cb) {
|
|
211
|
+
|
|
212
|
+
// This is only for worker
|
|
213
|
+
// Since it's only worker, no need to scrub results
|
|
214
|
+
|
|
215
|
+
const self = this;
|
|
146
216
|
|
|
147
|
-
|
|
217
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
218
|
+
|
|
219
|
+
options = helpers.getDefaultOptions(options);
|
|
220
|
+
|
|
221
|
+
if (!options.isWorkerProcess) { return cb(null, []); }
|
|
222
|
+
|
|
223
|
+
self
|
|
148
224
|
.find({
|
|
149
225
|
'active': true,
|
|
150
226
|
'calendar.active': true,
|
|
@@ -155,49 +231,19 @@ module.exports = function(mongoose, config) {
|
|
|
155
231
|
|
|
156
232
|
};
|
|
157
233
|
|
|
158
|
-
Account.statics.
|
|
159
|
-
|
|
160
|
-
// sort is done post retrieval because query sort is done pre-decryption
|
|
161
|
-
|
|
162
|
-
this
|
|
163
|
-
.find({'active': true})
|
|
164
|
-
.populate('person')
|
|
165
|
-
.exec(function (err, accounts) {
|
|
166
|
-
return cb(err, _.sortBy(accounts, function(account) {
|
|
167
|
-
if (account.person && account.person.name && account.person.name.last) {
|
|
168
|
-
return account.person.name.last;
|
|
169
|
-
}
|
|
170
|
-
else return '';
|
|
171
|
-
}));
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
};
|
|
234
|
+
Account.statics.upsert = function(account, cb) {
|
|
175
235
|
|
|
176
|
-
|
|
236
|
+
// No population so no need to scrub
|
|
177
237
|
|
|
178
|
-
|
|
179
|
-
this
|
|
180
|
-
.find({'active': true})
|
|
181
|
-
.exec(cb);
|
|
238
|
+
account.save(cb);
|
|
182
239
|
|
|
183
240
|
};
|
|
184
241
|
|
|
185
|
-
Account.statics.upsert = function(account, cb) {
|
|
186
|
-
account.save(cb);
|
|
187
|
-
};
|
|
188
242
|
|
|
189
|
-
Account.post('remove', function(doc) {
|
|
190
|
-
// CalendarEvent.account
|
|
191
|
-
// Person.account
|
|
192
|
-
});
|
|
193
243
|
|
|
194
244
|
Account.set('autoIndex', false);
|
|
195
|
-
Account.set('usePushEach', true);
|
|
196
245
|
Account.on('index', function(err) { console.log('error building account indexes: ' + err); });
|
|
197
246
|
|
|
198
|
-
var deepPopulate = require('mongoose-deep-populate')(mongoose);
|
|
199
|
-
Account.plugin(deepPopulate);
|
|
200
|
-
|
|
201
247
|
mongoose.model('Account', Account);
|
|
202
248
|
|
|
203
249
|
};
|
package/lib/Activity.js
CHANGED
|
@@ -5,7 +5,6 @@ module.exports = function(mongoose, config) {
|
|
|
5
5
|
var
|
|
6
6
|
|
|
7
7
|
Schema = mongoose.Schema,
|
|
8
|
-
env = process.env.NODE_ENV || 'development',
|
|
9
8
|
Geoip = require('@dhyasama/ffvc-geoip'),
|
|
10
9
|
geoip = new Geoip(),
|
|
11
10
|
async = require('async'),
|
|
@@ -131,7 +130,6 @@ module.exports = function(mongoose, config) {
|
|
|
131
130
|
};
|
|
132
131
|
|
|
133
132
|
Activity.set('autoIndex', false);
|
|
134
|
-
Activity.set('usePushEach', true);
|
|
135
133
|
Activity.on('index', function(err) { console.log('error building activity indexes: ' + err); });
|
|
136
134
|
|
|
137
135
|
mongoose.model('Activity', Activity);
|
package/lib/CalendarEvent.js
CHANGED
|
@@ -4,9 +4,7 @@ module.exports = function(mongoose, config) {
|
|
|
4
4
|
|
|
5
5
|
var
|
|
6
6
|
|
|
7
|
-
Schema = mongoose.Schema
|
|
8
|
-
env = process.env.NODE_ENV || 'development',
|
|
9
|
-
_ = require('underscore');
|
|
7
|
+
Schema = mongoose.Schema;
|
|
10
8
|
|
|
11
9
|
var CalendarEvent = new Schema({
|
|
12
10
|
|
|
@@ -178,12 +176,8 @@ module.exports = function(mongoose, config) {
|
|
|
178
176
|
|
|
179
177
|
};
|
|
180
178
|
|
|
181
|
-
CalendarEvent.post('remove', function(doc) {
|
|
182
|
-
// Person.calendarEventId
|
|
183
|
-
});
|
|
184
179
|
|
|
185
180
|
CalendarEvent.set('autoIndex', false);
|
|
186
|
-
CalendarEvent.set('usePushEach', true);
|
|
187
181
|
CalendarEvent.on('index', function(err) { console.log('error building calendar event indexes: ' + err); });
|
|
188
182
|
|
|
189
183
|
mongoose.model('CalendarEvent', CalendarEvent);
|
package/lib/CapTable.js
CHANGED
|
@@ -419,7 +419,6 @@ module.exports = function(mongoose, config) {
|
|
|
419
419
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
420
420
|
|
|
421
421
|
CapTable.set('toJSON', { virtuals: true });
|
|
422
|
-
CapTable.set('usePushEach', true);
|
|
423
422
|
CapTable.set('autoIndex', false);
|
|
424
423
|
|
|
425
424
|
CapTable.index({ organization: 1, customer: 1 }, { unique: true, partialFilterExpression : { type :"string" } });
|