@dhyasama/totem-models 9.10.0 → 9.11.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/Fund.js CHANGED
@@ -16,11 +16,6 @@ module.exports = function(mongoose, config) {
16
16
  closeDate: { type: Date },
17
17
  amount: { type: Number },
18
18
  crunchbase: { uuid: { type: String, default: '', unique: true } },
19
- transactions: [{
20
- type: { type: String, enum: ['fees', 'expenses', 'carry'] },
21
- amount: { type: Number, default: 0 },
22
- date: { type: Date, default: null },
23
- }],
24
19
  customFields: { type: Schema.Types.Mixed },
25
20
 
26
21
  // the stakeholders names we match to on cap tables
@@ -143,18 +138,6 @@ module.exports = function(mongoose, config) {
143
138
 
144
139
  };
145
140
 
146
- Fund.statics.removeTransactions = function removeTransactions(cb) {
147
-
148
- const self = this;
149
-
150
- let query = self.update(
151
- { $set: { transactions: [] } },
152
- { multi : true }
153
- );
154
- query.exec(cb);
155
-
156
- };
157
-
158
141
  Fund.statics.modify = function(filter, update, cb) {
159
142
 
160
143
  // VERY IMPORTANT NOTE
@@ -39,9 +39,10 @@ module.exports = function(mongoose, config) {
39
39
 
40
40
  transactions: [{
41
41
  fund: {type: Schema.ObjectId, ref: 'Fund'},
42
- type: { type: String, enum: ['commitment', 'contribution', 'distribution'] },
42
+ type: { type: String, enum: ['commitment', 'contribution', 'distribution', 'fee', 'expense', 'carry', 'income', 'realized', 'unrealized'] },
43
43
  amount: { type: Number, default: 0 },
44
44
  date: { type: Date, default: null },
45
+ description: { type: String, default: '' },
45
46
  }],
46
47
 
47
48
  contact: {
@@ -134,6 +135,48 @@ module.exports = function(mongoose, config) {
134
135
  }, 0);
135
136
  });
136
137
 
138
+ LimitedPartner.virtual('totalFee').get(function () {
139
+ var self = this;
140
+ return _.reduce(self.transactions, function(memo, transaction) {
141
+ return memo + ((transaction.type === 'fee' && Math.abs(transaction.amount) > 0) ? transaction.amount : 0);
142
+ }, 0);
143
+ });
144
+
145
+ LimitedPartner.virtual('totalExpense').get(function () {
146
+ var self = this;
147
+ return _.reduce(self.transactions, function(memo, transaction) {
148
+ return memo + ((transaction.type === 'expense' && Math.abs(transaction.amount) > 0) ? transaction.amount : 0);
149
+ }, 0);
150
+ });
151
+
152
+ LimitedPartner.virtual('totalCarry').get(function () {
153
+ var self = this;
154
+ return _.reduce(self.transactions, function(memo, transaction) {
155
+ return memo + ((transaction.type === 'carry' && Math.abs(transaction.amount) > 0) ? transaction.amount : 0);
156
+ }, 0);
157
+ });
158
+
159
+ LimitedPartner.virtual('totalIncome').get(function () {
160
+ var self = this;
161
+ return _.reduce(self.transactions, function(memo, transaction) {
162
+ return memo + ((transaction.type === 'income' && Math.abs(transaction.amount) > 0) ? transaction.amount : 0);
163
+ }, 0);
164
+ });
165
+
166
+ LimitedPartner.virtual('totalRealized').get(function () {
167
+ var self = this;
168
+ return _.reduce(self.transactions, function(memo, transaction) {
169
+ return memo + ((transaction.type === 'realized' && Math.abs(transaction.amount) > 0) ? transaction.amount : 0);
170
+ }, 0);
171
+ });
172
+
173
+ LimitedPartner.virtual('totalUnrealized').get(function () {
174
+ var self = this;
175
+ return _.reduce(self.transactions, function(memo, transaction) {
176
+ return memo + ((transaction.type === 'unrealized' && Math.abs(transaction.amount) > 0) ? transaction.amount : 0);
177
+ }, 0);
178
+ });
179
+
137
180
  LimitedPartner.virtual('fundsInvested').get(function () {
138
181
 
139
182
  var self = this;
@@ -151,7 +194,13 @@ module.exports = function(mongoose, config) {
151
194
  abbreviation: transaction.fund.abbreviation,
152
195
  commitment: 0,
153
196
  contribution: 0,
154
- distribution: 0
197
+ distribution: 0,
198
+ fee: 0,
199
+ expense: 0,
200
+ carry: 0,
201
+ income: 0,
202
+ realized: 0,
203
+ unrealized: 0
155
204
  });
156
205
  fundMatch = _.last(fundsInvested);
157
206
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "9.10.0",
3
+ "version": "9.11.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",