39a12e4c236e28d1fd9e83f24a624833b0809c0c
[motion.git] / server / models / voice_recording.js
1 /* jshint indent: 2 */
2 var moment = require('moment');
3
4 module.exports = function(sequelize, DataTypes) {
5   var VoiceRecording = sequelize.define('VoiceRecording', {
6     uniqueid: {
7       type: DataTypes.STRING
8     },
9     channel: {
10       type: DataTypes.STRING,
11       set: function(channel) {
12         if (channel) {
13           this.setDataValue('channel', channel);
14           this.setDataValue('membername', channel.split(/\/|-/)[1]);
15         }
16       }
17     },
18     membername: {
19       type: DataTypes.STRING
20     },
21     calleridnum: {
22       type: DataTypes.STRING
23     },
24     calleridname: {
25       type: DataTypes.STRING
26     },
27     connectedlinenum: {
28       type: DataTypes.STRING
29     },
30     connectedlinename: {
31       type: DataTypes.STRING
32     },
33     language: {
34       type: DataTypes.STRING
35     },
36     accountcode: {
37       type: DataTypes.STRING
38     },
39     context: {
40       type: DataTypes.STRING
41     },
42     exten: {
43       type: DataTypes.STRING
44     },
45     value: {
46       type: DataTypes.STRING
47     },
48     type: {
49       type: DataTypes.STRING
50     },
51     rating: {
52       type: DataTypes.INTEGER,
53       validate: {
54         max: 5,
55         min: 0
56       }
57     },
58     queue: {
59       type: DataTypes.STRING
60     },
61     createdAt: {
62       type: DataTypes.DATE,
63       get: function() {
64         // 'this' allows you to access attributes of the instance
65         return moment(this.getDataValue('createdAt')).format("MM-DD-YYYY HH:mm").toString();
66       }
67     },
68     updatedAt: {
69       type: DataTypes.DATE,
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_recordings',
77     associate: function(models) {
78       // VoiceRecording.belongsTo(models.ReportCall, {
79       //   foreignKey: 'uniqueid'
80       // });
81     }
82   });
83
84   return VoiceRecording;
85 };