@dhyasama/totem-models 12.3.0 → 12.4.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/Account.js +120 -109
- package/lib/Activity.js +23 -13
- package/lib/ApiKey.js +24 -21
- package/lib/CalendarEvent.js +100 -61
- package/lib/CapTable.js +148 -107
- package/lib/Deal.js +409 -364
- package/lib/DiffbotArticle.js +21 -15
- package/lib/DiffbotOrganization.js +21 -15
- package/lib/Document.js +60 -44
- package/lib/Event.js +38 -21
- package/lib/EventAttendee.js +29 -17
- package/lib/Financials.js +400 -367
- package/lib/FinancialsAnalysis.js +49 -38
- package/lib/Flag.js +42 -35
- package/lib/Folder.js +33 -20
- package/lib/Fund.js +103 -74
- package/lib/Interaction.js +182 -141
- package/lib/Investment.js +58 -49
- package/lib/LimitedPartner.js +241 -241
- package/lib/LimitedPartnerCampaign.js +59 -49
- package/lib/LimitedPartnerCommunication.js +91 -77
- package/lib/LimitedPartnerContactGroup.js +31 -33
- package/lib/LimitedPartnerReportGenerator.js +13 -9
- package/lib/List.js +68 -42
- package/lib/Meeting.js +56 -33
- package/lib/Message.js +225 -173
- package/lib/MessageRecipient.js +42 -31
- package/lib/News.js +30 -19
- package/lib/Note.js +40 -33
- package/lib/Organization.js +570 -506
- package/lib/Person.js +281 -246
- package/lib/Rate.js +24 -17
- package/lib/Round.js +309 -311
- package/lib/Snapshot.js +14 -9
- package/lib/Sync.js +19 -11
- package/lib/Webhook.js +8 -3
- package/package.json +1 -1
package/lib/CalendarEvent.js
CHANGED
|
@@ -52,103 +52,137 @@ module.exports = function(mongoose, config) {
|
|
|
52
52
|
try { return JSON.parse(this.raw); } catch (e) { return null; }
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
CalendarEvent.statics.delete = function(calendarEventId, cb) {
|
|
55
|
+
CalendarEvent.statics.delete = async function(calendarEventId, cb) {
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
try {
|
|
58
|
+
const result = await this.findByIdAndDelete(calendarEventId);
|
|
59
|
+
return cb(null, result);
|
|
60
|
+
} catch(err) {
|
|
61
|
+
return cb(err);
|
|
62
|
+
}
|
|
62
63
|
|
|
63
64
|
};
|
|
64
65
|
|
|
65
|
-
CalendarEvent.statics.findByAccountId = function (accountId, cb) {
|
|
66
|
-
|
|
67
|
-
.find({ account: accountId })
|
|
68
|
-
|
|
66
|
+
CalendarEvent.statics.findByAccountId = async function (accountId, cb) {
|
|
67
|
+
try {
|
|
68
|
+
const result = await this.find({ account: accountId });
|
|
69
|
+
return cb(null, result);
|
|
70
|
+
} catch(err) {
|
|
71
|
+
return cb(err);
|
|
72
|
+
}
|
|
69
73
|
};
|
|
70
74
|
|
|
71
|
-
CalendarEvent.statics.findByCreatedRange = function (since, until, cb) {
|
|
72
|
-
|
|
73
|
-
.find({ createdOn: { $gt: since, $lt: until } })
|
|
74
|
-
|
|
75
|
+
CalendarEvent.statics.findByCreatedRange = async function (since, until, cb) {
|
|
76
|
+
try {
|
|
77
|
+
const result = await this.find({ createdOn: { $gt: since, $lt: until } });
|
|
78
|
+
return cb(null, result);
|
|
79
|
+
} catch(err) {
|
|
80
|
+
return cb(err);
|
|
81
|
+
}
|
|
75
82
|
};
|
|
76
83
|
|
|
77
|
-
CalendarEvent.statics.findByCreatedSince = function (since, cb) {
|
|
78
|
-
|
|
79
|
-
.find({ createdOn: { $gt: since } })
|
|
80
|
-
|
|
84
|
+
CalendarEvent.statics.findByCreatedSince = async function (since, cb) {
|
|
85
|
+
try {
|
|
86
|
+
const result = await this.find({ createdOn: { $gt: since } });
|
|
87
|
+
return cb(null, result);
|
|
88
|
+
} catch(err) {
|
|
89
|
+
return cb(err);
|
|
90
|
+
}
|
|
81
91
|
};
|
|
82
92
|
|
|
83
|
-
CalendarEvent.statics.findByEmail = function (email, cb) {
|
|
84
|
-
|
|
85
|
-
.find({ email: email })
|
|
86
|
-
|
|
93
|
+
CalendarEvent.statics.findByEmail = async function (email, cb) {
|
|
94
|
+
try {
|
|
95
|
+
const result = await this.find({ email: email });
|
|
96
|
+
return cb(null, result);
|
|
97
|
+
} catch(err) {
|
|
98
|
+
return cb(err);
|
|
99
|
+
}
|
|
87
100
|
};
|
|
88
101
|
|
|
89
|
-
CalendarEvent.statics.findByEmailForRange = function (email, startsAfter, startsBefore, cb) {
|
|
102
|
+
CalendarEvent.statics.findByEmailForRange = async function (email, startsAfter, startsBefore, cb) {
|
|
90
103
|
|
|
91
|
-
var
|
|
92
|
-
var query = self.find({ email: email });
|
|
104
|
+
var query = this.find({ email: email });
|
|
93
105
|
query.where({ start: { $gte: startsAfter, $lte: startsBefore }});
|
|
94
|
-
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const result = await query;
|
|
109
|
+
return cb(null, result);
|
|
110
|
+
} catch(err) {
|
|
111
|
+
return cb(err);
|
|
112
|
+
}
|
|
95
113
|
|
|
96
114
|
};
|
|
97
115
|
|
|
98
|
-
CalendarEvent.statics.findByEventId = function (eventId, cb) {
|
|
99
|
-
|
|
100
|
-
.findOne({ 'eventId': eventId })
|
|
101
|
-
|
|
116
|
+
CalendarEvent.statics.findByEventId = async function (eventId, cb) {
|
|
117
|
+
try {
|
|
118
|
+
const result = await this.findOne({ 'eventId': eventId });
|
|
119
|
+
return cb(null, result);
|
|
120
|
+
} catch(err) {
|
|
121
|
+
return cb(err);
|
|
122
|
+
}
|
|
102
123
|
};
|
|
103
124
|
|
|
104
|
-
CalendarEvent.statics.findUnprocessedForAccount = function (id, cb) {
|
|
105
|
-
|
|
106
|
-
.find({ account: id, processed: false })
|
|
107
|
-
|
|
108
|
-
|
|
125
|
+
CalendarEvent.statics.findUnprocessedForAccount = async function (id, cb) {
|
|
126
|
+
try {
|
|
127
|
+
const result = await this.find({ account: id, processed: false }).populate('account', 'email customer');
|
|
128
|
+
return cb(null, result);
|
|
129
|
+
} catch(err) {
|
|
130
|
+
return cb(err);
|
|
131
|
+
}
|
|
109
132
|
};
|
|
110
133
|
|
|
111
|
-
CalendarEvent.statics.findByUsername = function (username, cb) {
|
|
112
|
-
|
|
113
|
-
.find({ 'account.username': username })
|
|
114
|
-
|
|
134
|
+
CalendarEvent.statics.findByUsername = async function (username, cb) {
|
|
135
|
+
try {
|
|
136
|
+
const result = await this.find({ 'account.username': username });
|
|
137
|
+
return cb(null, result);
|
|
138
|
+
} catch(err) {
|
|
139
|
+
return cb(err);
|
|
140
|
+
}
|
|
115
141
|
};
|
|
116
142
|
|
|
117
|
-
CalendarEvent.statics.getById = function (id, cb) {
|
|
118
|
-
|
|
119
|
-
.findOne({ '_id': id })
|
|
120
|
-
|
|
121
|
-
|
|
143
|
+
CalendarEvent.statics.getById = async function (id, cb) {
|
|
144
|
+
try {
|
|
145
|
+
const result = await this.findOne({ '_id': id }).populate('account', 'email customer');
|
|
146
|
+
return cb(null, result);
|
|
147
|
+
} catch(err) {
|
|
148
|
+
return cb(err);
|
|
149
|
+
}
|
|
122
150
|
};
|
|
123
151
|
|
|
124
|
-
CalendarEvent.statics.getNewest = function (email, cb) {
|
|
125
|
-
|
|
126
|
-
.findOne({email: email})
|
|
127
|
-
|
|
128
|
-
|
|
152
|
+
CalendarEvent.statics.getNewest = async function (email, cb) {
|
|
153
|
+
try {
|
|
154
|
+
const result = await this.findOne({email: email}).sort({createdOn: -1});
|
|
155
|
+
return cb(null, result);
|
|
156
|
+
} catch(err) {
|
|
157
|
+
return cb(err);
|
|
158
|
+
}
|
|
129
159
|
};
|
|
130
160
|
|
|
131
|
-
CalendarEvent.statics.getNewestProcessed = function (email, cb) {
|
|
132
|
-
|
|
133
|
-
.findOne({ email: email, processed: true })
|
|
134
|
-
|
|
135
|
-
|
|
161
|
+
CalendarEvent.statics.getNewestProcessed = async function (email, cb) {
|
|
162
|
+
try {
|
|
163
|
+
const result = await this.findOne({ email: email, processed: true }).sort({ createdOn: -1 });
|
|
164
|
+
return cb(null, result);
|
|
165
|
+
} catch(err) {
|
|
166
|
+
return cb(err);
|
|
167
|
+
}
|
|
136
168
|
};
|
|
137
169
|
|
|
138
|
-
CalendarEvent.statics.markAsProcessed = function markAsProcessed(id, cb) {
|
|
170
|
+
CalendarEvent.statics.markAsProcessed = async function markAsProcessed(id, cb) {
|
|
139
171
|
|
|
140
|
-
var self = this;
|
|
141
172
|
var filter = { '_id': id };
|
|
142
173
|
var update = { $set: { processed: true } };
|
|
143
174
|
var options = { 'upsert': false, 'new': true };
|
|
144
175
|
|
|
145
|
-
|
|
176
|
+
try {
|
|
177
|
+
const result = await this.findOneAndUpdate(filter, update, options);
|
|
178
|
+
return cb(null, result);
|
|
179
|
+
} catch(err) {
|
|
180
|
+
return cb(err);
|
|
181
|
+
}
|
|
146
182
|
|
|
147
183
|
};
|
|
148
184
|
|
|
149
|
-
CalendarEvent.statics.upsert = function(calendarEvent, cb) {
|
|
150
|
-
|
|
151
|
-
var self = this;
|
|
185
|
+
CalendarEvent.statics.upsert = async function(calendarEvent, cb) {
|
|
152
186
|
|
|
153
187
|
// Prevent dupe events
|
|
154
188
|
|
|
@@ -172,7 +206,12 @@ module.exports = function(mongoose, config) {
|
|
|
172
206
|
raw: calendarEvent.raw
|
|
173
207
|
};
|
|
174
208
|
|
|
175
|
-
|
|
209
|
+
try {
|
|
210
|
+
const result = await this.findOneAndUpdate(query, update, options);
|
|
211
|
+
return cb(null, result);
|
|
212
|
+
} catch(err) {
|
|
213
|
+
return cb(err);
|
|
214
|
+
}
|
|
176
215
|
|
|
177
216
|
};
|
|
178
217
|
CalendarEvent.set('autoIndex', false);
|
package/lib/CapTable.js
CHANGED
|
@@ -134,9 +134,7 @@ module.exports = function(mongoose, config) {
|
|
|
134
134
|
// Statics operate on the entire collection
|
|
135
135
|
//////////////////////////////////////////////////////
|
|
136
136
|
|
|
137
|
-
CapTable.statics.getForCustomer = function getForCustomer(customerid, options, cb) {
|
|
138
|
-
|
|
139
|
-
const self = this;
|
|
137
|
+
CapTable.statics.getForCustomer = async function getForCustomer(customerid, options, cb) {
|
|
140
138
|
|
|
141
139
|
if (!cb) { throw new Error('cb is required'); }
|
|
142
140
|
if (!customerid) { return cb(new Error('customerid is required'), null); }
|
|
@@ -145,7 +143,7 @@ module.exports = function(mongoose, config) {
|
|
|
145
143
|
|
|
146
144
|
let query;
|
|
147
145
|
|
|
148
|
-
query =
|
|
146
|
+
query = this.find({
|
|
149
147
|
customer: customerid,
|
|
150
148
|
});
|
|
151
149
|
|
|
@@ -165,26 +163,32 @@ module.exports = function(mongoose, config) {
|
|
|
165
163
|
query.populate('stakeholders.person', 'name avatarUrl title');
|
|
166
164
|
query.sort({ asOfDate: -1 });
|
|
167
165
|
|
|
168
|
-
|
|
166
|
+
try {
|
|
167
|
+
const result = await query;
|
|
168
|
+
return cb(null, result);
|
|
169
|
+
} catch(err) {
|
|
170
|
+
return cb(err);
|
|
171
|
+
}
|
|
169
172
|
|
|
170
173
|
};
|
|
171
174
|
|
|
172
|
-
CapTable.statics.deleteForCustomer = function deleteForCustomer(customerid, options, cb) {
|
|
173
|
-
|
|
174
|
-
const self = this;
|
|
175
|
+
CapTable.statics.deleteForCustomer = async function deleteForCustomer(customerid, options, cb) {
|
|
175
176
|
|
|
176
177
|
if (!cb) { throw new Error('cb is required'); }
|
|
177
178
|
if (!customerid) { return cb(new Error('customerid is required'), null); }
|
|
178
179
|
if (!mongoose.Types.ObjectId.isValid(customerid)) { return cb(new Error('customerid is not a valid ObjectId'), null); }
|
|
179
180
|
if (!options) { return cb(new Error('options is required'), null); }
|
|
180
181
|
|
|
181
|
-
|
|
182
|
+
try {
|
|
183
|
+
const result = await this.deleteMany({ customer: customerid, 'entered.by': { $ne: 'carta-parser' } });
|
|
184
|
+
return cb(null, result);
|
|
185
|
+
} catch(err) {
|
|
186
|
+
return cb(err);
|
|
187
|
+
}
|
|
182
188
|
|
|
183
189
|
};
|
|
184
190
|
|
|
185
|
-
CapTable.statics.getForOrg = function getForOrg(orgid, options, cb) {
|
|
186
|
-
|
|
187
|
-
var self = this;
|
|
191
|
+
CapTable.statics.getForOrg = async function getForOrg(orgid, options, cb) {
|
|
188
192
|
|
|
189
193
|
if (!cb) { throw new Error('cb is required'); }
|
|
190
194
|
if (!orgid) { return cb(new Error('orgid is required'), null); }
|
|
@@ -194,7 +198,7 @@ module.exports = function(mongoose, config) {
|
|
|
194
198
|
var query;
|
|
195
199
|
|
|
196
200
|
if (options.isWorkerProcess) {
|
|
197
|
-
query =
|
|
201
|
+
query = this.find({
|
|
198
202
|
organization: orgid
|
|
199
203
|
});
|
|
200
204
|
}
|
|
@@ -204,7 +208,7 @@ module.exports = function(mongoose, config) {
|
|
|
204
208
|
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
205
209
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
206
210
|
|
|
207
|
-
query =
|
|
211
|
+
query = this.find({
|
|
208
212
|
customer: options.CUSTOMER_ID,
|
|
209
213
|
organization: orgid
|
|
210
214
|
});
|
|
@@ -217,13 +221,16 @@ module.exports = function(mongoose, config) {
|
|
|
217
221
|
query.populate('stakeholders.person', 'name avatarUrl title')
|
|
218
222
|
query.sort({ asOfDate: -1 });
|
|
219
223
|
|
|
220
|
-
|
|
224
|
+
try {
|
|
225
|
+
const result = await query;
|
|
226
|
+
return cb(null, result);
|
|
227
|
+
} catch(err) {
|
|
228
|
+
return cb(err);
|
|
229
|
+
}
|
|
221
230
|
|
|
222
231
|
};
|
|
223
232
|
|
|
224
|
-
CapTable.statics.getByLP = function getByLP(lpid, options, cb) {
|
|
225
|
-
|
|
226
|
-
var self = this;
|
|
233
|
+
CapTable.statics.getByLP = async function getByLP(lpid, options, cb) {
|
|
227
234
|
|
|
228
235
|
if (!cb) { throw new Error('cb is required'); }
|
|
229
236
|
if (!lpid) { return cb(new Error('lpid is required'), null); }
|
|
@@ -233,7 +240,7 @@ module.exports = function(mongoose, config) {
|
|
|
233
240
|
var query;
|
|
234
241
|
|
|
235
242
|
if (options.isWorkerProcess) {
|
|
236
|
-
query =
|
|
243
|
+
query = this.find({
|
|
237
244
|
'stakeholders.lp': lpid
|
|
238
245
|
});
|
|
239
246
|
}
|
|
@@ -243,7 +250,7 @@ module.exports = function(mongoose, config) {
|
|
|
243
250
|
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
244
251
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
245
252
|
|
|
246
|
-
query =
|
|
253
|
+
query = this.find({
|
|
247
254
|
customer: options.CUSTOMER_ID,
|
|
248
255
|
'stakeholders.lp': lpid
|
|
249
256
|
});
|
|
@@ -251,13 +258,17 @@ module.exports = function(mongoose, config) {
|
|
|
251
258
|
}
|
|
252
259
|
|
|
253
260
|
query.populate('organization', 'name logoUrl')
|
|
254
|
-
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
255
261
|
|
|
256
|
-
|
|
262
|
+
try {
|
|
263
|
+
const result = await query;
|
|
264
|
+
return cb(null, result);
|
|
265
|
+
} catch(err) {
|
|
266
|
+
return cb(err);
|
|
267
|
+
}
|
|
257
268
|
|
|
258
|
-
|
|
269
|
+
};
|
|
259
270
|
|
|
260
|
-
|
|
271
|
+
CapTable.statics.getByLPs = async function getByLPs(lpids, options, cb) {
|
|
261
272
|
|
|
262
273
|
if (!cb) { throw new Error('cb is required'); }
|
|
263
274
|
if (!lpids) { return cb(new Error('lpids is required'), null); }
|
|
@@ -266,7 +277,7 @@ module.exports = function(mongoose, config) {
|
|
|
266
277
|
var query;
|
|
267
278
|
|
|
268
279
|
if (options.isWorkerProcess) {
|
|
269
|
-
query =
|
|
280
|
+
query = this.find({
|
|
270
281
|
'stakeholders.lp': { $in : lpids }
|
|
271
282
|
});
|
|
272
283
|
}
|
|
@@ -276,7 +287,7 @@ module.exports = function(mongoose, config) {
|
|
|
276
287
|
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
277
288
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
278
289
|
|
|
279
|
-
query =
|
|
290
|
+
query = this.find({
|
|
280
291
|
customer: options.CUSTOMER_ID,
|
|
281
292
|
'stakeholders.lp': { $in : lpids }
|
|
282
293
|
});
|
|
@@ -284,13 +295,17 @@ module.exports = function(mongoose, config) {
|
|
|
284
295
|
}
|
|
285
296
|
|
|
286
297
|
query.populate('organization', 'name logoUrl')
|
|
287
|
-
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
288
298
|
|
|
289
|
-
|
|
299
|
+
try {
|
|
300
|
+
const result = await query;
|
|
301
|
+
return cb(null, result);
|
|
302
|
+
} catch(err) {
|
|
303
|
+
return cb(err);
|
|
304
|
+
}
|
|
290
305
|
|
|
291
|
-
|
|
306
|
+
};
|
|
292
307
|
|
|
293
|
-
|
|
308
|
+
CapTable.statics.getByOrg = async function getByOrg(orgid, options, cb) {
|
|
294
309
|
|
|
295
310
|
if (!cb) { throw new Error('cb is required'); }
|
|
296
311
|
if (!orgid) { return cb(new Error('orgid is required'), null); }
|
|
@@ -300,7 +315,7 @@ module.exports = function(mongoose, config) {
|
|
|
300
315
|
var query;
|
|
301
316
|
|
|
302
317
|
if (options.isWorkerProcess) {
|
|
303
|
-
query =
|
|
318
|
+
query = this.find({
|
|
304
319
|
'stakeholders.org': orgid
|
|
305
320
|
});
|
|
306
321
|
}
|
|
@@ -310,7 +325,7 @@ module.exports = function(mongoose, config) {
|
|
|
310
325
|
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
311
326
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
312
327
|
|
|
313
|
-
query =
|
|
328
|
+
query = this.find({
|
|
314
329
|
customer: options.CUSTOMER_ID,
|
|
315
330
|
'stakeholders.org': orgid
|
|
316
331
|
});
|
|
@@ -318,13 +333,17 @@ module.exports = function(mongoose, config) {
|
|
|
318
333
|
}
|
|
319
334
|
|
|
320
335
|
query.populate('organization', 'name logoUrl')
|
|
321
|
-
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
322
336
|
|
|
323
|
-
|
|
337
|
+
try {
|
|
338
|
+
const result = await query;
|
|
339
|
+
return cb(null, result);
|
|
340
|
+
} catch(err) {
|
|
341
|
+
return cb(err);
|
|
342
|
+
}
|
|
324
343
|
|
|
325
|
-
|
|
344
|
+
};
|
|
326
345
|
|
|
327
|
-
|
|
346
|
+
CapTable.statics.getByPerson = async function getByPerson(personid, options, cb) {
|
|
328
347
|
|
|
329
348
|
if (!cb) { throw new Error('cb is required'); }
|
|
330
349
|
if (!personid) { return cb(new Error('personid is required'), null); }
|
|
@@ -334,7 +353,7 @@ module.exports = function(mongoose, config) {
|
|
|
334
353
|
var query;
|
|
335
354
|
|
|
336
355
|
if (options.isWorkerProcess) {
|
|
337
|
-
query =
|
|
356
|
+
query = this.find({
|
|
338
357
|
'stakeholders.person': personid
|
|
339
358
|
});
|
|
340
359
|
}
|
|
@@ -344,7 +363,7 @@ module.exports = function(mongoose, config) {
|
|
|
344
363
|
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
345
364
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
346
365
|
|
|
347
|
-
query =
|
|
366
|
+
query = this.find({
|
|
348
367
|
customer: options.CUSTOMER_ID,
|
|
349
368
|
'stakeholders.person': personid
|
|
350
369
|
});
|
|
@@ -352,13 +371,17 @@ module.exports = function(mongoose, config) {
|
|
|
352
371
|
}
|
|
353
372
|
|
|
354
373
|
query.populate('organization', 'name logoUrl')
|
|
355
|
-
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
356
374
|
|
|
357
|
-
|
|
375
|
+
try {
|
|
376
|
+
const result = await query;
|
|
377
|
+
return cb(null, result);
|
|
378
|
+
} catch(err) {
|
|
379
|
+
return cb(err);
|
|
380
|
+
}
|
|
358
381
|
|
|
359
|
-
|
|
382
|
+
};
|
|
360
383
|
|
|
361
|
-
|
|
384
|
+
CapTable.statics.search = async function search(terms, options, cb) {
|
|
362
385
|
|
|
363
386
|
if (!cb) { throw new Error('cb is required'); }
|
|
364
387
|
if (!terms) { return cb(new Error('terms is required'), null); }
|
|
@@ -370,7 +393,7 @@ module.exports = function(mongoose, config) {
|
|
|
370
393
|
|
|
371
394
|
let query;
|
|
372
395
|
|
|
373
|
-
query =
|
|
396
|
+
query = this.find({
|
|
374
397
|
customer: options.CUSTOMER_ID,
|
|
375
398
|
'stakeholders.name': new RegExp(terms, 'i'),
|
|
376
399
|
'stakeholders.person': null
|
|
@@ -378,13 +401,17 @@ module.exports = function(mongoose, config) {
|
|
|
378
401
|
|
|
379
402
|
query.populate('organization', 'name logoUrl');
|
|
380
403
|
query.sort({ 'name': -1 });
|
|
381
|
-
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
382
404
|
|
|
383
|
-
|
|
405
|
+
try {
|
|
406
|
+
const result = await query;
|
|
407
|
+
return cb(null, result);
|
|
408
|
+
} catch(err) {
|
|
409
|
+
return cb(err);
|
|
410
|
+
}
|
|
384
411
|
|
|
385
|
-
|
|
412
|
+
};
|
|
386
413
|
|
|
387
|
-
|
|
414
|
+
CapTable.statics.search2 = async function search2(value, options, cb) {
|
|
388
415
|
|
|
389
416
|
if (!cb) { throw new Error('cb is required'); }
|
|
390
417
|
if (!value) { return cb(new Error('value is required'), null); }
|
|
@@ -403,80 +430,94 @@ module.exports = function(mongoose, config) {
|
|
|
403
430
|
|
|
404
431
|
const path = 'stakeholders.name';
|
|
405
432
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
433
|
+
try {
|
|
434
|
+
const result = await this.aggregate([
|
|
435
|
+
{
|
|
436
|
+
"$search": {
|
|
437
|
+
index: 'default',
|
|
438
|
+
compound: {
|
|
439
|
+
should: [
|
|
440
|
+
{
|
|
441
|
+
autocomplete: {
|
|
442
|
+
query: value,
|
|
443
|
+
path: path
|
|
444
|
+
}
|
|
416
445
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
446
|
+
],
|
|
447
|
+
must: [
|
|
448
|
+
{
|
|
449
|
+
equals: {
|
|
450
|
+
path: 'customer',
|
|
451
|
+
value: new mongoose.Types.ObjectId(options.CUSTOMER_ID)
|
|
452
|
+
}
|
|
424
453
|
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
454
|
+
],
|
|
455
|
+
minimumShouldMatch: 1
|
|
456
|
+
},
|
|
457
|
+
highlight: {
|
|
458
|
+
path: path
|
|
459
|
+
}
|
|
431
460
|
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
$limit: options.limit,
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
$lookup:
|
|
467
|
+
{
|
|
468
|
+
from: "organizations",
|
|
469
|
+
localField: "organization",
|
|
470
|
+
foreignField: "_id",
|
|
471
|
+
as: "org"
|
|
472
|
+
}
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
$unwind: "$org"
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
$addFields: {
|
|
479
|
+
orgId: "$org._id",
|
|
480
|
+
name: "$org.name",
|
|
481
|
+
logoUrl: "$org.logoUrl"
|
|
482
|
+
}
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
$project: {
|
|
486
|
+
name: 1,
|
|
487
|
+
logoUrl: 1,
|
|
488
|
+
orgId: 1,
|
|
489
|
+
score: { $meta: "searchScore" },
|
|
490
|
+
highlights: { $meta: "searchHighlights" }
|
|
444
491
|
}
|
|
445
|
-
},
|
|
446
|
-
{
|
|
447
|
-
$unwind: "$org"
|
|
448
|
-
},
|
|
449
|
-
{
|
|
450
|
-
$addFields: {
|
|
451
|
-
orgId: "$org._id",
|
|
452
|
-
name: "$org.name",
|
|
453
|
-
logoUrl: "$org.logoUrl"
|
|
454
|
-
}
|
|
455
|
-
},
|
|
456
|
-
{
|
|
457
|
-
$project: {
|
|
458
|
-
name: 1,
|
|
459
|
-
logoUrl: 1,
|
|
460
|
-
orgId: 1,
|
|
461
|
-
score: { $meta: "searchScore" },
|
|
462
|
-
highlights: { $meta: "searchHighlights" }
|
|
463
492
|
}
|
|
464
|
-
|
|
465
|
-
|
|
493
|
+
]);
|
|
494
|
+
return cb(null, result);
|
|
495
|
+
} catch(err) {
|
|
496
|
+
return cb(err);
|
|
497
|
+
}
|
|
466
498
|
|
|
467
499
|
};
|
|
468
500
|
|
|
469
|
-
CapTable.statics.upsert = function upsert(capTable, cb) {
|
|
501
|
+
CapTable.statics.upsert = async function upsert(capTable, cb) {
|
|
470
502
|
|
|
471
503
|
if (!capTable) { return cb(new Error('cap table is required'), null); }
|
|
472
504
|
|
|
473
|
-
|
|
505
|
+
try {
|
|
506
|
+
const result = await capTable.save();
|
|
507
|
+
return cb(null, result);
|
|
508
|
+
} catch(err) {
|
|
509
|
+
return cb(err);
|
|
510
|
+
}
|
|
474
511
|
|
|
475
512
|
};
|
|
476
513
|
|
|
477
|
-
CapTable.statics.delete = function(id, cb) {
|
|
478
|
-
|
|
479
|
-
|
|
514
|
+
CapTable.statics.delete = async function(id, cb) {
|
|
515
|
+
try {
|
|
516
|
+
const result = await this.findByIdAndDelete(id);
|
|
517
|
+
return cb(null, result);
|
|
518
|
+
} catch(err) {
|
|
519
|
+
return cb(err);
|
|
520
|
+
}
|
|
480
521
|
};
|
|
481
522
|
|
|
482
523
|
///////////////////////////////////////////////////////////////////////////////////////
|