@dhyasama/totem-models 9.59.0 → 9.61.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,15 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module.exports = function(mongoose, config) {
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
Schema = mongoose.Schema,
|
|
8
|
-
_ = require('underscore');
|
|
5
|
+
const Schema = mongoose.Schema;
|
|
9
6
|
|
|
10
7
|
const LimitedPartnerCommunication = new Schema({
|
|
11
8
|
|
|
12
|
-
// name of the
|
|
13
|
-
|
|
9
|
+
// name of the campaign, e.g., "2022 Annual Audit"
|
|
10
|
+
campaign: { type: String, trim: true, required: true },
|
|
14
11
|
|
|
15
12
|
// customer sending this communication
|
|
16
13
|
customer: { type: Schema.ObjectId, ref: 'Organization', required: true },
|
|
@@ -18,91 +15,101 @@ module.exports = function(mongoose, config) {
|
|
|
18
15
|
// date and time to send
|
|
19
16
|
sendOn: { type: Date, required: true },
|
|
20
17
|
|
|
21
|
-
// email
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// email body
|
|
25
|
-
body: { type: String, trim: true, required: true },
|
|
26
|
-
|
|
27
|
-
// job was added to queue to send individual emails
|
|
28
|
-
sentToQueue: { type: Boolean, required: true, default: false },
|
|
18
|
+
// email content
|
|
19
|
+
email: {
|
|
29
20
|
|
|
30
|
-
|
|
21
|
+
// email subject
|
|
22
|
+
subject: { type: String, trim: true, required: true },
|
|
31
23
|
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// unique id for this document
|
|
36
|
-
uuid: { type: String, trim: true, required: true },
|
|
24
|
+
// email body
|
|
25
|
+
body: { type: String, trim: true, required: true },
|
|
37
26
|
|
|
38
|
-
|
|
39
|
-
email: { type: String, trim: true, required: true },
|
|
27
|
+
},
|
|
40
28
|
|
|
41
|
-
|
|
42
|
-
attachToEmail: { type: Boolean, required: true, default: false },
|
|
29
|
+
limitedPartners: [{
|
|
43
30
|
|
|
44
|
-
//
|
|
45
|
-
|
|
31
|
+
// the lp it's for
|
|
32
|
+
limitedPartner: { type: Schema.ObjectId, ref: 'LimitedPartner', required: true },
|
|
46
33
|
|
|
47
|
-
// email
|
|
48
|
-
|
|
34
|
+
// attach documents to email (only option currently supported)
|
|
35
|
+
attachToEmail: { type: Boolean, required: true, default: true },
|
|
49
36
|
|
|
50
|
-
|
|
37
|
+
// the documents included in this communication
|
|
38
|
+
documents: [{
|
|
51
39
|
|
|
52
|
-
|
|
53
|
-
oneTimePassword: { type: String, trim: true, required: true },
|
|
40
|
+
fileName: { type: String, trim: true, required: true },
|
|
54
41
|
|
|
55
|
-
|
|
56
|
-
|
|
42
|
+
// file type
|
|
43
|
+
contentType: { type: String, trim: true, required: true },
|
|
57
44
|
|
|
58
|
-
|
|
45
|
+
// file size
|
|
46
|
+
contentLength: { type: String, trim: true, required: true },
|
|
59
47
|
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
// where to find in s3
|
|
49
|
+
s3: {
|
|
50
|
+
bucket: { type: String, required: true, trim: true },
|
|
51
|
+
key: { type: String, required: true, trim: true }
|
|
52
|
+
}
|
|
62
53
|
|
|
63
|
-
|
|
64
|
-
contentLength: { type: String, trim: true, required: true },
|
|
54
|
+
}],
|
|
65
55
|
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
// emails of recipients
|
|
57
|
+
emails: [{ type: String, trim: true, required: true }],
|
|
58
|
+
|
|
59
|
+
notifications: [{
|
|
60
|
+
sendTo: { type: String, trim: true },
|
|
61
|
+
sendOn: { type: Date, required: false },
|
|
62
|
+
sentOn: { type: Date, required: false },
|
|
63
|
+
sentToQueue: { type: Boolean, default: false },
|
|
64
|
+
postmarkMessageId: { type: String, trim: true },
|
|
65
|
+
status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
|
|
66
|
+
}],
|
|
71
67
|
|
|
72
68
|
}]
|
|
73
69
|
|
|
74
70
|
});
|
|
75
71
|
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
// Use 2: Also, use this to get doc when an lp requests it. Use comm id from url to get it here,
|
|
79
|
-
// then in BLL use the uuid from url to select the doc. At that point, we can serve up
|
|
80
|
-
// the doc or go through the OTP process.
|
|
81
|
-
LimitedPartnerCommunication.statics.getById = function getById(id, options, cb) {
|
|
72
|
+
// So we can put these on lp pages
|
|
73
|
+
LimitedPartnerCommunication.statics.getForLimitedPartner = function getForLimitedPartner(lpid, options, cb) {
|
|
82
74
|
|
|
83
75
|
const self = this;
|
|
84
76
|
|
|
85
77
|
if (!cb) { throw new Error('cb is required'); }
|
|
86
|
-
if (!
|
|
87
|
-
if (!mongoose.Types.ObjectId.isValid(
|
|
78
|
+
if (!lpid) { return cb(new Error('lpid is required'), null); }
|
|
79
|
+
if (!mongoose.Types.ObjectId.isValid(lpid)) { return cb(new Error('lpid is not a valid ObjectId'), null); }
|
|
88
80
|
if (!options) { return cb(new Error('options is required'), null); }
|
|
89
81
|
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
90
82
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
91
83
|
|
|
92
|
-
let query = self.
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
let query = self.find({
|
|
85
|
+
limitedPartner: lpid,
|
|
86
|
+
customer: options.CUSTOMER_ID
|
|
95
87
|
});
|
|
96
88
|
|
|
97
|
-
query.
|
|
98
|
-
|
|
89
|
+
query.exec(cb);
|
|
90
|
+
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// Get all communications that haven't been sent but are scheduled to go
|
|
94
|
+
// Scheduled worker jobs will use this and add them to the queue to send
|
|
95
|
+
LimitedPartnerCommunication.statics.getReadyToSend = function getReadyToSend(options, cb) {
|
|
96
|
+
|
|
97
|
+
const self = this;
|
|
98
|
+
const now = new Date();
|
|
99
|
+
|
|
100
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
101
|
+
|
|
102
|
+
let query = self.find({
|
|
103
|
+
sentToQueue: false,
|
|
104
|
+
sendOn: { $lte: now }
|
|
105
|
+
});
|
|
99
106
|
|
|
100
107
|
query.exec(cb);
|
|
101
108
|
|
|
102
109
|
};
|
|
103
110
|
|
|
104
|
-
//
|
|
105
|
-
LimitedPartnerCommunication.statics.
|
|
111
|
+
// For the "Historical" page
|
|
112
|
+
LimitedPartnerCommunication.statics.getSentForCustomer = function getSentForCustomer(customerId, options, cb) {
|
|
106
113
|
|
|
107
114
|
const self = this;
|
|
108
115
|
|
|
@@ -111,25 +118,26 @@ module.exports = function(mongoose, config) {
|
|
|
111
118
|
if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
|
|
112
119
|
|
|
113
120
|
let query = self.find({
|
|
114
|
-
|
|
121
|
+
customer: customerId,
|
|
122
|
+
sentOn: { $ne: null }
|
|
115
123
|
});
|
|
116
124
|
|
|
117
125
|
query.exec(cb);
|
|
118
126
|
|
|
119
127
|
};
|
|
120
128
|
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
LimitedPartnerCommunication.statics.getReadyToSend = function getReadyToSend(options, cb) {
|
|
129
|
+
// For the "Scheduled" page
|
|
130
|
+
LimitedPartnerCommunication.statics.getUnsentForCustomer = function getUnsentForCustomer(customerId, options, cb) {
|
|
124
131
|
|
|
125
132
|
const self = this;
|
|
126
|
-
const now = new Date();
|
|
127
133
|
|
|
128
134
|
if (!cb) { throw new Error('cb is required'); }
|
|
135
|
+
if (!customerId) { return cb(new Error('customerId is required'), null); }
|
|
136
|
+
if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
|
|
129
137
|
|
|
130
138
|
let query = self.find({
|
|
131
|
-
|
|
132
|
-
|
|
139
|
+
customer: customerId,
|
|
140
|
+
sentOn: null
|
|
133
141
|
});
|
|
134
142
|
|
|
135
143
|
query.exec(cb);
|