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,
42 // 'this' allows you to access attributes of the instance
43 if (!this.getDataValue('id')) {
44 if (this.getDataValue('app') === 'Dial' && this.getDataValue('type') === 'outbound') {
45 var appdata = reverseMustache({
46 template: 'SIP/{{trunk}}/{{prefix}}${EXTEN:{{cutdigits}}}',
47 content: this.getDataValue('appdata')
49 return [appdata.trunk, this.getDataValue('callerID') || '', appdata.cutdigits, appdata.prefix];
51 return this.getDataValue('appdata').split(',');
54 return this.getDataValue('appdata');
59 type: DataTypes.ENUM('inbound', 'outbound', 'internal', 'inbound-fax', 'outbound-fax', 'system', 'any'),
63 type: DataTypes.STRING,
66 type: DataTypes.STRING,
69 type: DataTypes.INTEGER,
72 type: DataTypes.BOOLEAN,
76 type: DataTypes.STRING,
80 type: DataTypes.BOOLEAN,
84 tableName: 'voice_extensions',
85 associate: function(models) {
86 VoiceExtension.hasMany(models.VoiceExtension, {
92 VoiceExtension.addScope('application', {
94 model: models.VoiceExtension,
100 attributes: ['app', 'interval', 'IntervalId', 'callerID', 'appdata', 'type']
104 VoiceExtension.addScope('routes', {
106 VoiceExtensionId: null
112 return VoiceExtension;