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