@dhyasama/totem-models 9.84.0 → 9.86.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.
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const _ = require('underscore');
|
|
4
4
|
|
|
5
|
+
const MAX_PROCESSING_ATTEMPTS = 2;
|
|
6
|
+
|
|
5
7
|
module.exports = function(mongoose, config) {
|
|
6
8
|
|
|
7
9
|
const Schema = mongoose.Schema;
|
|
@@ -24,7 +26,10 @@ module.exports = function(mongoose, config) {
|
|
|
24
26
|
body: { type: String, trim: true },
|
|
25
27
|
|
|
26
28
|
// sent all emails to queue
|
|
27
|
-
|
|
29
|
+
processed: { type: Boolean, required: true, default: false },
|
|
30
|
+
|
|
31
|
+
// Keep track of failures so we don't keep trying
|
|
32
|
+
numberOfFailedAttempts: { type: Number, required: true, default: 0, max: MAX_PROCESSING_ATTEMPTS }
|
|
28
33
|
|
|
29
34
|
});
|
|
30
35
|
|
|
@@ -47,7 +52,7 @@ module.exports = function(mongoose, config) {
|
|
|
47
52
|
|
|
48
53
|
};
|
|
49
54
|
|
|
50
|
-
// Scheduled but not sent
|
|
55
|
+
// Scheduled but not sent and not done trying
|
|
51
56
|
LimitedPartnerCampaign.statics.getUpcoming = function getUpcoming(customerId, options, cb) {
|
|
52
57
|
|
|
53
58
|
const self = this;
|
|
@@ -61,7 +66,8 @@ module.exports = function(mongoose, config) {
|
|
|
61
66
|
|
|
62
67
|
const query = self.find({
|
|
63
68
|
customer: customerId,
|
|
64
|
-
|
|
69
|
+
processed: false,
|
|
70
|
+
numberOfFailedAttempts: { $lt: MAX_PROCESSING_ATTEMPTS }
|
|
65
71
|
});
|
|
66
72
|
|
|
67
73
|
query.exec(cb);
|
|
@@ -78,7 +84,8 @@ module.exports = function(mongoose, config) {
|
|
|
78
84
|
if (!cb) { throw new Error('cb is required'); }
|
|
79
85
|
|
|
80
86
|
let query = self.find({
|
|
81
|
-
|
|
87
|
+
processed: false,
|
|
88
|
+
numberOfFailedAttempts: { $lt: MAX_PROCESSING_ATTEMPTS },
|
|
82
89
|
sendOn: { $lte: now }
|
|
83
90
|
});
|
|
84
91
|
|
|
@@ -91,7 +98,7 @@ module.exports = function(mongoose, config) {
|
|
|
91
98
|
|
|
92
99
|
};
|
|
93
100
|
|
|
94
|
-
// Scheduled and sent
|
|
101
|
+
// Scheduled and sent or done trying
|
|
95
102
|
LimitedPartnerCampaign.statics.getHistorical = function getHistorical(customerId, options, cb) {
|
|
96
103
|
|
|
97
104
|
const self = this;
|
|
@@ -100,13 +107,14 @@ module.exports = function(mongoose, config) {
|
|
|
100
107
|
if (!customerId) { return cb(new Error('customerId is required'), null); }
|
|
101
108
|
if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
|
|
102
109
|
|
|
103
|
-
// No need to check send on. If sentEmailsToQueue then safe to assume sendOn is in the past.
|
|
104
|
-
|
|
105
110
|
const query = self.find({
|
|
106
|
-
customer: customerId
|
|
107
|
-
sentEmailsToQueue: true
|
|
111
|
+
customer: customerId
|
|
108
112
|
});
|
|
109
113
|
|
|
114
|
+
// Processed or done trying
|
|
115
|
+
query['$or'].push({ processed: true });
|
|
116
|
+
query['$or'].push({ numberOfFailedAttempts: { $lt: MAX_PROCESSING_ATTEMPTS } });
|
|
117
|
+
|
|
110
118
|
query.exec(cb);
|
|
111
119
|
|
|
112
120
|
};
|
|
@@ -63,6 +63,8 @@ module.exports = function(mongoose, config) {
|
|
|
63
63
|
campaign: campaignId
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
+
query.populate('limitedPartner', 'name');
|
|
67
|
+
|
|
66
68
|
query.exec(cb);
|
|
67
69
|
|
|
68
70
|
};
|
|
@@ -101,6 +103,22 @@ module.exports = function(mongoose, config) {
|
|
|
101
103
|
|
|
102
104
|
};
|
|
103
105
|
|
|
106
|
+
LimitedPartnerCommunication.statics.getById = function getById(id, options, cb) {
|
|
107
|
+
|
|
108
|
+
const self = this;
|
|
109
|
+
|
|
110
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
111
|
+
if (!id) { return cb(new Error('id is required'), null); }
|
|
112
|
+
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
113
|
+
|
|
114
|
+
let query = self.find({
|
|
115
|
+
_id: id
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
query.exec(cb);
|
|
119
|
+
|
|
120
|
+
};
|
|
121
|
+
|
|
104
122
|
// So we can put these on lp pages
|
|
105
123
|
LimitedPartnerCommunication.statics.getForLimitedPartner = function getForLimitedPartner(lpid, options, cb) {
|
|
106
124
|
|
|
@@ -139,6 +157,18 @@ module.exports = function(mongoose, config) {
|
|
|
139
157
|
|
|
140
158
|
};
|
|
141
159
|
|
|
160
|
+
LimitedPartnerCommunication.statics.modifyById = function modifyById(id, update, options, cb) {
|
|
161
|
+
|
|
162
|
+
const self = this;
|
|
163
|
+
|
|
164
|
+
if (!cb) throw new Error('cb is required');
|
|
165
|
+
if (!id) { return cb(new Error('id is required'), null); }
|
|
166
|
+
if (!update) { return cb(new Error('update is required'), null); }
|
|
167
|
+
|
|
168
|
+
self.findByIdAndUpdate(id, update, { upsert: false, new: true }, cb);
|
|
169
|
+
|
|
170
|
+
};
|
|
171
|
+
|
|
142
172
|
// Remove all the docs associated with a campaign
|
|
143
173
|
LimitedPartnerCommunication.statics.removeByCampaign = function removeByCampaign(campaignId, options, cb) {
|
|
144
174
|
|