Built motion from commit a11024eac.|1.0.35
[motion.git] / server / models / voice_voicemail_messages.js
1 /* jshint indent: 2 */
2 var moment = require('moment');
3
4 module.exports = function(sequelize, DataTypes) {
5   var VoiceVoicemailMessages = sequelize.define('VoiceVoicemailMessages', {
6     msgnum: {
7       type: DataTypes.INTEGER(11),
8       defaultValue: 0,
9       allowNull: false
10     },
11     dir: {
12       type: DataTypes.STRING,
13       defaultValue: ''
14     },
15     context: {
16       type: DataTypes.STRING,
17       defaultValue: ''
18     },
19     macrocontext: {
20       type: DataTypes.STRING,
21       defaultValue: ''
22     },
23     callerid: {
24       type: DataTypes.STRING,
25       defaultValue: ''
26     },
27     origtime: {
28       type: DataTypes.STRING,
29       defaultValue: ''
30     },
31     duration: {
32       type: DataTypes.STRING,
33       defaultValue: ''
34     },
35     mailboxuser: {
36       type: DataTypes.STRING,
37       defaultValue: ''
38     },
39     mailboxcontext: {
40       type: DataTypes.STRING,
41       defaultValue: ''
42     },
43     recording: {
44       type: DataTypes.BLOB('long'),
45       defaultValue: null
46     },
47     flag: {
48       type: DataTypes.STRING,
49       defaultValue: ''
50     },
51     msg_id: {
52       type: DataTypes.STRING,
53       defaultValue: ''
54     },
55     stamp: {
56       type: 'TIMESTAMP',
57       allowNull: false
58     },
59     createdAt: {
60       type: DataTypes.DATE,
61       defaultValue: sequelize.fn('NOW'),
62       get: function() {
63         // 'this' allows you to access attributes of the instance
64         return moment(this.getDataValue('createdAt')).format("MM-DD-YYYY HH:mm").toString();
65       }
66     },
67     updatedAt: {
68       type: DataTypes.DATE,
69       defaultValue: sequelize.fn('NOW'),
70       get: function() {
71         // 'this' allows you to access attributes of the instance
72         return moment(this.getDataValue('updatedAt')).format("MM-DD-YYYY HH:mm").toString();
73       }
74     }
75   }, {
76     tableName: 'voice_voicemail_messages',
77     associate: function(models) {
78       VoiceVoicemailMessages.belongsTo(models.VoiceVoicemail, {
79           "foreignKey": "mailboxuser",
80           "targetKey": "mailbox"
81       });
82       VoiceVoicemailMessages.addScope('mailbox', function(query) {
83         var scope = {
84           where: {}
85         };
86         if (query.context && query.mailbox) {
87           where: {
88             scope.where.mailboxcontext = query.context;
89             scope.where.mailboxuser = query.mailbox;
90           }
91           delete query.context;
92           delete query.mailbox;
93         }
94         return scope;
95       });
96     },
97     indexes: [{
98       name: 'dir',
99       fields: ['dir']
100     }]
101   });
102
103   return VoiceVoicemailMessages;
104 };