@dhyasama/totem-models 7.47.0 → 7.50.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/Deal.js +1 -0
- package/lib/Financials.js +43 -135
- package/lib/Organization.js +1 -0
- package/lib/Person.js +1 -1
- package/package.json +1 -1
- package/test/Financials.js +0 -3
package/lib/Deal.js
CHANGED
|
@@ -386,6 +386,7 @@ module.exports = function(mongoose, config) {
|
|
|
386
386
|
// CONFIG
|
|
387
387
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
388
388
|
|
|
389
|
+
Deal.set('usePushEach', true);
|
|
389
390
|
Deal.set('toJSON', { virtuals: true });
|
|
390
391
|
Deal.set('autoIndex', false);
|
|
391
392
|
Deal.set('usePushEach', true);
|
package/lib/Financials.js
CHANGED
|
@@ -28,8 +28,6 @@ module.exports = function(mongoose, config) {
|
|
|
28
28
|
|
|
29
29
|
uuid: { type: String },
|
|
30
30
|
|
|
31
|
-
campaignId: { type: String },
|
|
32
|
-
|
|
33
31
|
managedServices: { type: Boolean, default: false, required: true },
|
|
34
32
|
|
|
35
33
|
status: { type: String },
|
|
@@ -116,7 +114,9 @@ module.exports = function(mongoose, config) {
|
|
|
116
114
|
|
|
117
115
|
submittedOn: { type: Date, index: false },
|
|
118
116
|
submittedBy: { type: String, trim: true },
|
|
117
|
+
|
|
119
118
|
reviewedOn: { type: Date, index: false },
|
|
119
|
+
rejection: { type: String, trim: true },
|
|
120
120
|
|
|
121
121
|
notifications: {
|
|
122
122
|
|
|
@@ -127,25 +127,27 @@ module.exports = function(mongoose, config) {
|
|
|
127
127
|
name: { type: String, trim: true }
|
|
128
128
|
}],
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
sendOn: [{
|
|
131
131
|
sendOn: { type: Date, required: false },
|
|
132
132
|
sentOn: { type: Date, required: false },
|
|
133
133
|
postmarkMessageId: { type: String, trim: true },
|
|
134
134
|
status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
|
|
135
|
-
},
|
|
135
|
+
}],
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
// INITIAL AND REMINDER BEING DELETED
|
|
138
|
+
initial: {
|
|
138
139
|
sendOn: { type: Date, required: false },
|
|
139
140
|
sentOn: { type: Date, required: false },
|
|
140
141
|
postmarkMessageId: { type: String, trim: true },
|
|
141
142
|
status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
|
|
142
143
|
},
|
|
143
144
|
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
reminder: {
|
|
146
|
+
sendOn: { type: Date, required: false },
|
|
147
|
+
sentOn: { type: Date, required: false },
|
|
146
148
|
postmarkMessageId: { type: String, trim: true },
|
|
147
149
|
status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
|
|
148
|
-
}
|
|
150
|
+
},
|
|
149
151
|
|
|
150
152
|
},
|
|
151
153
|
|
|
@@ -181,8 +183,6 @@ module.exports = function(mongoose, config) {
|
|
|
181
183
|
|
|
182
184
|
});
|
|
183
185
|
|
|
184
|
-
|
|
185
|
-
|
|
186
186
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
187
187
|
// METHODS
|
|
188
188
|
// Methods operate on a single document
|
|
@@ -211,21 +211,6 @@ module.exports = function(mongoose, config) {
|
|
|
211
211
|
|
|
212
212
|
};
|
|
213
213
|
|
|
214
|
-
Financials.statics.getByPostmarkMessageId = function getByPostmarkMessageId(postmarkMessageId, cb) {
|
|
215
|
-
|
|
216
|
-
var self = this;
|
|
217
|
-
|
|
218
|
-
var query = self.findOne({
|
|
219
|
-
$or: [
|
|
220
|
-
{ 'snapshots.notifications.company.initial.postmarkMessageId': postmarkMessageId },
|
|
221
|
-
{ 'snapshots.notifications.company.reminder.postmarkMessageId': postmarkMessageId }
|
|
222
|
-
]
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
query.exec(cb);
|
|
226
|
-
|
|
227
|
-
};
|
|
228
|
-
|
|
229
214
|
Financials.statics.getByUUID = function getByUUID(customerId, uuid, cb) {
|
|
230
215
|
|
|
231
216
|
var self = this;
|
|
@@ -246,20 +231,6 @@ module.exports = function(mongoose, config) {
|
|
|
246
231
|
|
|
247
232
|
};
|
|
248
233
|
|
|
249
|
-
Financials.statics.getForCampaign = function getForCampaign(customerId, cb) {
|
|
250
|
-
|
|
251
|
-
var self = this;
|
|
252
|
-
|
|
253
|
-
var query = self.find({
|
|
254
|
-
'customer': customerId,
|
|
255
|
-
'notification.contact.exclude': { $ne: true }, // null, false, or non-existing field
|
|
256
|
-
'notification.contact.email': { $ne: null } // field exists and has a value
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
query.exec(cb);
|
|
260
|
-
|
|
261
|
-
};
|
|
262
|
-
|
|
263
234
|
Financials.statics.getForCustomer = function getForCustomer(customerId, cb) {
|
|
264
235
|
|
|
265
236
|
var self = this;
|
|
@@ -287,19 +258,27 @@ module.exports = function(mongoose, config) {
|
|
|
287
258
|
}
|
|
288
259
|
});
|
|
289
260
|
|
|
290
|
-
query.
|
|
261
|
+
query.populate('organization', 'name');
|
|
262
|
+
|
|
263
|
+
query.exec(function(err, results) {
|
|
291
264
|
|
|
292
|
-
var snapshots =
|
|
293
|
-
snapshots = _.flatten(snapshots);
|
|
265
|
+
var snapshots = [];
|
|
294
266
|
|
|
295
|
-
|
|
267
|
+
_.each(results, function(result) {
|
|
268
|
+
_.each(result.snapshots, function(snapshot) {
|
|
296
269
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
270
|
+
var bool = snapshot.managedServices;
|
|
271
|
+
bool = bool && snapshot.submittedOn;
|
|
272
|
+
bool = bool && !snapshot.reviewedOn;
|
|
300
273
|
|
|
301
|
-
|
|
274
|
+
if(bool) {
|
|
275
|
+
snapshots.push({
|
|
276
|
+
organization: result.organization.name,
|
|
277
|
+
snapshot: snapshot
|
|
278
|
+
});
|
|
279
|
+
}
|
|
302
280
|
|
|
281
|
+
});
|
|
303
282
|
});
|
|
304
283
|
|
|
305
284
|
if (err) { return cb(err, null); }
|
|
@@ -324,86 +303,6 @@ module.exports = function(mongoose, config) {
|
|
|
324
303
|
|
|
325
304
|
};
|
|
326
305
|
|
|
327
|
-
Financials.statics.getUUIDsToSendInitial = function getUUIDsToSendInitial(cb) {
|
|
328
|
-
|
|
329
|
-
var self = this;
|
|
330
|
-
var now = new Date();
|
|
331
|
-
|
|
332
|
-
var query = self.find({
|
|
333
|
-
'snapshots': {
|
|
334
|
-
$elemMatch: {
|
|
335
|
-
'notifications.company.sendTo': { $gt: [] },
|
|
336
|
-
'notifications.company.initial.sendOn': { $lte: now },
|
|
337
|
-
'notifications.company.initial.sentOn': null,
|
|
338
|
-
'submittedOn': null
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
query.exec(function(err, result) {
|
|
344
|
-
|
|
345
|
-
if (err) { return cb(err, null); }
|
|
346
|
-
|
|
347
|
-
var snapshots = _.pluck(result || [], 'snapshots');
|
|
348
|
-
|
|
349
|
-
snapshots = _.flatten(snapshots);
|
|
350
|
-
|
|
351
|
-
snapshots = _.filter(snapshots, function(snapshot) {
|
|
352
|
-
|
|
353
|
-
var bool = !!snapshot.notifications.company.sendTo.length > 0;
|
|
354
|
-
bool = bool && snapshot.notifications.company.initial.sendOn < now;
|
|
355
|
-
bool = bool && !snapshot.notifications.company.initial.sentOn;
|
|
356
|
-
|
|
357
|
-
return bool;
|
|
358
|
-
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
return cb(null, _.pluck(snapshots, 'uuid'));
|
|
362
|
-
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
Financials.statics.getUUIDsToSendReminder = function getUUIDsToSendReminder(cb) {
|
|
368
|
-
|
|
369
|
-
var self = this;
|
|
370
|
-
var now = new Date();
|
|
371
|
-
|
|
372
|
-
var query = self.find({
|
|
373
|
-
'snapshots': {
|
|
374
|
-
$elemMatch: {
|
|
375
|
-
'notifications.company.sendTo': { $gt: [] },
|
|
376
|
-
'notifications.company.reminder.sendOn': { $lte: now },
|
|
377
|
-
'notifications.company.reminder.sentOn': null,
|
|
378
|
-
'submittedOn': null
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
query.exec(function(err, result) {
|
|
384
|
-
|
|
385
|
-
if (err) { return cb(err, null); }
|
|
386
|
-
|
|
387
|
-
var snapshots = _.pluck(result || [], 'snapshots');
|
|
388
|
-
|
|
389
|
-
snapshots = _.flatten(snapshots);
|
|
390
|
-
|
|
391
|
-
snapshots = _.filter(snapshots, function(snapshot) {
|
|
392
|
-
|
|
393
|
-
var bool = !!snapshot.notifications.company.sendTo.length > 0;
|
|
394
|
-
bool = bool && snapshot.notifications.company.reminder.sendOn < now;
|
|
395
|
-
bool = bool && !snapshot.notifications.company.reminder.sentOn;
|
|
396
|
-
|
|
397
|
-
return bool;
|
|
398
|
-
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
return cb(null, _.pluck(snapshots, 'uuid'));
|
|
402
|
-
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
};
|
|
406
|
-
|
|
407
306
|
Financials.statics.removeCustomerFinancials = function removeCustomerFinancials(customerId, cb) {
|
|
408
307
|
|
|
409
308
|
// this is only used to wipe out financials created by the google sheet import process
|
|
@@ -458,17 +357,26 @@ module.exports = function(mongoose, config) {
|
|
|
458
357
|
|
|
459
358
|
if(!snapshot) return;
|
|
460
359
|
|
|
360
|
+
var isManagedServices = snapshot.managedServices;
|
|
361
|
+
var isSubmitted = !_.isEmpty(snapshot.submittedOn);
|
|
362
|
+
var isReviewed = !_.isEmpty(snapshot.reviewedOn);
|
|
363
|
+
var isRejected = !_.isEmpty(snapshot.rejection);
|
|
364
|
+
|
|
461
365
|
// no uuid means the data was captured from the google sheet
|
|
462
|
-
if((!snapshot.uuid) || (!
|
|
366
|
+
if((!snapshot.uuid) || (!isManagedServices && isSubmitted) || (managedServices && isReviewed)) {
|
|
463
367
|
snapshot.status = 'Completed';
|
|
464
368
|
snapshot.action = null;
|
|
465
369
|
}
|
|
466
370
|
|
|
467
|
-
else if(snapshot.notifications.company.
|
|
371
|
+
else if(!_.isEmpty(snapshot.notifications.company.sendOn)) {
|
|
372
|
+
|
|
373
|
+
var earliestSendOn = _.min(snapshot.notifications.company.sendOn, function(s) { return new Date(s.sendOn); });
|
|
374
|
+
var latestSendOn = _.max(snapshot.notifications.company.sendOn, function(s) { return new Date(s.sendOn); });
|
|
375
|
+
var latestSentOn = _.max(snapshot.notifications.company.sentOn, function(s) { return new Date(s.sentOn); })
|
|
376
|
+
|
|
377
|
+
var isScheduled = earliestSendOn.sendOn && moment().isBefore(moment(earliestSendOn.sendOn));
|
|
378
|
+
var isOverdue = latestSendOn.sendOn && moment().subtract(14, 'd').isAfter(moment(latestSendOn.sendOn));
|
|
468
379
|
|
|
469
|
-
var isScheduled = moment().isBefore(moment(snapshot.notifications.company.initial.sendOn));
|
|
470
|
-
var isOverdue = moment().subtract(30, 'd').isAfter(moment(snapshot.notifications.company.reminder.sendOn || snapshot.notifications.company.initial.sendOn));
|
|
471
|
-
|
|
472
380
|
if(isScheduled) {
|
|
473
381
|
snapshot.status = 'Scheduled';
|
|
474
382
|
snapshot.action = null;
|
|
@@ -481,9 +389,9 @@ module.exports = function(mongoose, config) {
|
|
|
481
389
|
|
|
482
390
|
else {
|
|
483
391
|
snapshot.status = 'In Progress';
|
|
484
|
-
if(
|
|
485
|
-
else if(
|
|
486
|
-
else if
|
|
392
|
+
if(managedServices && isSubmitted && !isRejected) snapshot.action = 'Review';
|
|
393
|
+
else if(managedServices && isSubmitted && isRejected) snapshot.action = 'Rejected';
|
|
394
|
+
else if(latestSentOn.status) snapshot.action = latestSentOn.status;
|
|
487
395
|
}
|
|
488
396
|
|
|
489
397
|
}
|
package/lib/Organization.js
CHANGED
|
@@ -2209,6 +2209,7 @@ module.exports = function(mongoose, config) {
|
|
|
2209
2209
|
Organization.set('toJSON', { virtuals: true });
|
|
2210
2210
|
Organization.set('usePushEach', true);
|
|
2211
2211
|
Organization.set('autoIndex', false);
|
|
2212
|
+
Organization.set('usePushEach', true);
|
|
2212
2213
|
|
|
2213
2214
|
Organization.index({ website: 1, websiteAliases: 1 }, { unique: true, partialFilterExpression : { type :"string" } });
|
|
2214
2215
|
Organization.on('index', function(err) { console.log('error building organization_new indexes: ' + err); });
|
package/lib/Person.js
CHANGED
|
@@ -884,7 +884,7 @@ module.exports = function(mongoose, config) {
|
|
|
884
884
|
|
|
885
885
|
this
|
|
886
886
|
.find({ 'contact.email.email': { $in : emails }, 'deleted': {$ne: true}})
|
|
887
|
-
.select('name avatarUrl title doNotDisplay')
|
|
887
|
+
.select('name avatarUrl title doNotDisplay contact')
|
|
888
888
|
.exec(function (err, people) {
|
|
889
889
|
cb(err, _.sortBy(people, function(person) { return person.name.full; }));
|
|
890
890
|
});
|
package/package.json
CHANGED
package/test/Financials.js
CHANGED
|
@@ -88,13 +88,10 @@ describe('Financials', function() {
|
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
// getByOrg
|
|
91
|
-
// getByPostmarkMessageId
|
|
92
91
|
// getByUUID
|
|
93
92
|
// getForCampaign
|
|
94
93
|
// getForCustomer
|
|
95
94
|
// getToSend
|
|
96
|
-
// getUUIDsToSendInitial
|
|
97
|
-
// getUUIDsToSendReminder
|
|
98
95
|
// removeCustomerFinancials
|
|
99
96
|
// upsert
|
|
100
97
|
|