@dhyasama/totem-models 9.6.0 → 9.9.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 +109 -60
- package/package.json +1 -1
package/lib/CapTable.js
CHANGED
|
@@ -134,129 +134,178 @@ 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');
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
query.populate('stakeholders.org', 'name logoUrl')
|
|
157
|
-
query.populate('stakeholders.person', 'name avatarUrl title')
|
|
158
|
-
}
|
|
153
|
+
query.populate('stakeholders.lp', 'name')
|
|
154
|
+
query.populate('stakeholders.org', 'name logoUrl')
|
|
155
|
+
query.populate('stakeholders.person', 'name avatarUrl title')
|
|
159
156
|
|
|
160
157
|
query.exec(cb);
|
|
161
158
|
|
|
162
159
|
};
|
|
163
160
|
|
|
164
|
-
CapTable.statics.deleteForCustomer = function deleteForCustomer(options, cb) {
|
|
161
|
+
CapTable.statics.deleteForCustomer = function deleteForCustomer(customerid, options, cb) {
|
|
165
162
|
|
|
166
163
|
var self = this;
|
|
167
164
|
|
|
168
165
|
if (!cb) { throw new Error('cb is required'); }
|
|
166
|
+
if (!customerid) { return cb(new Error('customerid is required'), null); }
|
|
167
|
+
if (!mongoose.Types.ObjectId.isValid(customerid)) { return cb(new Error('customerid is not a valid ObjectId'), null); }
|
|
169
168
|
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);
|
|
169
|
+
|
|
170
|
+
self.remove({ customer: customerid, 'entered.by': { $ne: 'carta-parser' } }, cb);
|
|
174
171
|
|
|
175
172
|
};
|
|
176
173
|
|
|
177
|
-
CapTable.statics.getForOrg = function getForOrg(options, cb) {
|
|
174
|
+
CapTable.statics.getForOrg = function getForOrg(orgid, options, cb) {
|
|
178
175
|
|
|
179
176
|
var self = this;
|
|
180
177
|
|
|
181
178
|
if (!cb) { throw new Error('cb is required'); }
|
|
179
|
+
if (!orgid) { return cb(new Error('orgid is required'), null); }
|
|
180
|
+
if (!mongoose.Types.ObjectId.isValid(orgid)) { return cb(new Error('orgid is not a valid ObjectId'), null); }
|
|
182
181
|
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
|
-
|
|
182
|
+
|
|
186
183
|
var query;
|
|
187
184
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
185
|
+
if (options.isWorkerProcess) {
|
|
186
|
+
query = self.find({
|
|
187
|
+
organization: orgid
|
|
188
|
+
});
|
|
189
|
+
}
|
|
192
190
|
|
|
193
|
-
|
|
191
|
+
else {
|
|
192
|
+
|
|
193
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
194
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
195
|
+
|
|
196
|
+
query = self.findOne({
|
|
197
|
+
customer: options.CUSTOMER_ID,
|
|
198
|
+
organization: orgid
|
|
199
|
+
});
|
|
194
200
|
|
|
195
|
-
if(options.populateStakeholders) {
|
|
196
|
-
query.populate('stakeholders.lp', 'name')
|
|
197
|
-
query.populate('stakeholders.org', 'name logoUrl')
|
|
198
|
-
query.populate('stakeholders.person', 'name avatarUrl title')
|
|
199
201
|
}
|
|
200
202
|
|
|
203
|
+
query.populate('organization', 'name logoUrl');
|
|
204
|
+
query.populate('stakeholders.lp', 'name')
|
|
205
|
+
query.populate('stakeholders.org', 'name logoUrl')
|
|
206
|
+
query.populate('stakeholders.person', 'name avatarUrl title')
|
|
207
|
+
|
|
208
|
+
query.exec(cb);
|
|
209
|
+
|
|
201
210
|
};
|
|
202
211
|
|
|
203
|
-
CapTable.statics.getByLP = function getByLP(options, cb) {
|
|
212
|
+
CapTable.statics.getByLP = function getByLP(lpid, options, cb) {
|
|
204
213
|
|
|
205
214
|
var self = this;
|
|
206
215
|
|
|
207
216
|
if (!cb) { throw new Error('cb is required'); }
|
|
217
|
+
if (!lpid) { return cb(new Error('lpid is required'), null); }
|
|
218
|
+
if (!mongoose.Types.ObjectId.isValid(lpid)) { return cb(new Error('lpid is not a valid ObjectId'), null); }
|
|
208
219
|
if (!options) { return cb(new Error('options is required'), null); }
|
|
209
|
-
|
|
210
|
-
if (
|
|
220
|
+
|
|
221
|
+
if (options.isWorkerProcess) {
|
|
222
|
+
query = self.find({
|
|
223
|
+
'stakeholders.lp': lpid
|
|
224
|
+
});
|
|
225
|
+
}
|
|
211
226
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
'
|
|
215
|
-
|
|
227
|
+
else {
|
|
228
|
+
|
|
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.lp': lpid
|
|
235
|
+
});
|
|
216
236
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
query.populate('organization', 'name logoUrl')
|
|
240
|
+
query.exec(cb);
|
|
220
241
|
|
|
221
242
|
};
|
|
222
243
|
|
|
223
|
-
CapTable.statics.getByOrg = function getByOrg(options, cb) {
|
|
244
|
+
CapTable.statics.getByOrg = function getByOrg(orgid, options, cb) {
|
|
224
245
|
|
|
225
246
|
var self = this;
|
|
226
247
|
|
|
227
248
|
if (!cb) { throw new Error('cb is required'); }
|
|
249
|
+
if (!orgid) { return cb(new Error('orgid is required'), null); }
|
|
250
|
+
if (!mongoose.Types.ObjectId.isValid(orgid)) { return cb(new Error('orgid is not a valid ObjectId'), null); }
|
|
228
251
|
if (!options) { return cb(new Error('options is required'), null); }
|
|
229
|
-
|
|
230
|
-
|
|
252
|
+
|
|
253
|
+
var query;
|
|
231
254
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
255
|
+
if (options.isWorkerProcess) {
|
|
256
|
+
query = self.find({
|
|
257
|
+
'stakeholders.org': orgid
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
else {
|
|
236
262
|
|
|
237
|
-
|
|
238
|
-
.
|
|
239
|
-
|
|
263
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
264
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
265
|
+
|
|
266
|
+
query = self.find({
|
|
267
|
+
customer: options.CUSTOMER_ID,
|
|
268
|
+
'stakeholders.org': orgid
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
query.populate('organization', 'name logoUrl')
|
|
274
|
+
query.exec(cb);
|
|
240
275
|
|
|
241
276
|
};
|
|
242
277
|
|
|
243
|
-
CapTable.statics.getByPerson = function getByPerson(options, cb) {
|
|
278
|
+
CapTable.statics.getByPerson = function getByPerson(personid, options, cb) {
|
|
244
279
|
|
|
245
280
|
var self = this;
|
|
246
281
|
|
|
247
282
|
if (!cb) { throw new Error('cb is required'); }
|
|
283
|
+
if (!personid) { return cb(new Error('personid is required'), null); }
|
|
284
|
+
if (!mongoose.Types.ObjectId.isValid(personid)) { return cb(new Error('personid is not a valid ObjectId'), null); }
|
|
248
285
|
if (!options) { return cb(new Error('options is required'), null); }
|
|
249
|
-
|
|
250
|
-
|
|
286
|
+
|
|
287
|
+
var query;
|
|
251
288
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
289
|
+
if (options.isWorkerProcess) {
|
|
290
|
+
query = self.find({
|
|
291
|
+
'stakeholders.person': personid
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
else {
|
|
256
296
|
|
|
257
|
-
|
|
258
|
-
.
|
|
259
|
-
|
|
297
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
298
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
299
|
+
|
|
300
|
+
query = self.find({
|
|
301
|
+
customer: options.CUSTOMER_ID,
|
|
302
|
+
'stakeholders.person': personid
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
query.populate('organization', 'name logoUrl')
|
|
308
|
+
query.exec(cb);
|
|
260
309
|
|
|
261
310
|
};
|
|
262
311
|
|
|
@@ -267,7 +316,7 @@ module.exports = function(mongoose, config) {
|
|
|
267
316
|
if (!capTable) { return cb(new Error('capTable is required'), null); }
|
|
268
317
|
if (!username) { return cb(new Error('username is required'), null); }
|
|
269
318
|
|
|
270
|
-
capTable.constructor.
|
|
319
|
+
capTable.constructor.getForOrg(capTable.organization, { CUSTOMER_ID: capTable.customer }, function(err, result) {
|
|
271
320
|
|
|
272
321
|
if (err) return cb(err, null);
|
|
273
322
|
if (result) return cb(new Error('A cap table already exists for this customer/org combo'), null);
|