@dhyasama/totem-models 9.5.0 → 9.6.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.
Files changed (2) hide show
  1. package/lib/CapTable.js +84 -20
  2. package/package.json +1 -1
package/lib/CapTable.js CHANGED
@@ -107,6 +107,22 @@ module.exports = function(mongoose, config) {
107
107
  // Properties that are not persisted to the database
108
108
  ///////////////////////////////////////////////////////////////////////////////////////
109
109
 
110
+ CapTable.virtual('shares').get(function() {
111
+
112
+ var self = this;
113
+
114
+ var shares = 0;
115
+
116
+ _.each(self.stakeholders, function(stakeholder) {
117
+ _.each(stakeholder.rounds, function(round) {
118
+ shares += round.shares;
119
+ });
120
+ });
121
+
122
+ return shares;
123
+
124
+ });
125
+
110
126
  ///////////////////////////////////////////////////////////////////////////////////////
111
127
  // METHODS
112
128
  // Methods operate on a single document that has already been returned
@@ -118,20 +134,47 @@ module.exports = function(mongoose, config) {
118
134
  // Statics operate on the entire collection
119
135
  //////////////////////////////////////////////////////
120
136
 
121
- CapTable.statics.getForCustomer = function getForCustomer(orgId, customerId, cb) {
137
+ CapTable.statics.getForCustomer = function getForCustomer(options, cb) {
122
138
 
123
139
  var self = this;
124
140
 
125
- self
126
- .findOne({customer: customerId, organization: orgId })
127
- .populate('stakeholders.lp', 'name')
128
- .populate('stakeholders.org', 'name logoUrl')
129
- .populate('stakeholders.person', 'name avatarUrl title')
130
- .exec(cb);
141
+ if (!cb) { throw new Error('cb is required'); }
142
+ if (!options) { return cb(new Error('options is required'), null); }
143
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
144
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
145
+
146
+ var query;
147
+
148
+ query = self.find({
149
+ customer: options.CUSTOMER_ID,
150
+ });
151
+
152
+ query.populate('organization', 'name logoUrl');
153
+
154
+ if(options.populateStakeholders) {
155
+ query.populate('stakeholders.lp', 'name')
156
+ query.populate('stakeholders.org', 'name logoUrl')
157
+ query.populate('stakeholders.person', 'name avatarUrl title')
158
+ }
159
+
160
+ query.exec(cb);
161
+
162
+ };
163
+
164
+ CapTable.statics.deleteForCustomer = function deleteForCustomer(options, cb) {
165
+
166
+ var self = this;
167
+
168
+ if (!cb) { throw new Error('cb is required'); }
169
+ if (!options) { return cb(new Error('options is required'), null); }
170
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
171
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
172
+
173
+ self.remove({ customer: options.CUSTOMER_ID, 'entered.by': { $ne: 'carta-parser' } }, cb);
131
174
 
132
175
  };
133
176
 
134
- CapTable.statics.getAllForCustomer = function getAllForCustomer(options, cb) {
177
+ CapTable.statics.getForOrg = function getForOrg(options, cb) {
135
178
 
136
179
  var self = this;
137
180
 
@@ -144,6 +187,7 @@ module.exports = function(mongoose, config) {
144
187
 
145
188
  query = self.find({
146
189
  customer: options.CUSTOMER_ID,
190
+ organization: options.orgId
147
191
  });
148
192
 
149
193
  query.populate('organization', 'name logoUrl');
@@ -153,44 +197,64 @@ module.exports = function(mongoose, config) {
153
197
  query.populate('stakeholders.org', 'name logoUrl')
154
198
  query.populate('stakeholders.person', 'name avatarUrl title')
155
199
  }
156
-
157
- query.exec(cb);
158
200
 
159
201
  };
160
202
 
161
- CapTable.statics.deleteAllForCustomer = function deleteAllForCustomer(customerId, cb) {
203
+ CapTable.statics.getByLP = function getByLP(options, cb) {
204
+
162
205
  var self = this;
163
- self.remove({ customer: customerId, 'entered.by': { $ne: 'carta-parser' } }, cb);
164
- };
165
206
 
166
- CapTable.statics.getByLP = function getByLP(lpId, cb) {
207
+ if (!cb) { throw new Error('cb is required'); }
208
+ if (!options) { return cb(new Error('options is required'), null); }
209
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
210
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
167
211
 
168
- var self = this;
212
+ query = self.find({
213
+ customer: options.CUSTOMER_ID,
214
+ 'stakeholders.lp': options.lpId
215
+ });
169
216
 
170
217
  self
171
- .find({ 'stakeholders.lp': lpId })
172
218
  .populate('organization', 'name logoUrl')
173
219
  .exec(cb);
174
220
 
175
221
  };
176
222
 
177
- CapTable.statics.getByOrg = function getByOrg(orgId, cb) {
223
+ CapTable.statics.getByOrg = function getByOrg(options, cb) {
178
224
 
179
225
  var self = this;
180
226
 
227
+ if (!cb) { throw new Error('cb is required'); }
228
+ if (!options) { return cb(new Error('options is required'), null); }
229
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
230
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
231
+
232
+ query = self.find({
233
+ customer: options.CUSTOMER_ID,
234
+ 'stakeholders.org': options.orgId
235
+ });
236
+
181
237
  self
182
- .find({ 'stakeholders.org': orgId })
183
238
  .populate('organization', 'name logoUrl')
184
239
  .exec(cb);
185
240
 
186
241
  };
187
242
 
188
- CapTable.statics.getByPerson = function getByPerson(personId, cb) {
243
+ CapTable.statics.getByPerson = function getByPerson(options, cb) {
189
244
 
190
245
  var self = this;
191
246
 
247
+ if (!cb) { throw new Error('cb is required'); }
248
+ if (!options) { return cb(new Error('options is required'), null); }
249
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
250
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
251
+
252
+ query = self.find({
253
+ customer: options.CUSTOMER_ID,
254
+ 'stakeholders.person': options.personId
255
+ });
256
+
192
257
  self
193
- .find({ 'stakeholders.person': personId })
194
258
  .populate('organization', 'name logoUrl')
195
259
  .exec(cb);
196
260
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "9.5.0",
3
+ "version": "9.6.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",