@dhyasama/totem-models 9.5.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 +153 -34
- 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,33 +134,74 @@ module.exports = function(mongoose, config) {
|
|
|
118
134
|
// Statics operate on the entire collection
|
|
119
135
|
//////////////////////////////////////////////////////
|
|
120
136
|
|
|
121
|
-
CapTable.statics.getForCustomer = function getForCustomer(
|
|
137
|
+
CapTable.statics.getForCustomer = function getForCustomer(customerid, options, cb) {
|
|
122
138
|
|
|
123
139
|
var self = this;
|
|
124
140
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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); }
|
|
144
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
145
|
+
|
|
146
|
+
var query;
|
|
147
|
+
|
|
148
|
+
query = self.find({
|
|
149
|
+
customer: customerid,
|
|
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);
|
|
131
161
|
|
|
132
162
|
};
|
|
133
163
|
|
|
134
|
-
CapTable.statics.
|
|
164
|
+
CapTable.statics.deleteForCustomer = function deleteForCustomer(customerid, options, cb) {
|
|
135
165
|
|
|
136
166
|
var self = this;
|
|
137
167
|
|
|
138
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); }
|
|
139
171
|
if (!options) { return cb(new Error('options is required'), null); }
|
|
140
|
-
|
|
141
|
-
|
|
172
|
+
|
|
173
|
+
self.remove({ customer: customerid, 'entered.by': { $ne: 'carta-parser' } }, cb);
|
|
174
|
+
|
|
175
|
+
};
|
|
142
176
|
|
|
177
|
+
CapTable.statics.getForOrg = function getForOrg(orgid, options, cb) {
|
|
178
|
+
|
|
179
|
+
var self = this;
|
|
180
|
+
|
|
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); }
|
|
184
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
185
|
+
|
|
143
186
|
var query;
|
|
144
187
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
+
}
|
|
148
205
|
|
|
149
206
|
query.populate('organization', 'name logoUrl');
|
|
150
207
|
|
|
@@ -153,46 +210,108 @@ module.exports = function(mongoose, config) {
|
|
|
153
210
|
query.populate('stakeholders.org', 'name logoUrl')
|
|
154
211
|
query.populate('stakeholders.person', 'name avatarUrl title')
|
|
155
212
|
}
|
|
156
|
-
|
|
213
|
+
|
|
157
214
|
query.exec(cb);
|
|
158
215
|
|
|
159
216
|
};
|
|
160
217
|
|
|
161
|
-
CapTable.statics.
|
|
218
|
+
CapTable.statics.getByLP = function getByLP(lpid, options, cb) {
|
|
219
|
+
|
|
162
220
|
var self = this;
|
|
163
|
-
self.remove({ customer: customerId, 'entered.by': { $ne: 'carta-parser' } }, cb);
|
|
164
|
-
};
|
|
165
221
|
|
|
166
|
-
|
|
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); }
|
|
225
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
226
|
+
|
|
227
|
+
if (options.isWorkerProcess) {
|
|
228
|
+
query = self.find({
|
|
229
|
+
'stakeholders.lp': lpid
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
else {
|
|
167
234
|
|
|
168
|
-
|
|
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
|
+
});
|
|
169
242
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
query.populate('organization', 'name logoUrl')
|
|
246
|
+
query.exec(cb);
|
|
174
247
|
|
|
175
248
|
};
|
|
176
249
|
|
|
177
|
-
CapTable.statics.getByOrg = function getByOrg(
|
|
250
|
+
CapTable.statics.getByOrg = function getByOrg(orgid, options, cb) {
|
|
178
251
|
|
|
179
252
|
var self = this;
|
|
180
253
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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); }
|
|
257
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
258
|
+
|
|
259
|
+
var query;
|
|
260
|
+
|
|
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
|
+
}
|
|
278
|
+
|
|
279
|
+
query.populate('organization', 'name logoUrl')
|
|
280
|
+
query.exec(cb);
|
|
185
281
|
|
|
186
282
|
};
|
|
187
283
|
|
|
188
|
-
CapTable.statics.getByPerson = function getByPerson(
|
|
284
|
+
CapTable.statics.getByPerson = function getByPerson(personid, options, cb) {
|
|
189
285
|
|
|
190
286
|
var self = this;
|
|
191
287
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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); }
|
|
291
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
292
|
+
|
|
293
|
+
var query;
|
|
294
|
+
|
|
295
|
+
if (options.isWorkerProcess) {
|
|
296
|
+
query = self.find({
|
|
297
|
+
'stakeholders.person': personid
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
else {
|
|
302
|
+
|
|
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);
|
|
196
315
|
|
|
197
316
|
};
|
|
198
317
|
|
|
@@ -203,7 +322,7 @@ module.exports = function(mongoose, config) {
|
|
|
203
322
|
if (!capTable) { return cb(new Error('capTable is required'), null); }
|
|
204
323
|
if (!username) { return cb(new Error('username is required'), null); }
|
|
205
324
|
|
|
206
|
-
capTable.constructor.
|
|
325
|
+
capTable.constructor.getForOrg(capTable.organization, { CUSTOMER_ID: capTable.customer }, function(err, result) {
|
|
207
326
|
|
|
208
327
|
if (err) return cb(err, null);
|
|
209
328
|
if (result) return cb(new Error('A cap table already exists for this customer/org combo'), null);
|