@dhyasama/totem-models 12.3.0 → 12.5.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/helpers.js +0 -13
- package/lib/Account.js +149 -147
- package/lib/Activity.js +30 -16
- package/lib/ApiKey.js +25 -22
- package/lib/CalendarEvent.js +143 -70
- package/lib/CapTable.js +276 -231
- package/lib/Deal.js +548 -544
- package/lib/DiffbotArticle.js +29 -20
- package/lib/DiffbotOrganization.js +29 -20
- package/lib/Document.js +104 -86
- package/lib/Event.js +60 -43
- package/lib/EventAttendee.js +57 -45
- package/lib/Financials.js +456 -397
- package/lib/FinancialsAnalysis.js +50 -38
- package/lib/Flag.js +64 -54
- package/lib/Folder.js +49 -33
- package/lib/Fund.js +141 -100
- package/lib/Interaction.js +254 -213
- package/lib/Investment.js +70 -59
- package/lib/LimitedPartner.js +369 -328
- package/lib/LimitedPartnerCampaign.js +83 -61
- package/lib/LimitedPartnerCommunication.js +126 -88
- package/lib/LimitedPartnerContactGroup.js +44 -36
- package/lib/LimitedPartnerReportGenerator.js +19 -10
- package/lib/List.js +132 -103
- package/lib/Meeting.js +90 -66
- package/lib/Message.js +273 -208
- package/lib/MessageRecipient.js +56 -42
- package/lib/News.js +49 -35
- package/lib/Note.js +67 -57
- package/lib/Organization.js +864 -787
- package/lib/Person.js +351 -327
- package/lib/Rate.js +25 -14
- package/lib/Round.js +409 -404
- package/lib/Snapshot.js +15 -6
- package/lib/Sync.js +21 -9
- package/lib/Webhook.js +11 -3
- package/package.json +1 -1
package/helpers.js
CHANGED
|
@@ -134,16 +134,3 @@ const getPeopleSources = module.exports.getPeopleSources = function getPeopleSou
|
|
|
134
134
|
|
|
135
135
|
};
|
|
136
136
|
|
|
137
|
-
const sortPeopleSources = module.exports.sortPeopleSources = function sortPeopleSources(items, customerId) {
|
|
138
|
-
|
|
139
|
-
items = _.sortBy(items, function(item) {
|
|
140
|
-
return item.interactionsCount(customerId);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
items.reverse();
|
|
144
|
-
|
|
145
|
-
items = _.sortBy(items, 'name.full');
|
|
146
|
-
|
|
147
|
-
return items;
|
|
148
|
-
|
|
149
|
-
};
|
package/lib/Account.js
CHANGED
|
@@ -21,7 +21,7 @@ module.exports = function(mongoose, config) {
|
|
|
21
21
|
permissions: { type: Array, default: [] },
|
|
22
22
|
|
|
23
23
|
funds: [ { type: Schema.ObjectId, ref: 'Fund' } ],
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
totemLive: {
|
|
26
26
|
excelUser: { type: Boolean, default: true },
|
|
27
27
|
sheetsUser: { type: Boolean, default: true },
|
|
@@ -95,97 +95,87 @@ module.exports = function(mongoose, config) {
|
|
|
95
95
|
|
|
96
96
|
Account.statics.findByEmail = function(email, options, cb) {
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (!cb) { throw new Error('cb is required'); }
|
|
101
|
-
if (!email) { return cb(new Error('email is required'), null); }
|
|
98
|
+
const run = async () => {
|
|
99
|
+
if (!email) { throw new Error('email is required'); }
|
|
102
100
|
|
|
103
|
-
|
|
101
|
+
options = helpers.getDefaultOptions(options);
|
|
104
102
|
|
|
105
|
-
|
|
103
|
+
let query = { email: email.toLowerCase() };
|
|
106
104
|
|
|
107
|
-
|
|
105
|
+
if (options.current !== undefined || options.customerId !== undefined) {
|
|
108
106
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
self
|
|
113
|
-
.findOne(query)
|
|
114
|
-
.populate('person')
|
|
115
|
-
.exec().then(function(account) {
|
|
116
|
-
if (!account) { return cb(null, null); }
|
|
107
|
+
if (options.current !== undefined) { query.current = options.current; }
|
|
108
|
+
if (options.customerId !== undefined) { query.org = options.customerId; }
|
|
117
109
|
|
|
118
|
-
|
|
110
|
+
const account = await this.findOne(query).populate('person').lean({ virtuals: true });
|
|
111
|
+
if (!account) { return null; }
|
|
119
112
|
|
|
120
|
-
|
|
121
|
-
else { account.person.sources = []; }
|
|
113
|
+
if (account.populated('person')) {
|
|
122
114
|
|
|
123
|
-
}
|
|
115
|
+
if (account.org) { helpers.cleanPerson(account.person, account.org); }
|
|
116
|
+
else { account.person.sources = []; }
|
|
124
117
|
|
|
125
|
-
|
|
118
|
+
}
|
|
126
119
|
|
|
127
|
-
|
|
120
|
+
return account;
|
|
128
121
|
|
|
129
|
-
|
|
122
|
+
}
|
|
130
123
|
|
|
131
|
-
|
|
124
|
+
else {
|
|
132
125
|
|
|
133
|
-
|
|
134
|
-
.find(query)
|
|
135
|
-
.populate({
|
|
126
|
+
const result = await this.find(query).populate({
|
|
136
127
|
path: 'org',
|
|
137
128
|
select: 'name'
|
|
138
|
-
})
|
|
139
|
-
|
|
129
|
+
}).lean({ virtuals: true });
|
|
130
|
+
return result;
|
|
140
131
|
|
|
141
|
-
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
136
|
+
else { return run(); }
|
|
142
137
|
|
|
143
138
|
};
|
|
144
139
|
|
|
145
140
|
Account.statics.findByEmails = function(emails, cb) {
|
|
146
141
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (!cb) { throw new Error('cb is required'); }
|
|
150
|
-
if (!emails) { return cb(new Error('email is required'), null); }
|
|
142
|
+
const run = async () => {
|
|
143
|
+
if (!emails) { throw new Error('email is required'); }
|
|
151
144
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
.populate('person')
|
|
155
|
-
.exec().then(function(accounts) {
|
|
156
|
-
if (!accounts) { return cb(null, null); }
|
|
145
|
+
const accounts = await this.find({ 'email': { $in : emails }}).populate('person').lean({ virtuals: true });
|
|
146
|
+
if (!accounts) { return null; }
|
|
157
147
|
|
|
158
|
-
|
|
148
|
+
_.each(accounts, function(account) {
|
|
159
149
|
|
|
160
|
-
|
|
150
|
+
if (account.populated('person')) {
|
|
161
151
|
|
|
162
|
-
|
|
163
|
-
|
|
152
|
+
if (account.org) { helpers.cleanPerson(account.person, account.org); }
|
|
153
|
+
else { account.person.sources = []; }
|
|
164
154
|
|
|
165
|
-
|
|
155
|
+
}
|
|
166
156
|
|
|
167
|
-
|
|
157
|
+
});
|
|
168
158
|
|
|
169
|
-
|
|
159
|
+
return accounts;
|
|
160
|
+
};
|
|
170
161
|
|
|
171
|
-
|
|
162
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
163
|
+
else { return run(); }
|
|
172
164
|
|
|
173
165
|
};
|
|
174
166
|
|
|
175
167
|
Account.statics.getById = function (id, cb) {
|
|
176
168
|
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (!id) { throw new Error('id is required'); }
|
|
181
|
-
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
169
|
+
const run = async () => {
|
|
170
|
+
if (!id) { throw new Error('id is required'); }
|
|
171
|
+
if (!mongoose.Types.ObjectId.isValid(id)) { throw new Error('id is not a valid ObjectId'); }
|
|
182
172
|
|
|
183
|
-
|
|
173
|
+
let query = this.findById(id);
|
|
184
174
|
|
|
185
|
-
|
|
186
|
-
|
|
175
|
+
query.populate('person');
|
|
176
|
+
query.populate('org');
|
|
187
177
|
|
|
188
|
-
|
|
178
|
+
const account = await query.lean({ virtuals: true });
|
|
189
179
|
if (account && account.populated('person') && account.populated('org')) {
|
|
190
180
|
|
|
191
181
|
// Scrub customer info before returning
|
|
@@ -196,23 +186,25 @@ module.exports = function(mongoose, config) {
|
|
|
196
186
|
|
|
197
187
|
if (account.populated('person')) { helpers.cleanPerson(account.person, customerId); }
|
|
198
188
|
|
|
199
|
-
return
|
|
189
|
+
return account;
|
|
200
190
|
|
|
201
191
|
}
|
|
202
192
|
else if (!account) {
|
|
203
|
-
|
|
193
|
+
throw new Error('No account with id ' + id.toString());
|
|
204
194
|
}
|
|
205
195
|
else if (account && !account.person) {
|
|
206
|
-
|
|
196
|
+
throw new Error('Missing person reference on account with id ' + id.toString());
|
|
207
197
|
}
|
|
208
198
|
else if (account && !account.org) {
|
|
209
|
-
|
|
199
|
+
throw new Error('Missing org reference on account with id ' + id.toString());
|
|
210
200
|
}
|
|
211
201
|
else {
|
|
212
|
-
|
|
202
|
+
throw new Error('Unknown error');
|
|
213
203
|
}
|
|
204
|
+
};
|
|
214
205
|
|
|
215
|
-
|
|
206
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
207
|
+
else { return run(); }
|
|
216
208
|
|
|
217
209
|
};
|
|
218
210
|
|
|
@@ -220,75 +212,79 @@ module.exports = function(mongoose, config) {
|
|
|
220
212
|
|
|
221
213
|
// No population so no need to scrub
|
|
222
214
|
|
|
223
|
-
const
|
|
215
|
+
const run = async () => {
|
|
216
|
+
if (!customerId) { throw new Error('customerId is required'); }
|
|
217
|
+
if (!mongoose.Types.ObjectId.isValid(customerId)) { throw new Error('customerId is not a valid ObjectId'); }
|
|
224
218
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
219
|
+
const result = await this.find({ 'org': customerId }).lean({ virtuals: true });
|
|
220
|
+
return result;
|
|
221
|
+
};
|
|
228
222
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
223
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
224
|
+
else { return run(); }
|
|
232
225
|
|
|
233
226
|
};
|
|
234
227
|
|
|
235
228
|
Account.statics.updateCurrent = function(email, customerId, cb) {
|
|
236
229
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const self = this;
|
|
230
|
+
const run = async () => {
|
|
231
|
+
if (!email) { throw new Error('email is required'); }
|
|
232
|
+
if (!customerId) { throw new Error('customerId is required'); }
|
|
233
|
+
if (!mongoose.Types.ObjectId.isValid(customerId)) { throw new Error('customerId is not a valid ObjectId'); }
|
|
243
234
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
235
|
+
await this.updateMany({ email: email }, { $set: { current: false } });
|
|
236
|
+
const res = await this.updateOne({ email: email, org: customerId }, { $set: { current: true } });
|
|
237
|
+
return res;
|
|
238
|
+
};
|
|
247
239
|
|
|
248
|
-
|
|
240
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
241
|
+
else { return run(); }
|
|
249
242
|
|
|
250
243
|
};
|
|
251
244
|
|
|
252
245
|
Account.statics.updateOrg = function(email, customerId, cb) {
|
|
253
246
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
247
|
+
const run = async () => {
|
|
248
|
+
if (!email) { throw new Error('email is required'); }
|
|
249
|
+
if (!customerId) { throw new Error('customerId is required'); }
|
|
250
|
+
if (!mongoose.Types.ObjectId.isValid(customerId)) { throw new Error('customerId is not a valid ObjectId'); }
|
|
258
251
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
252
|
+
const res = await this.updateOne({ email: email }, { $set: { org: customerId } });
|
|
253
|
+
return res;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
257
|
+
else { return run(); }
|
|
264
258
|
|
|
265
259
|
};
|
|
266
260
|
|
|
267
261
|
Account.statics.listAdminAccounts = function (options, cb) {
|
|
268
262
|
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
263
|
+
const run = async () => {
|
|
264
|
+
const result = await this.find({ 'active': true, 'role': 'admin' }).lean({ virtuals: true });
|
|
265
|
+
return result;
|
|
266
|
+
};
|
|
272
267
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
268
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
269
|
+
else { return run(); }
|
|
276
270
|
|
|
277
271
|
};
|
|
278
272
|
|
|
279
273
|
Account.statics.listSummaryAccounts = function (options, cb) {
|
|
280
274
|
|
|
281
|
-
const
|
|
275
|
+
const run = async () => {
|
|
276
|
+
let queryObj = { 'active': true, 'summary.active': true };
|
|
282
277
|
|
|
283
|
-
|
|
278
|
+
if (options.CUSTOMER_ID) {
|
|
279
|
+
queryObj['org'] = options.CUSTOMER_ID;
|
|
280
|
+
}
|
|
284
281
|
|
|
285
|
-
|
|
282
|
+
const result = await this.find(queryObj).lean({ virtuals: true });
|
|
283
|
+
return result;
|
|
284
|
+
};
|
|
286
285
|
|
|
287
|
-
if (
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
self.find(queryObj).exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
286
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
287
|
+
else { return run(); }
|
|
292
288
|
|
|
293
289
|
};
|
|
294
290
|
|
|
@@ -297,36 +293,33 @@ module.exports = function(mongoose, config) {
|
|
|
297
293
|
// This is only for worker
|
|
298
294
|
// Since it's only worker, no need to scrub results
|
|
299
295
|
|
|
300
|
-
const
|
|
296
|
+
const run = async () => {
|
|
297
|
+
options = helpers.getDefaultOptions(options);
|
|
301
298
|
|
|
302
|
-
|
|
299
|
+
if (!options.isWorkerProcess) { return []; }
|
|
303
300
|
|
|
304
|
-
|
|
301
|
+
const result = await this.find({'active': true}).populate('person').sort({'person.name.last': 1}).lean({ virtuals: true });
|
|
302
|
+
return result;
|
|
303
|
+
};
|
|
305
304
|
|
|
306
|
-
if (
|
|
307
|
-
|
|
308
|
-
self
|
|
309
|
-
.find({'active': true})
|
|
310
|
-
.populate('person')
|
|
311
|
-
.sort({'person.name.last': 1})
|
|
312
|
-
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
305
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
306
|
+
else { return run(); }
|
|
313
307
|
|
|
314
308
|
};
|
|
315
309
|
|
|
316
310
|
Account.statics.listAllAccountsSkinny = function (options, cb) {
|
|
317
311
|
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
if (!cb) { throw new Error('cb is required'); }
|
|
312
|
+
const run = async () => {
|
|
313
|
+
options = helpers.getDefaultOptions(options);
|
|
321
314
|
|
|
322
|
-
|
|
315
|
+
if (!options.isWorkerProcess) { return []; }
|
|
323
316
|
|
|
324
|
-
|
|
317
|
+
const result = await this.find({'active': true}).select('active email auth').lean({ virtuals: true });
|
|
318
|
+
return result;
|
|
319
|
+
};
|
|
325
320
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
.select('active email auth')
|
|
329
|
-
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
321
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
322
|
+
else { return run(); }
|
|
330
323
|
|
|
331
324
|
};
|
|
332
325
|
|
|
@@ -335,22 +328,22 @@ module.exports = function(mongoose, config) {
|
|
|
335
328
|
// This is only for worker
|
|
336
329
|
// Since it's only worker, no need to scrub results
|
|
337
330
|
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
if (!cb) { throw new Error('cb is required'); }
|
|
341
|
-
|
|
342
|
-
options = helpers.getDefaultOptions(options);
|
|
331
|
+
const run = async () => {
|
|
332
|
+
options = helpers.getDefaultOptions(options);
|
|
343
333
|
|
|
344
|
-
|
|
334
|
+
if (!options.isWorkerProcess) { return []; }
|
|
345
335
|
|
|
346
|
-
|
|
347
|
-
.find({
|
|
336
|
+
const result = await this.find({
|
|
348
337
|
'active': true,
|
|
349
338
|
'calendar.active': true,
|
|
350
339
|
'auth.strategy': 'google',
|
|
351
340
|
'auth.google.refreshToken': { $ne: null }
|
|
352
|
-
})
|
|
353
|
-
|
|
341
|
+
}).lean({ virtuals: true });
|
|
342
|
+
return result;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
346
|
+
else { return run(); }
|
|
354
347
|
|
|
355
348
|
};
|
|
356
349
|
|
|
@@ -359,34 +352,37 @@ module.exports = function(mongoose, config) {
|
|
|
359
352
|
// This is only for worker
|
|
360
353
|
// Since it's only worker, no need to scrub results
|
|
361
354
|
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
if (!cb) { throw new Error('cb is required'); }
|
|
355
|
+
const run = async () => {
|
|
356
|
+
options = helpers.getDefaultOptions(options);
|
|
365
357
|
|
|
366
|
-
|
|
358
|
+
if (!options.isWorkerProcess) { return []; }
|
|
367
359
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
self
|
|
371
|
-
.find({
|
|
360
|
+
const result = await this.find({
|
|
372
361
|
'active': true,
|
|
373
362
|
'calendar.active': true,
|
|
374
363
|
'auth.strategy': 'microsoft',
|
|
375
364
|
'auth.microsoft.refreshToken': { $ne: null }
|
|
376
|
-
})
|
|
377
|
-
|
|
365
|
+
}).lean({ virtuals: true });
|
|
366
|
+
return result;
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
370
|
+
else { return run(); }
|
|
378
371
|
|
|
379
372
|
};
|
|
380
373
|
|
|
381
374
|
Account.statics.delete = function (id, options, cb) {
|
|
382
375
|
|
|
383
|
-
const
|
|
376
|
+
const run = async () => {
|
|
377
|
+
if (!id) { throw new Error('id is required'); }
|
|
378
|
+
if (!mongoose.Types.ObjectId.isValid(id)) { throw new Error('id is not a valid ObjectId'); }
|
|
384
379
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
380
|
+
const result = await this.findByIdAndDelete(id);
|
|
381
|
+
return result;
|
|
382
|
+
};
|
|
388
383
|
|
|
389
|
-
|
|
384
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
385
|
+
else { return run(); }
|
|
390
386
|
|
|
391
387
|
};
|
|
392
388
|
|
|
@@ -394,7 +390,13 @@ module.exports = function(mongoose, config) {
|
|
|
394
390
|
|
|
395
391
|
// No population so no need to scrub
|
|
396
392
|
|
|
397
|
-
|
|
393
|
+
const run = async () => {
|
|
394
|
+
const result = await account.save();
|
|
395
|
+
return result;
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
399
|
+
else { return run(); }
|
|
398
400
|
|
|
399
401
|
};
|
|
400
402
|
Account.set('autoIndex', false);
|
package/lib/Activity.js
CHANGED
|
@@ -42,15 +42,14 @@ module.exports = function(mongoose, config) {
|
|
|
42
42
|
|
|
43
43
|
Activity.statics.add = function(username, type, remoteAddress, url, filename, callback) {
|
|
44
44
|
|
|
45
|
-
const
|
|
45
|
+
const run = async () => {
|
|
46
|
+
if (!username) throw new Error('username is required');
|
|
47
|
+
if (!type) throw new Error('type is required');
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
if (!type) throw new Error('type is required');
|
|
49
|
-
if (!callback) throw new Error('callback is required');
|
|
49
|
+
username = username.toLowerCase();
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
self.findOne({ 'username': username }).then(function(activity) {if (!activity) {
|
|
51
|
+
let activity = await this.findOne({ 'username': username });
|
|
52
|
+
if (!activity) {
|
|
54
53
|
const A = mongoose.model('Activity');
|
|
55
54
|
activity = new A();
|
|
56
55
|
activity.username = username;
|
|
@@ -71,29 +70,44 @@ module.exports = function(mongoose, config) {
|
|
|
71
70
|
|
|
72
71
|
if (activity) {
|
|
73
72
|
activity.items.unshift(item);
|
|
74
|
-
activity.save()
|
|
75
|
-
|
|
76
|
-
}).catch(function(err) { callback(err); });
|
|
73
|
+
await activity.save();
|
|
74
|
+
return item;
|
|
77
75
|
}
|
|
78
76
|
else {
|
|
79
|
-
return
|
|
77
|
+
return null;
|
|
80
78
|
}
|
|
79
|
+
};
|
|
81
80
|
|
|
82
|
-
|
|
81
|
+
if (typeof callback === 'function') { run().then(result => callback(null, result)).catch(callback); }
|
|
82
|
+
else { return run(); }
|
|
83
83
|
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
Activity.statics.forMessage = function(username, messageId, cb) {
|
|
87
|
-
|
|
87
|
+
|
|
88
|
+
const run = async () => {
|
|
89
|
+
const result = await this.find({ 'username': username.toLowerCase(), 'items.document.messageId': messageId }).lean({ virtuals: true });
|
|
90
|
+
return result;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
94
|
+
else { return run(); }
|
|
95
|
+
|
|
88
96
|
};
|
|
89
97
|
|
|
90
98
|
Activity.statics.list = function(username, maxItems, cb) {
|
|
91
99
|
|
|
92
|
-
|
|
100
|
+
const run = async () => {
|
|
101
|
+
var query = this.findOne({ 'username': username.toLowerCase() });
|
|
102
|
+
|
|
103
|
+
if (maxItems && maxItems >= 1) { query = query.slice('items', maxItems); }
|
|
93
104
|
|
|
94
|
-
|
|
105
|
+
const result = await query.lean({ virtuals: true });
|
|
106
|
+
return result;
|
|
107
|
+
};
|
|
95
108
|
|
|
96
|
-
|
|
109
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
110
|
+
else { return run(); }
|
|
97
111
|
|
|
98
112
|
};
|
|
99
113
|
Activity.set('autoIndex', false);
|
package/lib/ApiKey.js
CHANGED
|
@@ -20,44 +20,47 @@ module.exports = function(mongoose, config) {
|
|
|
20
20
|
|
|
21
21
|
ApiKey.statics.getByTokenHash = function(hash, cb) {
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
const run = async () => {
|
|
24
|
+
if (!hash) { throw new Error('hash is required'); }
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
const result = await this.findOne({ tokenHash: hash }).lean({ virtuals: true });
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
30
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
31
|
+
else { return run(); }
|
|
31
32
|
|
|
32
33
|
};
|
|
33
34
|
|
|
34
35
|
ApiKey.statics.getByAccount = function(accountId, customerId, cb) {
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
const run = async () => {
|
|
38
|
+
if (!accountId) { throw new Error('accountId is required'); }
|
|
39
|
+
if (!customerId) { throw new Error('customerId is required'); }
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
const result = await this.find({ account: accountId, customer: customerId, active: true }).sort({ createdOn: -1 }).select('scopes createdOn lastUsedOn').lean({ virtuals: true });
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
.sort({ createdOn: -1 })
|
|
45
|
-
.select('scopes createdOn lastUsedOn')
|
|
46
|
-
.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
45
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
46
|
+
else { return run(); }
|
|
47
47
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
ApiKey.statics.revoke = function(tokenId, accountId, customerId, cb) {
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
const run = async () => {
|
|
53
|
+
if (!tokenId) { throw new Error('tokenId is required'); }
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
const result = await this.findOneAndUpdate(
|
|
56
|
+
{ _id: tokenId, account: accountId, customer: customerId },
|
|
57
|
+
{ active: false },
|
|
58
|
+
{ new: true });
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
{ active: false },
|
|
60
|
-
{ new: true }).then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
62
|
+
if (typeof cb === 'function') { run().then(result => cb(null, result)).catch(cb); return; }
|
|
63
|
+
else { return run(); }
|
|
61
64
|
|
|
62
65
|
};
|
|
63
66
|
ApiKey.set('autoIndex', false);
|