2 var util = require('util');
3 var reverseMustache = require('reverse-mustache');
5 module.exports = function(sequelize, DataTypes) {
6 var VoiceExtension = sequelize.define('VoiceExtension', {
8 type: DataTypes.STRING,
10 unique: 'compositeIndex',
13 is: /[A-Za-z0-9\.\_]+$/i
17 type: DataTypes.STRING,
19 unique: 'compositeIndex'
22 type: DataTypes.STRING,
25 unique: 'compositeIndex'
28 type: DataTypes.STRING,
33 type: DataTypes.STRING,
38 type: DataTypes.STRING,
41 // 'this' allows you to access attributes of the instance
42 if (!this.getDataValue('id')) {
43 if (this.getDataValue('app') === 'Dial' && this.getDataValue('type') === 'outbound') {
44 var appdata = reverseMustache({
45 template: 'SIP/{{trunk}}/{{prefix}}${EXTEN:{{cutdigits}}}',
46 content: this.getDataValue('appdata')
48 return [appdata.trunk, this.getDataValue('callerID') || '', appdata.cutdigits, appdata.prefix];
50 return this.getDataValue('appdata').split(',');
53 return this.getDataValue('appdata');
58 type: DataTypes.ENUM('inbound', 'outbound', 'internal', 'inbound-fax', 'outbound-fax', 'system', 'any'),
62 type: DataTypes.STRING,
65 type: DataTypes.STRING,
68 type: DataTypes.INTEGER,
71 type: DataTypes.BOOLEAN,
75 type: DataTypes.STRING,
79 type: DataTypes.BOOLEAN,
83 tableName: 'voice_extensions',
84 associate: function(models) {
85 VoiceExtension.hasMany(models.VoiceExtension, {
91 VoiceExtension.addScope('application', {
93 model: models.VoiceExtension,
99 attributes: ['app', 'interval', 'IntervalId', 'callerID', 'appdata', 'type']
103 VoiceExtension.addScope('routes', {
105 VoiceExtensionId: null
111 return VoiceExtension;