@dhyasama/totem-models 7.48.0 → 7.50.1
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 +27 -127
- 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;
|
|
@@ -332,86 +303,6 @@ module.exports = function(mongoose, config) {
|
|
|
332
303
|
|
|
333
304
|
};
|
|
334
305
|
|
|
335
|
-
Financials.statics.getUUIDsToSendInitial = function getUUIDsToSendInitial(cb) {
|
|
336
|
-
|
|
337
|
-
var self = this;
|
|
338
|
-
var now = new Date();
|
|
339
|
-
|
|
340
|
-
var query = self.find({
|
|
341
|
-
'snapshots': {
|
|
342
|
-
$elemMatch: {
|
|
343
|
-
'notifications.company.sendTo': { $gt: [] },
|
|
344
|
-
'notifications.company.initial.sendOn': { $lte: now },
|
|
345
|
-
'notifications.company.initial.sentOn': null,
|
|
346
|
-
'submittedOn': null
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
query.exec(function(err, result) {
|
|
352
|
-
|
|
353
|
-
if (err) { return cb(err, null); }
|
|
354
|
-
|
|
355
|
-
var snapshots = _.pluck(result || [], 'snapshots');
|
|
356
|
-
|
|
357
|
-
snapshots = _.flatten(snapshots);
|
|
358
|
-
|
|
359
|
-
snapshots = _.filter(snapshots, function(snapshot) {
|
|
360
|
-
|
|
361
|
-
var bool = !!snapshot.notifications.company.sendTo.length > 0;
|
|
362
|
-
bool = bool && snapshot.notifications.company.initial.sendOn < now;
|
|
363
|
-
bool = bool && !snapshot.notifications.company.initial.sentOn;
|
|
364
|
-
|
|
365
|
-
return bool;
|
|
366
|
-
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
return cb(null, _.pluck(snapshots, 'uuid'));
|
|
370
|
-
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
Financials.statics.getUUIDsToSendReminder = function getUUIDsToSendReminder(cb) {
|
|
376
|
-
|
|
377
|
-
var self = this;
|
|
378
|
-
var now = new Date();
|
|
379
|
-
|
|
380
|
-
var query = self.find({
|
|
381
|
-
'snapshots': {
|
|
382
|
-
$elemMatch: {
|
|
383
|
-
'notifications.company.sendTo': { $gt: [] },
|
|
384
|
-
'notifications.company.reminder.sendOn': { $lte: now },
|
|
385
|
-
'notifications.company.reminder.sentOn': null,
|
|
386
|
-
'submittedOn': null
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
query.exec(function(err, result) {
|
|
392
|
-
|
|
393
|
-
if (err) { return cb(err, null); }
|
|
394
|
-
|
|
395
|
-
var snapshots = _.pluck(result || [], 'snapshots');
|
|
396
|
-
|
|
397
|
-
snapshots = _.flatten(snapshots);
|
|
398
|
-
|
|
399
|
-
snapshots = _.filter(snapshots, function(snapshot) {
|
|
400
|
-
|
|
401
|
-
var bool = !!snapshot.notifications.company.sendTo.length > 0;
|
|
402
|
-
bool = bool && snapshot.notifications.company.reminder.sendOn < now;
|
|
403
|
-
bool = bool && !snapshot.notifications.company.reminder.sentOn;
|
|
404
|
-
|
|
405
|
-
return bool;
|
|
406
|
-
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
return cb(null, _.pluck(snapshots, 'uuid'));
|
|
410
|
-
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
};
|
|
414
|
-
|
|
415
306
|
Financials.statics.removeCustomerFinancials = function removeCustomerFinancials(customerId, cb) {
|
|
416
307
|
|
|
417
308
|
// this is only used to wipe out financials created by the google sheet import process
|
|
@@ -466,17 +357,26 @@ module.exports = function(mongoose, config) {
|
|
|
466
357
|
|
|
467
358
|
if(!snapshot) return;
|
|
468
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
|
+
|
|
469
365
|
// no uuid means the data was captured from the google sheet
|
|
470
|
-
if((!snapshot.uuid) || (!
|
|
366
|
+
if((!snapshot.uuid) || (!isManagedServices && isSubmitted) || (isManagedServices && isReviewed)) {
|
|
471
367
|
snapshot.status = 'Completed';
|
|
472
368
|
snapshot.action = null;
|
|
473
369
|
}
|
|
474
370
|
|
|
475
|
-
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));
|
|
476
379
|
|
|
477
|
-
var isScheduled = moment().isBefore(moment(snapshot.notifications.company.initial.sendOn));
|
|
478
|
-
var isOverdue = moment().subtract(30, 'd').isAfter(moment(snapshot.notifications.company.reminder.sendOn || snapshot.notifications.company.initial.sendOn));
|
|
479
|
-
|
|
480
380
|
if(isScheduled) {
|
|
481
381
|
snapshot.status = 'Scheduled';
|
|
482
382
|
snapshot.action = null;
|
|
@@ -489,9 +389,9 @@ module.exports = function(mongoose, config) {
|
|
|
489
389
|
|
|
490
390
|
else {
|
|
491
391
|
snapshot.status = 'In Progress';
|
|
492
|
-
if(
|
|
493
|
-
else if(
|
|
494
|
-
else if
|
|
392
|
+
if(isManagedServices && isSubmitted && !isRejected) snapshot.action = 'Review';
|
|
393
|
+
else if(isManagedServices && isSubmitted && isRejected) snapshot.action = 'Rejected';
|
|
394
|
+
else if(latestSentOn.status) snapshot.action = latestSentOn.status;
|
|
495
395
|
}
|
|
496
396
|
|
|
497
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
|
|