@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 communication, e.g., "2022 Annual Audit"
13
- name: { type: String, trim: true, required: true },
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 subject
22
- subject: { type: String, trim: true, required: true },
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
- documents: [{
21
+ // email subject
22
+ subject: { type: String, trim: true, required: true },
31
23
 
32
- // the lp this doc is for
33
- limitedPartner: { type: Schema.ObjectId, ref: 'LimitedPartner', required: true },
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
- // email of recipient for notification and access
39
- email: { type: String, trim: true, required: true },
27
+ },
40
28
 
41
- // attach document to email
42
- attachToEmail: { type: Boolean, required: true, default: false },
29
+ limitedPartners: [{
43
30
 
44
- // when notification was sent
45
- sentOn: { type: Date, required: false },
31
+ // the lp it's for
32
+ limitedPartner: { type: Schema.ObjectId, ref: 'LimitedPartner', required: true },
46
33
 
47
- // email reference
48
- postmarkMessageId: { type: String, trim: true, required: false },
34
+ // attach documents to email (only option currently supported)
35
+ attachToEmail: { type: Boolean, required: true, default: true },
49
36
 
50
- emailStatus: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked'], required: false },
37
+ // the documents included in this communication
38
+ documents: [{
51
39
 
52
- // OTP used to access the document
53
- oneTimePassword: { type: String, trim: true, required: true },
40
+ fileName: { type: String, trim: true, required: true },
54
41
 
55
- // OTP only good for limited time and then a new one must be requested
56
- oneTimePasswordExpiration: { type: Date, trim: true, required: true },
42
+ // file type
43
+ contentType: { type: String, trim: true, required: true },
57
44
 
58
- fileName: { type: String, trim: true, required: true },
45
+ // file size
46
+ contentLength: { type: String, trim: true, required: true },
59
47
 
60
- // file type
61
- contentType: { type: String, trim: true, required: true },
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
- // file size
64
- contentLength: { type: String, trim: true, required: true },
54
+ }],
65
55
 
66
- // where to find in s3
67
- s3: {
68
- bucket: { type: String, required: true, trim: true },
69
- key: { type: String, required: true, trim: true }
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
- // Get a full communication for a customer
77
- // Use 1: Customer can use while setting up or viewing a batch
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 (!id) { return cb(new Error('id is required'), null); }
87
- if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
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.findOne({
93
- '_id': id,
94
- 'customer': options.CUSTOMER_ID
84
+ let query = self.find({
85
+ limitedPartner: lpid,
86
+ customer: options.CUSTOMER_ID
95
87
  });
96
88
 
97
- query.populate('customer');
98
- query.populate('documents.limitedPartner', 'name');
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
- // Get all communications for a customer
105
- LimitedPartnerCommunication.statics.getForCustomer = function getForCustomer(customerId, options, cb) {
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
- 'customer': customerId
121
+ customer: customerId,
122
+ sentOn: { $ne: null }
115
123
  });
116
124
 
117
125
  query.exec(cb);
118
126
 
119
127
  };
120
128
 
121
- // Get all batches that haven't been sent but are scheduled to go
122
- // Use case 1: Worker pulls this list and sends docs to lps
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
- 'sentToQueue': false,
132
- 'sendOn': { $lte: now }
139
+ customer: customerId,
140
+ sentOn: null
133
141
  });
134
142
 
135
143
  query.exec(cb);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "9.59.0",
3
+ "version": "9.61.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",