@dhyasama/totem-models 3.7.0 → 3.8.1

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/Document.js CHANGED
@@ -34,6 +34,42 @@ module.exports = function(mongoose, config) {
34
34
 
35
35
 
36
36
 
37
+ ///////////////////////////////////////////////////////////////////////////////////////
38
+ // VIRTUALS
39
+ // Properties that are not persisted to the database
40
+ ///////////////////////////////////////////////////////////////////////////////////////
41
+
42
+ Document.virtual('ignore').get(function () {
43
+
44
+ var self = this;
45
+ var contentLength = self.contentLength || 0;
46
+ var name = self.name || '';
47
+ name = name.toUpperCase();
48
+
49
+ // Probably an Exchange file
50
+ // Exchange creates files such as ATT00001.htm and ATT00002.txt, one for each attachment
51
+ if (name.indexOf('ATT00') == 0) return true;
52
+
53
+ // Google Calendar invitation
54
+ // No need to show since it's in-lined
55
+ else if (name == 'INVITE.ICS' || name == 'INVITATION.ICS') return true;
56
+
57
+ // Probably a signature logo
58
+ else if (name.indexOf('IMAGE0') == 0 && contentLength < 3000) return true;
59
+
60
+ else return false;
61
+
62
+ // {
63
+ // "Name": "image001.jpg",
64
+ // "ContentType": "image/jpeg",
65
+ // "ContentLength": 2468,
66
+ // "ContentID": ""
67
+ // }
68
+
69
+ });
70
+
71
+
72
+
37
73
  ///////////////////////////////////////////////////////////////////////////////////////
38
74
  // METHODS
39
75
  // Methods operate on a single document that has already been returned
@@ -131,6 +167,7 @@ module.exports = function(mongoose, config) {
131
167
  // CONFIG
132
168
  ///////////////////////////////////////////////////////////////////////////////////////
133
169
 
170
+ Document.set('toJSON', { virtuals: true });
134
171
  Document.set('autoIndex', false);
135
172
  Document.on('index', function(err) { console.log('error building document indexes: ' + err); });
136
173
 
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);
@@ -256,6 +270,7 @@ module.exports = function(mongoose, config) {
256
270
  ///////////////////////////////////////
257
271
 
258
272
  Message.set('autoIndex', false);
273
+ Message.set('toJSON', { virtuals: true });
259
274
 
260
275
  var deepPopulate = require('mongoose-deep-populate')(mongoose);
261
276
  Message.plugin(deepPopulate);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "3.7.0",
3
+ "version": "3.8.1",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",