@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/Message.js
CHANGED
|
@@ -50,39 +50,44 @@ module.exports = function(mongoose, config) {
|
|
|
50
50
|
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
Message.statics.delete = function(messageId, customerId, cb) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
Message.statics.delete = async function(messageId, customerId, cb) {
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const result = await this.findOneAndDelete({
|
|
57
|
+
'_id': messageId,
|
|
58
|
+
'customer': customerId
|
|
59
|
+
});
|
|
60
|
+
return cb(null, result);
|
|
61
|
+
} catch(err) {
|
|
62
|
+
return cb(err);
|
|
63
|
+
}
|
|
61
64
|
|
|
62
65
|
};
|
|
63
66
|
|
|
64
|
-
Message.statics.deleteDocument = function(docId, customerId, cb) {
|
|
67
|
+
Message.statics.deleteDocument = async function(docId, customerId, cb) {
|
|
65
68
|
|
|
66
69
|
// Delete the doc itself along with any references
|
|
67
70
|
|
|
68
|
-
|
|
71
|
+
try {
|
|
72
|
+
await new Promise((resolve, reject) => {
|
|
73
|
+
Document.delete({ CUSTOMER_ID: customerId }, docId, function(err, result) {
|
|
74
|
+
if (err) return reject(err);
|
|
75
|
+
resolve(result);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
69
78
|
|
|
70
|
-
|
|
71
|
-
self.updateMany({}, {
|
|
79
|
+
await this.updateMany({}, {
|
|
72
80
|
$pull: { 'documents' : [docId] }
|
|
73
|
-
})
|
|
74
|
-
};
|
|
81
|
+
});
|
|
75
82
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
removeReferences
|
|
79
|
-
], function(err, results) {
|
|
83
|
+
return cb(null, null);
|
|
84
|
+
} catch(err) {
|
|
80
85
|
return cb(err, null);
|
|
81
|
-
}
|
|
86
|
+
}
|
|
82
87
|
|
|
83
88
|
};
|
|
84
89
|
|
|
85
|
-
Message.statics.getDocuments = function getDocuments(personIds, options, cb) {
|
|
90
|
+
Message.statics.getDocuments = async function getDocuments(personIds, options, cb) {
|
|
86
91
|
|
|
87
92
|
if (!cb) { throw new Error('cb is required'); }
|
|
88
93
|
if (!personIds) { return cb(new Error('personIds is required'), null); }
|
|
@@ -90,21 +95,25 @@ module.exports = function(mongoose, config) {
|
|
|
90
95
|
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
91
96
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
92
97
|
|
|
93
|
-
|
|
94
|
-
|
|
98
|
+
try {
|
|
99
|
+
let query = this.find({ customer: options.CUSTOMER_ID });
|
|
95
100
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
query.where({'attendees.external': { $in : personIds }});
|
|
102
|
+
query.populate({
|
|
103
|
+
path: 'documents',
|
|
104
|
+
match: { customer: options.CUSTOMER_ID },
|
|
105
|
+
populate: { path: 'createdBy', select: 'name avatarUrl title' }
|
|
106
|
+
});
|
|
102
107
|
|
|
103
|
-
|
|
108
|
+
const result = await query;
|
|
109
|
+
return cb(null, result);
|
|
110
|
+
} catch(err) {
|
|
111
|
+
return cb(err);
|
|
112
|
+
}
|
|
104
113
|
|
|
105
114
|
};
|
|
106
115
|
|
|
107
|
-
Message.statics.getById = function getById(id, options, cb) {
|
|
116
|
+
Message.statics.getById = async function getById(id, options, cb) {
|
|
108
117
|
|
|
109
118
|
if (!cb) { throw new Error('cb is required'); }
|
|
110
119
|
if (!id) { return cb(new Error('id is required'), null); }
|
|
@@ -113,50 +122,60 @@ module.exports = function(mongoose, config) {
|
|
|
113
122
|
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
114
123
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
115
124
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
try {
|
|
126
|
+
let query = this.findOne({
|
|
127
|
+
_id: id,
|
|
128
|
+
customer: options.CUSTOMER_ID
|
|
129
|
+
});
|
|
130
|
+
query.populate('organization', 'name logoUrl');
|
|
131
|
+
query.populate('recipients.internal', 'name avatarUrl title doNotDisplay');
|
|
132
|
+
query.populate('recipients.external', 'name avatarUrl title doNotDisplay');
|
|
133
|
+
query.populate({
|
|
134
|
+
path: 'documents',
|
|
135
|
+
match: { customer: options.CUSTOMER_ID }
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const result = await query;
|
|
139
|
+
return cb(null, result);
|
|
140
|
+
} catch(err) {
|
|
141
|
+
return cb(err);
|
|
142
|
+
}
|
|
130
143
|
|
|
131
144
|
};
|
|
132
145
|
|
|
133
|
-
Message.statics.getForCustomer = function getForCustomer(customerId, cb) {
|
|
146
|
+
Message.statics.getForCustomer = async function getForCustomer(customerId, cb) {
|
|
134
147
|
|
|
135
148
|
if (!cb) { throw new Error('cb is required'); }
|
|
136
149
|
if (!customerId) { return cb(new Error('customerId is required'), null); }
|
|
137
150
|
if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
|
|
138
151
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
152
|
+
try {
|
|
153
|
+
let query = this.find({ customer: customerId });
|
|
154
|
+
const result = await query;
|
|
155
|
+
return cb(null, result);
|
|
156
|
+
} catch(err) {
|
|
157
|
+
return cb(err);
|
|
158
|
+
}
|
|
143
159
|
|
|
144
160
|
};
|
|
145
161
|
|
|
146
|
-
Message.statics.getForDocument = function getForCustomer(docId, cb) {
|
|
162
|
+
Message.statics.getForDocument = async function getForCustomer(docId, cb) {
|
|
147
163
|
|
|
148
164
|
if (!cb) { throw new Error('cb is required'); }
|
|
149
165
|
if (!docId) { return cb(new Error('docId is required'), null); }
|
|
150
166
|
if (!mongoose.Types.ObjectId.isValid(docId)) { return cb(new Error('docId is not a valid ObjectId'), null); }
|
|
151
167
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
168
|
+
try {
|
|
169
|
+
let query = this.findOne({ documents: { $in: [docId] } });
|
|
170
|
+
const result = await query;
|
|
171
|
+
return cb(null, result);
|
|
172
|
+
} catch(err) {
|
|
173
|
+
return cb(err);
|
|
174
|
+
}
|
|
156
175
|
|
|
157
176
|
};
|
|
158
177
|
|
|
159
|
-
Message.statics.getForOrg = function getForOrg(orgId, options, cb) {
|
|
178
|
+
Message.statics.getForOrg = async function getForOrg(orgId, options, cb) {
|
|
160
179
|
|
|
161
180
|
if (!cb) { throw new Error('cb is required'); }
|
|
162
181
|
if (!orgId) { return cb(new Error('orgId is required'), null); }
|
|
@@ -167,23 +186,26 @@ module.exports = function(mongoose, config) {
|
|
|
167
186
|
|
|
168
187
|
// Note - This filters by customer so is NOT usable by admin tools
|
|
169
188
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
189
|
+
try {
|
|
190
|
+
let query = this.find({ customer: options.CUSTOMER_ID, organization: orgId });
|
|
191
|
+
|
|
192
|
+
query.populate('recipients.internal', 'name title avatarUrl doNotDisplay');
|
|
193
|
+
query.populate('recipients.external', 'name title avatarUrl doNotDisplay');
|
|
194
|
+
query.populate({
|
|
195
|
+
path: 'documents',
|
|
196
|
+
match: { customer: options.CUSTOMER_ID },
|
|
197
|
+
populate: { path: 'createdBy', select: 'name avatarUrl title' }
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const result = await query;
|
|
201
|
+
return cb(null, result);
|
|
202
|
+
} catch(err) {
|
|
203
|
+
return cb(err);
|
|
204
|
+
}
|
|
183
205
|
|
|
184
206
|
};
|
|
185
207
|
|
|
186
|
-
Message.statics.getForOrgs = function(orgIds, options, cb) {
|
|
208
|
+
Message.statics.getForOrgs = async function(orgIds, options, cb) {
|
|
187
209
|
|
|
188
210
|
if (!cb) { throw new Error('cb is required'); }
|
|
189
211
|
if (!orgIds) { return cb(new Error('orgIds is required'), null); }
|
|
@@ -191,27 +213,30 @@ module.exports = function(mongoose, config) {
|
|
|
191
213
|
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
192
214
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
193
215
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
216
|
+
try {
|
|
217
|
+
let query = this.find({ customer: options.CUSTOMER_ID });
|
|
218
|
+
query.find({ organization: { $in : orgIds }});
|
|
219
|
+
|
|
220
|
+
if (options.startDate) {
|
|
221
|
+
const startDate = options.startDate || moment().subtract(20, 'years').startOf('day').toISOString();
|
|
222
|
+
query.where('messageDate').gte(startDate)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (options.endDate) {
|
|
226
|
+
const endDate = options.endDate || moment().toISOString();
|
|
227
|
+
query.where('messageDate').lte(endDate)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
query.populate('documents');
|
|
231
|
+
const result = await query;
|
|
232
|
+
return cb(null, result);
|
|
233
|
+
} catch(err) {
|
|
234
|
+
return cb(err);
|
|
207
235
|
}
|
|
208
236
|
|
|
209
|
-
query.populate('documents');
|
|
210
|
-
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
211
|
-
|
|
212
237
|
};
|
|
213
238
|
|
|
214
|
-
Message.statics.getMostRecent = function getMostRecent(orgId, personIds, options, cb) {
|
|
239
|
+
Message.statics.getMostRecent = async function getMostRecent(orgId, personIds, options, cb) {
|
|
215
240
|
|
|
216
241
|
if (!cb) { throw new Error('cb is required'); }
|
|
217
242
|
if (!orgId) { return cb(new Error('orgId is required'), null); }
|
|
@@ -222,29 +247,32 @@ module.exports = function(mongoose, config) {
|
|
|
222
247
|
|
|
223
248
|
// Note - This filters by customer so is NOT usable by admin tools
|
|
224
249
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
let query = self.find({ customer: options.CUSTOMER_ID });
|
|
250
|
+
try {
|
|
251
|
+
// Must match customer
|
|
252
|
+
let query = this.find({ customer: options.CUSTOMER_ID });
|
|
229
253
|
|
|
230
|
-
|
|
231
|
-
|
|
254
|
+
// Match either the org or a list of people
|
|
255
|
+
query.where({ $or: [{organization: orgId}, {'recipients.external': { $in : personIds }}] });
|
|
232
256
|
|
|
233
|
-
|
|
234
|
-
|
|
257
|
+
// Optionally limit search space to message newer than some timestamp
|
|
258
|
+
if (options.timestamp) query.where({'messageDate': { $gte: options.timestamp }});
|
|
235
259
|
|
|
236
|
-
|
|
237
|
-
|
|
260
|
+
// Don't need the full raw message
|
|
261
|
+
query.select({ 'raw': 0 });
|
|
238
262
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
263
|
+
// Only need one
|
|
264
|
+
query.sort({ 'messageDate': -1 });
|
|
265
|
+
query.limit(1);
|
|
242
266
|
|
|
243
|
-
|
|
267
|
+
const result = await query;
|
|
268
|
+
return cb(null, result);
|
|
269
|
+
} catch(err) {
|
|
270
|
+
return cb(err);
|
|
271
|
+
}
|
|
244
272
|
|
|
245
273
|
};
|
|
246
274
|
|
|
247
|
-
Message.statics.getMostRecent2 = function getMostRecent2(orgId, personIds, options, cb) {
|
|
275
|
+
Message.statics.getMostRecent2 = async function getMostRecent2(orgId, personIds, options, cb) {
|
|
248
276
|
|
|
249
277
|
if (!cb) { throw new Error('cb is required'); }
|
|
250
278
|
if (!orgId) { return cb(new Error('orgId is required'), null); }
|
|
@@ -255,33 +283,36 @@ module.exports = function(mongoose, config) {
|
|
|
255
283
|
|
|
256
284
|
// Note - This filters by customer so is NOT usable by admin tools
|
|
257
285
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
let query = self.findOne({ customer: options.CUSTOMER_ID });
|
|
286
|
+
try {
|
|
287
|
+
// Must match customer
|
|
288
|
+
let query = this.findOne({ customer: options.CUSTOMER_ID });
|
|
262
289
|
|
|
263
|
-
|
|
290
|
+
personIds = personIds || [];
|
|
264
291
|
|
|
265
|
-
|
|
266
|
-
|
|
292
|
+
// Match either the org or a list of people
|
|
293
|
+
if (personIds.length >= 1) { query.where({ $or: [{organization: orgId}, {'recipients.external': { $in : personIds }}] }); }
|
|
267
294
|
|
|
268
|
-
|
|
269
|
-
|
|
295
|
+
// No people, just do the org
|
|
296
|
+
else { query.where({ organization: orgId }); }
|
|
270
297
|
|
|
271
|
-
|
|
272
|
-
|
|
298
|
+
// Optionally limit search space to message newer than some timestamp
|
|
299
|
+
if (options.timestamp) query.where({'messageDate': { $gt: options.timestamp }});
|
|
273
300
|
|
|
274
|
-
|
|
275
|
-
|
|
301
|
+
// Don't need the full raw message
|
|
302
|
+
query.select({ 'raw': 0 });
|
|
276
303
|
|
|
277
|
-
|
|
278
|
-
|
|
304
|
+
query.sort({ 'startTime': -1 });
|
|
305
|
+
query.limit(1);
|
|
279
306
|
|
|
280
|
-
|
|
307
|
+
const result = await query;
|
|
308
|
+
return cb(null, result);
|
|
309
|
+
} catch(err) {
|
|
310
|
+
return cb(err);
|
|
311
|
+
}
|
|
281
312
|
|
|
282
313
|
};
|
|
283
314
|
|
|
284
|
-
Message.statics.getForPeople = function getForPeople(personIds, options, cb) {
|
|
315
|
+
Message.statics.getForPeople = async function getForPeople(personIds, options, cb) {
|
|
285
316
|
|
|
286
317
|
if (!cb) { throw new Error('cb is required'); }
|
|
287
318
|
if (!personIds) { return cb(new Error('personIds is required'), null); }
|
|
@@ -291,24 +322,27 @@ module.exports = function(mongoose, config) {
|
|
|
291
322
|
|
|
292
323
|
// Note: This filters by customer so is NOT usable by admin tools
|
|
293
324
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
325
|
+
try {
|
|
326
|
+
let query = this.find({ customer: options.CUSTOMER_ID });
|
|
327
|
+
|
|
328
|
+
query.where({'recipients.external': { $in : personIds }});
|
|
329
|
+
query.populate('recipients.internal', 'name title avatarUrl doNotDisplay');
|
|
330
|
+
query.populate('recipients.external', 'name title avatarUrl doNotDisplay');
|
|
331
|
+
query.populate({
|
|
332
|
+
path: 'documents',
|
|
333
|
+
match: { customer: options.CUSTOMER_ID },
|
|
334
|
+
populate: { path: 'createdBy', select: 'name avatarUrl title' }
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
const result = await query;
|
|
338
|
+
return cb(null, result);
|
|
339
|
+
} catch(err) {
|
|
340
|
+
return cb(err);
|
|
341
|
+
}
|
|
308
342
|
|
|
309
343
|
};
|
|
310
344
|
|
|
311
|
-
Message.statics.getForPeopleLite = function getForPeopleLite(personIds, options, cb) {
|
|
345
|
+
Message.statics.getForPeopleLite = async function getForPeopleLite(personIds, options, cb) {
|
|
312
346
|
|
|
313
347
|
// Note - This doesn't filter by customer so is only usable by admin tools
|
|
314
348
|
|
|
@@ -319,49 +353,59 @@ module.exports = function(mongoose, config) {
|
|
|
319
353
|
|
|
320
354
|
if (!options.isWorkerProcess) { return cb(null, []); }
|
|
321
355
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
356
|
+
try {
|
|
357
|
+
let query = this.find({'recipients.external': { $in : personIds }});
|
|
358
|
+
const result = await query;
|
|
359
|
+
return cb(null, result);
|
|
360
|
+
} catch(err) {
|
|
361
|
+
return cb(err);
|
|
362
|
+
}
|
|
327
363
|
|
|
328
364
|
};
|
|
329
365
|
|
|
330
|
-
Message.statics.getUnprocessedDeals = function getUnprocessedDeals(customerId, cb) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
366
|
+
Message.statics.getUnprocessedDeals = async function getUnprocessedDeals(customerId, cb) {
|
|
367
|
+
|
|
368
|
+
try {
|
|
369
|
+
let query = this.find({
|
|
370
|
+
customer: customerId,
|
|
371
|
+
subtype: 'deals',
|
|
372
|
+
processed: { $ne: true }
|
|
373
|
+
});
|
|
374
|
+
query.populate({
|
|
375
|
+
path: 'documents',
|
|
376
|
+
match: { customer: customerId }
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
const result = await query;
|
|
380
|
+
return cb(null, result);
|
|
381
|
+
} catch(err) {
|
|
382
|
+
return cb(err);
|
|
383
|
+
}
|
|
344
384
|
|
|
345
385
|
};
|
|
346
386
|
|
|
347
|
-
Message.statics.getUnprocessedPortfolio = function getUnprocessedPortfolio(customerId, cb) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
387
|
+
Message.statics.getUnprocessedPortfolio = async function getUnprocessedPortfolio(customerId, cb) {
|
|
388
|
+
|
|
389
|
+
try {
|
|
390
|
+
let query = this.find({
|
|
391
|
+
customer: customerId,
|
|
392
|
+
subtype: 'portfolio',
|
|
393
|
+
processed: { $ne: true }
|
|
394
|
+
});
|
|
395
|
+
query.populate({
|
|
396
|
+
path: 'documents',
|
|
397
|
+
match: { customer: customerId }
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
const result = await query;
|
|
401
|
+
return cb(null, result);
|
|
402
|
+
} catch(err) {
|
|
403
|
+
return cb(err);
|
|
404
|
+
}
|
|
361
405
|
|
|
362
406
|
};
|
|
363
407
|
|
|
364
|
-
Message.statics.modifyById = function(id, update, cb) {
|
|
408
|
+
Message.statics.modifyById = async function(id, update, cb) {
|
|
365
409
|
|
|
366
410
|
// VERY IMPORTANT NOTE
|
|
367
411
|
// findByIdAndUpdate and findOneAndUpdate do not trigger pre-save hook so that code will not run here
|
|
@@ -370,16 +414,19 @@ module.exports = function(mongoose, config) {
|
|
|
370
414
|
if (!id) { return cb(new Error('id is required'), null); }
|
|
371
415
|
if (!update) { return cb(new Error('update is required'), null); }
|
|
372
416
|
|
|
373
|
-
const self = this;
|
|
374
|
-
|
|
375
417
|
// options runValidators defaults false which is ok since we have upsert false
|
|
376
418
|
// new returns the updated document
|
|
377
419
|
|
|
378
|
-
|
|
420
|
+
try {
|
|
421
|
+
const result = await this.findByIdAndUpdate(id, update, { upsert: false, new: true });
|
|
422
|
+
return cb(null, result);
|
|
423
|
+
} catch(err) {
|
|
424
|
+
return cb(err);
|
|
425
|
+
}
|
|
379
426
|
|
|
380
427
|
};
|
|
381
428
|
|
|
382
|
-
Message.statics.upsert = function(message, cb) {
|
|
429
|
+
Message.statics.upsert = async function(message, cb) {
|
|
383
430
|
|
|
384
431
|
const timestamp = new Date();
|
|
385
432
|
|
|
@@ -392,7 +439,12 @@ module.exports = function(mongoose, config) {
|
|
|
392
439
|
// The original message date isn't always contained in the email. In its absence, use created on.
|
|
393
440
|
message.messageDate = message.messageDate || message.originalMessageDate || message.createdOn;
|
|
394
441
|
|
|
395
|
-
|
|
442
|
+
try {
|
|
443
|
+
const result = await message.save();
|
|
444
|
+
return cb(null, result);
|
|
445
|
+
} catch(err) {
|
|
446
|
+
return cb(err);
|
|
447
|
+
}
|
|
396
448
|
|
|
397
449
|
};
|
|
398
450
|
|
|
@@ -402,4 +454,4 @@ module.exports = function(mongoose, config) {
|
|
|
402
454
|
|
|
403
455
|
mongoose.model('Message', Message);
|
|
404
456
|
|
|
405
|
-
};
|
|
457
|
+
};
|
package/lib/MessageRecipient.js
CHANGED
|
@@ -16,7 +16,7 @@ module.exports = function(mongoose, config) {
|
|
|
16
16
|
|
|
17
17
|
///////////////////////////////////////
|
|
18
18
|
|
|
19
|
-
MessageRecipient.statics.getMostRecent = function getMostRecent(orgId, customerId, personId, options, cb) {
|
|
19
|
+
MessageRecipient.statics.getMostRecent = async function getMostRecent(orgId, customerId, personId, options, cb) {
|
|
20
20
|
|
|
21
21
|
if (!cb) { throw new Error('cb is required'); }
|
|
22
22
|
if (!orgId) { return cb(new Error('orgId is required'), null); }
|
|
@@ -26,28 +26,31 @@ module.exports = function(mongoose, config) {
|
|
|
26
26
|
if (!personId) { return cb(new Error('personId is required'), null); }
|
|
27
27
|
if (!mongoose.Types.ObjectId.isValid(personId)) { return cb(new Error('personId is not a valid ObjectId'), null); }
|
|
28
28
|
|
|
29
|
-
const self = this;
|
|
30
|
-
|
|
31
29
|
options = options || {};
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
try {
|
|
32
|
+
let query = this.find({
|
|
33
|
+
customer: options.CUSTOMER_ID,
|
|
34
|
+
organization: orgId,
|
|
35
|
+
recipient: personId
|
|
36
|
+
});
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
// Optionally limit search space to message newer than some timestamp
|
|
39
|
+
if (options.timestamp) query.where({'messageDate': { $gte: options.timestamp }});
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
// Only need one
|
|
42
|
+
query.sort({ 'messageDate': -1 });
|
|
43
|
+
query.limit(1);
|
|
45
44
|
|
|
46
|
-
|
|
45
|
+
const result = await query;
|
|
46
|
+
return cb(null, result);
|
|
47
|
+
} catch(err) {
|
|
48
|
+
return cb(err);
|
|
49
|
+
}
|
|
47
50
|
|
|
48
51
|
};
|
|
49
52
|
|
|
50
|
-
MessageRecipient.statics.getMostRecentBatch = function getMostRecentBatch(orgId, customerId, personIds, options, cb) {
|
|
53
|
+
MessageRecipient.statics.getMostRecentBatch = async function getMostRecentBatch(orgId, customerId, personIds, options, cb) {
|
|
51
54
|
|
|
52
55
|
if (!cb) { throw new Error('cb is required'); }
|
|
53
56
|
if (!orgId) { return cb(new Error('orgId is required'), null); }
|
|
@@ -57,34 +60,42 @@ module.exports = function(mongoose, config) {
|
|
|
57
60
|
if (!personIds) { return cb(new Error('personIds is required'), null); }
|
|
58
61
|
if (!Array.isArray(personIds)) { return cb(new Error('personIds must be an array'), null); }
|
|
59
62
|
|
|
60
|
-
const self = this;
|
|
61
|
-
|
|
62
63
|
options = options || {};
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
try {
|
|
66
|
+
let query = this.find({
|
|
67
|
+
customer: options.CUSTOMER_ID,
|
|
68
|
+
organization: orgId
|
|
69
|
+
});
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
query.where({ 'recipient': { $in : personIds }});
|
|
70
72
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
// Optionally limit search space to message newer than some timestamp
|
|
74
|
+
if (options.timestamp) query.where({'messageDate': { $gte: options.timestamp }});
|
|
73
75
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
// Only need one
|
|
77
|
+
query.sort({ 'messageDate': -1 });
|
|
78
|
+
query.limit(1);
|
|
77
79
|
|
|
78
|
-
|
|
80
|
+
const result = await query;
|
|
81
|
+
return cb(null, result);
|
|
82
|
+
} catch(err) {
|
|
83
|
+
return cb(err);
|
|
84
|
+
}
|
|
79
85
|
|
|
80
86
|
};
|
|
81
87
|
|
|
82
|
-
MessageRecipient.statics.upsert = function(message, cb) {
|
|
83
|
-
|
|
88
|
+
MessageRecipient.statics.upsert = async function(message, cb) {
|
|
89
|
+
try {
|
|
90
|
+
const result = await message.save();
|
|
91
|
+
return cb(null, result);
|
|
92
|
+
} catch(err) {
|
|
93
|
+
return cb(err);
|
|
94
|
+
}
|
|
84
95
|
};
|
|
85
96
|
|
|
86
97
|
///////////////////////////////////////
|
|
87
98
|
|
|
88
99
|
mongoose.model('MessageRecipient', MessageRecipient);
|
|
89
100
|
|
|
90
|
-
};
|
|
101
|
+
};
|