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