@dhyasama/totem-models 9.50.0 → 9.52.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/lib/Organization.js +4 -4
- package/lib/Round.js +0 -90
- package/package.json +1 -1
package/lib/Organization.js
CHANGED
|
@@ -249,7 +249,7 @@ module.exports = function(mongoose, config) {
|
|
|
249
249
|
filters: [{
|
|
250
250
|
_id: false,
|
|
251
251
|
key: { type: String, trim: true },
|
|
252
|
-
condition: { type: String, enum: [null, 'equals', 'doesNotEqual', 'contains', 'doesNotContain', 'lessThan', 'greaterThan']},
|
|
252
|
+
condition: { type: String, enum: [null, 'equals', 'doesNotEqual', 'contains', 'doesNotContain', 'lessThan', 'greaterThan', 'isEmpty', 'isNotEmpty']},
|
|
253
253
|
values: [{ type: String, trim: true }]
|
|
254
254
|
}],
|
|
255
255
|
sort: {
|
|
@@ -367,7 +367,7 @@ module.exports = function(mongoose, config) {
|
|
|
367
367
|
filters: [{
|
|
368
368
|
_id: false,
|
|
369
369
|
key: { type: String, trim: true },
|
|
370
|
-
condition: { type: String, enum: [null, 'equals', 'doesNotEqual', 'contains', 'doesNotContain', 'lessThan', 'greaterThan']},
|
|
370
|
+
condition: { type: String, enum: [null, 'equals', 'doesNotEqual', 'contains', 'doesNotContain', 'lessThan', 'greaterThan', 'isEmpty', 'isNotEmpty']},
|
|
371
371
|
values: [{ type: String, trim: true }]
|
|
372
372
|
}],
|
|
373
373
|
sort: {
|
|
@@ -430,7 +430,7 @@ module.exports = function(mongoose, config) {
|
|
|
430
430
|
filters: [{
|
|
431
431
|
_id: false,
|
|
432
432
|
key: { type: String, trim: true },
|
|
433
|
-
condition: { type: String, enum: [null, 'equals', 'doesNotEqual', 'contains', 'doesNotContain', 'lessThan', 'greaterThan']},
|
|
433
|
+
condition: { type: String, enum: [null, 'equals', 'doesNotEqual', 'contains', 'doesNotContain', 'lessThan', 'greaterThan', 'isEmpty', 'isNotEmpty']},
|
|
434
434
|
values: [{ type: String, trim: true }]
|
|
435
435
|
}],
|
|
436
436
|
sort: {
|
|
@@ -495,7 +495,7 @@ module.exports = function(mongoose, config) {
|
|
|
495
495
|
filters: [{
|
|
496
496
|
_id: false,
|
|
497
497
|
key: { type: String, trim: true },
|
|
498
|
-
condition: { type: String, enum: [null, 'equals', 'doesNotEqual', 'contains', 'doesNotContain', 'lessThan', 'greaterThan']},
|
|
498
|
+
condition: { type: String, enum: [null, 'equals', 'doesNotEqual', 'contains', 'doesNotContain', 'lessThan', 'greaterThan', 'isEmpty', 'isNotEmpty']},
|
|
499
499
|
values: [{ type: String, trim: true }]
|
|
500
500
|
}],
|
|
501
501
|
sort: {
|
package/lib/Round.js
CHANGED
|
@@ -29,14 +29,6 @@ module.exports = function(mongoose, config) {
|
|
|
29
29
|
|
|
30
30
|
roundName: { type: String, trim: true, required: true },
|
|
31
31
|
|
|
32
|
-
// People that participated in this round
|
|
33
|
-
// This is a public list of people that invested
|
|
34
|
-
// Use the addPerson method and removePerson static
|
|
35
|
-
people: [{
|
|
36
|
-
person: { type: Schema.ObjectId, ref: 'Person', index: true },
|
|
37
|
-
_id: false
|
|
38
|
-
}],
|
|
39
|
-
|
|
40
32
|
// Investment vehicles that participated in this round
|
|
41
33
|
// Currently only funds. May expand to SPVs.
|
|
42
34
|
// Recall that a fund belongs to an organization
|
|
@@ -146,15 +138,11 @@ module.exports = function(mongoose, config) {
|
|
|
146
138
|
// Fuck shit up so it gets taken care of
|
|
147
139
|
|
|
148
140
|
var vehicles = _.compact(_.flatten(_.pluck(rounds, 'vehicles')));
|
|
149
|
-
var people = _.compact(_.flatten(_.pluck(rounds, 'people')));
|
|
150
141
|
var badData = null;
|
|
151
142
|
|
|
152
143
|
badData = _.find(rounds, function(item) { return !item.organization; });
|
|
153
144
|
if (badData) return new Error(fnName + ' has one or more orgs that is not populated which means there is bad data');
|
|
154
145
|
|
|
155
|
-
badData = _.find(people, function(p) { return !p.person; });
|
|
156
|
-
if (badData) return new Error(fnName + ' has one or more people that is not populated which means there is bad data');
|
|
157
|
-
|
|
158
146
|
badData = _.find(vehicles, function(item) { return !item.fund; });
|
|
159
147
|
if (badData) return new Error(fnName + ' has one or more funds that is not populated which means there is bad data');
|
|
160
148
|
|
|
@@ -244,34 +232,6 @@ module.exports = function(mongoose, config) {
|
|
|
244
232
|
|
|
245
233
|
};
|
|
246
234
|
|
|
247
|
-
Round.methods.addPerson = function addPerson(person) {
|
|
248
|
-
|
|
249
|
-
// Add a reference to a person that participated in this round
|
|
250
|
-
|
|
251
|
-
var self = this;
|
|
252
|
-
|
|
253
|
-
if (!person) throw new Error('Must supply person to add');
|
|
254
|
-
|
|
255
|
-
// Do our best to accept an object or an objectid
|
|
256
|
-
if (!mongoose.Types.ObjectId.isValid(person)) {
|
|
257
|
-
person = person._id;
|
|
258
|
-
if (!mongoose.Types.ObjectId.isValid(person)) throw new Error('Need a valid objectid!');
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// Check if person is already added
|
|
262
|
-
var match = _.find(self.people, function(existingPerson) {
|
|
263
|
-
var p = existingPerson.person || existingPerson;
|
|
264
|
-
var id = mongoose.Types.ObjectId.isValid(p) ? p : p._id;
|
|
265
|
-
return id.toString() === person.toString();
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
// If not, add it
|
|
269
|
-
if (!match) self.people.push({
|
|
270
|
-
person: person
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
};
|
|
274
|
-
|
|
275
235
|
Round.methods.addVehicle = function addVehicle(fund) {
|
|
276
236
|
|
|
277
237
|
// Add a vehicle, which is a fund
|
|
@@ -338,7 +298,6 @@ module.exports = function(mongoose, config) {
|
|
|
338
298
|
});
|
|
339
299
|
|
|
340
300
|
query.populate('organization', 'name logoUrl website websiteAliases');
|
|
341
|
-
query.populate('people.person', 'name avatarUrl title');
|
|
342
301
|
query.populate('vehicles.fund', 'name shortName');
|
|
343
302
|
|
|
344
303
|
if (options.isWorkerProcess) {
|
|
@@ -399,7 +358,6 @@ module.exports = function(mongoose, config) {
|
|
|
399
358
|
});
|
|
400
359
|
|
|
401
360
|
query.populate('organization', 'name logoUrl website websiteAliases');
|
|
402
|
-
query.populate('people.person', 'name avatarUrl');
|
|
403
361
|
query.populate('vehicles.fund');
|
|
404
362
|
|
|
405
363
|
if (options.isWorkerProcess) {
|
|
@@ -646,40 +604,6 @@ module.exports = function(mongoose, config) {
|
|
|
646
604
|
|
|
647
605
|
};
|
|
648
606
|
|
|
649
|
-
Round.statics.getPortfolioByPerson = function getPortfolioByPerson(personId, options, cb) {
|
|
650
|
-
|
|
651
|
-
// Returns a list of orgs that have rounds participated in by the given person id
|
|
652
|
-
|
|
653
|
-
if (!cb) { throw new Error('cb is required'); }
|
|
654
|
-
if (!personId) { throw new Error('personId is required'); }
|
|
655
|
-
if (!mongoose.Types.ObjectId.isValid(personId)) { return cb(new Error('personId is not a valid ObjectId'), null); }
|
|
656
|
-
|
|
657
|
-
const self = this;
|
|
658
|
-
|
|
659
|
-
let query = self.find({ 'people.person': personId });
|
|
660
|
-
|
|
661
|
-
query.select('organization');
|
|
662
|
-
query.populate('organization', 'name logoUrl description website websiteAliases');
|
|
663
|
-
|
|
664
|
-
query.exec(function(err, rounds) {
|
|
665
|
-
|
|
666
|
-
if (err) return cb(err, null);
|
|
667
|
-
if (!rounds || rounds.length === 0) return cb(null, []);
|
|
668
|
-
|
|
669
|
-
let error = checkForUnpopulatedData(rounds, 'Round.getPortfolioByPerson');
|
|
670
|
-
if (error) return cb(error, null);
|
|
671
|
-
|
|
672
|
-
// Return a list of orgs, not a list of rounds
|
|
673
|
-
let portfolio = _.pluck(rounds, 'organization');
|
|
674
|
-
portfolio = _.uniq(portfolio, function(org) { return org.name; });
|
|
675
|
-
portfolio = _.sortBy(portfolio, 'name');
|
|
676
|
-
|
|
677
|
-
return cb(null, portfolio);
|
|
678
|
-
|
|
679
|
-
});
|
|
680
|
-
|
|
681
|
-
};
|
|
682
|
-
|
|
683
607
|
Round.statics.removeInvestment = function(investmentId, cb) {
|
|
684
608
|
|
|
685
609
|
// Do not call this directly. It will leave an orphaned investment document.
|
|
@@ -714,20 +638,6 @@ module.exports = function(mongoose, config) {
|
|
|
714
638
|
|
|
715
639
|
};
|
|
716
640
|
|
|
717
|
-
Round.statics.removePerson = function(roundId, personId, cb) {
|
|
718
|
-
|
|
719
|
-
const self = this;
|
|
720
|
-
|
|
721
|
-
self
|
|
722
|
-
.findOneAndUpdate(
|
|
723
|
-
{ '_id': roundId },
|
|
724
|
-
{ $pull : { 'people': { 'person': personId } } },
|
|
725
|
-
{ multi : false }
|
|
726
|
-
)
|
|
727
|
-
.exec(cb);
|
|
728
|
-
|
|
729
|
-
};
|
|
730
|
-
|
|
731
641
|
Round.statics.removeVehicle = function(roundId, fundId, cb) {
|
|
732
642
|
|
|
733
643
|
const self = this;
|