@dhyasama/totem-models 8.107.0 → 8.109.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 +58 -18
- package/package.json +1 -1
package/lib/CapTable.js
CHANGED
|
@@ -58,7 +58,7 @@ module.exports = function(mongoose, config) {
|
|
|
58
58
|
required: false,
|
|
59
59
|
validate: {
|
|
60
60
|
validator: function(v) {
|
|
61
|
-
if (v && this.lp || this.org || this.person) return false;
|
|
61
|
+
if (v && (this.lp || this.org || this.person)) return false;
|
|
62
62
|
else return true;
|
|
63
63
|
},
|
|
64
64
|
message: 'A stakeholder can only be linked to one of the following: fund, lp, org, person'
|
|
@@ -73,7 +73,7 @@ module.exports = function(mongoose, config) {
|
|
|
73
73
|
required: false,
|
|
74
74
|
validate: {
|
|
75
75
|
validator: function(v) {
|
|
76
|
-
if (v
|
|
76
|
+
if (v && (this.fund || this.org || this.person)) return false;
|
|
77
77
|
else return true;
|
|
78
78
|
},
|
|
79
79
|
message: 'A stakeholder can only be linked to one of the following: fund, lp, org, person'
|
|
@@ -88,7 +88,7 @@ module.exports = function(mongoose, config) {
|
|
|
88
88
|
required: false,
|
|
89
89
|
validate: {
|
|
90
90
|
validator: function(v) {
|
|
91
|
-
if (v
|
|
91
|
+
if (v && (this.fund || this.lp || this.person)) return false;
|
|
92
92
|
else return true;
|
|
93
93
|
},
|
|
94
94
|
message: 'A stakeholder can only be linked to one of the following: fund, lp, org, person'
|
|
@@ -103,7 +103,7 @@ module.exports = function(mongoose, config) {
|
|
|
103
103
|
required: false,
|
|
104
104
|
validate: {
|
|
105
105
|
validator: function(v) {
|
|
106
|
-
if (v && this.fund || this.lp || this.org) return false;
|
|
106
|
+
if (v && (this.fund || this.lp || this.org)) return false;
|
|
107
107
|
else return true;
|
|
108
108
|
},
|
|
109
109
|
message: 'A stakeholder can only be linked to one of the following: fund, lp, org, person'
|
|
@@ -269,64 +269,104 @@ module.exports = function(mongoose, config) {
|
|
|
269
269
|
self.findByIdAndRemove(id, cb);
|
|
270
270
|
};
|
|
271
271
|
|
|
272
|
+
CapTable.statics.getForCustomer = function getForCustomer(orgId, customerId, cb) {
|
|
273
|
+
|
|
274
|
+
var self = this;
|
|
275
|
+
|
|
276
|
+
self
|
|
277
|
+
.findOne({customer: customerId, organization: orgId })
|
|
278
|
+
query.populate('stakeholders.fund', 'name shortName')
|
|
279
|
+
query.populate('stakeholders.lp', 'name')
|
|
280
|
+
query.populate('stakeholders.org', 'name logoUrl')
|
|
281
|
+
query.populate('stakeholders.person', 'name avatarUrl title')
|
|
282
|
+
.exec(cb);
|
|
283
|
+
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
CapTable.statics.getAllForCustomer = function getAllForCustomer(options, cb) {
|
|
287
|
+
|
|
288
|
+
var self = this;
|
|
289
|
+
|
|
290
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
291
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
292
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
293
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
294
|
+
|
|
295
|
+
var query;
|
|
296
|
+
|
|
297
|
+
query = self.find({
|
|
298
|
+
customer: options.CUSTOMER_ID,
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
query.populate('organization', 'name logoUrl');
|
|
302
|
+
|
|
303
|
+
if(options.populateStakeholders) {
|
|
304
|
+
query.populate('stakeholders.fund', 'name shortName')
|
|
305
|
+
query.populate('stakeholders.lp', 'name')
|
|
306
|
+
query.populate('stakeholders.org', 'name logoUrl')
|
|
307
|
+
query.populate('stakeholders.person', 'name avatarUrl title')
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
query.exec(cb);
|
|
311
|
+
|
|
312
|
+
};
|
|
313
|
+
|
|
272
314
|
CapTable.statics.deleteAllForCustomer = function(customerId, cb) {
|
|
273
315
|
var self = this;
|
|
274
316
|
self.remove({ customer: customerId, 'entered.by': { $ne: 'carta-parser' } }, cb);
|
|
275
317
|
};
|
|
276
318
|
|
|
277
|
-
CapTable.statics.
|
|
319
|
+
CapTable.statics.getByFunds = function getByFunds(fundIds, cb) {
|
|
278
320
|
|
|
279
321
|
var self = this;
|
|
280
322
|
|
|
281
323
|
self
|
|
282
|
-
.find({
|
|
324
|
+
.find({ 'stakeholders.fund': { $in: fundIds } })
|
|
283
325
|
.populate('organization', 'name logoUrl')
|
|
284
326
|
.exec(cb);
|
|
285
327
|
|
|
286
328
|
};
|
|
287
329
|
|
|
288
|
-
CapTable.statics.
|
|
330
|
+
CapTable.statics.getByFund = function getByFund(fundId, cb) {
|
|
289
331
|
|
|
290
332
|
var self = this;
|
|
291
333
|
|
|
292
334
|
self
|
|
293
|
-
.find({
|
|
294
|
-
.populate('
|
|
295
|
-
.populate('stakeholders.fund', 'name shortName')
|
|
335
|
+
.find({ 'stakeholders.fund': fundId })
|
|
336
|
+
.populate('organization', 'name logoUrl')
|
|
296
337
|
.exec(cb);
|
|
297
338
|
|
|
298
339
|
};
|
|
299
340
|
|
|
300
|
-
CapTable.statics.
|
|
341
|
+
CapTable.statics.getByLP = function getByLP(lpId, cb) {
|
|
301
342
|
|
|
302
343
|
var self = this;
|
|
303
344
|
|
|
304
345
|
self
|
|
305
|
-
.find({ 'stakeholders.
|
|
346
|
+
.find({ 'stakeholders.lp': lpId })
|
|
306
347
|
.populate('organization', 'name logoUrl')
|
|
307
348
|
.exec(cb);
|
|
308
349
|
|
|
309
350
|
};
|
|
310
351
|
|
|
311
|
-
CapTable.statics.
|
|
352
|
+
CapTable.statics.getByOrg = function getByOrg(orgId, cb) {
|
|
312
353
|
|
|
313
354
|
var self = this;
|
|
314
355
|
|
|
315
356
|
self
|
|
316
|
-
.find({ 'stakeholders.
|
|
357
|
+
.find({ 'stakeholders.org': orgId })
|
|
317
358
|
.populate('organization', 'name logoUrl')
|
|
318
359
|
.exec(cb);
|
|
319
360
|
|
|
320
361
|
};
|
|
321
362
|
|
|
322
|
-
CapTable.statics.
|
|
363
|
+
CapTable.statics.getByPerson = function getByPerson(personId, cb) {
|
|
323
364
|
|
|
324
365
|
var self = this;
|
|
325
366
|
|
|
326
367
|
self
|
|
327
|
-
.
|
|
328
|
-
.populate('
|
|
329
|
-
.populate('stakeholders.fund', 'name shortName')
|
|
368
|
+
.find({ 'stakeholders.person': personId })
|
|
369
|
+
.populate('organization', 'name logoUrl')
|
|
330
370
|
.exec(cb);
|
|
331
371
|
|
|
332
372
|
};
|