Built motion from commit b33b832.|1.0.17
[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: 'uniqueid'
11     },
12     type: {
13       type: DataTypes.ENUM,
14       values: ['inbound', 'internal', 'outbound', 'inbound-fax', 'outbound-fax', 'tigerdial', 'chanspy']
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     agentDisposition: DataTypes.STRING,
44     contactId: DataTypes.INTEGER
45   }, {
46     tableName: 'report_call',
47     associate: function(models) {
48       ReportCall.hasMany(models.ReportQueue, {
49         as: 'QueueCalls',
50         foreignKey: 'uniqueid',
51         constraints: false
52       })
53       ReportCall.hasMany(models.ReportAgent, {
54         as: 'ReportAgents',
55         foreignKey: 'uniqueid',
56         constraints: false
57       })
58     }
59   });
60
61   return ReportCall;
62 };