@dhyasama/totem-models 9.6.0 → 9.8.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 +104 -49
  2. package/package.json +1 -1
package/lib/CapTable.js CHANGED
@@ -134,19 +134,19 @@ module.exports = function(mongoose, config) {
134
134
  // Statics operate on the entire collection
135
135
  //////////////////////////////////////////////////////
136
136
 
137
- CapTable.statics.getForCustomer = function getForCustomer(options, cb) {
137
+ CapTable.statics.getForCustomer = function getForCustomer(customerid, options, cb) {
138
138
 
139
139
  var self = this;
140
140
 
141
141
  if (!cb) { throw new Error('cb is required'); }
142
+ if (!customerid) { return cb(new Error('customerid is required'), null); }
143
+ if (!mongoose.Types.ObjectId.isValid(customerid)) { return cb(new Error('customerid is not a valid ObjectId'), null); }
142
144
  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
-
145
+
146
146
  var query;
147
147
 
148
148
  query = self.find({
149
- customer: options.CUSTOMER_ID,
149
+ customer: customerid,
150
150
  });
151
151
 
152
152
  query.populate('organization', 'name logoUrl');
@@ -161,34 +161,47 @@ module.exports = function(mongoose, config) {
161
161
 
162
162
  };
163
163
 
164
- CapTable.statics.deleteForCustomer = function deleteForCustomer(options, cb) {
164
+ CapTable.statics.deleteForCustomer = function deleteForCustomer(customerid, options, cb) {
165
165
 
166
166
  var self = this;
167
167
 
168
168
  if (!cb) { throw new Error('cb is required'); }
169
+ if (!customerid) { return cb(new Error('customerid is required'), null); }
170
+ if (!mongoose.Types.ObjectId.isValid(customerid)) { return cb(new Error('customerid is not a valid ObjectId'), null); }
169
171
  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);
172
+
173
+ self.remove({ customer: customerid, 'entered.by': { $ne: 'carta-parser' } }, cb);
174
174
 
175
175
  };
176
176
 
177
- CapTable.statics.getForOrg = function getForOrg(options, cb) {
177
+ CapTable.statics.getForOrg = function getForOrg(orgid, options, cb) {
178
178
 
179
179
  var self = this;
180
180
 
181
181
  if (!cb) { throw new Error('cb is required'); }
182
+ if (!orgid) { return cb(new Error('orgid is required'), null); }
183
+ if (!mongoose.Types.ObjectId.isValid(orgid)) { return cb(new Error('orgid is not a valid ObjectId'), null); }
182
184
  if (!options) { return cb(new Error('options is required'), null); }
183
- if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
184
- if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
185
-
185
+
186
186
  var query;
187
187
 
188
- query = self.find({
189
- customer: options.CUSTOMER_ID,
190
- organization: options.orgId
191
- });
188
+ if (options.isWorkerProcess) {
189
+ query = self.find({
190
+ organization: orgid
191
+ });
192
+ }
193
+
194
+ else {
195
+
196
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
197
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
198
+
199
+ query = self.find({
200
+ customer: options.CUSTOMER_ID,
201
+ organization: orgid
202
+ });
203
+
204
+ }
192
205
 
193
206
  query.populate('organization', 'name logoUrl');
194
207
 
@@ -198,65 +211,107 @@ module.exports = function(mongoose, config) {
198
211
  query.populate('stakeholders.person', 'name avatarUrl title')
199
212
  }
200
213
 
214
+ query.exec(cb);
215
+
201
216
  };
202
217
 
203
- CapTable.statics.getByLP = function getByLP(options, cb) {
218
+ CapTable.statics.getByLP = function getByLP(lpid, options, cb) {
204
219
 
205
220
  var self = this;
206
221
 
207
222
  if (!cb) { throw new Error('cb is required'); }
223
+ if (!lpid) { return cb(new Error('lpid is required'), null); }
224
+ if (!mongoose.Types.ObjectId.isValid(lpid)) { return cb(new Error('lpid is not a valid ObjectId'), null); }
208
225
  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); }
226
+
227
+ if (options.isWorkerProcess) {
228
+ query = self.find({
229
+ 'stakeholders.lp': lpid
230
+ });
231
+ }
211
232
 
212
- query = self.find({
213
- customer: options.CUSTOMER_ID,
214
- 'stakeholders.lp': options.lpId
215
- });
233
+ else {
234
+
235
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
236
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
237
+
238
+ query = self.find({
239
+ customer: options.CUSTOMER_ID,
240
+ 'stakeholders.lp': lpid
241
+ });
216
242
 
217
- self
218
- .populate('organization', 'name logoUrl')
219
- .exec(cb);
243
+ }
244
+
245
+ query.populate('organization', 'name logoUrl')
246
+ query.exec(cb);
220
247
 
221
248
  };
222
249
 
223
- CapTable.statics.getByOrg = function getByOrg(options, cb) {
250
+ CapTable.statics.getByOrg = function getByOrg(orgid, options, cb) {
224
251
 
225
252
  var self = this;
226
253
 
227
254
  if (!cb) { throw new Error('cb is required'); }
255
+ if (!orgid) { return cb(new Error('orgid is required'), null); }
256
+ if (!mongoose.Types.ObjectId.isValid(orgid)) { return cb(new Error('orgid is not a valid ObjectId'), null); }
228
257
  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); }
258
+
259
+ var query;
231
260
 
232
- query = self.find({
233
- customer: options.CUSTOMER_ID,
234
- 'stakeholders.org': options.orgId
235
- });
261
+ if (options.isWorkerProcess) {
262
+ query = self.find({
263
+ 'stakeholders.org': orgid
264
+ });
265
+ }
266
+
267
+ else {
268
+
269
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
270
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
271
+
272
+ query = self.find({
273
+ customer: options.CUSTOMER_ID,
274
+ 'stakeholders.org': orgid
275
+ });
276
+
277
+ }
236
278
 
237
- self
238
- .populate('organization', 'name logoUrl')
239
- .exec(cb);
279
+ query.populate('organization', 'name logoUrl')
280
+ query.exec(cb);
240
281
 
241
282
  };
242
283
 
243
- CapTable.statics.getByPerson = function getByPerson(options, cb) {
284
+ CapTable.statics.getByPerson = function getByPerson(personid, options, cb) {
244
285
 
245
286
  var self = this;
246
287
 
247
288
  if (!cb) { throw new Error('cb is required'); }
289
+ if (!personid) { return cb(new Error('personid is required'), null); }
290
+ if (!mongoose.Types.ObjectId.isValid(personid)) { return cb(new Error('personid is not a valid ObjectId'), null); }
248
291
  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); }
292
+
293
+ var query;
251
294
 
252
- query = self.find({
253
- customer: options.CUSTOMER_ID,
254
- 'stakeholders.person': options.personId
255
- });
295
+ if (options.isWorkerProcess) {
296
+ query = self.find({
297
+ 'stakeholders.person': personid
298
+ });
299
+ }
300
+
301
+ else {
256
302
 
257
- self
258
- .populate('organization', 'name logoUrl')
259
- .exec(cb);
303
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
304
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
305
+
306
+ query = self.find({
307
+ customer: options.CUSTOMER_ID,
308
+ 'stakeholders.person': personid
309
+ });
310
+
311
+ }
312
+
313
+ query.populate('organization', 'name logoUrl')
314
+ query.exec(cb);
260
315
 
261
316
  };
262
317
 
@@ -267,7 +322,7 @@ module.exports = function(mongoose, config) {
267
322
  if (!capTable) { return cb(new Error('capTable is required'), null); }
268
323
  if (!username) { return cb(new Error('username is required'), null); }
269
324
 
270
- capTable.constructor.getForCustomer(capTable.organization, capTable.customer, function(err, result) {
325
+ capTable.constructor.getForOrg(capTable.organization, { CUSTOMER_ID: capTable.customer }, function(err, result) {
271
326
 
272
327
  if (err) return cb(err, null);
273
328
  if (result) return cb(new Error('A cap table already exists for this customer/org combo'), null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "9.6.0",
3
+ "version": "9.8.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",