@dhyasama/totem-models 9.4.2 → 9.5.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/CapTable.js +18 -133
- package/package.json +1 -1
package/lib/CapTable.js
CHANGED
|
@@ -34,41 +34,21 @@ module.exports = function(mongoose, config) {
|
|
|
34
34
|
// optional reference to download the cap table file
|
|
35
35
|
document: { type: Schema.ObjectId, ref: 'Document', required: false },
|
|
36
36
|
|
|
37
|
-
// computed on save (via pre-save hook); don't set directly;
|
|
38
|
-
shares: { type: Number, default: 0 },
|
|
39
|
-
|
|
40
37
|
stakeholders: [{
|
|
38
|
+
|
|
39
|
+
_id: false,
|
|
41
40
|
|
|
42
|
-
//
|
|
41
|
+
// the raw stakeholder name on the cap table
|
|
43
42
|
name: { type: String, trim: true, required: true },
|
|
44
43
|
|
|
44
|
+
// the stakeholders shares broken down by round
|
|
45
45
|
rounds: [{
|
|
46
|
-
|
|
46
|
+
_id: false,
|
|
47
|
+
name: { type: String, trim: true, required: true },
|
|
47
48
|
shares: { type: Number, default: 0 },
|
|
48
49
|
}],
|
|
49
50
|
|
|
50
|
-
//
|
|
51
|
-
shares: { type: Number, default: 0 },
|
|
52
|
-
|
|
53
|
-
// computed on save (via pre-save hook); don't set directly;
|
|
54
|
-
ownership: { type: Number, default: 0 },
|
|
55
|
-
|
|
56
|
-
// link stakeholder to a fund in our system
|
|
57
|
-
fund: {
|
|
58
|
-
type: Schema.ObjectId,
|
|
59
|
-
ref: 'Fund',
|
|
60
|
-
default: null,
|
|
61
|
-
required: false,
|
|
62
|
-
validate: {
|
|
63
|
-
validator: function(v) {
|
|
64
|
-
if (v && (this.lp || this.org || this.person)) return false;
|
|
65
|
-
else return true;
|
|
66
|
-
},
|
|
67
|
-
message: 'A stakeholder can only be linked to one of the following: fund, lp, org, person'
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
// link stakeholder to a lp in our system
|
|
51
|
+
// stakeholder reference to an lp
|
|
72
52
|
lp: {
|
|
73
53
|
type: Schema.ObjectId,
|
|
74
54
|
ref: 'LimitedPartner',
|
|
@@ -76,14 +56,14 @@ module.exports = function(mongoose, config) {
|
|
|
76
56
|
required: false,
|
|
77
57
|
validate: {
|
|
78
58
|
validator: function(v) {
|
|
79
|
-
if (v && (this.
|
|
59
|
+
if (v && (this.org || this.person)) return false;
|
|
80
60
|
else return true;
|
|
81
61
|
},
|
|
82
|
-
message: 'A stakeholder can only be linked to one of the following:
|
|
62
|
+
message: 'A stakeholder can only be linked to one of the following: lp, org, person'
|
|
83
63
|
}
|
|
84
64
|
},
|
|
85
65
|
|
|
86
|
-
//
|
|
66
|
+
// stakeholder reference to an org
|
|
87
67
|
org: {
|
|
88
68
|
type: Schema.ObjectId,
|
|
89
69
|
ref: 'Organization',
|
|
@@ -91,14 +71,14 @@ module.exports = function(mongoose, config) {
|
|
|
91
71
|
required: false,
|
|
92
72
|
validate: {
|
|
93
73
|
validator: function(v) {
|
|
94
|
-
if (v && (this.
|
|
74
|
+
if (v && (this.lp || this.person)) return false;
|
|
95
75
|
else return true;
|
|
96
76
|
},
|
|
97
|
-
message: 'A stakeholder can only be linked to one of the following:
|
|
77
|
+
message: 'A stakeholder can only be linked to one of the following: lp, org, person'
|
|
98
78
|
}
|
|
99
79
|
},
|
|
100
80
|
|
|
101
|
-
//
|
|
81
|
+
// stakeholder reference to an person
|
|
102
82
|
person: {
|
|
103
83
|
type: Schema.ObjectId,
|
|
104
84
|
ref: 'Person',
|
|
@@ -106,12 +86,12 @@ module.exports = function(mongoose, config) {
|
|
|
106
86
|
required: false,
|
|
107
87
|
validate: {
|
|
108
88
|
validator: function(v) {
|
|
109
|
-
if (v && (this.
|
|
89
|
+
if (v && (this.lp || this.org)) return false;
|
|
110
90
|
else return true;
|
|
111
91
|
},
|
|
112
|
-
message: 'A stakeholder can only be linked to one of the following:
|
|
92
|
+
message: 'A stakeholder can only be linked to one of the following: lp, org, person'
|
|
113
93
|
}
|
|
114
|
-
}
|
|
94
|
+
}
|
|
115
95
|
|
|
116
96
|
}],
|
|
117
97
|
|
|
@@ -127,33 +107,6 @@ module.exports = function(mongoose, config) {
|
|
|
127
107
|
// Properties that are not persisted to the database
|
|
128
108
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
129
109
|
|
|
130
|
-
CapTable.virtual('stakeholdersByRound').get(function () {
|
|
131
|
-
|
|
132
|
-
var self = this;
|
|
133
|
-
|
|
134
|
-
var stakeholdersByRound = [];
|
|
135
|
-
|
|
136
|
-
_.each(self.stakeholders, function(stakeholder) {
|
|
137
|
-
_.each(stakeholder.rounds, function(round) {
|
|
138
|
-
|
|
139
|
-
var roundMatch = _.find(stakeholdersByRound, function(r) { return r.round == round.round });
|
|
140
|
-
|
|
141
|
-
if(roundMatch) {
|
|
142
|
-
roundMatch.stakeholders.push(stakeholder);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
else {
|
|
146
|
-
stakeholdersByRound.push({round: round.round, stakeholders: []});
|
|
147
|
-
_.last(stakeholdersByRound).stakeholders.push(stakeholder);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
return stakeholdersByRound;
|
|
154
|
-
|
|
155
|
-
});
|
|
156
|
-
|
|
157
110
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
158
111
|
// METHODS
|
|
159
112
|
// Methods operate on a single document that has already been returned
|
|
@@ -171,7 +124,6 @@ module.exports = function(mongoose, config) {
|
|
|
171
124
|
|
|
172
125
|
self
|
|
173
126
|
.findOne({customer: customerId, organization: orgId })
|
|
174
|
-
.populate('stakeholders.fund', 'name shortName')
|
|
175
127
|
.populate('stakeholders.lp', 'name')
|
|
176
128
|
.populate('stakeholders.org', 'name logoUrl')
|
|
177
129
|
.populate('stakeholders.person', 'name avatarUrl title')
|
|
@@ -197,7 +149,6 @@ module.exports = function(mongoose, config) {
|
|
|
197
149
|
query.populate('organization', 'name logoUrl');
|
|
198
150
|
|
|
199
151
|
if(options.populateStakeholders) {
|
|
200
|
-
query.populate('stakeholders.fund', 'name shortName')
|
|
201
152
|
query.populate('stakeholders.lp', 'name')
|
|
202
153
|
query.populate('stakeholders.org', 'name logoUrl')
|
|
203
154
|
query.populate('stakeholders.person', 'name avatarUrl title')
|
|
@@ -212,28 +163,6 @@ module.exports = function(mongoose, config) {
|
|
|
212
163
|
self.remove({ customer: customerId, 'entered.by': { $ne: 'carta-parser' } }, cb);
|
|
213
164
|
};
|
|
214
165
|
|
|
215
|
-
CapTable.statics.getByFunds = function getByFunds(fundIds, cb) {
|
|
216
|
-
|
|
217
|
-
var self = this;
|
|
218
|
-
|
|
219
|
-
self
|
|
220
|
-
.find({ 'stakeholders.fund': { $in: fundIds } })
|
|
221
|
-
.populate('organization', 'name logoUrl')
|
|
222
|
-
.exec(cb);
|
|
223
|
-
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
CapTable.statics.getByFund = function getByFund(fundId, cb) {
|
|
227
|
-
|
|
228
|
-
var self = this;
|
|
229
|
-
|
|
230
|
-
self
|
|
231
|
-
.find({ 'stakeholders.fund': fundId })
|
|
232
|
-
.populate('organization', 'name logoUrl')
|
|
233
|
-
.exec(cb);
|
|
234
|
-
|
|
235
|
-
};
|
|
236
|
-
|
|
237
166
|
CapTable.statics.getByLP = function getByLP(lpId, cb) {
|
|
238
167
|
|
|
239
168
|
var self = this;
|
|
@@ -298,12 +227,7 @@ module.exports = function(mongoose, config) {
|
|
|
298
227
|
capTable.entered.by = username;
|
|
299
228
|
capTable.entered.on = new Date();
|
|
300
229
|
|
|
301
|
-
self.update(
|
|
302
|
-
{ '_id': capTable._id },
|
|
303
|
-
capTable,
|
|
304
|
-
{ upsert: false, multi: false, overwrite: true },
|
|
305
|
-
cb
|
|
306
|
-
);
|
|
230
|
+
self.update({ '_id': capTable._id }, capTable, { upsert: false, multi: false, overwrite: true }, cb);
|
|
307
231
|
|
|
308
232
|
};
|
|
309
233
|
|
|
@@ -324,8 +248,7 @@ module.exports = function(mongoose, config) {
|
|
|
324
248
|
query = self.find({
|
|
325
249
|
customer: options.CUSTOMER_ID,
|
|
326
250
|
'stakeholders.name': new RegExp(terms, 'i'),
|
|
327
|
-
'stakeholders.person': null
|
|
328
|
-
'stakeholders.fund': null
|
|
251
|
+
'stakeholders.person': null
|
|
329
252
|
});
|
|
330
253
|
|
|
331
254
|
query.populate('organization', 'name logoUrl');
|
|
@@ -352,44 +275,6 @@ module.exports = function(mongoose, config) {
|
|
|
352
275
|
// Pre-save: fired on every document before it is saved
|
|
353
276
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
354
277
|
|
|
355
|
-
CapTable.pre('save', function(next) {
|
|
356
|
-
|
|
357
|
-
var self = this;
|
|
358
|
-
|
|
359
|
-
// Sum each stakeholders shares
|
|
360
|
-
_.each(self.stakeholders, function(stakeholder) {
|
|
361
|
-
|
|
362
|
-
var shares = _.reduce(stakeholder.rounds, function(memo, i) {
|
|
363
|
-
return memo + i.shares;
|
|
364
|
-
}, 0);
|
|
365
|
-
|
|
366
|
-
stakeholder.shares = shares;
|
|
367
|
-
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
// Sum total shares
|
|
371
|
-
self.shares = _.reduce(self.stakeholders, function(memo, stakeholder) {
|
|
372
|
-
return memo + stakeholder.shares;
|
|
373
|
-
}, 0);
|
|
374
|
-
|
|
375
|
-
// Calculate each stakeholders ownership
|
|
376
|
-
_.each(self.stakeholders, function(stakeholder) {
|
|
377
|
-
if (self.shares == 0) stakeholder.shares = 0;
|
|
378
|
-
else stakeholder.ownership = ((stakeholder.shares / self.shares) * 100).toFixed(2);
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
return next();
|
|
382
|
-
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
CapTable.post('init', function(doc, next) {
|
|
386
|
-
|
|
387
|
-
doc.stakeholders = _.sortBy(doc.stakeholders, 'ownership').reverse();
|
|
388
|
-
|
|
389
|
-
return next();
|
|
390
|
-
|
|
391
|
-
});
|
|
392
|
-
|
|
393
278
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
394
279
|
// CONFIG
|
|
395
280
|
///////////////////////////////////////////////////////////////////////////////////////
|