var crypto = require('crypto');
var md5 = require('md5');
var _ = require('lodash');
+var moment = require('moment');
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define('User', {
name: {
type: DataTypes.STRING,
- unique: true,
+ unique: 'name',
validate: {
- notEmpty: true
+ notEmpty: true,
+ is: /^[A-Za-z0-9\.\_]+$/i
},
set: function(name) {
this.setDataValue('name', name);
this.setDataValue('defaultuser', name);
}
},
+ fullname: {
+ type: DataTypes.STRING,
+ allowNull: false,
+ },
email: {
type: DataTypes.STRING,
- unique: true,
+ unique: 'email',
+ isEmail: true,
set: function(email) {
if (email) {
this.setDataValue('email', email.toLowerCase());
}
-
},
defaultValue: null
},
},
internal: {
type: DataTypes.INTEGER(11),
- unique: true,
+ unique: 'internal',
set: function(internal) {
this.setDataValue('internal', internal);
this.setDataValue('accountcode', internal);
country: {
type: DataTypes.STRING
},
- facebookUserId: {
- type: DataTypes.INTEGER
+ online: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ lastLoginAt: {
+ type: DataTypes.DATE
},
- twitterUserId: {
- type: DataTypes.INTEGER
+ status: {
+ type: DataTypes.STRING,
+ defaultValue: 'UNKNOWN'
},
- twitterKey: {
- type: DataTypes.STRING
+ statusAt: {
+ type: DataTypes.DATE
},
- twitterSecret: {
- type: DataTypes.STRING
+ queueStatus: {
+ type: DataTypes.STRING,
+ defaultValue: 'complete'
},
- github: {
- type: DataTypes.STRING
+ queueStatusAt: {
+ type: DataTypes.DATE
},
- openId: {
+ lastQueue: {
type: DataTypes.STRING
},
- online: {
+ voicePause: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false,
+ // set: function(voicePause) {
+ // this.setDataValue('voicePause', voicePause);
+ // if (voicePause) {
+ // this.setDataValue('queueStatus', 'paused');
+ // this.setDataValue('queueStatusAt', moment().format("YYYY-MM-DD HH:mm:ss"));
+ // } else {
+ // this.setDataValue('queueStatus', 'complete');
+ // this.setDataValue('queueStatusAt', moment().format("YYYY-MM-DD HH:mm:ss"));
+ // }
+ // }
+ },
+ chatPause: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
- lastLoginAt: {
+ mailPause: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ faxPause: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ smsPause: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ openchannelPause: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ pauseType: {
+ type: DataTypes.STRING,
+ defaultValue: 'Default Pause'
+ },
+ lastPauseAt: {
type: DataTypes.DATE
},
- ipaddr: {
+ chatCapacity: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
+ mailCapacity: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
+ faxCapacity: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
+ smsCapacity: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
+ openchannelCapacity: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
+ },
+ phoneBarAutoAnswer: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ phoneBarEnableSettings: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: true
+ },
+ phoneBarUnconditionalNumber: {
type: DataTypes.STRING,
- allowNull: true,
+ get: function() {
+ if (this.getDataValue('phoneBarUnconditional')) {
+ return this.getDataValue('phoneBarUnconditionalNumber');
+ }
+ return null;
+ }
+ },
+ phoneBarNoReplyNumber: {
+ type: DataTypes.STRING,
+ get: function() {
+ if (this.getDataValue('phoneBarNoReply')) {
+ return this.getDataValue('phoneBarNoReplyNumber');
+ }
+ return null;
+ }
+ },
+ phoneBarBusyNumber: {
+ type: DataTypes.STRING,
+ get: function() {
+ if (this.getDataValue('phoneBarBusy')) {
+ return this.getDataValue('phoneBarBusyNumber');
+ }
+ return null;
+ }
},
- port: {
+ phoneBarUnconditional: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ phoneBarNoReply: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ phoneBarBusy: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ phoneBarListenPort: {
type: DataTypes.INTEGER(5),
- allowNull: true,
+ defaultValue: 5060
},
- regseconds: {
- type: DataTypes.INTEGER(11),
- allowNull: true,
+ phoneBarECTail: {
+ type: DataTypes.INTEGER(5),
+ defaultValue: 200
},
- defaultuser: {
+ phoneBarExpires: {
+ type: DataTypes.INTEGER(5),
+ defaultValue: 120
+ },
+ phoneBarNameServer: {
type: DataTypes.STRING,
- allowNull: true,
+ allowNull: true
+ },
+ phoneBarStunServer: {
+ type: DataTypes.STRING,
+ allowNull: true
+ },
+ phoneBarVADEnabled: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ phoneBarNoUDP: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ phoneBarNoTCP: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: true
+ },
+ phoneBarLogLevel: {
+ type: DataTypes.INTEGER(5),
+ defaultValue: 1
+ },
+ phoneBarPublishEnabled: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ phoneBarRemoteControl: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ phoneBarRemoteControlPort: {
+ type: DataTypes.INTEGER,
+ defaultValue: 9888
+ },
+ chanspy: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
},
- fullcontact: {
+ description: {
type: DataTypes.STRING,
allowNull: true,
},
- regserver: {
+ host: {
type: DataTypes.STRING,
allowNull: true,
+ defaultValue: 'dynamic'
},
- useragent: {
+ ipaddr: { //REALTIME ASTERISK
type: DataTypes.STRING,
allowNull: true,
},
- lastms: {
+ port: { //REALTIME ASTERISK
+ type: DataTypes.INTEGER(5),
+ allowNull: true,
+ },
+ regseconds: { //REALTIME ASTERISK
type: DataTypes.INTEGER(11),
allowNull: true,
},
- host: {
+ fullcontact: { //REALTIME ASTERISK
+ type: DataTypes.STRING,
+ allowNull: true,
+ },
+ regserver: { //REALTIME ASTERISK
+ type: DataTypes.STRING,
+ allowNull: true,
+ },
+ useragent: { //REALTIME ASTERISK
type: DataTypes.STRING,
allowNull: true,
- defaultValue: 'dynamic'
+ },
+ lastms: { //REALTIME ASTERISK
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
},
type: {
type: DataTypes.ENUM('friend', 'user', 'peer'),
allowNull: true,
defaultValue: 'from-sip'
},
- permit: {
- type: DataTypes.STRING,
+ callingpres: {
+ type: DataTypes.ENUM('ALLOWED_NOT_SCREENED',
+ 'ALLOWED_PASSED_SCREEN', 'ALLOWED_FAILED_SCREEN', 'ALLOWED',
+ 'PROHIB_NOT_SCREENED', 'PROHIB_PASSED_SCREEN',
+ 'PROHIB_FAILED_SCREEN', 'PROHIB'),
allowNull: true,
},
deny: {
type: DataTypes.STRING,
allowNull: true,
},
+ permit: {
+ type: DataTypes.STRING,
+ allowNull: true,
+ },
secret: {
type: DataTypes.STRING,
allowNull: true,
},
md5secret: {
type: DataTypes.STRING,
- allowNull: true
+ allowNull: true,
},
remotesecret: {
type: DataTypes.STRING,
defaultValue: 'rfc2833'
},
directmedia: {
- type: DataTypes.ENUM('yes', 'no', 'nonat', 'update'),
+ type: DataTypes.ENUM('yes', 'no', 'nonat', 'update', 'outgoing'),
+ allowNull: true,
+ defaultValue: 'no'
+ },
+ directrtpsetup: {
+ type: DataTypes.ENUM('yes', 'no'),
allowNull: true,
defaultValue: 'no'
},
+ directmediapermit: {
+ type: DataTypes.STRING,
+ allowNull: true,
+ },
+ directmediadeny: {
+ type: DataTypes.STRING,
+ allowNull: true,
+ },
nat: {
type: DataTypes.STRING,
allowNull: true,
type: DataTypes.STRING,
allowNull: true,
},
+ namedcallgroup: { //We are in named call groups engineering,sales,netgroup,protgroup
+ type: DataTypes.STRING,
+ allowNull: true,
+ },
pickupgroup: {
type: DataTypes.STRING,
allowNull: true,
},
+ namedpickupgroup: { //We can do call pick-p for named call group sales
+ type: DataTypes.STRING,
+ allowNull: true,
+ },
language: {
type: DataTypes.STRING,
allowNull: true,
defaultValue: 'en'
},
+ tonezone: {
+ type: DataTypes.STRING,
+ allowNull: true
+ },
disallow: {
type: DataTypes.STRING,
allowNull: true,
allow: {
type: DataTypes.STRING,
allowNull: true,
- defaultValue: 'alaw;ulaw;gsm'
+ defaultValue: 'ulaw;gsm'
+ },
+ autoframing: {
+ type: DataTypes.ENUM('yes', 'no'),
+ allowNull: true,
},
insecure: {
type: DataTypes.STRING,
allowNull: true,
defaultValue: 'no'
},
+ trust_id_outbound: {
+ type: DataTypes.ENUM('yes', 'no'),
+ allowNull: true,
+ defaultValue: 'no'
+ },
progressinband: {
type: DataTypes.ENUM('yes', 'no', 'never'),
allowNull: true,
type: DataTypes.ENUM('yes', 'no'),
allowNull: true,
},
- videosupport: {
+ allowtransfer: {
type: DataTypes.ENUM('yes', 'no'),
allowNull: true,
},
+ ignoresdpversion: {
+ type: DataTypes.ENUM('yes', 'no'),
+ allowNull: true,
+ },
+ subscribecontext: {
+ type: DataTypes.STRING,
+ allowNull: true,
+ },
+ template: {
+ type: DataTypes.STRING,
+ allowNull: true,
+ },
+ videosupport: {
+ type: DataTypes.ENUM('yes', 'no', 'always'),
+ allowNull: true,
+ defaultValue: 'no'
+ },
maxcallbitrate: {
type: DataTypes.INTEGER(11),
allowNull: true,
type: DataTypes.STRING,
allowNull: true,
},
- "session-timers": {
+ session_timers: {
type: DataTypes.ENUM('accept', 'refuse', 'originate'),
allowNull: true,
},
- "session-expires": {
+ session_expires: {
type: DataTypes.INTEGER(11),
allowNull: true,
},
- "session-minse": {
+ session_minse: {
type: DataTypes.INTEGER(11),
allowNull: true,
},
- "session-refresher": {
+ session_refresher: {
type: DataTypes.ENUM('uac', 'uas'),
allowNull: true,
+ defaultValue: 'uas'
},
t38pt_usertpsource: {
type: DataTypes.STRING,
allowNull: true,
defaultValue: 'yes'
},
+ keepalive: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ },
defaultip: {
type: DataTypes.STRING,
allowNull: true,
},
- rtptimeout: {
+ defaultuser: {
+ type: DataTypes.STRING,
+ allowNull: true,
+ },
+ rtptimeout: { // Terminate call if 60 seconds of no RTP or RTCP activity on the audio channel when we're not on hold.
type: DataTypes.INTEGER(11),
allowNull: true,
},
- rtpholdtimeout: {
+ rtpholdtimeout: { // Terminate call if 300 seconds of no RTP or RTCP activity on the audio channel when we're on hold (must be > rtptimeout)
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ },
+ rtpkeepalive: { // Send keepalives in the RTP stream to keep NAT open (default is off - zero)
type: DataTypes.INTEGER(11),
allowNull: true,
},
type: DataTypes.INTEGER(11),
allowNull: true,
},
- constantssrc: {
- type: DataTypes.ENUM('yes', 'no'),
- allowNull: true,
- },
contactpermit: {
type: DataTypes.STRING,
allowNull: true,
type: DataTypes.STRING,
allowNull: true,
},
- usereqphone: {
+ contactacl: {
+ type: DataTypes.STRING,
+ allowNull: true,
+ },
+ unsolicited_mailbox: {
+ type: DataTypes.STRING,
+ allowNull: true,
+ },
+ use_q850_reason: {
+ type: DataTypes.STRING,
+ allowNull: true,
+ },
+ maxforwards: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ },
+ encryption: {
type: DataTypes.ENUM('yes', 'no'),
allowNull: true,
defaultValue: 'no'
},
- textsupport: {
+ avpf: {
type: DataTypes.ENUM('yes', 'no'),
- allowNull: true,
+ allowNull: true
},
- faxdetect: {
+ force_avp: {
type: DataTypes.ENUM('yes', 'no'),
- allowNull: true,
+ allowNull: true
},
- buggymwi: {
+ icesupport: {
type: DataTypes.ENUM('yes', 'no'),
- allowNull: true,
+ allowNull: true
},
- auth: {
- type: DataTypes.STRING,
- allowNull: true,
+ dtlsenable: {
+ type: DataTypes.ENUM('yes', 'no'),
+ allowNull: true
},
- fullname: {
- type: DataTypes.STRING,
+ dtlsverify: {
+ type: DataTypes.ENUM('yes', 'no', 'fingerprint', 'certificate'),
+ allowNull: true
+ },
+ dtlsrekey: {
+ type: DataTypes.INTEGER(11),
allowNull: true,
},
- trunkname: {
+ dtlscertfile: {
type: DataTypes.STRING,
allowNull: true,
},
- cid_number: {
+ dtlsprivatekey: {
type: DataTypes.STRING,
allowNull: true,
},
- callingpres: {
- type: DataTypes.ENUM('ALLOWED_NOT_SCREENED',
- 'ALLOWED_PASSED_SCREEN', 'ALLOWED_FAILED_SCREEN', 'ALLOWED',
- 'PROHIB_NOT_SCREENED', 'PROHIB_PASSED_SCREEN',
- 'PROHIB_FAILED_SCREEN', 'PROHIB'),
+ dtlscipher: {
+ type: DataTypes.STRING,
allowNull: true,
},
- mohinterpret: {
+ dtlscafile: {
type: DataTypes.STRING,
allowNull: true,
},
- mohsuggest: {
+ dtlscapath: {
type: DataTypes.STRING,
allowNull: true,
},
- parkinglot: {
+ dtlssetup: {
+ type: DataTypes.ENUM('active', 'passive', 'actpass'),
+ allowNull: true
+ },
+ dtlsfingerprint: {
type: DataTypes.STRING,
allowNull: true,
},
- hasvoicemail: {
+ usereqphone: { //This provider requires ";user=phone" on URI
type: DataTypes.ENUM('yes', 'no'),
allowNull: true,
+ defaultValue: 'no'
},
- subscribemwi: {
- type: DataTypes.ENUM('yes', 'no'),
+ recordonfeature: { //Feature to use when INFO with Record: on is received.
+ type: DataTypes.STRING,
allowNull: true,
},
- vmexten: {
+ recordofffeature: { //Feature to use when INFO with Record: off is received.
type: DataTypes.STRING,
allowNull: true,
},
- description: {
- type: DataTypes.STRING,
+ call_limit: {
+ type: DataTypes.INTEGER(11),
allowNull: true,
+ defaultValue: 10
},
- autoframing: {
+ registertrying: { //Send a 100 Trying when the device registers.
type: DataTypes.ENUM('yes', 'no'),
allowNull: true,
},
- limitonpeers: {
+ subscribemwi: { //Only send notifications if this phone subscribes for mailbox notification
type: DataTypes.ENUM('yes', 'no'),
allowNull: true,
- defaultValue: 'yes'
},
- rtpkeepalive: {
- type: DataTypes.INTEGER(11),
+ vmexten: { // dialplan extension to reach mailbox. defaults to global vmexten which defaults to "asterisk"
+ type: DataTypes.STRING,
allowNull: true,
},
- "call-limit": {
- type: DataTypes.INTEGER(11),
+ mohinterpret: { // This option specifies a preference for which music on hold class this channel should listen to when put on hold
+ type: DataTypes.STRING,
allowNull: true,
- defaultValue: null
},
- g726nonstandard: {
- type: DataTypes.ENUM('yes', 'no'),
+ mohsuggest: { // This option specifies which music on hold class to suggest to the peer channel when this channel places the peer on hold.
+ type: DataTypes.STRING,
allowNull: true,
},
- ignoresdpversion: {
- type: DataTypes.ENUM('yes', 'no'),
+ parkinglot: {
+ type: DataTypes.STRING,
allowNull: true,
},
- allowtransfer: {
- type: DataTypes.ENUM('yes', 'no'),
+ canreinvite: {
+ type: DataTypes.ENUM('yes', 'no', 'nonat', 'update', 'update,nonat'),
allowNull: true,
+ defaultValue: 'no'
},
- dynamic: {
- type: DataTypes.ENUM('yes', 'no'),
- allowNull: true,
+ loginInPause: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
},
- encryption: {
- type: DataTypes.ENUM('yes', 'no'),
- allowNull: true,
- defaultValue: 'no'
+ resetPasswordToken: {
+ type: DataTypes.STRING
},
- registry: {
- type: DataTypes.STRING,
- allowNull: true,
+ resetPasswordExpires: {
+ type: DataTypes.DATE
+ },
+ phoneBarEnableRecording: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: true
+ },
+ showWebBar: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ phoneBarShowOmniDesktop: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: true
+ },
+ phoneBarRingInUse: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ phoneBarDnd: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: true
+ },
+ phoneBarUnansweredCallBadge: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: true
+ },
+ phonebarEnableDtmfTone: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false
+ },
+ phonebarAutoAnswerDelay: {
+ type: DataTypes.INTEGER,
+ defaultValue: 0
}
-
}, {
tableName: 'users',
- getterMethods: {
- // profile: function() {
- // return {
- // name: this.name,
- // role: this.role
- // }
- // }
- },
+ charset: 'utf8',
+ collate: 'utf8_bin',
instanceMethods: {
/**
* Authenticate - check if the passwords are the same
associate: function(models) {
// BELOGNS TO MANY
User.hasMany(models.ChatMessage);
+ User.hasMany(models.MailMessage);
User.hasMany(models.Contact);
+ User.hasMany(models.Action);
User.belongsToMany(models.Module, {
- through: 'user_has_modules'
+ through: models.UserHasModule,
+ required: false
+ });
+ User.belongsToMany(models.MailRoom, {
+ through: models.UserHasMailRoom,
});
User.belongsToMany(models.Channel, {
through: 'user_has_channels'
});
+ User.belongsToMany(models.SmsRoom, {
+ through: 'user_has_sms_rooms'
+ });
+ User.belongsToMany(models.OpenchannelRoom, {
+ through: 'user_has_openchannel_rooms'
+ });
+ User.belongsToMany(models.FaxRoom, {
+ through: 'user_has_fax_rooms'
+ });
User.belongsToMany(models.Team, {
through: models.UserHasTeam
});
- User.belongsToMany(models.ChatRoom, {
- through: models.UserHasChatRoom
+ User.belongsToMany(models.VoiceQueue, {
+ through: models.UserHasVoiceQueue,
+ required: false
+ });
+ User.belongsToMany(models.VoiceQueue, {
+ through: models.UserHasVoiceQueuePermit,
+ as: 'PVoiceQueues'
+ });
+ User.belongsToMany(models.MailQueue, {
+ through: models.UserHasMailQueue,
+ required: false
+ });
+ User.belongsToMany(models.SmsQueue, {
+ through: models.UserHasSmsQueue,
+ required: false
+ });
+ User.belongsToMany(models.SmsQueue, {
+ through: models.UserHasSmsQueuePermit,
+ as: 'PSmsQueues'
+ });
+ User.belongsToMany(models.OpenchannelQueue, {
+ through: models.UserHasOpenchannelQueue,
+ required: false
+ });
+ User.belongsToMany(models.OpenchannelQueue, {
+ through: models.UserHasOpenchannelQueuePermit,
+ as: 'POpenchannelQueues'
});
User.belongsToMany(models.MailQueue, {
- through: models.UserHasMailQueue
+ through: models.UserHasMailQueuePermit,
+ as: 'PMailQueues'
+ });
+ User.belongsToMany(models.FaxQueue, {
+ through: models.UserHasFaxQueue,
+ required: false
+ });
+ User.belongsToMany(models.FaxQueue, {
+ through: models.UserHasFaxQueuePermit,
+ as: 'PFaxQueues'
});
User.belongsToMany(models.ChatQueue, {
- through: models.UserHasChatQueue
+ through: models.UserHasChatQueue,
+ required: false
});
- User.belongsToMany(models.VoiceQueue, {
- through: models.UserHasVoiceQueue
+ User.belongsToMany(models.ChatQueue, {
+ through: models.UserHasChatQueuePermit,
+ as: 'PChatQueues'
+ });
+ User.belongsToMany(models.ChatRoom, {
+ through: models.UserHasChatRoom
+ });
+ User.belongsToMany(models.List, {
+ through: models.UserHasList
});
User.hasMany(models.VoiceExtension, {
foreignKey: 'UserId',
as: 'UserExtensions',
- onDelete: 'cascade'
+ onDelete: 'cascade',
+ hooks: true
+ });
+
+ // SCOPES MANAGEMENT
+ User.addScope('all', {
+ attributes: ['id',
+ 'name',
+ 'email',
+ 'internal',
+ 'fullname',
+ 'role',
+ 'online',
+ 'userpic',
+ 'accountcode',
+ 'transport',
+ 'host',
+ 'role',
+ 'nat',
+ 'type',
+ 'allow',
+ 'lastLoginAt',
+ 'ipaddr',
+ 'fullcontact',
+ 'port',
+ 'lastms',
+ 'description',
+ 'callgroup',
+ 'pickupgroup'
+ ]
+ });
+
+ // SCOPES MANAGEMENT
+ User.addScope('user', {
+ where: {
+ role: {
+ $in: ['admin', 'user']
+ },
+ },
+ attributes: ['id',
+ 'name',
+ 'email',
+ 'internal',
+ 'fullname',
+ 'role',
+ 'userpic',
+ 'accountcode',
+ 'transport',
+ 'host',
+ 'role',
+ 'nat',
+ 'type',
+ 'allow',
+ 'lastLoginAt',
+ 'ipaddr',
+ 'fullcontact',
+ 'port',
+ 'lastms',
+ 'description',
+ 'callgroup',
+ 'pickupgroup'
+ ]
+ });
+ User.addScope('agent', {
+ where: {
+ role: 'agent'
+ },
+ attributes: ['id',
+ 'name',
+ 'email',
+ 'internal',
+ 'fullname',
+ 'role',
+ 'userpic',
+ 'accountcode',
+ 'transport',
+ 'host',
+ 'nat',
+ 'type',
+ 'allow',
+ 'chatCapacity',
+ 'mailCapacity',
+ 'faxCapacity',
+ 'smsCapacity',
+ 'openchannelCapacity',
+ 'online',
+ 'lastLoginAt',
+ 'phoneBarAutoAnswer',
+ 'phoneBarEnableSettings',
+ 'phoneBarUnconditional',
+ 'phoneBarNoReply',
+ 'phoneBarBusy',
+ 'phoneBarUnconditionalNumber',
+ 'phoneBarNoReplyNumber',
+ 'phoneBarBusyNumber',
+ 'phoneBarListenPort',
+ 'phoneBarExpires',
+ 'phoneBarRemoteControl',
+ 'phoneBarRemoteControlPort',
+ 'phoneBarEnableRecording',
+ 'chanspy',
+ 'voicePause',
+ 'mailPause',
+ 'faxPause',
+ 'chatPause',
+ 'smsPause',
+ 'openchannelPause',
+ 'pauseType',
+ 'lastPauseAt',
+ 'status',
+ 'statusAt',
+ 'queueStatus',
+ 'queueStatusAt',
+ 'lastQueue',
+ 'useragent',
+ 'ipaddr',
+ 'fullcontact',
+ 'port',
+ 'lastms',
+ 'description',
+ 'loginInPause',
+ 'showWebBar',
+ 'callgroup',
+ 'pickupgroup',
+ 'phoneBarShowOmniDesktop',
+ 'phoneBarRingInUse',
+ 'phoneBarDnd',
+ 'phoneBarUnansweredCallBadge',
+ 'phone',
+ 'mobile',
+ 'phonebarEnableDtmfTone',
+ 'phonebarAutoAnswerDelay'
+ ]
+ });
+ User.addScope('telephone', {
+ where: {
+ role: 'telephone'
+ }
+ });
+ User.addScope('queues', {
+ include: [{
+ model: models.VoiceQueue,
+ required: false
+ }, {
+ model: models.ChatQueue,
+ required: false
+ }, {
+ model: models.MailQueue,
+ required: false
+ }, {
+ model: models.FaxQueue,
+ required: false
+ }, {
+ model: models.SmsQueue,
+ required: false
+ }, {
+ model: models.OpenchannelQueue,
+ required: false
+ }]
});
+ User.addScope('checkPauseStatus', function(query) {
+ var scope = {
+ where: {}
+ };
+ if (query.voicePause) {
+ scope.where.voicePause = (query.voicePause === 'true') ?
+ true : false;
+ delete query.voicePause;
+ } else if (query.faxPause) {
+ scope.where.faxPause = (query.faxPause === 'true') ? true :
+ false;
+ delete query.faxPause;
+ } else if (query.chatPause) {
+ scope.where.chatPause = (query.chatPause === 'true') ?
+ true : false;
+ delete query.chatPause;
+ } else if (query.mailPause) {
+ scope.where.mailPause = (query.mailPause === 'true') ?
+ true : false;
+ delete query.mailPause;
+ } else if (query.smsPause) {
+ scope.where.smsPause = (query.smsPause === 'true') ?
+ true : false;
+ delete query.smsPause;
+ } else if (query.openchannelPause) {
+ scope.where.openchannelPause = (query.openchannelPause === 'true') ?
+ true : false;
+ delete query.openchannelPause;
+ }
+ return scope;
+ });
+ User.addScope('checkOnlineStatus', function(query) {
+ var scope = {
+ where: {}
+ };
+ if (query.online) {
+ scope.where.online = (query.online === 'true') ? true :
+ false;
+ delete query.online;
+ }
+ return scope;
+ });
+ User.addScope('checkSipStatus', function(query) {
+ var scope = {
+ where: {}
+ };
+ if (query.status) {
+ scope.where.status = query.status;
+ delete query.status;
+ }
+ return scope;
+ });
+ User.addScope('checkQueueStatus', function(query) { //to be executed before checkOnlineStatus
+ var scope = {
+ where: {}
+ };
+ if (query.queueStatus) {
+ if (query.queueStatus === 'paused') {
+ scope.where.voicePause = true;
+ } else {
+ scope.where.queueStatus = query.queueStatus;
+ scope.where.voicePause = false;
+ query.online = 'true';
+ }
+ delete query.queueStatus;
+ }
+ return scope;
+ });
+ User.addScope('me', function(userId) {
+ var scope = {
+ where: {
+ id: userId
+ },
+ attributes: ['id', 'fullname', 'name', 'email', 'role', 'userpic', 'lastLoginAt', 'voicePause',
+ 'mailPause',
+ 'chatPause',
+ 'faxPause',
+ 'smsPause',
+ 'openchannelPause',
+ 'lastPauseAt',
+ 'pauseType',
+ 'phoneBarRemoteControl',
+ 'phoneBarRemoteControlPort',
+ 'loginInPause',
+ 'showWebBar',
+ 'phonebarEnableDtmfTone',
+ 'phonebarAutoAnswerDelay'
+ ],
+ include: [{
+ model: models.Module,
+ attributes: ['id', 'path'],
+ include: [{
+ model: models.Module,
+ attributes: ['id', 'path'],
+ as: 'SubModules',
+ required: false,
+ include: [{
+ model: models.Module,
+ attributes: ['id', 'path'],
+ as: 'SubModules'
+ }]
+ }]
+ }]
+ };
+ return scope;
+ });
}
});