@dhyasama/totem-models 3.6.3 → 3.8.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.
- package/lib/Message.js +44 -0
- package/package.json +1 -1
- package/test/Message.js +18 -0
package/lib/Message.js
CHANGED
|
@@ -35,6 +35,20 @@ module.exports = function(mongoose, config) {
|
|
|
35
35
|
|
|
36
36
|
///////////////////////////////////////
|
|
37
37
|
|
|
38
|
+
Message.virtual('messageDate').get(function () {
|
|
39
|
+
|
|
40
|
+
// A little helper to get the message date since
|
|
41
|
+
// the original message date isn't always contained
|
|
42
|
+
// in the email. In its absence, use created on.
|
|
43
|
+
|
|
44
|
+
var self = this;
|
|
45
|
+
|
|
46
|
+
return self.originalMessageDate || self.createdOn;
|
|
47
|
+
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
///////////////////////////////////////
|
|
51
|
+
|
|
38
52
|
Message.statics.addDocument = function(messageId, doc, cb) {
|
|
39
53
|
|
|
40
54
|
Document.createForModel(doc, this, messageId, cb);
|
|
@@ -154,6 +168,36 @@ module.exports = function(mongoose, config) {
|
|
|
154
168
|
|
|
155
169
|
};
|
|
156
170
|
|
|
171
|
+
Message.statics.getForOrg = function getForOrg(orgId, options, cb) {
|
|
172
|
+
|
|
173
|
+
// This filters by customer so is NOT usable by admin tools
|
|
174
|
+
if (config.CUSTOMER_ID == 'GLOBAL_PROCESS') return cb(new Error('Access denied. Use getForPeopleLite.'), null);
|
|
175
|
+
|
|
176
|
+
var self = this;
|
|
177
|
+
var query = self.find({ customer: config.CUSTOMER_ID, organization: orgId });
|
|
178
|
+
query.populate('recipients.internal', 'name title avatarUrl doNotDisplay');
|
|
179
|
+
query.populate('recipients.external', 'name title avatarUrl doNotDisplay');
|
|
180
|
+
query.populate({
|
|
181
|
+
path: 'notes',
|
|
182
|
+
match: { customer: config.CUSTOMER_ID }
|
|
183
|
+
});
|
|
184
|
+
query.populate({
|
|
185
|
+
path: 'documents',
|
|
186
|
+
match: { customer: config.CUSTOMER_ID }
|
|
187
|
+
});
|
|
188
|
+
query.deepPopulate([
|
|
189
|
+
'notes.createdBy',
|
|
190
|
+
'documents.createdBy'
|
|
191
|
+
], {
|
|
192
|
+
populate: {
|
|
193
|
+
'notes.createdBy': { select: 'name avatarUrl title' },
|
|
194
|
+
'documents.createdBy': { select: 'name avatarUrl title' }
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
query.exec(cb);
|
|
198
|
+
|
|
199
|
+
};
|
|
200
|
+
|
|
157
201
|
Message.statics.getForPeople = function getForPeople(personIds, options, cb) {
|
|
158
202
|
|
|
159
203
|
// This filters by customer so is NOT usable by admin tools
|
package/package.json
CHANGED
package/test/Message.js
CHANGED
|
@@ -16,6 +16,8 @@ var totemCustomerId1 = new mongoose.Types.ObjectId();
|
|
|
16
16
|
var totemCustomerId2 = new mongoose.Types.ObjectId();
|
|
17
17
|
var externalAttendee1 = new mongoose.Types.ObjectId();
|
|
18
18
|
var externalAttendee2 = new mongoose.Types.ObjectId();
|
|
19
|
+
var orgId1 = new mongoose.Types.ObjectId();
|
|
20
|
+
var orgId2 = new mongoose.Types.ObjectId();
|
|
19
21
|
|
|
20
22
|
var messageOne;
|
|
21
23
|
|
|
@@ -35,6 +37,7 @@ describe('Message', function() {
|
|
|
35
37
|
var message = new Message({
|
|
36
38
|
webhook: new mongoose.Types.ObjectId(),
|
|
37
39
|
customer: totemCustomerId1,
|
|
40
|
+
organization: orgId1,
|
|
38
41
|
subject: 'Message one',
|
|
39
42
|
type: 'email',
|
|
40
43
|
subtype: 'boards',
|
|
@@ -58,6 +61,7 @@ describe('Message', function() {
|
|
|
58
61
|
var message = new Message({
|
|
59
62
|
webhook: new mongoose.Types.ObjectId(),
|
|
60
63
|
customer: totemCustomerId2,
|
|
64
|
+
organization: orgId2,
|
|
61
65
|
subject: 'Message two',
|
|
62
66
|
type: 'email',
|
|
63
67
|
subtype: 'boards',
|
|
@@ -153,6 +157,20 @@ describe('Message', function() {
|
|
|
153
157
|
|
|
154
158
|
});
|
|
155
159
|
|
|
160
|
+
it('gets messages for an org', function(done) {
|
|
161
|
+
|
|
162
|
+
config.CUSTOMER_ID = totemCustomerId1;
|
|
163
|
+
|
|
164
|
+
Message.getForOrg(orgId1, { before: moment().add(1, 'hour').toISOString()}, function(err, result) {
|
|
165
|
+
should.not.exist(err);
|
|
166
|
+
should.exist(result);
|
|
167
|
+
result.length.should.equal(1);
|
|
168
|
+
result[0].subject.should.equal('Message one');
|
|
169
|
+
done();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
});
|
|
173
|
+
|
|
156
174
|
it('tries to get messages for a person as an admin process', function(done) {
|
|
157
175
|
|
|
158
176
|
config.CUSTOMER_ID = 'GLOBAL_PROCESS';
|