d64d11d603a57e601fc7d1d552476a6bef65be30
[motion.git] / server / models / report_call.js
1 /**
2  * CDR Model
3  */
4
5 module.exports = function(sequelize, DataTypes) {
6
7   var ReportCall = sequelize.define('ReportCall', {
8     uniqueid: {
9       type: DataTypes.STRING,
10       unique: true
11     },
12     type: {
13       type: DataTypes.ENUM,
14       values: ['inbound', 'internal', 'outbound', 'inbound-fax', 'outbound-fax', 'tigerdial']
15     },
16     tag: DataTypes.STRING,
17     accountcode: DataTypes.STRING,
18     source: DataTypes.STRING,
19     destination: DataTypes.STRING,
20     destinationcontext: DataTypes.STRING,
21     callerid: DataTypes.STRING,
22     channel: DataTypes.STRING,
23     destinationchannel: DataTypes.STRING,
24     lastapplication: DataTypes.STRING,
25     lastdata: DataTypes.STRING,
26     starttime: DataTypes.DATE,
27     answertime: {
28       type: DataTypes.DATE,
29       set: function(answertime) {
30         if (answertime !== '') {
31           this.setDataValue('answertime', answertime);
32         } else {
33           this.setDataValue('answertime', null);
34         }
35       }
36     },
37     endtime: DataTypes.DATE,
38     duration: DataTypes.INTEGER,
39     billableseconds: DataTypes.INTEGER,
40     disposition: DataTypes.STRING,
41     amaflags: DataTypes.STRING,
42     userfield: DataTypes.STRING
43   }, {
44     tableName: 'report_call',
45     associate: function(models) {
46       ReportCall.hasMany(models.ReportQueue, {
47         as: 'QueueCalls',
48         foreignKey: 'uniqueid',
49         constraints: false
50       })
51       ReportCall.hasMany(models.ReportAgent, {
52         as: 'ReportAgents',
53         foreignKey: 'uniqueid',
54         constraints: false
55       })
56     }
57   });
58
59   return ReportCall;
60 };