Built motion from commit 1d6aa77.|0.0.94
[motion.git] / server / models / tools_interval.js
1 /* jshint indent: 2 */
2
3 module.exports = function(sequelize, DataTypes) {
4   var Interval = sequelize.define('Interval', {
5     name: {
6       type: DataTypes.STRING
7     },
8     description: DataTypes.STRING,
9     interval: {
10       type: DataTypes.STRING,
11       allowNull: true
12     }
13   }, {
14     tableName: 'tools_intervals',
15     associate: function(models) {
16       Interval.hasMany(models.Interval, {
17         as: 'SubIntervals',
18         onDelete: 'cascade',
19         hooks: true,
20         required: false
21       });
22       Interval.hasMany(models.VoiceExtension, {
23         as: 'VoiceExtensions',
24         foreignKey: 'IntervalId',
25         onDelete: 'restrict'
26       });
27       Interval.hasMany(models.MailApplication, {
28         as: 'MailApplications'
29       });
30       Interval.hasMany(models.ChatApplication, {
31         as: 'ChatApplications'
32       });
33       Interval.hasMany(models.FaxApplication, {
34         as: 'FaxApplications'
35       });
36       // SCOPES MANAGEMENT
37       Interval.addScope('subintervals', {
38         include: [{
39           model: models.Interval,
40           as: 'SubIntervals',
41           required: false,
42           attributes: ['name', 'interval', 'id']
43         }]
44       });
45
46       Interval.addScope('intervals', {
47         where: {
48           IntervalId: null
49         }
50       });
51     }
52   });
53
54
55   return Interval;
56 };