@dhyasama/totem-models 9.84.0 → 9.85.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
|
};
|
|
@@ -101,6 +101,22 @@ module.exports = function(mongoose, config) {
|
|
|
101
101
|
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
+
LimitedPartnerCommunication.statics.getById = function getById(id, options, cb) {
|
|
105
|
+
|
|
106
|
+
const self = this;
|
|
107
|
+
|
|
108
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
109
|
+
if (!id) { return cb(new Error('id is required'), null); }
|
|
110
|
+
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
111
|
+
|
|
112
|
+
let query = self.find({
|
|
113
|
+
_id: id
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
query.exec(cb);
|
|
117
|
+
|
|
118
|
+
};
|
|
119
|
+
|
|
104
120
|
// So we can put these on lp pages
|
|
105
121
|
LimitedPartnerCommunication.statics.getForLimitedPartner = function getForLimitedPartner(lpid, options, cb) {
|
|
106
122
|
|
|
@@ -139,6 +155,18 @@ module.exports = function(mongoose, config) {
|
|
|
139
155
|
|
|
140
156
|
};
|
|
141
157
|
|
|
158
|
+
LimitedPartnerCommunication.statics.modifyById = function modifyById(id, update, options, cb) {
|
|
159
|
+
|
|
160
|
+
const self = this;
|
|
161
|
+
|
|
162
|
+
if (!cb) throw new Error('cb is required');
|
|
163
|
+
if (!id) { return cb(new Error('id is required'), null); }
|
|
164
|
+
if (!update) { return cb(new Error('update is required'), null); }
|
|
165
|
+
|
|
166
|
+
self.findByIdAndUpdate(id, update, { upsert: false, new: true }, cb);
|
|
167
|
+
|
|
168
|
+
};
|
|
169
|
+
|
|
142
170
|
// Remove all the docs associated with a campaign
|
|
143
171
|
LimitedPartnerCommunication.statics.removeByCampaign = function removeByCampaign(campaignId, options, cb) {
|
|
144
172
|
|