@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.
- package/lib/CapTable.js +104 -49
- 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
|
-
|
|
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:
|
|
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
|
-
|
|
171
|
-
|
|
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
|
-
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
210
|
-
if (
|
|
226
|
+
|
|
227
|
+
if (options.isWorkerProcess) {
|
|
228
|
+
query = self.find({
|
|
229
|
+
'stakeholders.lp': lpid
|
|
230
|
+
});
|
|
231
|
+
}
|
|
211
232
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
'
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
230
|
-
|
|
258
|
+
|
|
259
|
+
var query;
|
|
231
260
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
-
|
|
238
|
-
|
|
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
|
-
|
|
250
|
-
|
|
292
|
+
|
|
293
|
+
var query;
|
|
251
294
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
295
|
+
if (options.isWorkerProcess) {
|
|
296
|
+
query = self.find({
|
|
297
|
+
'stakeholders.person': personid
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
else {
|
|
256
302
|
|
|
257
|
-
|
|
258
|
-
.
|
|
259
|
-
|
|
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.
|
|
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);
|