Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / api / user / user.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xccbb=['getSmsInteractions','getFaxInteractions','getWhatsappInteractions','WhatsappInteraction','login','phone','mobile','LOCAL/%s@from-sip/n','intrf','SIP/%s','user:%s','user:forcelogout','headers','x-forwarded-for','connection','remoteAddress','socket','User\x20not\x20found\x20or\x20not\x20allowed\x20to\x20perform\x20login\x20method','getVoiceQueues','loginInPause','UserVoiceQueue.penalty','MemberReport','getChannels','YYYY-MM-DD\x20HH:mm:ss','forEach','LOGIN','device','PAUSE','LOGININPAUSE','isMiddleware','resolve','logout','pause','QueuePause','updateAttributes','DEFAULT\x20PAUSE','unpause','mailPause','chatPause','faxPause','openchannelPause','smsPause','whatsapppause','lastPauseAt','manual','set','%s%s','Pause','getTeams','Team','addTeams','Voice','setDataValue','Chat','getMailQueues','getSmsQueues','Sms','Whatsapp','getFaxQueues','Fax','getOpenchannelQueues','Openchannel','transaction','addAgent','getDataValue','removeTeams','Mail','flatten','getLists','getAgents','values','You\x20can\x27t\x20delete\x20yourself','addChatInteractions','user_has_chat_interactions:save','removeChatInteractions','isArray','user_has_chat_interactions:remove','addMailInteractions','user_has_mail_interactions:save','removeMailInteractions','user_has_mail_interactions:remove','addFaxInteractions','user_has_fax_interactions:save','user_has_fax_interactions:remove','addSmsInteractions','user_has_sms_interactions:save','user_has_sms_interactions:remove','addOpenchannelInteractions','user_has_openchannel_interactions:save','removeOpenchannelInteractions','addWhatsappInteractions','removeWhatsappInteractions','getVoicePrefixes','VoicePrefix','getFaxAccounts','FaxAccount','addFaxAccounts','removeFaxAccounts','getMailAccounts','addMailAccounts','removeMailAccounts','getOpenchannelAccounts','OpenchannelAccount','addOpenchannelAccounts','removeOpenchannelAccounts','SmsAccount','getSmsAccounts','addSmsAccounts','removeSmsAccounts','getChatWebsites','addChatWebsites','removeChatWebsites','getWhatsappAccounts','addWhatsappAccounts','removeWhatsappAccounts','getSquareProjects','SquareProject','addSquareProjects','removeSquareProjects','getScheduledCalls','CmHopper','concat','$or','$gt','$gte','$lte','$ne','$eq','$not','$between','$notBetween','$in','$like','$notLike','$iLike','$notILike','$overlap','$contains','$contained','$any','firstName','lastName','dialActive','getApiKey','retrieveApiKey','token','You\x20don\x27t\x20have\x20sufficient\x20privileges\x20to\x20access\x20this\x20resource.','generateApiKey','iat','nonce','removeApiKey','apiKeyNonce','apiKeyIat','API\x20key\x20not\x20available','getPresence','teams','queues','inbound','col','toString','asc','desc','substring','uniqBy','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','client','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)','offline','idle','unknown','unavailable','ringing','busy','slice','toUpperCase','select','ui.','InteractionId','field','ui.createdAt','_interactions','ui.UserId\x20=\x20?','rimraf','fast-json-patch','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','redis','defaults','localhost','./user.socket','register','jayson/promise','http','request','info','request\x20sent','debug','User,\x20%s,\x20%s,\x20%s','error','User,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','json','undefined','limit','count','offset','Content-Range','apply','reject','update','then','destroy','get','role','admin','user','telephone','ignore','map','value','find','name','UserProfileResource','stack','send','index','User','rawAttributes','fieldName','key','model','password','query','keys','filters','intersection','fields','attributes','length','nolimit','order','sort','where','filter','merge','type','VIRTUAL','sequelize','lower','options','includeAll','include','includes','push','findAll','rows','openTabs','true','dataValues','sms','fax','mail','openchannel','all','params','salt','chat','whatsapp','body','describe','addContacts','ids','omit','Setting','validatePasswordPattern','max','internal','isNil','min_internal','select\x20(select\x20IFNULL(max(internal)+1,1)\x20from\x20users\x20where\x20internal\x20<\x20md.internal)\x20as\x20\x27from\x27,\x20md.internal\x20-\x201\x20as\x20\x27to\x27\x20from\x20users\x20md\x20where\x20md.internal\x20!=\x201\x20and\x20not\x20exists\x20(select\x201\x20from\x20users\x20md2\x20where\x20md2.internal\x20=\x20md.internal\x20-\x201)','QueryTypes','SELECT','from','mailbox','fullname','permissions','102','113','110','104','105','108','109','111','114','create','Unauthorized','Unauthorized.\x20You\x20must\x20be\x20an\x20administrator\x20in\x20order\x20to\x20create\x20an\x20user','Unauthorized.\x20You\x20must\x20be\x20an\x20administrator\x20in\x20order\x20to\x20create\x20another\x20administrator','checkUserLimits','userProfileId','VoiceMail','UserProfileSection','agent','Agents','autoAssociation','bulkCreate','some','Unauthorized.\x20You\x20must\x20be\x20an\x20administrator\x20in\x20order\x20to\x20create\x20an\x20administrator','each','Telephones','isEmpty','compact','changePassword','oldPassword','newPassword','Sequelize','Invalid\x20body\x20format.\x20Use\x20oldPassword\x20and\x20newPassword','authenticate','ValidationError','Wrong\x20credentials','New\x20password\x20must\x20be\x20different\x20from\x20old\x20password','Invalid\x20body\x20format.\x20Use\x20newPassword','findOne','enforcePasswordHistory','passwordHistoryLimit','securePassword','validatePasswordHistory','previousPasswords','channel','online','voicePause','interface','Unknown\x20channel','add','capitalize','toLowerCase','Queues','penalty','spread','QueueId','Queue:save','voice','VoiceQueue','format','UserVoiceQueueRt','upsert','removeQueues','isValidChannel','remove','emit','Queue:remove','addAvatar','userpic','file','filename','getAvatar','join','root','server/files/images/logos/default_profile.png','download','existsSync','server/files/images/','ChatOpenTabs','CHAT','createdAt','FaxOpenTabs','FAX','OpenchannelOpenTabs','OPENCHANNEL','MailOpenTabs','MAIL','SmsOpenTabs','SMS','WhatsappOpenTabs','WHATSAPP','CmContact','pick','CmList','List','Tag','color','tag','hasOwnProperty','getContacts','getQueues','Queue','Unknown\x20role','getVoiceQueuesRt','getGroups','ChatGroup','getRecordings','VoiceRecording','getScreenRecordings','ScreenRecording','getChatInteractions','ChatInteraction','getOpenchannelInteractions','OpenchannelInteraction','getMailInteractions','MailInteraction','UserId'];(function(_0x5d1566,_0x3fed4b){var _0x3441a2=function(_0x57c3fe){while(--_0x57c3fe){_0x5d1566['push'](_0x5d1566['shift']());}};_0x3441a2(++_0x3fed4b);}(_0xccbb,0xb6));var _0xbccb=function(_0x5e73ee,_0x4147e4){_0x5e73ee=_0x5e73ee-0x0;var _0x3caedd=_0xccbb[_0x5e73ee];return _0x3caedd;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xbccb('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xbccb('0x1'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xbccb('0x2'));var Mustache=require(_0xbccb('0x3'));var util=require('util');var path=require(_0xbccb('0x4'));var sox=require(_0xbccb('0x5'));var csv=require(_0xbccb('0x6'));var ejs=require(_0xbccb('0x7'));var fs=require('fs');var fs_extra=require(_0xbccb('0x8'));var _=require('lodash');var squel=require(_0xbccb('0x9'));var crypto=require(_0xbccb('0xa'));var jsforce=require(_0xbccb('0xb'));var deskjs=require(_0xbccb('0xc'));var toCsv=require(_0xbccb('0x6'));var querystring=require(_0xbccb('0xd'));var Papa=require(_0xbccb('0xe'));var Redis=require(_0xbccb('0xf'));var values;var authService=require(_0xbccb('0x10'));var qs=require(_0xbccb('0x11'));var as=require(_0xbccb('0x12'));var hardwareService=require(_0xbccb('0x13'));var logger=require(_0xbccb('0x14'))(_0xbccb('0x15'));var utils=require('../../config/utils');var config=require(_0xbccb('0x16'));var licenseUtil=require(_0xbccb('0x17'));var db=require('../../mysqldb')['db'];config[_0xbccb('0x18')]=_[_0xbccb('0x19')](config[_0xbccb('0x18')],{'host':_0xbccb('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xbccb('0x18')]));require(_0xbccb('0x1b'))[_0xbccb('0x1c')](socket);var jayson=require(_0xbccb('0x1d'));var client=jayson['client'][_0xbccb('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x26f719,_0x10a153,_0x219708,_0x599ed5){return new BPromise(function(_0x11808c,_0x50817f){var _0x1a9cee=_0x599ed5||client;return _0x1a9cee[_0xbccb('0x1f')](_0x26f719,_0x219708)['then'](function(_0x48aa47){logger[_0xbccb('0x20')]('User,\x20%s,\x20%s',_0x10a153,_0xbccb('0x21'));logger[_0xbccb('0x22')](_0xbccb('0x23'),_0x10a153,_0xbccb('0x21'),JSON['stringify'](_0x48aa47));if(_0x48aa47['error']){if(_0x48aa47[_0xbccb('0x24')]['code']===0x1f4){logger[_0xbccb('0x24')](_0xbccb('0x25'),_0x10a153,_0x48aa47[_0xbccb('0x24')]['message']);return _0x50817f(_0x48aa47[_0xbccb('0x24')][_0xbccb('0x26')]);}logger['error'](_0xbccb('0x25'),_0x10a153,_0x48aa47[_0xbccb('0x24')][_0xbccb('0x26')]);return _0x11808c(_0x48aa47[_0xbccb('0x24')][_0xbccb('0x26')]);}else{logger[_0xbccb('0x20')]('User,\x20%s,\x20%s',_0x10a153,'request\x20sent');_0x11808c(_0x48aa47[_0xbccb('0x27')]['message']);}})[_0xbccb('0x28')](function(_0x1e565d){logger[_0xbccb('0x24')](_0xbccb('0x25'),_0x10a153,_0x1e565d);_0x50817f(_0x1e565d);});});}function respondWithStatusCode(_0xfc54d1,_0x4fe1cb){_0x4fe1cb=_0x4fe1cb||0xcc;return function(_0x26bb40){if(_0x26bb40){return _0xfc54d1[_0xbccb('0x29')](_0x4fe1cb);}return _0xfc54d1[_0xbccb('0x2a')](_0x4fe1cb)[_0xbccb('0x2b')]();};}function respondWithResult(_0x7b16ce,_0x1a7068){_0x1a7068=_0x1a7068||0xc8;return function(_0x331aad){if(_0x331aad){return _0x7b16ce[_0xbccb('0x2a')](_0x1a7068)[_0xbccb('0x2c')](_0x331aad);}};}function respondWithFilteredResult(_0x4cb336,_0x1ef67e){return function(_0x343e01){if(_0x343e01){var _0x6a207c=typeof _0x1ef67e['offset']===_0xbccb('0x2d')&&typeof _0x1ef67e[_0xbccb('0x2e')]===_0xbccb('0x2d');var _0x562b43=_0x343e01[_0xbccb('0x2f')];var _0x692871=_0x6a207c?0x0:_0x1ef67e[_0xbccb('0x30')];var _0x2754ca=_0x6a207c?_0x343e01[_0xbccb('0x2f')]:_0x1ef67e['offset']+_0x1ef67e[_0xbccb('0x2e')];var _0x3e5aba;if(_0x2754ca>=_0x562b43){_0x2754ca=_0x562b43;_0x3e5aba=0xc8;}else{_0x3e5aba=0xce;}_0x4cb336['status'](_0x3e5aba);return _0x4cb336['set'](_0xbccb('0x31'),_0x692871+'-'+_0x2754ca+'/'+_0x562b43)[_0xbccb('0x2c')](_0x343e01);}return null;};}function patchUpdates(_0x432785){return function(_0x836c88){try{jsonpatch[_0xbccb('0x32')](_0x836c88,_0x432785,!![]);}catch(_0xfbcd74){return BPromise[_0xbccb('0x33')](_0xfbcd74);}return _0x836c88['save']();};}function saveUpdates(_0x59ad2f,_0x23e21){return function(_0x2116e9){if(_0x2116e9){return _0x2116e9[_0xbccb('0x34')](_0x59ad2f)[_0xbccb('0x35')](function(_0x13a253){return _0x13a253;});}return null;};}function removeEntity(_0x5b4b20,_0x516765){return function(_0x297ca4){if(_0x297ca4){return _0x297ca4[_0xbccb('0x36')]()[_0xbccb('0x35')](function(){var _0x318098=_0x297ca4[_0xbccb('0x37')]({'plain':!![]});if(_0x318098[_0xbccb('0x38')]===_0xbccb('0x39'))return;var _0x23ff3e=[{'name':'Users','value':_0xbccb('0x3a'),'ignore':!![]},{'name':'Agents','value':'agent','ignore':![]},{'name':'Telephones','value':_0xbccb('0x3b'),'ignore':![]}];var _0x1c0852=_(_0x23ff3e)['filter'](_0xbccb('0x3c'))[_0xbccb('0x3d')](_0xbccb('0x3e'))[_0xbccb('0x3e')]();if(_['includes'](_0x1c0852,_0x318098[_0xbccb('0x38')])){return;}var _0x4cc92b=_[_0xbccb('0x3f')](_0x23ff3e,[_0xbccb('0x3e'),_0x318098[_0xbccb('0x38')]])[_0xbccb('0x40')];return db[_0xbccb('0x41')][_0xbccb('0x36')]({'where':{'type':_0x4cc92b,'resourceId':_0x318098['id']}})[_0xbccb('0x35')](function(){return _0x297ca4;});})[_0xbccb('0x35')](function(){_0x5b4b20[_0xbccb('0x2a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x26c900,_0x37eb2a){return function(_0x4fd7cb){if(!_0x4fd7cb){_0x26c900[_0xbccb('0x29')](0x194);}return _0x4fd7cb;};}function handleError(_0x3b67d6,_0x14e3ba){_0x14e3ba=_0x14e3ba||0x1f4;return function(_0x17fff0){logger[_0xbccb('0x24')](_0x17fff0[_0xbccb('0x42')]);if(_0x17fff0['name']){delete _0x17fff0['name'];}_0x3b67d6[_0xbccb('0x2a')](_0x14e3ba)[_0xbccb('0x43')](_0x17fff0);};}exports[_0xbccb('0x44')]=function(_0x4c522f,_0x453d20){var _0x5e6665={},_0x4bc21b={},_0x4f4983={'count':0x0,'rows':[]};var _0x38e6e8=_[_0xbccb('0x3d')](db[_0xbccb('0x45')][_0xbccb('0x46')],function(_0x339027){return{'name':_0x339027[_0xbccb('0x47')],'type':_0x339027['type'][_0xbccb('0x48')]};});_0x4bc21b[_0xbccb('0x49')]=_['differenceBy'](_[_0xbccb('0x3d')](_0x38e6e8,_0xbccb('0x40')),[_0xbccb('0x4a'),'salt']);_0x4bc21b[_0xbccb('0x4b')]=_[_0xbccb('0x4c')](_0x4c522f['query']);_0x4bc21b[_0xbccb('0x4d')]=_['intersection'](_0x4bc21b[_0xbccb('0x49')],_0x4bc21b[_0xbccb('0x4b')]);_0x5e6665['attributes']=_[_0xbccb('0x4e')](_0x4bc21b[_0xbccb('0x49')],qs['fields'](_0x4c522f['query'][_0xbccb('0x4f')]));_0x5e6665['attributes']=_0x5e6665[_0xbccb('0x50')][_0xbccb('0x51')]?_0x5e6665[_0xbccb('0x50')]:_0x4bc21b['model'];if(!_0x4c522f[_0xbccb('0x4b')]['hasOwnProperty'](_0xbccb('0x52'))){_0x5e6665[_0xbccb('0x2e')]=qs[_0xbccb('0x2e')](_0x4c522f[_0xbccb('0x4b')][_0xbccb('0x2e')]);_0x5e6665[_0xbccb('0x30')]=qs[_0xbccb('0x30')](_0x4c522f[_0xbccb('0x4b')]['offset']);}_0x5e6665[_0xbccb('0x53')]=qs['sort'](_0x4c522f['query'][_0xbccb('0x54')]);_0x5e6665[_0xbccb('0x55')]=qs[_0xbccb('0x4d')](_['pick'](_0x4c522f[_0xbccb('0x4b')],_0x4bc21b[_0xbccb('0x4d')]),_0x38e6e8);if(_0x4c522f[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x5e6665[_0xbccb('0x55')]=_[_0xbccb('0x57')](_0x5e6665[_0xbccb('0x55')],{'$or':_[_0xbccb('0x3d')](_0x38e6e8,function(_0x3b2c81){if(_0x3b2c81[_0xbccb('0x58')]!==_0xbccb('0x59')){return db[_0xbccb('0x5a')][_0xbccb('0x55')](db[_0xbccb('0x5a')]['fn'](_0xbccb('0x5b'),db[_0xbccb('0x5a')]['col'](_0x3b2c81['name'])),{'$like':db[_0xbccb('0x5a')]['fn'](_0xbccb('0x5b'),'%'+_0x4c522f[_0xbccb('0x4b')][_0xbccb('0x56')]+'%')});}})});}_0x5e6665=_[_0xbccb('0x57')]({},_0x5e6665,_0x4c522f[_0xbccb('0x5c')]);var _0x5331cb={'where':_0x5e6665[_0xbccb('0x55')]};return db['User']['count'](_0x5331cb)[_0xbccb('0x35')](function(_0x57b829){_0x4f4983['count']=_0x57b829;if(_0x4c522f[_0xbccb('0x4b')][_0xbccb('0x5d')]){_0x5e6665[_0xbccb('0x5e')]=[{'all':!![]}];}if(!_[_0xbccb('0x5f')](_0x5e6665[_0xbccb('0x50')],'id')){_0x5e6665[_0xbccb('0x50')][_0xbccb('0x60')]('id');}return db[_0xbccb('0x45')][_0xbccb('0x61')](_0x5e6665);})[_0xbccb('0x35')](function(_0x22e31c){_0x4f4983[_0xbccb('0x62')]=_0x22e31c;if(_0x4c522f[_0xbccb('0x4b')][_0xbccb('0x63')]===_0xbccb('0x64')){var _0x2027e7=[];for(var _0x4c3fb0=0x0;_0x4c3fb0<_0x4f4983[_0xbccb('0x62')][_0xbccb('0x51')];_0x4c3fb0++){_0x2027e7[_0xbccb('0x60')](get_open_tabs('chat',_0x4f4983['rows'][_0x4c3fb0][_0xbccb('0x65')]));_0x2027e7[_0xbccb('0x60')](get_open_tabs(_0xbccb('0x66'),_0x4f4983['rows'][_0x4c3fb0][_0xbccb('0x65')]));_0x2027e7[_0xbccb('0x60')](get_open_tabs(_0xbccb('0x67'),_0x4f4983[_0xbccb('0x62')][_0x4c3fb0]['dataValues']));_0x2027e7[_0xbccb('0x60')](get_open_tabs(_0xbccb('0x68'),_0x4f4983['rows'][_0x4c3fb0][_0xbccb('0x65')]));_0x2027e7[_0xbccb('0x60')](get_open_tabs(_0xbccb('0x69'),_0x4f4983['rows'][_0x4c3fb0]['dataValues']));_0x2027e7[_0xbccb('0x60')](get_open_tabs('whatsapp',_0x4f4983[_0xbccb('0x62')][_0x4c3fb0][_0xbccb('0x65')]));}return BPromise[_0xbccb('0x6a')](_0x2027e7)[_0xbccb('0x35')](function(_0x167179){return _0x4f4983;});}else{return _0x4f4983;}})[_0xbccb('0x35')](respondWithFilteredResult(_0x453d20,_0x5e6665))['catch'](handleError(_0x453d20,null));};exports['show']=function(_0x4a63b7,_0x538453){var _0x51f581={'raw':![],'where':{'id':_0x4a63b7[_0xbccb('0x6b')]['id']}},_0x29c0ed={};_0x29c0ed[_0xbccb('0x49')]=_['differenceBy'](_[_0xbccb('0x4c')](db[_0xbccb('0x45')]['rawAttributes']),['password',_0xbccb('0x6c')]);_0x29c0ed[_0xbccb('0x4b')]=_[_0xbccb('0x4c')](_0x4a63b7[_0xbccb('0x4b')]);_0x29c0ed[_0xbccb('0x4d')]=_[_0xbccb('0x4e')](_0x29c0ed[_0xbccb('0x49')],_0x29c0ed[_0xbccb('0x4b')]);_0x51f581[_0xbccb('0x50')]=_[_0xbccb('0x4e')](_0x29c0ed['model'],qs[_0xbccb('0x4f')](_0x4a63b7[_0xbccb('0x4b')][_0xbccb('0x4f')]));_0x51f581['attributes']=_0x51f581[_0xbccb('0x50')][_0xbccb('0x51')]?_0x51f581[_0xbccb('0x50')]:_0x29c0ed['model'];if(_0x4a63b7[_0xbccb('0x4b')][_0xbccb('0x5d')]){_0x51f581['include']=[{'all':!![]}];}_0x51f581=_[_0xbccb('0x57')]({},_0x51f581,_0x4a63b7['options']);if(!_[_0xbccb('0x5f')](_0x51f581[_0xbccb('0x50')],'id')){_0x51f581[_0xbccb('0x50')][_0xbccb('0x60')]('id');}return db[_0xbccb('0x45')][_0xbccb('0x3f')](_0x51f581)[_0xbccb('0x35')](handleEntityNotFound(_0x538453,null))[_0xbccb('0x35')](function(_0x56f372){var _0x4be746=[];values=_0x56f372;if(_0x4a63b7['query']['openTabs']==='true'){_0x4be746[_0xbccb('0x60')](get_open_tabs(_0xbccb('0x6d'),_0x56f372[_0xbccb('0x65')]));_0x4be746[_0xbccb('0x60')](get_open_tabs(_0xbccb('0x66'),_0x56f372[_0xbccb('0x65')]));_0x4be746[_0xbccb('0x60')](get_open_tabs(_0xbccb('0x69'),_0x56f372[_0xbccb('0x65')]));_0x4be746[_0xbccb('0x60')](get_open_tabs(_0xbccb('0x6e'),_0x56f372[_0xbccb('0x65')]));_0x4be746['push'](get_open_tabs(_0xbccb('0x67'),_0x56f372[_0xbccb('0x65')]));_0x4be746[_0xbccb('0x60')](get_open_tabs('mail',_0x56f372[_0xbccb('0x65')]));return BPromise[_0xbccb('0x6a')](_0x4be746);}else{return values;}})[_0xbccb('0x35')](function(_0x11df4c){return values;})['then'](respondWithResult(_0x538453,null))[_0xbccb('0x28')](handleError(_0x538453,null));};exports[_0xbccb('0x34')]=function(_0x287ce2,_0x2d345a){if(_0x287ce2[_0xbccb('0x6f')]['id']){delete _0x287ce2[_0xbccb('0x6f')]['id'];}delete _0x287ce2[_0xbccb('0x6f')][_0xbccb('0x38')];return db['User'][_0xbccb('0x3f')]({'where':{'id':_0x287ce2[_0xbccb('0x6b')]['id']}})['then'](handleEntityNotFound(_0x2d345a,null))[_0xbccb('0x35')](saveUpdates(_0x287ce2[_0xbccb('0x6f')],null))[_0xbccb('0x35')](respondWithResult(_0x2d345a,null))[_0xbccb('0x28')](handleError(_0x2d345a,null));};exports[_0xbccb('0x70')]=function(_0x550857,_0x1c4547){return db['User'][_0xbccb('0x70')]()[_0xbccb('0x35')](respondWithResult(_0x1c4547,null))[_0xbccb('0x28')](handleError(_0x1c4547,null));};exports[_0xbccb('0x71')]=function(_0xc9afc2,_0x2c0918,_0x217103){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0xc9afc2['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x2c0918,null))[_0xbccb('0x35')](function(_0x150e46){if(_0x150e46){return _0x150e46[_0xbccb('0x71')](_0xc9afc2['body'][_0xbccb('0x72')],_[_0xbccb('0x73')](_0xc9afc2[_0xbccb('0x6f')],[_0xbccb('0x72'),'id'])||{});}})[_0xbccb('0x35')](respondWithResult(_0x2c0918,null))[_0xbccb('0x28')](handleError(_0x2c0918,null));};function validateUser(_0x366449){return new BPromise(function(_0x2f871a,_0x34995c){if(_0x366449['internal'])return _0x2f871a(_0x366449);return db[_0xbccb('0x74')]['findById'](0x1)[_0xbccb('0x35')](function(_0x495ff4){if(_0x495ff4['securePassword'])authService[_0xbccb('0x75')](_0x366449[_0xbccb('0x4a')]);db[_0xbccb('0x45')][_0xbccb('0x76')](_0xbccb('0x77'))[_0xbccb('0x35')](function(_0x3c6043){if(_[_0xbccb('0x78')](_0x3c6043)){_0x366449[_0xbccb('0x77')]=_0x495ff4['min_internal']||0x1;return;}if(_[_0xbccb('0x78')](_0x495ff4['min_internal'])||_0x495ff4['min_internal']===_0x3c6043){_0x366449[_0xbccb('0x77')]=_0x3c6043+0x1;return;}if(_0x495ff4['min_internal']>_0x3c6043){_0x366449[_0xbccb('0x77')]=_0x495ff4[_0xbccb('0x79')];return;}return db[_0xbccb('0x5a')][_0xbccb('0x4b')](_0xbccb('0x7a'),{'type':db[_0xbccb('0x5a')][_0xbccb('0x7b')][_0xbccb('0x7c')]})[_0xbccb('0x35')](function(_0x43978a){if(_0x43978a&&_0x43978a[_0xbccb('0x51')]){for(var _0x534c0f=0x0,_0xe151a6=_0x43978a[_0xbccb('0x51')];_0x534c0f<_0xe151a6&&_[_0xbccb('0x78')](_0x366449['internal']);_0x534c0f++){if(_0x495ff4[_0xbccb('0x79')]<=_0x43978a[_0x534c0f][_0xbccb('0x7d')]){_0x366449[_0xbccb('0x77')]=_0x43978a[_0x534c0f][_0xbccb('0x7d')];}else if(_0x495ff4[_0xbccb('0x79')]>_0x43978a[_0x534c0f][_0xbccb('0x7d')]&&_0x495ff4['min_internal']<=_0x43978a[_0x534c0f]['to']){_0x366449['internal']=_0x495ff4[_0xbccb('0x79')];}}}if(_[_0xbccb('0x78')](_0x366449['internal'])){_0x366449[_0xbccb('0x77')]=_0x3c6043+0x1;}return _0x2f871a(_0x366449);});});})[_0xbccb('0x28')](function(_0x5bc775){_0x34995c(_0x5bc775);});});}function updateUser(_0x1cd937){return new BPromise(function(_0x25592a,_0x1112ef){try{if(_0x1cd937['voicemail']){_0x1cd937[_0xbccb('0x7e')]=_0x1cd937[_0xbccb('0x77')];_0x1cd937['VoiceMail']={'mailbox':_0x1cd937[_0xbccb('0x77')],'password':_0x1cd937[_0xbccb('0x4a')],'fullname':_0x1cd937[_0xbccb('0x7f')],'email':_0x1cd937['email']};}if(_0x1cd937['role']==='agent'){if(!_0x1cd937[_0xbccb('0x80')])_0x1cd937[_0xbccb('0x80')]=['101',_0xbccb('0x81'),'103',_0xbccb('0x82'),_0xbccb('0x83'),_0xbccb('0x84'),_0xbccb('0x85'),'106','107',_0xbccb('0x86'),_0xbccb('0x87'),'100',_0xbccb('0x88'),_0xbccb('0x89'),'115'];}_0x25592a(_0x1cd937);}catch(_0x3eba86){_0x1112ef(_0x3eba86);}});}exports[_0xbccb('0x8a')]=function(_0x911d75,_0x5dd0b5){if(_0x911d75[_0xbccb('0x3a')][_0xbccb('0x38')]==='agent')throw new Error(_0xbccb('0x8b'));if(_0x911d75[_0xbccb('0x6f')][_0xbccb('0x38')]===_0xbccb('0x3a')&&_0x911d75['user'][_0xbccb('0x38')]!=='admin'){throw new Error(_0xbccb('0x8c'));}if(_0x911d75['body'][_0xbccb('0x38')]===_0xbccb('0x39')&&_0x911d75[_0xbccb('0x3a')]['role']!==_0xbccb('0x39')){throw new Error(_0xbccb('0x8d'));}return licenseUtil[_0xbccb('0x8e')]([_0x911d75[_0xbccb('0x6f')]])[_0xbccb('0x35')](function(){return validateUser(_0x911d75[_0xbccb('0x6f')]);})['then'](function(_0x45fe40){return updateUser(_0x45fe40)['then'](function(_0x51bcde){if(_0x51bcde[_0xbccb('0x38')]===_0xbccb('0x39')){_0x51bcde['settingsEnabled']=_0x911d75[_0xbccb('0x3a')]['settingsEnabled'];delete _0x51bcde[_0xbccb('0x8f')];}return _0x51bcde;});})['then'](function(_0x18b5d4){return db['User'][_0xbccb('0x8a')](_0x18b5d4,{'include':[{'model':db[_0xbccb('0x90')],'as':_0xbccb('0x90')}]});})[_0xbccb('0x35')](function(_0x1b9a73){if(_0x911d75[_0xbccb('0x6f')][_0xbccb('0x38')]==='user')return _0x1b9a73;if(_0x911d75[_0xbccb('0x3a')][_0xbccb('0x38')]!==_0xbccb('0x3a'))return _0x1b9a73;return db[_0xbccb('0x91')][_0xbccb('0x3f')]({'where':{'name':_0x1b9a73[_0xbccb('0x38')]===_0xbccb('0x92')?_0xbccb('0x93'):'Telephones','userProfileId':_0x911d75[_0xbccb('0x3a')][_0xbccb('0x8f')]},'raw':!![]})[_0xbccb('0x35')](function(_0x37d8f1){if(!_0x37d8f1||_0x37d8f1[_0xbccb('0x94')]!=0x0)return _0x1b9a73;return db[_0xbccb('0x41')][_0xbccb('0x8a')]({'name':_0x1b9a73[_0xbccb('0x40')],'resourceId':_0x1b9a73['id'],'type':_0x37d8f1[_0xbccb('0x40')],'sectionId':_0x37d8f1['id']},{})['then'](function(){return _0x1b9a73;});})[_0xbccb('0x28')](function(_0x5ef3ff){logger[_0xbccb('0x24')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x5ef3ff);throw _0x5ef3ff;});})['then'](respondWithResult(_0x5dd0b5,0xc9))[_0xbccb('0x28')](handleError(_0x5dd0b5,null));};exports[_0xbccb('0x95')]=function(_0x2d24b5,_0x2ba96a){var _0xead3f2=_0x2d24b5[_0xbccb('0x6f')];var _0x5d2eb7=[];if(_0x2d24b5[_0xbccb('0x3a')]['role']==='agent')throw new Error(_0xbccb('0x8b'));if(_[_0xbccb('0x96')](_0xead3f2,['role',_0xbccb('0x3a')])&&_0x2d24b5[_0xbccb('0x3a')]['role']!==_0xbccb('0x39')){throw new Error(_0xbccb('0x8c'));}if(_[_0xbccb('0x96')](_0xead3f2,[_0xbccb('0x38'),_0xbccb('0x39')])&&_0x2d24b5[_0xbccb('0x3a')][_0xbccb('0x38')]!==_0xbccb('0x39')){throw new Error(_0xbccb('0x97'));}return licenseUtil[_0xbccb('0x8e')](_0xead3f2)[_0xbccb('0x35')](function(){return validateUser(_0xead3f2[0x0]);})[_0xbccb('0x35')](function(){for(var _0x466825=0x1;_0x466825<_0xead3f2[_0xbccb('0x51')];_0x466825++){var _0x8f02ce=_0xead3f2[_0x466825-0x1][_0xbccb('0x77')];if(!_0xead3f2[_0x466825]['internal'])_0xead3f2[_0x466825][_0xbccb('0x77')]=_0x8f02ce+0x1;_0x5d2eb7['push'](validateUser(_0xead3f2[_0x466825]));}return BPromise[_0xbccb('0x6a')](_0x5d2eb7);})[_0xbccb('0x35')](function(){_0x5d2eb7=[];for(var _0x37e482=0x0;_0x37e482<_0xead3f2[_0xbccb('0x51')];_0x37e482++){_0x5d2eb7[_0xbccb('0x60')](updateUser(_0xead3f2[_0x37e482]));}return BPromise['all'](_0x5d2eb7);})[_0xbccb('0x35')](function(){return BPromise[_0xbccb('0x98')](_0xead3f2,function(_0x15fa9b){return db[_0xbccb('0x45')][_0xbccb('0x8a')](_0x15fa9b,{'include':[{'model':db[_0xbccb('0x90')],'as':_0xbccb('0x90')}]})[_0xbccb('0x35')](function(_0x174ec4){_0x15fa9b['id']=_0x174ec4['id'];return _0x15fa9b;});});})[_0xbccb('0x35')](function(_0x21c679){if(_0x2d24b5['body']['role']==='user')return _0x21c679;if(_0x2d24b5[_0xbccb('0x3a')][_0xbccb('0x38')]!==_0xbccb('0x3a'))return _0x21c679;var _0x63d9cc=_[_0xbccb('0x96')](_0x21c679,function(_0x3fc093){return _0x3fc093[_0xbccb('0x38')]==='agent'||_0x3fc093[_0xbccb('0x38')]===_0xbccb('0x3b');});if(!_0x63d9cc)return _0x21c679;return db[_0xbccb('0x91')][_0xbccb('0x61')]({'where':{'name':{'$or':['Agents',_0xbccb('0x99')]},'userProfileId':_0x2d24b5[_0xbccb('0x3a')][_0xbccb('0x8f')]},'raw':!![]})[_0xbccb('0x35')](function(_0x522e4e){if(_[_0xbccb('0x9a')](_0x522e4e)||!_[_0xbccb('0x96')](_0x522e4e,[_0xbccb('0x94'),0x0]))return _0x21c679;_0x5d2eb7=[];var _0x51b3be=_(_0x522e4e)[_0xbccb('0x3d')](function(_0x4e8933){if(_0x4e8933[_0xbccb('0x94')]===0x1)return;return _0x4e8933[_0xbccb('0x40')]==='Agents'?_0xbccb('0x92'):_0xbccb('0x3b');})[_0xbccb('0x9b')]()[_0xbccb('0x3e')]();for(var _0x254be=0x0;_0x254be<_0x21c679['length'];_0x254be++){if(!_[_0xbccb('0x5f')](_0x51b3be,_0x21c679[_0x254be][_0xbccb('0x38')]))return;var _0x5b00cd=_0x21c679[_0x254be][_0xbccb('0x38')]===_0xbccb('0x92')?'Agents':_0xbccb('0x99');_0x5d2eb7[_0xbccb('0x60')](db[_0xbccb('0x41')]['create']({'name':_0x21c679[_0x254be][_0xbccb('0x40')],'resourceId':_0x21c679[_0x254be]['id'],'type':_0x5b00cd,'sectionId':_[_0xbccb('0x3f')](_0x522e4e,['name',_0x5b00cd])['id']},{}));}return BPromise[_0xbccb('0x6a')](_0x5d2eb7);});})['then'](respondWithResult(_0x2ba96a,0xc9))[_0xbccb('0x28')](handleError(_0x2ba96a,null));};exports[_0xbccb('0x9c')]=function(_0x44b948,_0x44daac,_0x38d042){if(_0x44b948[_0xbccb('0x6f')]['id']){delete _0x44b948['body']['id'];}return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0x44b948[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](function(_0x555eb6){if(!_0x555eb6)return null;if(_0x555eb6['id']===_0x44b948[_0xbccb('0x3a')]['id']){if(!_0x44b948['body'][_0xbccb('0x9d')]||!_0x44b948['body'][_0xbccb('0x9e')]){throw new db[(_0xbccb('0x9f'))]['ValidationError'](_0xbccb('0xa0'));}if(!_0x555eb6[_0xbccb('0xa1')](_0x44b948[_0xbccb('0x6f')]['oldPassword'])){throw new db[(_0xbccb('0x9f'))][(_0xbccb('0xa2'))](_0xbccb('0xa3'));}if(_0x44b948[_0xbccb('0x6f')][_0xbccb('0x9d')]===_0x44b948['body']['newPassword']){throw new db[(_0xbccb('0x9f'))]['ValidationError'](_0xbccb('0xa4'));}}else if(_0x44b948[_0xbccb('0x3a')]['role']===_0xbccb('0x39')){if(!_0x44b948[_0xbccb('0x6f')]['newPassword']){throw new db[(_0xbccb('0x9f'))][(_0xbccb('0xa2'))]('Invalid\x20body\x20format.\x20Use\x20newPassword');}}else if(_0x44b948[_0xbccb('0x3a')][_0xbccb('0x38')]===_0xbccb('0x3a')){if(!_0x44b948['body'][_0xbccb('0x9e')]){throw new db[(_0xbccb('0x9f'))][(_0xbccb('0xa2'))](_0xbccb('0xa5'));}if(_0x555eb6[_0xbccb('0x38')]!=='agent'){throw new db[(_0xbccb('0x9f'))]['ValidationError'](_0xbccb('0x8b'));}}else{throw new db['Sequelize'][(_0xbccb('0xa2'))](_0xbccb('0x8b'));}return _0x555eb6;})[_0xbccb('0x35')](handleEntityNotFound(_0x44daac,null))[_0xbccb('0x35')](function(_0xaf0cb9){return db['Setting'][_0xbccb('0xa6')]({'attributes':['id','securePassword',_0xbccb('0xa7'),_0xbccb('0xa8')]})[_0xbccb('0x35')](function(_0x66e01b){if(_0x66e01b[_0xbccb('0xa9')])authService[_0xbccb('0x75')](_0x44b948[_0xbccb('0x6f')][_0xbccb('0x9e')]);if(!_0x66e01b[_0xbccb('0xa7')]||!_0xaf0cb9['previousPasswords'])return _0xaf0cb9;authService[_0xbccb('0xaa')](_0x44b948[_0xbccb('0x6f')]['newPassword'],_0xaf0cb9[_0xbccb('0xab')],_0x66e01b['passwordHistoryLimit']);return _0xaf0cb9;})[_0xbccb('0x35')](saveUpdates({'password':_0x44b948[_0xbccb('0x6f')][_0xbccb('0x9e')],'passwordResetAt':_0x44b948[_0xbccb('0x3a')]['id']==_0x44b948[_0xbccb('0x6b')]['id']?moment():null,'previousPasswords':authService['updatePasswordsHistory'](_0x44b948[_0xbccb('0x6f')][_0xbccb('0x9e')],_0xaf0cb9[_0xbccb('0xab')])},null));})[_0xbccb('0x35')](respondWithResult(_0x44daac,null))[_0xbccb('0x28')](handleError(_0x44daac,null));};exports['addQueues']=function(_0x408312,_0xc7b8e8,_0x29f484){var _0x1488ed=_0x408312[_0xbccb('0x6f')][_0xbccb('0xac')];return db['User'][_0xbccb('0x3f')]({'where':{'id':_0x408312[_0xbccb('0x6b')]['id']},'attributes':['id','name','role',_0xbccb('0xad'),'loginInPause',_0xbccb('0xae'),_0xbccb('0xaf')]})[_0xbccb('0x35')](handleEntityNotFound(_0xc7b8e8,null))[_0xbccb('0x35')](function(_0x440e9e){if(_0x440e9e){if(!utils['isValidChannel'](_0x1488ed)){throw new db[(_0xbccb('0x9f'))]['ValidationError'](_0xbccb('0xb0'));}return _0x440e9e[_0xbccb('0xb1')+_[_0xbccb('0xb2')](_0x1488ed[_0xbccb('0xb3')]())+_0xbccb('0xb4')](_0x408312[_0xbccb('0x6f')][_0xbccb('0x72')],{'penalty':_0x408312[_0xbccb('0x6f')][_0xbccb('0xb5')]||0x0})[_0xbccb('0xb6')](function(_0x41b655){for(var _0x180d69=0x0;_0x180d69<_0x408312[_0xbccb('0x6f')]['ids'][_0xbccb('0x51')];_0x180d69+=0x1){var _0x3fb3af={'UserId':_0x408312[_0xbccb('0x6b')]['id']};_0x3fb3af[_[_0xbccb('0xb2')](_0x1488ed[_0xbccb('0xb3')]())+_0xbccb('0xb7')]=_0x408312['body']['ids'][_0x180d69];socket['emit']('user'+_[_0xbccb('0xb2')](_0x1488ed[_0xbccb('0xb3')]())+_0xbccb('0xb8'),_0x3fb3af);}return _0x41b655;})[_0xbccb('0x35')](function(){if(_0x1488ed===_0xbccb('0xb9')){return db[_0xbccb('0xba')]['findAll']({'where':{'id':_0x408312['body'][_0xbccb('0x72')]||[]},'raw':!![],'attributes':['id','name']});}})[_0xbccb('0x35')](function(_0x1e07ef){var _0x14f1bd=_0x440e9e['get']({'plain':!![]});var _0xf70c2=[];if(_0x1488ed===_0xbccb('0xb9')&&_0x14f1bd['role']===_0xbccb('0x92')&&_0x14f1bd[_0xbccb('0xad')]){for(var _0x55610d=0x0;_0x55610d<_0x1e07ef[_0xbccb('0x51')];_0x55610d+=0x1){_0xf70c2[_0xbccb('0x60')]({'membername':_0x14f1bd[_0xbccb('0x40')],'UserId':_0x14f1bd['id'],'queue_name':_0x1e07ef[_0x55610d][_0xbccb('0x40')],'VoiceQueueId':_0x1e07ef[_0x55610d]['id'],'interface':_['isNil'](_0x14f1bd['interface'])?util[_0xbccb('0xbb')]('SIP/%s',_0x14f1bd[_0xbccb('0x40')]):_0x14f1bd[_0xbccb('0xaf')],'paused':_0x14f1bd[_0xbccb('0xae')]||![],'penalty':_0x408312[_0xbccb('0x6f')]['penalty']||0x0});}return BPromise[_0xbccb('0x98')](_0xf70c2,function(_0x369a95){return db[_0xbccb('0xbc')][_0xbccb('0xbd')](_0x369a95);});}return _0x440e9e;});}})[_0xbccb('0x35')](respondWithStatusCode(_0xc7b8e8,null))[_0xbccb('0x28')](handleError(_0xc7b8e8,null));};exports[_0xbccb('0xbe')]=function(_0xc6414b,_0x119eb2,_0x3b521a){var _0x2d8bd4;return db['User'][_0xbccb('0x3f')]({'where':{'id':_0xc6414b[_0xbccb('0x6b')]['id']},'attributes':['id',_0xbccb('0x40'),_0xbccb('0x38')]})[_0xbccb('0x35')](handleEntityNotFound(_0x119eb2,null))[_0xbccb('0x35')](function(_0x30b337){if(_0x30b337){_0x2d8bd4=_0x30b337;if(!_0xc6414b[_0xbccb('0x4b')][_0xbccb('0xac')]||!utils[_0xbccb('0xbf')](_0xc6414b['query'][_0xbccb('0xac')])){throw new db[(_0xbccb('0x9f'))][(_0xbccb('0xa2'))](_0xbccb('0xb0'));}return _0x30b337[_0xbccb('0xc0')+_[_0xbccb('0xb2')](_0xc6414b[_0xbccb('0x4b')][_0xbccb('0xac')][_0xbccb('0xb3')]())+_0xbccb('0xb4')](_0xc6414b[_0xbccb('0x4b')][_0xbccb('0x72')]);}})[_0xbccb('0x35')](function(_0x5ab0e4){for(var _0x147c66=0x0;_0x147c66<_0xc6414b[_0xbccb('0x4b')][_0xbccb('0x72')][_0xbccb('0x51')];_0x147c66+=0x1){var _0x327986={'UserId':_0xc6414b[_0xbccb('0x6b')]['id']};_0x327986[_[_0xbccb('0xb2')](_0xc6414b[_0xbccb('0x4b')]['channel'][_0xbccb('0xb3')]())+_0xbccb('0xb7')]=_0xc6414b[_0xbccb('0x4b')]['ids'][_0x147c66];socket[_0xbccb('0xc1')](_0xbccb('0x3a')+_[_0xbccb('0xb2')](_0xc6414b[_0xbccb('0x4b')]['channel']['toLowerCase']())+_0xbccb('0xc2'),_0x327986);}return _0x5ab0e4;})[_0xbccb('0x35')](function(){if(_0xc6414b[_0xbccb('0x4b')]['channel']==='voice'){return db['UserVoiceQueueRt'][_0xbccb('0x36')]({'where':{'UserId':_0xc6414b[_0xbccb('0x6b')]['id'],'VoiceQueueId':_0xc6414b[_0xbccb('0x4b')]['ids']},'individualHooks':!![]})[_0xbccb('0x35')](function(){return _0x2d8bd4;});}return _0x2d8bd4;})['then'](respondWithStatusCode(_0x119eb2,null))[_0xbccb('0x28')](handleError(_0x119eb2,null));};exports[_0xbccb('0xc3')]=function(_0x323b1f,_0x453ad8,_0x3b0d40){_0x323b1f[_0xbccb('0x6f')][_0xbccb('0xc4')]=_0x323b1f[_0xbccb('0xc5')][_0xbccb('0xc6')];return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0x323b1f[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x453ad8,null))[_0xbccb('0x35')](saveUpdates(_0x323b1f[_0xbccb('0x6f')],null))[_0xbccb('0x35')](respondWithResult(_0x453ad8,null))['catch'](handleError(_0x453ad8,null));};exports[_0xbccb('0xc7')]=function(_0x1326de,_0x56bf63,_0xc55a31){var _0x40fe68=path[_0xbccb('0xc8')](config[_0xbccb('0xc9')],_0xbccb('0xca'));return db['User'][_0xbccb('0x3f')]({'where':{'id':_0x1326de[_0xbccb('0x6b')]['id']},'attributes':['id','userpic'],'raw':!![]})['then'](handleEntityNotFound(_0x56bf63,null))[_0xbccb('0x35')](function(_0x302c26){if(_0x302c26){if(_['isNil'](_0x302c26['userpic'])){return _0x56bf63[_0xbccb('0xcb')](_0x40fe68);}else{if(!fs[_0xbccb('0xcc')](path['join'](config[_0xbccb('0xc9')],_0xbccb('0xcd'),_0x302c26[_0xbccb('0xc4')]))){return _0x56bf63[_0xbccb('0xcb')](_0x40fe68);}return _0x56bf63['download'](path['join'](config[_0xbccb('0xc9')],_0xbccb('0xcd'),_0x302c26[_0xbccb('0xc4')]));}}})[_0xbccb('0x28')](handleError(_0x56bf63,null));};exports['getOpenTabs']=function(_0x5809ea,_0x285830,_0x3da7ab){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0x5809ea[_0xbccb('0x6b')]['id']},'attributes':['id']})[_0xbccb('0x35')](handleEntityNotFound(_0x285830,null))[_0xbccb('0x35')](function(_0x8f7f57){var _0x1e85ec=[];values=_0x8f7f57[_0xbccb('0x65')];_0x1e85ec[_0xbccb('0x60')](get_open_tabs(_0xbccb('0x6d'),_0x8f7f57['dataValues']));_0x1e85ec[_0xbccb('0x60')](get_open_tabs('sms',_0x8f7f57[_0xbccb('0x65')]));_0x1e85ec[_0xbccb('0x60')](get_open_tabs(_0xbccb('0x69'),_0x8f7f57['dataValues']));_0x1e85ec[_0xbccb('0x60')](get_open_tabs(_0xbccb('0x6e'),_0x8f7f57[_0xbccb('0x65')]));_0x1e85ec['push'](get_open_tabs(_0xbccb('0x67'),_0x8f7f57[_0xbccb('0x65')]));_0x1e85ec[_0xbccb('0x60')](get_open_tabs(_0xbccb('0x68'),_0x8f7f57['dataValues']));return BPromise[_0xbccb('0x6a')](_0x1e85ec);})[_0xbccb('0x35')](function(_0x2a784f){var _0x42c4c7=[];if(_0x2a784f){for(var _0x169e0a=0x0;_0x169e0a<values[_0xbccb('0xce')][_0xbccb('0x51')];_0x169e0a++){var _0x12cdd1=values[_0xbccb('0xce')][_0x169e0a];_0x42c4c7[_0xbccb('0x60')]({'channel':_0xbccb('0xcf'),'id':_0x12cdd1['id'],'createdAt':_0x12cdd1[_0xbccb('0xd0')]});}for(var _0x169e0a=0x0;_0x169e0a<values[_0xbccb('0xd1')][_0xbccb('0x51')];_0x169e0a++){var _0x12cdd1=values['FaxOpenTabs'][_0x169e0a];_0x42c4c7[_0xbccb('0x60')]({'channel':_0xbccb('0xd2'),'id':_0x12cdd1['id'],'createdAt':_0x12cdd1[_0xbccb('0xd0')]});}for(var _0x169e0a=0x0;_0x169e0a<values['OpenchannelOpenTabs'][_0xbccb('0x51')];_0x169e0a++){var _0x12cdd1=values[_0xbccb('0xd3')][_0x169e0a];_0x42c4c7[_0xbccb('0x60')]({'channel':_0xbccb('0xd4'),'id':_0x12cdd1['id'],'createdAt':_0x12cdd1[_0xbccb('0xd0')]});}for(var _0x169e0a=0x0;_0x169e0a<values[_0xbccb('0xd5')][_0xbccb('0x51')];_0x169e0a++){var _0x12cdd1=values[_0xbccb('0xd5')][_0x169e0a];_0x42c4c7[_0xbccb('0x60')]({'channel':_0xbccb('0xd6'),'id':_0x12cdd1['id'],'createdAt':_0x12cdd1[_0xbccb('0xd0')]});}for(var _0x169e0a=0x0;_0x169e0a<values['SmsOpenTabs'][_0xbccb('0x51')];_0x169e0a++){var _0x12cdd1=values[_0xbccb('0xd7')][_0x169e0a];_0x42c4c7['push']({'channel':_0xbccb('0xd8'),'id':_0x12cdd1['id'],'createdAt':_0x12cdd1[_0xbccb('0xd0')]});}for(var _0x169e0a=0x0;_0x169e0a<values[_0xbccb('0xd9')][_0xbccb('0x51')];_0x169e0a++){var _0x12cdd1=values[_0xbccb('0xd9')][_0x169e0a];_0x42c4c7['push']({'channel':_0xbccb('0xda'),'id':_0x12cdd1['id'],'createdAt':_0x12cdd1[_0xbccb('0xd0')]});}var _0x540695={'count':_0x42c4c7['length'],'rows':_0x42c4c7};return _0x540695;}else return null;})[_0xbccb('0x35')](respondWithResult(_0x285830,null))[_0xbccb('0x28')](handleError(_0x285830,null));};exports['getContacts']=function(_0x3b89f0,_0x4c6e78,_0x31b455){var _0x3c2481={};var _0x1c284d={};var _0x42f3f5;var _0x13d9a2;return db[_0xbccb('0x45')][_0xbccb('0xa6')]({'where':{'id':_0x3b89f0[_0xbccb('0x6b')]['id']}})['then'](handleEntityNotFound(_0x4c6e78,null))[_0xbccb('0x35')](function(_0x337b10){if(_0x337b10){_0x42f3f5=_0x337b10;_0x1c284d[_0xbccb('0x49')]=_['keys'](db[_0xbccb('0xdb')][_0xbccb('0x46')]);_0x1c284d[_0xbccb('0x4b')]=_['keys'](_0x3b89f0[_0xbccb('0x4b')]);_0x1c284d[_0xbccb('0x4d')]=_[_0xbccb('0x4e')](_0x1c284d[_0xbccb('0x49')],_0x1c284d['query']);_0x3c2481[_0xbccb('0x50')]=_[_0xbccb('0x4e')](_0x1c284d[_0xbccb('0x49')],qs[_0xbccb('0x4f')](_0x3b89f0[_0xbccb('0x4b')][_0xbccb('0x4f')]));_0x3c2481[_0xbccb('0x50')]=_0x3c2481[_0xbccb('0x50')][_0xbccb('0x51')]?_0x3c2481[_0xbccb('0x50')]:_0x1c284d[_0xbccb('0x49')];_0x3c2481[_0xbccb('0x53')]=qs['sort'](_0x3b89f0[_0xbccb('0x4b')]['sort']);_0x3c2481[_0xbccb('0x55')]=qs['filters'](_[_0xbccb('0xdc')](_0x3b89f0[_0xbccb('0x4b')],_0x1c284d['filters']));if(_0x3b89f0[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x3c2481[_0xbccb('0x55')]=_[_0xbccb('0x57')](_0x3c2481[_0xbccb('0x55')],{'$or':_['map'](_0x3c2481[_0xbccb('0x50')],function(_0x40da8f){var _0x44ec61={};_0x44ec61[_0x40da8f]={'$like':'%'+_0x3b89f0['query'][_0xbccb('0x56')]+'%'};return _0x44ec61;})});}_0x3c2481=_[_0xbccb('0x57')]({},_0x3c2481,_0x3b89f0['options']);return _0x42f3f5['getContacts'](_0x3c2481);}})[_0xbccb('0x35')](function(_0x2474d4){if(_0x2474d4){_0x13d9a2=_0x2474d4[_0xbccb('0x51')];if(_0x3b89f0[_0xbccb('0x4b')]['hasOwnProperty'](_0xbccb('0x5d'))){_0x3c2481[_0xbccb('0x5e')]=[{'model':db[_0xbccb('0xdd')],'as':_0xbccb('0xde'),'required':![]},{'model':db[_0xbccb('0xdf')],'as':'Tags','attributes':['id',_0xbccb('0x40'),_0xbccb('0xe0')],'where':_0x3b89f0[_0xbccb('0x4b')][_0xbccb('0xe1')]?{'id':_0x3b89f0[_0xbccb('0x4b')][_0xbccb('0xe1')]}:undefined,'required':_0x3b89f0[_0xbccb('0x4b')][_0xbccb('0xe1')]?!![]:![]}];}if(!_0x3b89f0[_0xbccb('0x4b')][_0xbccb('0xe2')]('nolimit')){_0x3c2481[_0xbccb('0x2e')]=qs[_0xbccb('0x2e')](_0x3b89f0[_0xbccb('0x4b')][_0xbccb('0x2e')]);_0x3c2481['offset']=qs[_0xbccb('0x30')](_0x3b89f0[_0xbccb('0x4b')]['offset']);}return _0x42f3f5[_0xbccb('0xe3')](_0x3c2481);}})[_0xbccb('0x35')](function(_0x2e7569){if(_0x2e7569){return _0x2e7569?{'count':_0x13d9a2,'rows':_0x2e7569}:null;}})[_0xbccb('0x35')](respondWithResult(_0x4c6e78,null))[_0xbccb('0x28')](handleError(_0x4c6e78,null));};exports[_0xbccb('0xe4')]=function(_0x2d68c6,_0x444ff5,_0x32cb75){var _0x1445b2;var _0x51eb1b;var _0xcf8683={};var _0x13a3dd;return db[_0xbccb('0x45')]['findOne']({'where':{'id':_0x2d68c6[_0xbccb('0x6b')]['id']},'attributes':['id',_0xbccb('0x40'),_0xbccb('0x38')]})[_0xbccb('0x35')](handleEntityNotFound(_0x444ff5,null))[_0xbccb('0x35')](function(_0x1d4efe){if(!utils[_0xbccb('0xbf')](_0x2d68c6[_0xbccb('0x4b')][_0xbccb('0xac')])){throw new db[(_0xbccb('0x9f'))][(_0xbccb('0xa2'))]('Unknown\x20channel');}_0x1445b2=_0x1d4efe;var _0x341c5c={};_0x341c5c[_0xbccb('0x49')]=_[_0xbccb('0x4c')](db[_[_0xbccb('0xb2')](_0x2d68c6[_0xbccb('0x4b')][_0xbccb('0xac')])+_0xbccb('0xe5')]['rawAttributes']);_0x341c5c[_0xbccb('0x4b')]=_['keys'](_0x2d68c6['query']);_0x341c5c[_0xbccb('0x4d')]=_['intersection'](_0x341c5c[_0xbccb('0x49')],_0x341c5c['query']);_0xcf8683[_0xbccb('0x50')]=_[_0xbccb('0x4e')](_0x341c5c[_0xbccb('0x49')],qs['fields'](_0x2d68c6[_0xbccb('0x4b')][_0xbccb('0x4f')]));_0xcf8683['attributes']=_0xcf8683['attributes'][_0xbccb('0x51')]?_0xcf8683[_0xbccb('0x50')]:_0x341c5c[_0xbccb('0x49')];_0xcf8683[_0xbccb('0x53')]=qs[_0xbccb('0x54')](_0x2d68c6[_0xbccb('0x4b')]['sort']);_0xcf8683[_0xbccb('0x55')]=qs['filters'](_[_0xbccb('0xdc')](_0x2d68c6['query'],_0x341c5c[_0xbccb('0x4d')]));if(_0x2d68c6['query']['filter']){_0xcf8683['where']=_[_0xbccb('0x57')](_0xcf8683[_0xbccb('0x55')],{'$or':_[_0xbccb('0x3d')](_0xcf8683[_0xbccb('0x50')],function(_0x1201ef){var _0x11ae05={};_0x11ae05[_0x1201ef]={'$like':'%'+_0x2d68c6[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'};return _0x11ae05;})});}_0xcf8683=_[_0xbccb('0x57')]({},_0xcf8683,_0x2d68c6[_0xbccb('0x5c')]);switch(_0x1445b2[_0xbccb('0x38')]){case _0xbccb('0x39'):return db[_['capitalize'](_0x2d68c6[_0xbccb('0x4b')][_0xbccb('0xac')])+'Queue']['findAll'](_0xcf8683);case _0xbccb('0x3a'):case'agent':return _0x1445b2['get'+_['capitalize'](_0x2d68c6[_0xbccb('0x4b')]['channel'])+_0xbccb('0xb4')](_0xcf8683);default:throw new db[(_0xbccb('0x9f'))]['ValidationError'](_0xbccb('0xe6'));}})[_0xbccb('0x35')](function(_0x2222a2){_0x13a3dd=_0x2222a2['length'];if(!_0x2d68c6[_0xbccb('0x4b')][_0xbccb('0xe2')]('nolimit')){_0xcf8683[_0xbccb('0x2e')]=qs[_0xbccb('0x2e')](_0x2d68c6[_0xbccb('0x4b')]['limit']);_0xcf8683['offset']=qs['offset'](_0x2d68c6[_0xbccb('0x4b')][_0xbccb('0x30')]);}switch(_0x1445b2[_0xbccb('0x38')]){case _0xbccb('0x39'):return db[_[_0xbccb('0xb2')](_0x2d68c6[_0xbccb('0x4b')][_0xbccb('0xac')])+_0xbccb('0xe5')][_0xbccb('0x61')](_0xcf8683);case _0xbccb('0x3a'):case _0xbccb('0x92'):return _0x1445b2[_0xbccb('0x37')+_[_0xbccb('0xb2')](_0x2d68c6['query'][_0xbccb('0xac')])+'Queues'](_0xcf8683);}})[_0xbccb('0x35')](function(_0x4678ae){return{'count':_0x13a3dd,'rows':_0x4678ae};})[_0xbccb('0x35')](respondWithResult(_0x444ff5,null))[_0xbccb('0x28')](handleError(_0x444ff5,null));};exports[_0xbccb('0xe7')]=function(_0x45206c,_0x21e4c1,_0x2d03db){var _0x35ce9c={};var _0x40e043={};var _0x3b89bb;var _0x46b80f;return db[_0xbccb('0x45')][_0xbccb('0xa6')]({'where':{'id':_0x45206c['params']['id']}})['then'](handleEntityNotFound(_0x21e4c1,null))[_0xbccb('0x35')](function(_0x5907fb){if(_0x5907fb){_0x3b89bb=_0x5907fb;_0x40e043['model']=_[_0xbccb('0x4c')](db[_0xbccb('0xbc')][_0xbccb('0x46')]);_0x40e043[_0xbccb('0x4b')]=_[_0xbccb('0x4c')](_0x45206c[_0xbccb('0x4b')]);_0x40e043[_0xbccb('0x4d')]=_['intersection'](_0x40e043['model'],_0x40e043[_0xbccb('0x4b')]);_0x35ce9c[_0xbccb('0x50')]=_[_0xbccb('0x4e')](_0x40e043['model'],qs[_0xbccb('0x4f')](_0x45206c['query'][_0xbccb('0x4f')]));_0x35ce9c[_0xbccb('0x50')]=_0x35ce9c[_0xbccb('0x50')][_0xbccb('0x51')]?_0x35ce9c[_0xbccb('0x50')]:_0x40e043[_0xbccb('0x49')];_0x35ce9c[_0xbccb('0x53')]=qs[_0xbccb('0x54')](_0x45206c['query'][_0xbccb('0x54')]);_0x35ce9c['where']=qs['filters'](_[_0xbccb('0xdc')](_0x45206c['query'],_0x40e043[_0xbccb('0x4d')]));if(_0x45206c[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x35ce9c[_0xbccb('0x55')]=_[_0xbccb('0x57')](_0x35ce9c[_0xbccb('0x55')],{'$or':_['map'](_0x35ce9c[_0xbccb('0x50')],function(_0x1b2187){var _0x5d9f88={};_0x5d9f88[_0x1b2187]={'$like':'%'+_0x45206c[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'};return _0x5d9f88;})});}_0x35ce9c=_[_0xbccb('0x57')]({},_0x35ce9c,_0x45206c[_0xbccb('0x5c')]);return _0x3b89bb[_0xbccb('0xe7')](_0x35ce9c);}})[_0xbccb('0x35')](function(_0x27803b){if(_0x27803b){_0x46b80f=_0x27803b[_0xbccb('0x51')];if(!_0x45206c['query']['hasOwnProperty'](_0xbccb('0x52'))){_0x35ce9c['limit']=qs[_0xbccb('0x2e')](_0x45206c[_0xbccb('0x4b')]['limit']);_0x35ce9c[_0xbccb('0x30')]=qs['offset'](_0x45206c[_0xbccb('0x4b')][_0xbccb('0x30')]);}return _0x3b89bb[_0xbccb('0xe7')](_0x35ce9c);}})[_0xbccb('0x35')](function(_0x5b02b6){if(_0x5b02b6){return _0x5b02b6?{'count':_0x46b80f,'rows':_0x5b02b6}:null;}})[_0xbccb('0x35')](respondWithResult(_0x21e4c1,null))[_0xbccb('0x28')](handleError(_0x21e4c1,null));};exports[_0xbccb('0xe8')]=function(_0x144dde,_0x43dc0d,_0x9b7535){var _0x58c393={};var _0x5e0798={};var _0x1b97fd;var _0x174aae;return db[_0xbccb('0x45')][_0xbccb('0xa6')]({'where':{'id':_0x144dde[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x43dc0d,null))[_0xbccb('0x35')](function(_0x386d54){if(_0x386d54){_0x1b97fd=_0x386d54;_0x5e0798[_0xbccb('0x49')]=_[_0xbccb('0x4c')](db[_0xbccb('0xe9')][_0xbccb('0x46')]);_0x5e0798[_0xbccb('0x4b')]=_[_0xbccb('0x4c')](_0x144dde[_0xbccb('0x4b')]);_0x5e0798[_0xbccb('0x4d')]=_[_0xbccb('0x4e')](_0x5e0798[_0xbccb('0x49')],_0x5e0798[_0xbccb('0x4b')]);_0x58c393[_0xbccb('0x50')]=_[_0xbccb('0x4e')](_0x5e0798[_0xbccb('0x49')],qs[_0xbccb('0x4f')](_0x144dde[_0xbccb('0x4b')][_0xbccb('0x4f')]));_0x58c393[_0xbccb('0x50')]=_0x58c393[_0xbccb('0x50')][_0xbccb('0x51')]?_0x58c393[_0xbccb('0x50')]:_0x5e0798[_0xbccb('0x49')];_0x58c393[_0xbccb('0x53')]=qs[_0xbccb('0x54')](_0x144dde[_0xbccb('0x4b')]['sort']);_0x58c393['where']=qs[_0xbccb('0x4d')](_[_0xbccb('0xdc')](_0x144dde[_0xbccb('0x4b')],_0x5e0798[_0xbccb('0x4d')]));if(_0x144dde[_0xbccb('0x4b')]['filter']){_0x58c393['where']=_[_0xbccb('0x57')](_0x58c393['where'],{'$or':_['map'](_0x58c393[_0xbccb('0x50')],function(_0x561b7e){var _0x3feede={};_0x3feede[_0x561b7e]={'$like':'%'+_0x144dde[_0xbccb('0x4b')]['filter']+'%'};return _0x3feede;})});}_0x58c393=_[_0xbccb('0x57')]({},_0x58c393,_0x144dde[_0xbccb('0x5c')]);return _0x1b97fd[_0xbccb('0xe8')](_0x58c393);}})[_0xbccb('0x35')](function(_0x2f700b){if(_0x2f700b){_0x174aae=_0x2f700b[_0xbccb('0x51')];if(!_0x144dde[_0xbccb('0x4b')]['hasOwnProperty'](_0xbccb('0x52'))){_0x58c393[_0xbccb('0x2e')]=qs[_0xbccb('0x2e')](_0x144dde[_0xbccb('0x4b')][_0xbccb('0x2e')]);_0x58c393['offset']=qs['offset'](_0x144dde[_0xbccb('0x4b')][_0xbccb('0x30')]);}return _0x1b97fd[_0xbccb('0xe8')](_0x58c393);}})['then'](function(_0xe0a979){if(_0xe0a979){return _0xe0a979?{'count':_0x174aae,'rows':_0xe0a979}:null;}})['then'](respondWithResult(_0x43dc0d,null))['catch'](handleError(_0x43dc0d,null));};exports[_0xbccb('0xea')]=function(_0x1a4a71,_0x17a426,_0x5d42fb){var _0x11d4c4={'raw':!![],'where':{}};var _0x4cce07={};var _0x1298da={'count':0x0,'rows':[]};return db[_0xbccb('0x45')][_0xbccb('0xa6')]({'where':{'id':_0x1a4a71[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x17a426,null))[_0xbccb('0x35')](function(_0x19dd87){if(_0x19dd87){_0x4cce07['model']=_[_0xbccb('0x4c')](db[_0xbccb('0xeb')][_0xbccb('0x46')]);_0x4cce07[_0xbccb('0x4b')]=_[_0xbccb('0x4c')](_0x1a4a71[_0xbccb('0x4b')]);_0x4cce07[_0xbccb('0x4d')]=_['intersection'](_0x4cce07[_0xbccb('0x49')],_0x4cce07[_0xbccb('0x4b')]);_0x11d4c4[_0xbccb('0x50')]=_[_0xbccb('0x4e')](_0x4cce07[_0xbccb('0x49')],qs[_0xbccb('0x4f')](_0x1a4a71[_0xbccb('0x4b')][_0xbccb('0x4f')]));_0x11d4c4[_0xbccb('0x50')]=_0x11d4c4['attributes'][_0xbccb('0x51')]?_0x11d4c4['attributes']:_0x4cce07[_0xbccb('0x49')];if(!_0x1a4a71[_0xbccb('0x4b')]['hasOwnProperty'](_0xbccb('0x52'))){_0x11d4c4['limit']=qs['limit'](_0x1a4a71[_0xbccb('0x4b')][_0xbccb('0x2e')]);_0x11d4c4[_0xbccb('0x30')]=qs[_0xbccb('0x30')](_0x1a4a71[_0xbccb('0x4b')][_0xbccb('0x30')]);}_0x11d4c4[_0xbccb('0x53')]=qs[_0xbccb('0x54')](_0x1a4a71[_0xbccb('0x4b')][_0xbccb('0x54')]);_0x11d4c4['where']=qs['filters'](_['pick'](_0x1a4a71[_0xbccb('0x4b')],_0x4cce07[_0xbccb('0x4d')]));_0x11d4c4[_0xbccb('0x55')]['UserId']=_0x19dd87['id'];if(_0x1a4a71[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x11d4c4[_0xbccb('0x55')]=_[_0xbccb('0x57')](_0x11d4c4[_0xbccb('0x55')],{'$or':_['map'](_0x11d4c4['attributes'],function(_0x354fd5){var _0x7a4832={};_0x7a4832[_0x354fd5]={'$like':'%'+_0x1a4a71[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'};return _0x7a4832;})});}_0x11d4c4=_['merge']({},_0x11d4c4,_0x1a4a71[_0xbccb('0x5c')]);return db[_0xbccb('0xeb')]['count']({'where':_0x11d4c4[_0xbccb('0x55')]})[_0xbccb('0x35')](function(_0x2fccc5){_0x1298da[_0xbccb('0x2f')]=_0x2fccc5;if(_0x1a4a71[_0xbccb('0x4b')][_0xbccb('0x5d')]){_0x11d4c4[_0xbccb('0x5e')]=[{'all':!![]}];}return db[_0xbccb('0xeb')]['findAll'](_0x11d4c4);})[_0xbccb('0x35')](function(_0x516cd7){_0x1298da[_0xbccb('0x62')]=_0x516cd7;return _0x1298da;});}})[_0xbccb('0x35')](respondWithFilteredResult(_0x17a426,_0x11d4c4))['catch'](handleError(_0x17a426,null));};exports[_0xbccb('0xec')]=function(_0x3599ad,_0x3acb0e,_0x16e05e){var _0x16ceb4={'raw':!![],'where':{}};var _0x375221={};var _0x1326fe={'count':0x0,'rows':[]};return db['User'][_0xbccb('0xa6')]({'where':{'id':_0x3599ad[_0xbccb('0x6b')]['id']}})['then'](handleEntityNotFound(_0x3acb0e,null))['then'](function(_0x4ad563){if(_0x4ad563){_0x375221['model']=_[_0xbccb('0x4c')](db[_0xbccb('0xed')]['rawAttributes']);_0x375221[_0xbccb('0x4b')]=_[_0xbccb('0x4c')](_0x3599ad['query']);_0x375221[_0xbccb('0x4d')]=_['intersection'](_0x375221['model'],_0x375221['query']);_0x16ceb4[_0xbccb('0x50')]=_['intersection'](_0x375221[_0xbccb('0x49')],qs[_0xbccb('0x4f')](_0x3599ad['query'][_0xbccb('0x4f')]));_0x16ceb4[_0xbccb('0x50')]=_0x16ceb4[_0xbccb('0x50')][_0xbccb('0x51')]?_0x16ceb4[_0xbccb('0x50')]:_0x375221[_0xbccb('0x49')];if(!_0x3599ad[_0xbccb('0x4b')][_0xbccb('0xe2')](_0xbccb('0x52'))){_0x16ceb4[_0xbccb('0x2e')]=qs['limit'](_0x3599ad[_0xbccb('0x4b')][_0xbccb('0x2e')]);_0x16ceb4[_0xbccb('0x30')]=qs[_0xbccb('0x30')](_0x3599ad['query'][_0xbccb('0x30')]);}_0x16ceb4['order']=qs[_0xbccb('0x54')](_0x3599ad[_0xbccb('0x4b')][_0xbccb('0x54')]);_0x16ceb4[_0xbccb('0x55')]=qs['filters'](_[_0xbccb('0xdc')](_0x3599ad[_0xbccb('0x4b')],_0x375221[_0xbccb('0x4d')]));_0x16ceb4[_0xbccb('0x55')]['UserId']=_0x4ad563['id'];if(_0x3599ad[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x16ceb4[_0xbccb('0x55')]=_[_0xbccb('0x57')](_0x16ceb4['where'],{'$or':_[_0xbccb('0x3d')](_0x16ceb4['attributes'],function(_0x3c7984){var _0x99f44c={};_0x99f44c[_0x3c7984]={'$like':'%'+_0x3599ad[_0xbccb('0x4b')]['filter']+'%'};return _0x99f44c;})});}_0x16ceb4=_[_0xbccb('0x57')]({},_0x16ceb4,_0x3599ad[_0xbccb('0x5c')]);return db[_0xbccb('0xed')]['count']({'where':_0x16ceb4['where']})['then'](function(_0x211068){_0x1326fe['count']=_0x211068;if(_0x3599ad[_0xbccb('0x4b')][_0xbccb('0x5d')]){_0x16ceb4[_0xbccb('0x5e')]=[{'all':!![]}];}return db[_0xbccb('0xed')][_0xbccb('0x61')](_0x16ceb4);})[_0xbccb('0x35')](function(_0x23cad6){_0x1326fe['rows']=_0x23cad6;return _0x1326fe;});}})[_0xbccb('0x35')](respondWithFilteredResult(_0x3acb0e,_0x16ceb4))[_0xbccb('0x28')](handleError(_0x3acb0e,null));};exports[_0xbccb('0xee')]=function(_0x5eb05b,_0x59772d,_0x319887){var _0x137c26={};var _0x1032f8={};var _0xdb31b8;var _0x9ffe08;return db[_0xbccb('0x45')]['findOne']({'where':{'id':_0x5eb05b[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x59772d,null))[_0xbccb('0x35')](function(_0x3aca07){if(_0x3aca07){_0xdb31b8=_0x3aca07;_0x1032f8[_0xbccb('0x49')]=_[_0xbccb('0x4c')](db[_0xbccb('0xef')][_0xbccb('0x46')]);_0x1032f8[_0xbccb('0x4b')]=_[_0xbccb('0x4c')](_0x5eb05b[_0xbccb('0x4b')]);_0x1032f8['filters']=_[_0xbccb('0x4e')](_0x1032f8[_0xbccb('0x49')],_0x1032f8[_0xbccb('0x4b')]);_0x137c26[_0xbccb('0x50')]=_[_0xbccb('0x4e')](_0x1032f8['model'],qs[_0xbccb('0x4f')](_0x5eb05b['query'][_0xbccb('0x4f')]));_0x137c26[_0xbccb('0x50')]=_0x137c26[_0xbccb('0x50')][_0xbccb('0x51')]?_0x137c26[_0xbccb('0x50')]:_0x1032f8['model'];_0x137c26[_0xbccb('0x53')]=qs[_0xbccb('0x54')](_0x5eb05b[_0xbccb('0x4b')][_0xbccb('0x54')]);_0x137c26[_0xbccb('0x55')]=qs[_0xbccb('0x4d')](_['pick'](_0x5eb05b[_0xbccb('0x4b')],_0x1032f8[_0xbccb('0x4d')]));if(_0x5eb05b[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x137c26[_0xbccb('0x55')]=_[_0xbccb('0x57')](_0x137c26[_0xbccb('0x55')],{'$or':_[_0xbccb('0x3d')](_0x137c26[_0xbccb('0x50')],function(_0x2d91b5){var _0x1bc837={};_0x1bc837[_0x2d91b5]={'$like':'%'+_0x5eb05b[_0xbccb('0x4b')]['filter']+'%'};return _0x1bc837;})});}_0x137c26=_[_0xbccb('0x57')]({},_0x137c26,_0x5eb05b[_0xbccb('0x5c')]);return _0xdb31b8[_0xbccb('0xee')](_0x137c26);}})[_0xbccb('0x35')](function(_0x34df8f){if(_0x34df8f){_0x9ffe08=_0x34df8f[_0xbccb('0x51')];if(!_0x5eb05b[_0xbccb('0x4b')][_0xbccb('0xe2')](_0xbccb('0x52'))){_0x137c26[_0xbccb('0x2e')]=qs['limit'](_0x5eb05b[_0xbccb('0x4b')][_0xbccb('0x2e')]);_0x137c26[_0xbccb('0x30')]=qs[_0xbccb('0x30')](_0x5eb05b[_0xbccb('0x4b')][_0xbccb('0x30')]);}return _0xdb31b8[_0xbccb('0xee')](_0x137c26);}})[_0xbccb('0x35')](function(_0xefa38b){if(_0xefa38b){return _0xefa38b?{'count':_0x9ffe08,'rows':_0xefa38b}:null;}})[_0xbccb('0x35')](respondWithResult(_0x59772d,null))[_0xbccb('0x28')](handleError(_0x59772d,null));};exports[_0xbccb('0xf0')]=function(_0x1d4c1a,_0x3f0517,_0x154034){var _0x26e1e1={};var _0x25dd5a={};var _0x452a33;var _0xd98be9;return db[_0xbccb('0x45')]['findOne']({'where':{'id':_0x1d4c1a[_0xbccb('0x6b')]['id']}})['then'](handleEntityNotFound(_0x3f0517,null))[_0xbccb('0x35')](function(_0x20e6a1){if(_0x20e6a1){_0x452a33=_0x20e6a1;_0x25dd5a['model']=_['keys'](db[_0xbccb('0xf1')][_0xbccb('0x46')]);_0x25dd5a[_0xbccb('0x4b')]=_['keys'](_0x1d4c1a[_0xbccb('0x4b')]);_0x25dd5a[_0xbccb('0x4d')]=_['intersection'](_0x25dd5a[_0xbccb('0x49')],_0x25dd5a['query']);_0x26e1e1['attributes']=_[_0xbccb('0x4e')](_0x25dd5a[_0xbccb('0x49')],qs[_0xbccb('0x4f')](_0x1d4c1a['query'][_0xbccb('0x4f')]));_0x26e1e1['attributes']=_0x26e1e1[_0xbccb('0x50')][_0xbccb('0x51')]?_0x26e1e1[_0xbccb('0x50')]:_0x25dd5a[_0xbccb('0x49')];_0x26e1e1[_0xbccb('0x53')]=qs[_0xbccb('0x54')](_0x1d4c1a[_0xbccb('0x4b')][_0xbccb('0x54')]);_0x26e1e1['where']=qs['filters'](_[_0xbccb('0xdc')](_0x1d4c1a['query'],_0x25dd5a['filters']));if(_0x1d4c1a[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x26e1e1[_0xbccb('0x55')]=_['merge'](_0x26e1e1[_0xbccb('0x55')],{'$or':_[_0xbccb('0x3d')](_0x26e1e1[_0xbccb('0x50')],function(_0x219aed){var _0x461b7a={};_0x461b7a[_0x219aed]={'$like':'%'+_0x1d4c1a[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'};return _0x461b7a;})});}_0x26e1e1=_['merge']({},_0x26e1e1,_0x1d4c1a[_0xbccb('0x5c')]);return _0x452a33['getOpenchannelInteractions'](_0x26e1e1);}})['then'](function(_0x10661b){if(_0x10661b){_0xd98be9=_0x10661b[_0xbccb('0x51')];if(!_0x1d4c1a[_0xbccb('0x4b')][_0xbccb('0xe2')](_0xbccb('0x52'))){_0x26e1e1['limit']=qs[_0xbccb('0x2e')](_0x1d4c1a['query'][_0xbccb('0x2e')]);_0x26e1e1[_0xbccb('0x30')]=qs['offset'](_0x1d4c1a[_0xbccb('0x4b')]['offset']);}return _0x452a33['getOpenchannelInteractions'](_0x26e1e1);}})[_0xbccb('0x35')](function(_0x2d5183){if(_0x2d5183){return _0x2d5183?{'count':_0xd98be9,'rows':_0x2d5183}:null;}})[_0xbccb('0x35')](respondWithResult(_0x3f0517,null))[_0xbccb('0x28')](handleError(_0x3f0517,null));};exports[_0xbccb('0xf2')]=function(_0x5d8299,_0x80c077,_0x2946a5){var _0x5deb78={'raw':!![],'where':{}};var _0x2c9f34={};var _0xe82c7e={'count':0x0,'rows':[]};return db[_0xbccb('0x45')][_0xbccb('0xa6')]({'where':{'id':_0x5d8299[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x80c077,null))['then'](function(_0x40b71a){if(_0x40b71a){_0x2c9f34[_0xbccb('0x49')]=_['keys'](db[_0xbccb('0xf3')][_0xbccb('0x46')]);_0x2c9f34[_0xbccb('0x4b')]=_['keys'](_0x5d8299[_0xbccb('0x4b')]);_0x2c9f34['filters']=_[_0xbccb('0x4e')](_0x2c9f34['model'],_0x2c9f34['query']);_0x5deb78[_0xbccb('0x50')]=_['intersection'](_0x2c9f34[_0xbccb('0x49')],qs[_0xbccb('0x4f')](_0x5d8299['query'][_0xbccb('0x4f')]));_0x5deb78['attributes']=_0x5deb78[_0xbccb('0x50')][_0xbccb('0x51')]?_0x5deb78['attributes']:_0x2c9f34[_0xbccb('0x49')];if(!_0x5d8299[_0xbccb('0x4b')][_0xbccb('0xe2')]('nolimit')){_0x5deb78[_0xbccb('0x2e')]=qs['limit'](_0x5d8299['query'][_0xbccb('0x2e')]);_0x5deb78[_0xbccb('0x30')]=qs[_0xbccb('0x30')](_0x5d8299['query'][_0xbccb('0x30')]);}_0x5deb78[_0xbccb('0x53')]=qs[_0xbccb('0x54')](_0x5d8299[_0xbccb('0x4b')]['sort']);_0x5deb78['where']=qs[_0xbccb('0x4d')](_[_0xbccb('0xdc')](_0x5d8299[_0xbccb('0x4b')],_0x2c9f34[_0xbccb('0x4d')]));_0x5deb78[_0xbccb('0x55')][_0xbccb('0xf4')]=_0x40b71a['id'];if(_0x5d8299[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x5deb78['where']=_[_0xbccb('0x57')](_0x5deb78[_0xbccb('0x55')],{'$or':_[_0xbccb('0x3d')](_0x5deb78[_0xbccb('0x50')],function(_0x33ee3f){var _0xef52c5={};_0xef52c5[_0x33ee3f]={'$like':'%'+_0x5d8299[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'};return _0xef52c5;})});}_0x5deb78=_[_0xbccb('0x57')]({},_0x5deb78,_0x5d8299[_0xbccb('0x5c')]);return db[_0xbccb('0xf3')][_0xbccb('0x2f')]({'where':_0x5deb78[_0xbccb('0x55')]})[_0xbccb('0x35')](function(_0x12eff2){_0xe82c7e[_0xbccb('0x2f')]=_0x12eff2;if(_0x5d8299[_0xbccb('0x4b')][_0xbccb('0x5d')]){_0x5deb78['include']=[{'all':!![]}];}return db[_0xbccb('0xf3')][_0xbccb('0x61')](_0x5deb78);})[_0xbccb('0x35')](function(_0x576e7d){_0xe82c7e['rows']=_0x576e7d;return _0xe82c7e;});}})['then'](respondWithFilteredResult(_0x80c077,_0x5deb78))[_0xbccb('0x28')](handleError(_0x80c077,null));};exports[_0xbccb('0xf5')]=function(_0x234961,_0x5cd133,_0x18c0e1){var _0x2b1f84={};var _0x56e41e={};var _0x4e0a8b;var _0x4d1c1c;return db['User'][_0xbccb('0xa6')]({'where':{'id':_0x234961[_0xbccb('0x6b')]['id']}})['then'](handleEntityNotFound(_0x5cd133,null))['then'](function(_0x56cc1b){if(_0x56cc1b){_0x4e0a8b=_0x56cc1b;_0x56e41e[_0xbccb('0x49')]=_[_0xbccb('0x4c')](db['SmsInteraction'][_0xbccb('0x46')]);_0x56e41e[_0xbccb('0x4b')]=_['keys'](_0x234961[_0xbccb('0x4b')]);_0x56e41e['filters']=_[_0xbccb('0x4e')](_0x56e41e[_0xbccb('0x49')],_0x56e41e[_0xbccb('0x4b')]);_0x2b1f84[_0xbccb('0x50')]=_['intersection'](_0x56e41e[_0xbccb('0x49')],qs[_0xbccb('0x4f')](_0x234961[_0xbccb('0x4b')][_0xbccb('0x4f')]));_0x2b1f84[_0xbccb('0x50')]=_0x2b1f84[_0xbccb('0x50')]['length']?_0x2b1f84[_0xbccb('0x50')]:_0x56e41e['model'];_0x2b1f84[_0xbccb('0x53')]=qs[_0xbccb('0x54')](_0x234961[_0xbccb('0x4b')][_0xbccb('0x54')]);_0x2b1f84[_0xbccb('0x55')]=qs['filters'](_[_0xbccb('0xdc')](_0x234961[_0xbccb('0x4b')],_0x56e41e[_0xbccb('0x4d')]));if(_0x234961['query'][_0xbccb('0x56')]){_0x2b1f84[_0xbccb('0x55')]=_[_0xbccb('0x57')](_0x2b1f84[_0xbccb('0x55')],{'$or':_['map'](_0x2b1f84['attributes'],function(_0x1d004a){var _0x2dc36e={};_0x2dc36e[_0x1d004a]={'$like':'%'+_0x234961[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'};return _0x2dc36e;})});}_0x2b1f84=_['merge']({},_0x2b1f84,_0x234961['options']);return _0x4e0a8b[_0xbccb('0xf5')](_0x2b1f84);}})[_0xbccb('0x35')](function(_0x319ddb){if(_0x319ddb){_0x4d1c1c=_0x319ddb[_0xbccb('0x51')];if(!_0x234961[_0xbccb('0x4b')]['hasOwnProperty'](_0xbccb('0x52'))){_0x2b1f84['limit']=qs[_0xbccb('0x2e')](_0x234961[_0xbccb('0x4b')][_0xbccb('0x2e')]);_0x2b1f84['offset']=qs[_0xbccb('0x30')](_0x234961[_0xbccb('0x4b')][_0xbccb('0x30')]);}return _0x4e0a8b[_0xbccb('0xf5')](_0x2b1f84);}})['then'](function(_0x57d128){if(_0x57d128){return _0x57d128?{'count':_0x4d1c1c,'rows':_0x57d128}:null;}})[_0xbccb('0x35')](respondWithResult(_0x5cd133,null))[_0xbccb('0x28')](handleError(_0x5cd133,null));};exports[_0xbccb('0xf6')]=function(_0x1a8de9,_0x120e66,_0x49161a){var _0x4dff60={};var _0x545078={};var _0x809b32;var _0x235131;return db['User']['findOne']({'where':{'id':_0x1a8de9[_0xbccb('0x6b')]['id']}})['then'](handleEntityNotFound(_0x120e66,null))['then'](function(_0x77aacf){if(_0x77aacf){_0x809b32=_0x77aacf;_0x545078[_0xbccb('0x49')]=_[_0xbccb('0x4c')](db['FaxInteraction'][_0xbccb('0x46')]);_0x545078[_0xbccb('0x4b')]=_[_0xbccb('0x4c')](_0x1a8de9['query']);_0x545078['filters']=_[_0xbccb('0x4e')](_0x545078[_0xbccb('0x49')],_0x545078['query']);_0x4dff60[_0xbccb('0x50')]=_[_0xbccb('0x4e')](_0x545078[_0xbccb('0x49')],qs[_0xbccb('0x4f')](_0x1a8de9[_0xbccb('0x4b')][_0xbccb('0x4f')]));_0x4dff60[_0xbccb('0x50')]=_0x4dff60[_0xbccb('0x50')][_0xbccb('0x51')]?_0x4dff60[_0xbccb('0x50')]:_0x545078[_0xbccb('0x49')];_0x4dff60[_0xbccb('0x53')]=qs[_0xbccb('0x54')](_0x1a8de9['query'][_0xbccb('0x54')]);_0x4dff60['where']=qs[_0xbccb('0x4d')](_[_0xbccb('0xdc')](_0x1a8de9[_0xbccb('0x4b')],_0x545078[_0xbccb('0x4d')]));if(_0x1a8de9[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x4dff60['where']=_[_0xbccb('0x57')](_0x4dff60[_0xbccb('0x55')],{'$or':_[_0xbccb('0x3d')](_0x4dff60[_0xbccb('0x50')],function(_0x541609){var _0x373943={};_0x373943[_0x541609]={'$like':'%'+_0x1a8de9[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'};return _0x373943;})});}_0x4dff60=_[_0xbccb('0x57')]({},_0x4dff60,_0x1a8de9[_0xbccb('0x5c')]);return _0x809b32[_0xbccb('0xf6')](_0x4dff60);}})['then'](function(_0x56ee4d){if(_0x56ee4d){_0x235131=_0x56ee4d[_0xbccb('0x51')];if(!_0x1a8de9[_0xbccb('0x4b')][_0xbccb('0xe2')](_0xbccb('0x52'))){_0x4dff60['limit']=qs[_0xbccb('0x2e')](_0x1a8de9[_0xbccb('0x4b')]['limit']);_0x4dff60[_0xbccb('0x30')]=qs[_0xbccb('0x30')](_0x1a8de9[_0xbccb('0x4b')][_0xbccb('0x30')]);}return _0x809b32[_0xbccb('0xf6')](_0x4dff60);}})[_0xbccb('0x35')](function(_0x345e13){if(_0x345e13){return _0x345e13?{'count':_0x235131,'rows':_0x345e13}:null;}})[_0xbccb('0x35')](respondWithResult(_0x120e66,null))[_0xbccb('0x28')](handleError(_0x120e66,null));};exports[_0xbccb('0xf7')]=function(_0x20482c,_0x35422a,_0x301c0c){var _0x9bce7f={};var _0x4e2d79={};var _0x1c1759;var _0x330002;return db['User']['findOne']({'where':{'id':_0x20482c[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x35422a,null))[_0xbccb('0x35')](function(_0xfc16ab){if(_0xfc16ab){_0x1c1759=_0xfc16ab;_0x4e2d79[_0xbccb('0x49')]=_['keys'](db[_0xbccb('0xf8')][_0xbccb('0x46')]);_0x4e2d79[_0xbccb('0x4b')]=_['keys'](_0x20482c['query']);_0x4e2d79['filters']=_[_0xbccb('0x4e')](_0x4e2d79['model'],_0x4e2d79[_0xbccb('0x4b')]);_0x9bce7f[_0xbccb('0x50')]=_[_0xbccb('0x4e')](_0x4e2d79[_0xbccb('0x49')],qs['fields'](_0x20482c[_0xbccb('0x4b')][_0xbccb('0x4f')]));_0x9bce7f[_0xbccb('0x50')]=_0x9bce7f[_0xbccb('0x50')][_0xbccb('0x51')]?_0x9bce7f[_0xbccb('0x50')]:_0x4e2d79[_0xbccb('0x49')];_0x9bce7f[_0xbccb('0x53')]=qs['sort'](_0x20482c[_0xbccb('0x4b')][_0xbccb('0x54')]);_0x9bce7f[_0xbccb('0x55')]=qs[_0xbccb('0x4d')](_[_0xbccb('0xdc')](_0x20482c[_0xbccb('0x4b')],_0x4e2d79[_0xbccb('0x4d')]));if(_0x20482c[_0xbccb('0x4b')]['filter']){_0x9bce7f['where']=_[_0xbccb('0x57')](_0x9bce7f[_0xbccb('0x55')],{'$or':_[_0xbccb('0x3d')](_0x9bce7f[_0xbccb('0x50')],function(_0x2841f8){var _0x2ad627={};_0x2ad627[_0x2841f8]={'$like':'%'+_0x20482c[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'};return _0x2ad627;})});}_0x9bce7f=_[_0xbccb('0x57')]({},_0x9bce7f,_0x20482c[_0xbccb('0x5c')]);return _0x1c1759[_0xbccb('0xf7')](_0x9bce7f);}})['then'](function(_0x1a7530){if(_0x1a7530){_0x330002=_0x1a7530[_0xbccb('0x51')];if(!_0x20482c[_0xbccb('0x4b')]['hasOwnProperty'](_0xbccb('0x52'))){_0x9bce7f[_0xbccb('0x2e')]=qs[_0xbccb('0x2e')](_0x20482c['query'][_0xbccb('0x2e')]);_0x9bce7f[_0xbccb('0x30')]=qs['offset'](_0x20482c['query']['offset']);}return _0x1c1759[_0xbccb('0xf7')](_0x9bce7f);}})[_0xbccb('0x35')](function(_0x21f967){if(_0x21f967){return _0x21f967?{'count':_0x330002,'rows':_0x21f967}:null;}})[_0xbccb('0x35')](respondWithResult(_0x35422a,null))[_0xbccb('0x28')](handleError(_0x35422a,null));};exports[_0xbccb('0xf9')]=function(_0x1fdf45,_0xf0aa3e,_0x1deaa9){var _0x5e210d;var _0x13ff90;var _0x3e018c;var _0x7cdba2=!_[_0xbccb('0x78')](_0x1fdf45[_0xbccb('0x6b')]['id'])?_0x1fdf45[_0xbccb('0x6b')]['id']:!_[_0xbccb('0x78')](_0x1fdf45[_0xbccb('0x3a')]['id'])?_0x1fdf45[_0xbccb('0x3a')]['id']:null;return db[_0xbccb('0x45')]['find']({'where':{'id':_0x7cdba2,'role':{'$or':['admin',_0xbccb('0x3a'),_0xbccb('0x92')]}},'attributes':['id','name',_0xbccb('0xfa'),_0xbccb('0xfb'),_0xbccb('0x38'),_0xbccb('0x77'),'loginInPause']})['then'](function(_0x4b25ac){if(_0x4b25ac){if(_0x4b25ac['role']===_0xbccb('0x92')){_0x5e210d=_0x4b25ac;if(_0x1fdf45['body'][_0xbccb('0xaf')]){_0x3e018c=util['format'](_0xbccb('0xfc'),_0x5e210d[_0x1fdf45[_0xbccb('0x6f')][_0xbccb('0xaf')]]);}else if(_0x1fdf45[_0xbccb('0x6f')][_0xbccb('0xfd')]){_0x3e018c=util[_0xbccb('0xbb')](_0xbccb('0xfe'),_0x1fdf45[_0xbccb('0x6f')]['intrf']);}else{_0x3e018c=util[_0xbccb('0xbb')](_0xbccb('0xfe'),_0x5e210d[_0xbccb('0x40')]);}socket['to'](util['format'](_0xbccb('0xff'),_0x5e210d['name']))[_0xbccb('0xc1')](_0xbccb('0x100'),{'user':{'id':_0x5e210d['id'],'name':_0x5e210d[_0xbccb('0x40')]},'ip':_0x1fdf45[_0xbccb('0x101')][_0xbccb('0x102')]||_0x1fdf45[_0xbccb('0x103')][_0xbccb('0x104')]||_0x1fdf45[_0xbccb('0x105')][_0xbccb('0x104')]||_0x1fdf45['connection']['socket'][_0xbccb('0x104')]});return db[_0xbccb('0xbc')]['destroy']({'where':{'membername':_0x5e210d[_0xbccb('0x40')]},'individualHooks':!![]});}}else{throw new db[(_0xbccb('0x9f'))][(_0xbccb('0xa2'))](_0xbccb('0x106'));}})[_0xbccb('0x35')](function(){if(_0x5e210d){return _0x5e210d[_0xbccb('0x107')]({'raw':!![]});}})[_0xbccb('0x35')](function(_0x3b5ae1){if(_0x5e210d){var _0x60aab2=[];if(_0x3b5ae1){_0x13ff90=_0x3b5ae1;if(_0x13ff90[_0xbccb('0x51')]){for(var _0x2aa7a6=0x0;_0x2aa7a6<_0x13ff90['length'];_0x2aa7a6++){_0x60aab2[_0xbccb('0x60')]({'membername':_0x5e210d[_0xbccb('0x40')],'UserId':_0x5e210d['id'],'queue_name':_0x13ff90[_0x2aa7a6][_0xbccb('0x40')],'VoiceQueueId':_0x13ff90[_0x2aa7a6]['id'],'interface':_0x3e018c,'paused':_0x5e210d[_0xbccb('0x108')]||![],'penalty':_0x13ff90[_0x2aa7a6][_0xbccb('0x109')]||0x0});}return BPromise['each'](_0x60aab2,function(_0x2b1440){return db['UserVoiceQueueRt']['upsert'](_0x2b1440);});}}}})[_0xbccb('0x35')](function(){if(_0x5e210d){return db[_0xbccb('0x10a')][_0xbccb('0x61')]({'where':{'membername':_0x5e210d['name'],'exitAt':null}});}})[_0xbccb('0x35')](function(_0x5c06e3){if(_0x5e210d){var _0x1efd8e=[];_0x5c06e3['forEach'](function(_0xa5050f){_0x1efd8e[_0xbccb('0x60')](_0xa5050f['update']({'exitAt':moment()[_0xbccb('0xbb')]('YYYY-MM-DD\x20HH:mm:ss')}));});return BPromise[_0xbccb('0x6a')](_0x1efd8e);}})[_0xbccb('0x35')](function(){if(_0x5e210d){var _0x48e4aa=[];var _0x4c9d74=[];var _0x3fba3b=utils[_0xbccb('0x10b')]();var _0x3a98ed={'membername':_0x5e210d[_0xbccb('0x40')],'interface':_0x3e018c,'enterAt':moment()['format'](_0xbccb('0x10c')),'role':_0x5e210d[_0xbccb('0x38')],'internal':_0x5e210d[_0xbccb('0x77')]};_0x3fba3b[_0xbccb('0x10d')](function(_0x46038c){_0x48e4aa[_0xbccb('0x60')](_['merge']({'channel':_0x46038c,'type':_0xbccb('0x10e'),'data1':_0x1fdf45[_0xbccb('0x6f')][_0xbccb('0x10f')],'data2':_0x3e018c},_0x3a98ed));if(_0x5e210d['loginInPause']){_0x4c9d74['push'](_[_0xbccb('0x57')]({'channel':_0x46038c,'type':_0xbccb('0x110'),'data1':_0xbccb('0x111')},_0x3a98ed));}});return db['MemberReport']['bulkCreate'](_0x48e4aa['concat'](_0x4c9d74),{'individualHooks':!![]});}})[_0xbccb('0x35')](function(){if(_0x5e210d){return _0x5e210d[_0xbccb('0x34')]({'online':!![],'lastLoginAt':moment()[_0xbccb('0xbb')](_0xbccb('0x10c')),'voicePause':_0x5e210d[_0xbccb('0x108')]||![],'mailPause':_0x5e210d[_0xbccb('0x108')]||![],'chatPause':_0x5e210d['loginInPause']||![],'faxPause':_0x5e210d[_0xbccb('0x108')]||![],'smsPause':_0x5e210d[_0xbccb('0x108')]||![],'openchannelPause':_0x5e210d[_0xbccb('0x108')]||![],'whatsappPause':_0x5e210d[_0xbccb('0x108')]||![],'pauseType':_0x5e210d[_0xbccb('0x108')]?'LOGININPAUSE':null,'interface':_0x3e018c,'lastPauseAt':moment()[_0xbccb('0xbb')](_0xbccb('0x10c'))});}})[_0xbccb('0x35')](function(_0x56f3ed){if(_0x1fdf45[_0xbccb('0x112')]){return _0x1deaa9();}else{return BPromise[_0xbccb('0x113')](_0x56f3ed)['then'](respondWithResult(_0xf0aa3e,null));}})[_0xbccb('0x28')](handleError(_0xf0aa3e,null));};exports[_0xbccb('0x114')]=function(_0xbc0535,_0x31e8ea,_0x3eb8a2){var _0xb468ea;return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0xbc0535[_0xbccb('0x6b')]['id'],'role':_0xbccb('0x92')},'attributes':['id',_0xbccb('0x40'),_0xbccb('0x38')]})[_0xbccb('0x35')](handleEntityNotFound(_0x31e8ea,null))[_0xbccb('0x35')](function(_0x181a6b){if(_0x181a6b){_0xb468ea=_0x181a6b;return db[_0xbccb('0xbc')][_0xbccb('0x36')]({'where':{'membername':_0xb468ea[_0xbccb('0x40')]},'individualHooks':!![]});}})['then'](function(){return db['MemberReport']['findAll']({'where':{'membername':_0xb468ea['name'],'exitAt':null}});})['then'](function(_0x2e88ed){var _0xa73862=[];_0x2e88ed[_0xbccb('0x10d')](function(_0x535804){_0xa73862['push'](_0x535804['update']({'exitAt':moment()[_0xbccb('0xbb')](_0xbccb('0x10c'))}));});return BPromise[_0xbccb('0x6a')](_0xa73862);})[_0xbccb('0x35')](function(){return _0xb468ea[_0xbccb('0x34')]({'online':![],'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![],'whatsappPause':![],'interface':null});})[_0xbccb('0x35')](respondWithResult(_0x31e8ea,null))[_0xbccb('0x28')](handleError(_0x31e8ea,null));};exports[_0xbccb('0x115')]=function(_0x29c9b3,_0x3241cb,_0x378eb0){var _0x3587a4;return db[_0xbccb('0xbc')]['update']({'paused':0x1},{'where':{'UserId':_0x29c9b3[_0xbccb('0x6b')]['id']},'individualHooks':!![]})[_0xbccb('0x35')](function(){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0x29c9b3[_0xbccb('0x6b')]['id'],'role':_0xbccb('0x92')},'attributes':['id','name',_0xbccb('0x38'),_0xbccb('0x77'),_0xbccb('0xaf')]});})[_0xbccb('0x35')](handleEntityNotFound(_0x3241cb,null))['then'](function(_0x69e5d6){if(_0x69e5d6){_0x3587a4=_0x69e5d6;return respondWithRpcPromise(_0xbccb('0x116'),'pause',{'id':_0x3587a4['id'],'name':_0x3587a4[_0xbccb('0x40')],'pause':!![]});}})[_0xbccb('0x35')](function(){if(_0x3587a4){return db[_0xbccb('0x10a')][_0xbccb('0x61')]({'where':{'membername':_0x3587a4[_0xbccb('0x40')],'type':_0xbccb('0x110'),'exitAt':null}});}})['then'](function(_0x261863){if(_0x261863['length']){var _0x1b77ab=moment()[_0xbccb('0xbb')]('YYYY-MM-DD\x20HH:mm:ss');for(var _0x1ecd86=0x0,_0x5797ba=_0x261863[_0xbccb('0x51')];_0x1ecd86<_0x5797ba;_0x1ecd86++){_0x261863[_0x1ecd86][_0xbccb('0x117')]({'exitAt':_0x1b77ab});}}})['then'](function(){var _0x24412d=[];var _0x211b29=utils[_0xbccb('0x10b')]();_0x211b29[_0xbccb('0x10d')](function(_0xacef9c){_0x24412d['push']({'channel':_0xacef9c,'membername':_0x3587a4[_0xbccb('0x40')],'interface':_[_0xbccb('0x78')](_0x3587a4[_0xbccb('0xaf')])?util[_0xbccb('0xbb')]('SIP/%s',_0x3587a4['name']):_0x3587a4[_0xbccb('0xaf')],'type':_0xbccb('0x110'),'enterAt':moment()[_0xbccb('0xbb')](_0xbccb('0x10c')),'data1':_0x29c9b3[_0xbccb('0x6f')][_0xbccb('0x58')]||_0xbccb('0x118'),'role':_0x3587a4[_0xbccb('0x38')],'internal':_0x3587a4[_0xbccb('0x77')]});});return db[_0xbccb('0x10a')][_0xbccb('0x95')](_0x24412d,{'individualHooks':!![]});})[_0xbccb('0x35')](function(){return _0x3587a4[_0xbccb('0x34')]({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'whatsappPause':!![],'openchannelPause':!![],'pauseType':_0x29c9b3['body'][_0xbccb('0x58')]||_0xbccb('0x118'),'lastPauseAt':moment()[_0xbccb('0xbb')](_0xbccb('0x10c'))});})[_0xbccb('0x35')](respondWithResult(_0x3241cb,null))[_0xbccb('0x28')](handleError(_0x3241cb,null));};exports[_0xbccb('0x119')]=function(_0x59ab58,_0x5a28a8,_0x3e7f95){var _0x7ba87d;return db['User'][_0xbccb('0x3f')]({'where':{'id':_0x59ab58[_0xbccb('0x6b')]['id']},'attributes':['id','name',_0xbccb('0x38'),_0xbccb('0xae'),_0xbccb('0x11a'),_0xbccb('0x11b'),_0xbccb('0x11c'),_0xbccb('0x11d'),_0xbccb('0x11e'),_0xbccb('0x11f'),'pauseType',_0xbccb('0x120')]})[_0xbccb('0x35')](handleEntityNotFound(_0x5a28a8,null))[_0xbccb('0x35')](function(_0x3022f2){if(_0x3022f2){_0x7ba87d=_0x3022f2;if(_0x59ab58[_0xbccb('0x6f')][_0xbccb('0xac')]&&!utils[_0xbccb('0xbf')](_0x59ab58[_0xbccb('0x6f')][_0xbccb('0xac')])){throw new db[(_0xbccb('0x9f'))][(_0xbccb('0xa2'))](_0xbccb('0xb0'));}switch(_0x59ab58['body'][_0xbccb('0xac')]){case _0xbccb('0xb9'):return respondWithRpcPromise('QueuePause',_0xbccb('0x119'),{'id':_0x7ba87d['id'],'name':_0x7ba87d[_0xbccb('0x40')],'pause':![]})[_0xbccb('0x35')](function(){return db[_0xbccb('0xbc')]['update']({'paused':0x0},{'where':{'UserId':_0x7ba87d['id']},'individualHooks':!![]});})[_0xbccb('0x35')](function(){return db['MemberReport'][_0xbccb('0x3f')]({'where':{'channel':_0x59ab58['body'][_0xbccb('0xac')],'membername':_0x7ba87d[_0xbccb('0x40')],'type':_0xbccb('0x110'),'exitAt':null}});})[_0xbccb('0x35')](function(_0x24cb6e){if(_0x24cb6e){return _0x24cb6e['update']({'exitAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss'),'data2':_0xbccb('0x121')},{'individualHooks':!![]});}return null;})[_0xbccb('0x35')](function(){return _0x7ba87d[_0xbccb('0x34')]({'voicePause':![]});});case'mail':case _0xbccb('0x6d'):case _0xbccb('0x67'):case _0xbccb('0x66'):case _0xbccb('0x6e'):case _0xbccb('0x69'):return db[_0xbccb('0x10a')][_0xbccb('0x3f')]({'where':{'channel':_0x59ab58[_0xbccb('0x6f')][_0xbccb('0xac')],'membername':_0x7ba87d[_0xbccb('0x40')],'type':_0xbccb('0x110'),'exitAt':null}})[_0xbccb('0x35')](function(_0x2ef787){if(_0x2ef787){return _0x2ef787[_0xbccb('0x34')]({'exitAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss'),'data2':_0xbccb('0x121')},{'individualHooks':!![]});}return null;})[_0xbccb('0x35')](function(){var _0x5f42ce={};_[_0xbccb('0x122')](_0x5f42ce,util['format'](_0xbccb('0x123'),_0x59ab58[_0xbccb('0x6f')]['channel'],_0xbccb('0x124')),![]);return _0x7ba87d[_0xbccb('0x34')](_0x5f42ce);});default:return respondWithRpcPromise(_0xbccb('0x116'),_0xbccb('0x119'),{'id':_0x7ba87d['id'],'name':_0x7ba87d[_0xbccb('0x40')],'pause':![]})['then'](function(){return db[_0xbccb('0xbc')]['update']({'paused':0x0},{'where':{'UserId':_0x7ba87d['id']}});})['then'](function(){return db[_0xbccb('0x10a')][_0xbccb('0x61')]({'where':{'membername':_0x7ba87d[_0xbccb('0x40')],'type':_0xbccb('0x110'),'exitAt':null}});})[_0xbccb('0x35')](function(_0x509528){var _0x2b7112=[];_0x509528[_0xbccb('0x10d')](function(_0x330ff3){_0x2b7112[_0xbccb('0x60')](_0x330ff3[_0xbccb('0x34')]({'exitAt':moment()[_0xbccb('0xbb')](_0xbccb('0x10c')),'data2':'manual'}));});return BPromise[_0xbccb('0x6a')](_0x2b7112);})[_0xbccb('0x35')](function(){return _0x7ba87d[_0xbccb('0x34')]({'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'whatsappPause':![],'openchannelPause':![]});});}}})[_0xbccb('0x35')](respondWithResult(_0x5a28a8,null))[_0xbccb('0x28')](handleError(_0x5a28a8,null));};exports[_0xbccb('0x125')]=function(_0x3e0c09,_0x5e95ff,_0x148887){var _0x51f0bb={};var _0x37ed89={};var _0x3c5b2d;var _0x95a218;return db[_0xbccb('0x45')][_0xbccb('0xa6')]({'where':{'id':_0x3e0c09[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x5e95ff,null))['then'](function(_0x4a7f3a){if(_0x4a7f3a){_0x3c5b2d=_0x4a7f3a;_0x37ed89[_0xbccb('0x49')]=_[_0xbccb('0x4c')](db[_0xbccb('0x126')]['rawAttributes']);_0x37ed89[_0xbccb('0x4b')]=_[_0xbccb('0x4c')](_0x3e0c09[_0xbccb('0x4b')]);_0x37ed89[_0xbccb('0x4d')]=_[_0xbccb('0x4e')](_0x37ed89[_0xbccb('0x49')],_0x37ed89[_0xbccb('0x4b')]);_0x51f0bb[_0xbccb('0x50')]=_[_0xbccb('0x4e')](_0x37ed89['model'],qs[_0xbccb('0x4f')](_0x3e0c09[_0xbccb('0x4b')][_0xbccb('0x4f')]));_0x51f0bb[_0xbccb('0x50')]=_0x51f0bb['attributes'][_0xbccb('0x51')]?_0x51f0bb['attributes']:_0x37ed89[_0xbccb('0x49')];_0x51f0bb[_0xbccb('0x53')]=qs[_0xbccb('0x54')](_0x3e0c09['query'][_0xbccb('0x54')]);_0x51f0bb[_0xbccb('0x55')]=qs[_0xbccb('0x4d')](_[_0xbccb('0xdc')](_0x3e0c09[_0xbccb('0x4b')],_0x37ed89[_0xbccb('0x4d')]));if(_0x3e0c09['query']['filter']){_0x51f0bb[_0xbccb('0x55')]=_[_0xbccb('0x57')](_0x51f0bb['where'],{'$or':_[_0xbccb('0x3d')](_0x51f0bb[_0xbccb('0x50')],function(_0x2365d4){var _0xfd4deb={};_0xfd4deb[_0x2365d4]={'$like':'%'+_0x3e0c09[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'};return _0xfd4deb;})});}_0x51f0bb=_['merge']({},_0x51f0bb,_0x3e0c09[_0xbccb('0x5c')]);return _0x3c5b2d[_0xbccb('0x125')](_0x51f0bb);}})[_0xbccb('0x35')](function(_0x7a8fa4){if(_0x7a8fa4){_0x95a218=_0x7a8fa4[_0xbccb('0x51')];if(!_0x3e0c09[_0xbccb('0x4b')][_0xbccb('0xe2')](_0xbccb('0x52'))){_0x51f0bb[_0xbccb('0x2e')]=qs[_0xbccb('0x2e')](_0x3e0c09['query'][_0xbccb('0x2e')]);_0x51f0bb[_0xbccb('0x30')]=qs[_0xbccb('0x30')](_0x3e0c09[_0xbccb('0x4b')][_0xbccb('0x30')]);}return _0x3c5b2d[_0xbccb('0x125')](_0x51f0bb);}})[_0xbccb('0x35')](function(_0x829545){if(_0x829545){return _0x829545?{'count':_0x95a218,'rows':_0x829545}:null;}})['then'](respondWithResult(_0x5e95ff,null))['catch'](handleError(_0x5e95ff,null));};exports[_0xbccb('0x127')]=function(_0xccd89d,_0x1311b6){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0xccd89d[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x1311b6,null))['then'](function(_0x115cc4){if(_0x115cc4){var _0x2998bd=_0x115cc4[_0xbccb('0x37')]({'plain':!![]});return _0x115cc4[_0xbccb('0x127')](_0xccd89d[_0xbccb('0x6f')][_0xbccb('0x72')],_[_0xbccb('0x73')](_0xccd89d[_0xbccb('0x6f')],['ids','id'])||{})[_0xbccb('0x35')](function(){for(var _0x290e71=0x0;_0x290e71<_0xccd89d[_0xbccb('0x6f')][_0xbccb('0x72')]['length'];_0x290e71++){var _0x4fedf9=[];db[_0xbccb('0x126')][_0xbccb('0xa6')]({'where':{'id':_0xccd89d[_0xbccb('0x6f')][_0xbccb('0x72')][_0x290e71]}})[_0xbccb('0x35')](function(_0x2b98de){_0x4fedf9[_0xbccb('0x60')](_0x2b98de[_0xbccb('0x107')]()[_0xbccb('0x35')](function(_0x149dfc){for(var _0x15b5ae=0x0;_0x15b5ae<_0x149dfc[_0xbccb('0x51')];_0x15b5ae++){_0x149dfc[_0x15b5ae]['setDataValue'](_0xbccb('0xac'),_0xbccb('0x128'));}return _0x149dfc;}));_0x4fedf9[_0xbccb('0x60')](_0x2b98de['getChatQueues']()[_0xbccb('0x35')](function(_0x40fd52){for(var _0x485ad8=0x0;_0x485ad8<_0x40fd52[_0xbccb('0x51')];_0x485ad8++){_0x40fd52[_0x485ad8][_0xbccb('0x129')]('channel',_0xbccb('0x12a'));}return _0x40fd52;}));_0x4fedf9[_0xbccb('0x60')](_0x2b98de[_0xbccb('0x12b')]()[_0xbccb('0x35')](function(_0x8cf693){for(var _0x5a0896=0x0;_0x5a0896<_0x8cf693['length'];_0x5a0896++){_0x8cf693[_0x5a0896]['setDataValue'](_0xbccb('0xac'),'Mail');}return _0x8cf693;}));_0x4fedf9[_0xbccb('0x60')](_0x2b98de[_0xbccb('0x12c')]()[_0xbccb('0x35')](function(_0x4a5a27){for(var _0x586cc2=0x0;_0x586cc2<_0x4a5a27[_0xbccb('0x51')];_0x586cc2++){_0x4a5a27[_0x586cc2][_0xbccb('0x129')](_0xbccb('0xac'),_0xbccb('0x12d'));}return _0x4a5a27;}));_0x4fedf9['push'](_0x2b98de['getWhatsappQueues']()['then'](function(_0x25895e){for(var _0x22e01d=0x0;_0x22e01d<_0x25895e[_0xbccb('0x51')];_0x22e01d++){_0x25895e[_0x22e01d]['setDataValue']('channel',_0xbccb('0x12e'));}return _0x25895e;}));_0x4fedf9[_0xbccb('0x60')](_0x2b98de[_0xbccb('0x12f')]()[_0xbccb('0x35')](function(_0x2661f3){for(var _0x574459=0x0;_0x574459<_0x2661f3[_0xbccb('0x51')];_0x574459++){_0x2661f3[_0x574459][_0xbccb('0x129')](_0xbccb('0xac'),_0xbccb('0x130'));}return _0x2661f3;}));_0x4fedf9[_0xbccb('0x60')](_0x2b98de[_0xbccb('0x131')]()[_0xbccb('0x35')](function(_0x447e61){for(var _0x5210ce=0x0;_0x5210ce<_0x447e61['length'];_0x5210ce++){_0x447e61[_0x5210ce][_0xbccb('0x129')]('channel',_0xbccb('0x132'));}return _0x447e61;}));return BPromise[_0xbccb('0x6a')](_0x4fedf9);})['then'](function(_0x8b5351){var _0x2d5f2d=_['flatten'](_0x8b5351);_0x4fedf9=[];return db[_0xbccb('0x5a')][_0xbccb('0x133')](function(_0x33bcc8){for(var _0x222173=0x0;_0x222173<_0x2d5f2d['length'];_0x222173++){_0x4fedf9['push'](_0x2d5f2d[_0x222173][_0xbccb('0x134')](_0x2998bd['id']),{'transaction':_0x33bcc8});}return BPromise['all'](_0x4fedf9)[_0xbccb('0x35')](function(){if(_0x2998bd[_0xbccb('0xad')]){return BPromise[_0xbccb('0x98')](_[_0xbccb('0x56')](_0x2d5f2d,function(_0xdb4481){return _0xdb4481[_0xbccb('0x135')](_0xbccb('0xac'))==='Voice';}),function(_0x495fa7){return db[_0xbccb('0xbc')][_0xbccb('0xbd')]({'membername':_0x2998bd[_0xbccb('0x40')],'UserId':_0x2998bd['id'],'queue_name':_0x495fa7[_0xbccb('0x40')],'VoiceQueueId':_0x495fa7['id'],'interface':_[_0xbccb('0x78')](_0x2998bd['interface'])?util['format'](_0xbccb('0xfe'),_0x2998bd[_0xbccb('0x40')]):_0x2998bd['interface'],'paused':_0x2998bd[_0xbccb('0xae')]||![],'penalty':_0x2998bd[_0xbccb('0xb5')]},{'transaction':_0x33bcc8});});}else{return;}})[_0xbccb('0x35')](function(){for(var _0x10d707=0x0;_0x10d707<_0x2d5f2d['length'];_0x10d707++){var _0x1e98d8=_0x2d5f2d[_0x10d707][_0xbccb('0x135')]('channel');var _0x2296a2=_0x1e98d8+_0xbccb('0xb7');socket[_0xbccb('0xc1')]('user'+_0x1e98d8+_0xbccb('0xb8'),{'UserId':_0x2998bd['id'],['queueField']:_0x2d5f2d[_0x10d707]['id']});}});});});}});}})[_0xbccb('0x35')](respondWithStatusCode(_0x1311b6,null))[_0xbccb('0x28')](handleError(_0x1311b6,null));};exports[_0xbccb('0x136')]=function(_0xfaa195,_0x3a7aef){return db['User'][_0xbccb('0xa6')]({'where':{'id':_0xfaa195['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x3a7aef,null))[_0xbccb('0x35')](function(_0xd7b499){if(_0xd7b499){var _0x5b2ef2=_0xd7b499[_0xbccb('0x37')]({'plain':!![]});var _0x1223b2=_0xfaa195['query'][_0xbccb('0x72')];return _0xd7b499[_0xbccb('0x136')](_0x1223b2)[_0xbccb('0x35')](function(){for(var _0x3b2082=0x0;_0x3b2082<_0x1223b2[_0xbccb('0x51')];_0x3b2082++){var _0xd85bc2=[];db[_0xbccb('0x126')][_0xbccb('0xa6')]({'where':{'id':_0x1223b2[_0x3b2082]}})['then'](function(_0x1aaac5){_0xd85bc2['push'](_0x1aaac5[_0xbccb('0x107')]()[_0xbccb('0x35')](function(_0x168f5d){for(var _0x37df7d=0x0;_0x37df7d<_0x168f5d[_0xbccb('0x51')];_0x37df7d++){_0x168f5d[_0x37df7d]['setDataValue'](_0xbccb('0xac'),_0xbccb('0x128'));}return _0x168f5d;}));_0xd85bc2['push'](_0x1aaac5['getChatQueues']()[_0xbccb('0x35')](function(_0x39f2ae){for(var _0x40375a=0x0;_0x40375a<_0x39f2ae['length'];_0x40375a++){_0x39f2ae[_0x40375a][_0xbccb('0x129')](_0xbccb('0xac'),'Chat');}return _0x39f2ae;}));_0xd85bc2['push'](_0x1aaac5['getMailQueues']()[_0xbccb('0x35')](function(_0x26bdd1){for(var _0x2a39d3=0x0;_0x2a39d3<_0x26bdd1[_0xbccb('0x51')];_0x2a39d3++){_0x26bdd1[_0x2a39d3]['setDataValue'](_0xbccb('0xac'),_0xbccb('0x137'));}return _0x26bdd1;}));_0xd85bc2[_0xbccb('0x60')](_0x1aaac5[_0xbccb('0x12c')]()['then'](function(_0x44b4a6){for(var _0x49675f=0x0;_0x49675f<_0x44b4a6[_0xbccb('0x51')];_0x49675f++){_0x44b4a6[_0x49675f][_0xbccb('0x129')]('channel',_0xbccb('0x12d'));}return _0x44b4a6;}));_0xd85bc2[_0xbccb('0x60')](_0x1aaac5['getWhatsappQueues']()[_0xbccb('0x35')](function(_0x2f7abf){for(var _0x3555fc=0x0;_0x3555fc<_0x2f7abf['length'];_0x3555fc++){_0x2f7abf[_0x3555fc][_0xbccb('0x129')](_0xbccb('0xac'),'Whatsapp');}return _0x2f7abf;}));_0xd85bc2[_0xbccb('0x60')](_0x1aaac5[_0xbccb('0x12f')]()[_0xbccb('0x35')](function(_0x2820e5){for(var _0x1c109e=0x0;_0x1c109e<_0x2820e5[_0xbccb('0x51')];_0x1c109e++){_0x2820e5[_0x1c109e][_0xbccb('0x129')]('channel',_0xbccb('0x130'));}return _0x2820e5;}));_0xd85bc2[_0xbccb('0x60')](_0x1aaac5[_0xbccb('0x131')]()[_0xbccb('0x35')](function(_0x21e017){for(var _0x336a0b=0x0;_0x336a0b<_0x21e017['length'];_0x336a0b++){_0x21e017[_0x336a0b][_0xbccb('0x129')](_0xbccb('0xac'),_0xbccb('0x132'));}return _0x21e017;}));return BPromise[_0xbccb('0x6a')](_0xd85bc2);})[_0xbccb('0x35')](function(_0x588548){var _0x159103=_[_0xbccb('0x138')](_0x588548);_0xd85bc2=[];return db[_0xbccb('0x5a')][_0xbccb('0x133')](function(_0xd34333){for(var _0x4fbdf5=0x0;_0x4fbdf5<_0x159103[_0xbccb('0x51')];_0x4fbdf5++){_0xd85bc2[_0xbccb('0x60')](_0x159103[_0x4fbdf5]['removeAgent'](_0x5b2ef2['id']),{'transaction':_0xd34333});}return BPromise['all'](_0xd85bc2)['then'](function(){if(_0x5b2ef2['online']){return BPromise[_0xbccb('0x98')](_[_0xbccb('0x56')](_0x159103,function(_0xeab16c){return _0xeab16c['getDataValue'](_0xbccb('0xac'))===_0xbccb('0x128');}),function(_0x1fb8b2){return db[_0xbccb('0xbc')]['destroy']({'where':{'VoiceQueueId':_0x1fb8b2['id'],'UserId':_0x5b2ef2['id']},'transaction':_0xd34333});});}else{return;}})[_0xbccb('0x35')](function(){for(var _0x298a64=0x0;_0x298a64<_0x159103['length'];_0x298a64++){var _0x2ab90e=_0x159103[_0x298a64]['getDataValue'](_0xbccb('0xac'));var _0x10ad9f=_0x2ab90e+_0xbccb('0xb7');socket[_0xbccb('0xc1')](_0xbccb('0x3a')+_0x2ab90e+_0xbccb('0xc2'),{'UserId':_0x5b2ef2['id'],['queueField']:_0x159103[_0x298a64]['id']});}});});});}});}})['then'](respondWithStatusCode(_0x3a7aef,null))[_0xbccb('0x28')](handleError(_0x3a7aef,null));};exports[_0xbccb('0x139')]=function(_0x21bd3a,_0x12e46a,_0x5be2cd){var _0x1baf0c={};var _0x3fe5fc={};var _0x46d2c2;var _0x1149d2;return db[_0xbccb('0x45')][_0xbccb('0xa6')]({'where':{'id':_0x21bd3a[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x12e46a,null))[_0xbccb('0x35')](function(_0x345fbd){if(_0x345fbd){_0x46d2c2=_0x345fbd;_0x3fe5fc['model']=_['keys'](db[_0xbccb('0xdd')][_0xbccb('0x46')]);_0x3fe5fc['query']=_[_0xbccb('0x4c')](_0x21bd3a[_0xbccb('0x4b')]);_0x3fe5fc[_0xbccb('0x4d')]=_[_0xbccb('0x4e')](_0x3fe5fc[_0xbccb('0x49')],_0x3fe5fc[_0xbccb('0x4b')]);_0x1baf0c['attributes']=_[_0xbccb('0x4e')](_0x3fe5fc[_0xbccb('0x49')],qs['fields'](_0x21bd3a[_0xbccb('0x4b')]['fields']));_0x1baf0c[_0xbccb('0x50')]=_0x1baf0c[_0xbccb('0x50')][_0xbccb('0x51')]?_0x1baf0c['attributes']:_0x3fe5fc[_0xbccb('0x49')];_0x1baf0c[_0xbccb('0x53')]=qs[_0xbccb('0x54')](_0x21bd3a[_0xbccb('0x4b')][_0xbccb('0x54')]);_0x1baf0c[_0xbccb('0x55')]=qs[_0xbccb('0x4d')](_['pick'](_0x21bd3a['query'],_0x3fe5fc[_0xbccb('0x4d')]));if(_0x21bd3a[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x1baf0c[_0xbccb('0x55')]=_[_0xbccb('0x57')](_0x1baf0c[_0xbccb('0x55')],{'$or':_[_0xbccb('0x3d')](_0x1baf0c[_0xbccb('0x50')],function(_0x206d51){var _0x31bb0c={};_0x31bb0c[_0x206d51]={'$like':'%'+_0x21bd3a[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'};return _0x31bb0c;})});}_0x1baf0c=_[_0xbccb('0x57')]({},_0x1baf0c,_0x21bd3a[_0xbccb('0x5c')]);return _0x46d2c2[_0xbccb('0x139')](_0x1baf0c);}})[_0xbccb('0x35')](function(_0x1eb080){if(_0x1eb080){_0x1149d2=_0x1eb080[_0xbccb('0x51')];if(!_0x21bd3a[_0xbccb('0x4b')][_0xbccb('0xe2')](_0xbccb('0x52'))){_0x1baf0c['limit']=qs['limit'](_0x21bd3a[_0xbccb('0x4b')][_0xbccb('0x2e')]);_0x1baf0c[_0xbccb('0x30')]=qs['offset'](_0x21bd3a['query'][_0xbccb('0x30')]);}return _0x46d2c2['getLists'](_0x1baf0c);}})[_0xbccb('0x35')](function(_0x587ed4){if(_0x587ed4){return _0x587ed4?{'count':_0x1149d2,'rows':_0x587ed4}:null;}})['then'](respondWithResult(_0x12e46a,null))['catch'](handleError(_0x12e46a,null));};exports[_0xbccb('0x13a')]=function(_0x234073,_0x479c31,_0x4d3ba7){var _0x5d182a={};var _0x2cacc8={};var _0x3d3066;var _0x3eed91;return db[_0xbccb('0x45')][_0xbccb('0xa6')]({'where':{'id':_0x234073[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x479c31,null))[_0xbccb('0x35')](function(_0x2715e9){if(_0x2715e9){_0x3d3066=_0x2715e9;_0x2cacc8[_0xbccb('0x49')]=_['keys'](db[_0xbccb('0x45')][_0xbccb('0x46')]);_0x2cacc8[_0xbccb('0x4b')]=_[_0xbccb('0x4c')](_0x234073[_0xbccb('0x4b')]);_0x2cacc8['filters']=_[_0xbccb('0x4e')](_0x2cacc8[_0xbccb('0x49')],_0x2cacc8[_0xbccb('0x4b')]);_0x5d182a[_0xbccb('0x50')]=_[_0xbccb('0x4e')](_0x2cacc8[_0xbccb('0x49')],qs[_0xbccb('0x4f')](_0x234073[_0xbccb('0x4b')][_0xbccb('0x4f')]));_0x5d182a['attributes']=_0x5d182a[_0xbccb('0x50')][_0xbccb('0x51')]?_0x5d182a['attributes']:_0x2cacc8['model'];_0x5d182a['order']=qs[_0xbccb('0x54')](_0x234073['query']['sort']);_0x5d182a[_0xbccb('0x55')]=qs['filters'](_[_0xbccb('0xdc')](_0x234073[_0xbccb('0x4b')],_0x2cacc8[_0xbccb('0x4d')]));if(_0x234073[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x5d182a[_0xbccb('0x55')]=_['merge'](_0x5d182a[_0xbccb('0x55')],{'$or':_[_0xbccb('0x3d')](_0x5d182a['attributes'],function(_0x5ae941){var _0x918d7b={};_0x918d7b[_0x5ae941]={'$like':'%'+_0x234073[_0xbccb('0x4b')]['filter']+'%'};return _0x918d7b;})});}_0x5d182a['model']=db[_0xbccb('0x45')];_0x5d182a['as']=_0xbccb('0x93');_0x5d182a=_[_0xbccb('0x57')]({},_0x5d182a,_0x234073[_0xbccb('0x5c')]);return _0x3d3066[_0xbccb('0x107')]({'include':[_0x5d182a]});}})['then'](function(_0x433f1f){if(_0x433f1f){var _0xb3b26d={},_0x40762b=[],_0x48774f=0x0;for(var _0x6f1165=0x0;_0x6f1165<_0x433f1f[_0xbccb('0x51')];_0x6f1165+=0x1){for(var _0x4d4398=0x0,_0x4a31f8;_0x4d4398<_0x433f1f[_0x6f1165][_0xbccb('0x93')][_0xbccb('0x51')];_0x4d4398+=0x1){_0x4a31f8=_0x433f1f[_0x6f1165][_0xbccb('0x93')][_0x4d4398][_0xbccb('0x37')]({'plain':!![]});_0xb3b26d[_0x4a31f8['id']]=_0x4a31f8;}}_0xb3b26d=_[_0xbccb('0x13b')](_0xb3b26d);for(var _0xe3d01e=qs[_0xbccb('0x30')](_0x234073[_0xbccb('0x4b')][_0xbccb('0x30')]);_0xe3d01e<_0xb3b26d[_0xbccb('0x51')]&&_0x40762b['length']<qs[_0xbccb('0x2e')](_0x234073[_0xbccb('0x4b')][_0xbccb('0x2e')]);_0xe3d01e+=0x1){if(_0xb3b26d[_0xe3d01e]){_0x40762b[_0xbccb('0x60')](_0xb3b26d[_0xe3d01e]);}}return{'count':_0xb3b26d[_0xbccb('0x51')],'rows':_0x40762b};}})[_0xbccb('0x35')](respondWithResult(_0x479c31,null))[_0xbccb('0x28')](handleError(_0x479c31,null));};exports['destroy']=function(_0x2e317f,_0x3fcd7d){if(_0x2e317f[_0xbccb('0x3a')]['id']==_0x2e317f['params']['id']){return _0x3fcd7d['status'](0x1f4)[_0xbccb('0x43')]({'message':_0xbccb('0x13c')});}return db[_0xbccb('0x45')]['find']({'where':{'id':_0x2e317f[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x3fcd7d,null))[_0xbccb('0x35')](removeEntity(_0x3fcd7d,null))['catch'](handleError(_0x3fcd7d,null));};exports[_0xbccb('0x13d')]=function(_0x53aeff,_0xccca4d,_0xd63cce){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0x53aeff['params']['id']}})['then'](handleEntityNotFound(_0xccca4d,null))[_0xbccb('0x35')](function(_0x12ac5d){if(_0x12ac5d){return _0x12ac5d[_0xbccb('0x13d')](_0x53aeff['body']['ids'],_[_0xbccb('0x73')](_0x53aeff['body'],[_0xbccb('0x72'),'id'])||{})[_0xbccb('0xb6')](function(){for(var _0x12fc2e=0x0;_0x12fc2e<_0x53aeff[_0xbccb('0x6f')][_0xbccb('0x72')][_0xbccb('0x51')];_0x12fc2e+=0x1){socket[_0xbccb('0xc1')](_0xbccb('0x13e'),{'ChatInteractionId':Number(_0x53aeff[_0xbccb('0x6f')][_0xbccb('0x72')][_0x12fc2e]),'UserId':Number(_0x53aeff[_0xbccb('0x6b')]['id'])});}return _0x53aeff['body'][_0xbccb('0x72')];});}})['then'](respondWithResult(_0xccca4d,null))[_0xbccb('0x28')](handleError(_0xccca4d,null));};exports[_0xbccb('0x13f')]=function(_0x2ea1fd,_0x2399e0,_0x2dc28f){return db[_0xbccb('0x45')]['find']({'where':{'id':_0x2ea1fd['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x2399e0,null))[_0xbccb('0x35')](function(_0x427036){if(_0x427036){return _0x427036[_0xbccb('0x13f')](_0x2ea1fd[_0xbccb('0x4b')][_0xbccb('0x72')])[_0xbccb('0x35')](function(){if(_[_0xbccb('0x140')](_0x2ea1fd['query'][_0xbccb('0x72')])){for(var _0x4d5c0e=0x0;_0x4d5c0e<_0x2ea1fd[_0xbccb('0x4b')][_0xbccb('0x72')][_0xbccb('0x51')];_0x4d5c0e+=0x1){socket[_0xbccb('0xc1')](_0xbccb('0x141'),{'ChatInteractionId':Number(_0x2ea1fd['query'][_0xbccb('0x72')][_0x4d5c0e]),'UserId':Number(_0x2ea1fd[_0xbccb('0x6b')]['id'])});}}else{socket[_0xbccb('0xc1')](_0xbccb('0x141'),{'ChatInteractionId':Number(_0x2ea1fd[_0xbccb('0x4b')]['ids']),'UserId':Number(_0x2ea1fd[_0xbccb('0x6b')]['id'])});}});}})[_0xbccb('0x35')](respondWithStatusCode(_0x2399e0,null))[_0xbccb('0x28')](handleError(_0x2399e0,null));};exports[_0xbccb('0x142')]=function(_0x249842,_0x3e52b7,_0x4b28f0){return db['User'][_0xbccb('0x3f')]({'where':{'id':_0x249842[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x3e52b7,null))[_0xbccb('0x35')](function(_0x3da837){if(_0x3da837){return _0x3da837[_0xbccb('0x142')](_0x249842[_0xbccb('0x6f')]['ids'],_[_0xbccb('0x73')](_0x249842[_0xbccb('0x6f')],[_0xbccb('0x72'),'id'])||{})['spread'](function(){for(var _0x49b6d3=0x0;_0x49b6d3<_0x249842[_0xbccb('0x6f')]['ids']['length'];_0x49b6d3+=0x1){socket[_0xbccb('0xc1')](_0xbccb('0x143'),{'MailInteractionId':Number(_0x249842[_0xbccb('0x6f')][_0xbccb('0x72')][_0x49b6d3]),'UserId':Number(_0x249842['params']['id'])});}return _0x249842['body'][_0xbccb('0x72')];});}})['then'](respondWithResult(_0x3e52b7,null))[_0xbccb('0x28')](handleError(_0x3e52b7,null));};exports['removeMailInteractions']=function(_0x53a250,_0x4dd921,_0x5c740e){return db['User']['find']({'where':{'id':_0x53a250['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x4dd921,null))[_0xbccb('0x35')](function(_0x31da2c){if(_0x31da2c){return _0x31da2c[_0xbccb('0x144')](_0x53a250[_0xbccb('0x4b')][_0xbccb('0x72')])[_0xbccb('0x35')](function(){if(_[_0xbccb('0x140')](_0x53a250[_0xbccb('0x4b')]['ids'])){for(var _0x1b52c1=0x0;_0x1b52c1<_0x53a250['query'][_0xbccb('0x72')]['length'];_0x1b52c1+=0x1){socket[_0xbccb('0xc1')](_0xbccb('0x145'),{'MailInteractionId':Number(_0x53a250[_0xbccb('0x4b')][_0xbccb('0x72')][_0x1b52c1]),'UserId':Number(_0x53a250[_0xbccb('0x6b')]['id'])});}}else{socket[_0xbccb('0xc1')](_0xbccb('0x145'),{'MailInteractionId':Number(_0x53a250[_0xbccb('0x4b')]['ids']),'UserId':Number(_0x53a250[_0xbccb('0x6b')]['id'])});}});}})[_0xbccb('0x35')](respondWithStatusCode(_0x4dd921,null))[_0xbccb('0x28')](handleError(_0x4dd921,null));};exports[_0xbccb('0x146')]=function(_0x2b0daa,_0x45dfcc,_0x190eaa){return db['User'][_0xbccb('0x3f')]({'where':{'id':_0x2b0daa[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x45dfcc,null))[_0xbccb('0x35')](function(_0x5d1e36){if(_0x5d1e36){return _0x5d1e36[_0xbccb('0x146')](_0x2b0daa[_0xbccb('0x6f')]['ids'],_[_0xbccb('0x73')](_0x2b0daa[_0xbccb('0x6f')],['ids','id'])||{})[_0xbccb('0xb6')](function(){for(var _0x181ae2=0x0;_0x181ae2<_0x2b0daa[_0xbccb('0x6f')][_0xbccb('0x72')][_0xbccb('0x51')];_0x181ae2+=0x1){socket[_0xbccb('0xc1')](_0xbccb('0x147'),{'FaxInteractionId':Number(_0x2b0daa[_0xbccb('0x6f')][_0xbccb('0x72')][_0x181ae2]),'UserId':Number(_0x2b0daa['params']['id'])});}return _0x2b0daa[_0xbccb('0x6f')][_0xbccb('0x72')];});}})[_0xbccb('0x35')](respondWithResult(_0x45dfcc,null))['catch'](handleError(_0x45dfcc,null));};exports['removeFaxInteractions']=function(_0x5a8897,_0x19f518,_0x4ee8de){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0x5a8897['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x19f518,null))['then'](function(_0x3135e4){if(_0x3135e4){return _0x3135e4['removeFaxInteractions'](_0x5a8897[_0xbccb('0x4b')][_0xbccb('0x72')])[_0xbccb('0x35')](function(){if(_[_0xbccb('0x140')](_0x5a8897[_0xbccb('0x4b')][_0xbccb('0x72')])){for(var _0x18a9ed=0x0;_0x18a9ed<_0x5a8897[_0xbccb('0x4b')][_0xbccb('0x72')][_0xbccb('0x51')];_0x18a9ed+=0x1){socket[_0xbccb('0xc1')](_0xbccb('0x148'),{'FaxInteractionId':Number(_0x5a8897['query'][_0xbccb('0x72')][_0x18a9ed]),'UserId':Number(_0x5a8897[_0xbccb('0x6b')]['id'])});}}else{socket[_0xbccb('0xc1')](_0xbccb('0x148'),{'FaxInteractionId':Number(_0x5a8897[_0xbccb('0x4b')][_0xbccb('0x72')]),'UserId':Number(_0x5a8897[_0xbccb('0x6b')]['id'])});}});}})[_0xbccb('0x35')](respondWithStatusCode(_0x19f518,null))[_0xbccb('0x28')](handleError(_0x19f518,null));};exports[_0xbccb('0x149')]=function(_0x2721f8,_0xade341,_0x576ab0){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0x2721f8[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0xade341,null))[_0xbccb('0x35')](function(_0x273bbd){if(_0x273bbd){return _0x273bbd[_0xbccb('0x149')](_0x2721f8[_0xbccb('0x6f')]['ids'],_[_0xbccb('0x73')](_0x2721f8['body'],[_0xbccb('0x72'),'id'])||{})['spread'](function(){for(var _0x166cd2=0x0;_0x166cd2<_0x2721f8[_0xbccb('0x6f')][_0xbccb('0x72')]['length'];_0x166cd2+=0x1){socket[_0xbccb('0xc1')](_0xbccb('0x14a'),{'SmsInteractionId':Number(_0x2721f8[_0xbccb('0x6f')][_0xbccb('0x72')][_0x166cd2]),'UserId':Number(_0x2721f8['params']['id'])});}return _0x2721f8[_0xbccb('0x6f')][_0xbccb('0x72')];});}})[_0xbccb('0x35')](respondWithResult(_0xade341,null))[_0xbccb('0x28')](handleError(_0xade341,null));};exports['removeSmsInteractions']=function(_0x4c79a5,_0x52e559,_0x1f1faa){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0x4c79a5['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x52e559,null))[_0xbccb('0x35')](function(_0x39340a){if(_0x39340a){return _0x39340a['removeSmsInteractions'](_0x4c79a5[_0xbccb('0x4b')][_0xbccb('0x72')])[_0xbccb('0x35')](function(){if(_[_0xbccb('0x140')](_0x4c79a5['query'][_0xbccb('0x72')])){for(var _0x58c040=0x0;_0x58c040<_0x4c79a5['query']['ids'][_0xbccb('0x51')];_0x58c040+=0x1){socket[_0xbccb('0xc1')](_0xbccb('0x14b'),{'SmsInteractionId':Number(_0x4c79a5[_0xbccb('0x4b')][_0xbccb('0x72')][_0x58c040]),'UserId':Number(_0x4c79a5[_0xbccb('0x6b')]['id'])});}}else{socket[_0xbccb('0xc1')](_0xbccb('0x14b'),{'SmsInteractionId':Number(_0x4c79a5[_0xbccb('0x4b')][_0xbccb('0x72')]),'UserId':Number(_0x4c79a5['params']['id'])});}});}})[_0xbccb('0x35')](respondWithStatusCode(_0x52e559,null))['catch'](handleError(_0x52e559,null));};exports[_0xbccb('0x14c')]=function(_0x1cfd8b,_0x33ecbf,_0x5e7f1b){return db[_0xbccb('0x45')]['find']({'where':{'id':_0x1cfd8b[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x33ecbf,null))[_0xbccb('0x35')](function(_0x36b777){if(_0x36b777){return _0x36b777[_0xbccb('0x14c')](_0x1cfd8b['body'][_0xbccb('0x72')],_[_0xbccb('0x73')](_0x1cfd8b[_0xbccb('0x6f')],['ids','id'])||{})[_0xbccb('0xb6')](function(){for(var _0x551fea=0x0;_0x551fea<_0x1cfd8b[_0xbccb('0x6f')]['ids']['length'];_0x551fea+=0x1){socket[_0xbccb('0xc1')](_0xbccb('0x14d'),{'OpenchannelInteractionId':Number(_0x1cfd8b[_0xbccb('0x6f')]['ids'][_0x551fea]),'UserId':Number(_0x1cfd8b[_0xbccb('0x6b')]['id'])});}return _0x1cfd8b[_0xbccb('0x6f')]['ids'];});}})[_0xbccb('0x35')](respondWithResult(_0x33ecbf,null))['catch'](handleError(_0x33ecbf,null));};exports[_0xbccb('0x14e')]=function(_0x5dce90,_0x535584,_0x2df1fa){return db['User'][_0xbccb('0x3f')]({'where':{'id':_0x5dce90[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x535584,null))[_0xbccb('0x35')](function(_0x5b3cf2){if(_0x5b3cf2){return _0x5b3cf2[_0xbccb('0x14e')](_0x5dce90['query'][_0xbccb('0x72')])[_0xbccb('0x35')](function(){if(_['isArray'](_0x5dce90[_0xbccb('0x4b')][_0xbccb('0x72')])){for(var _0x3f53da=0x0;_0x3f53da<_0x5dce90[_0xbccb('0x4b')][_0xbccb('0x72')]['length'];_0x3f53da+=0x1){socket['emit']('user_has_openchannel_interactions:remove',{'OpenchannelInteractionId':Number(_0x5dce90[_0xbccb('0x4b')][_0xbccb('0x72')][_0x3f53da]),'UserId':Number(_0x5dce90[_0xbccb('0x6b')]['id'])});}}else{socket[_0xbccb('0xc1')]('user_has_openchannel_interactions:remove',{'OpenchannelInteractionId':Number(_0x5dce90[_0xbccb('0x4b')][_0xbccb('0x72')]),'UserId':Number(_0x5dce90[_0xbccb('0x6b')]['id'])});}});}})[_0xbccb('0x35')](respondWithStatusCode(_0x535584,null))[_0xbccb('0x28')](handleError(_0x535584,null));};exports['addWhatsappInteractions']=function(_0x235fc7,_0x517a10,_0x1ce5bf){return db[_0xbccb('0x45')]['find']({'where':{'id':_0x235fc7[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x517a10,null))[_0xbccb('0x35')](function(_0xdf750b){if(_0xdf750b){return _0xdf750b[_0xbccb('0x14f')](_0x235fc7['body'][_0xbccb('0x72')],_['omit'](_0x235fc7[_0xbccb('0x6f')],[_0xbccb('0x72'),'id'])||{})[_0xbccb('0xb6')](function(){for(var _0x9d37be=0x0;_0x9d37be<_0x235fc7['body']['ids'][_0xbccb('0x51')];_0x9d37be+=0x1){socket[_0xbccb('0xc1')]('user_has_whatsapp_interactions:save',{'WhatsappInteractionId':Number(_0x235fc7[_0xbccb('0x6f')][_0xbccb('0x72')][_0x9d37be]),'UserId':Number(_0x235fc7[_0xbccb('0x6b')]['id'])});}return _0x235fc7[_0xbccb('0x6f')][_0xbccb('0x72')];});}})[_0xbccb('0x35')](respondWithResult(_0x517a10,null))[_0xbccb('0x28')](handleError(_0x517a10,null));};exports[_0xbccb('0x150')]=function(_0x517921,_0x22e6ef,_0x1d6816){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0x517921[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x22e6ef,null))[_0xbccb('0x35')](function(_0x205463){if(_0x205463){return _0x205463['removeWhatsappInteractions'](_0x517921[_0xbccb('0x4b')][_0xbccb('0x72')]);}})[_0xbccb('0x35')](respondWithStatusCode(_0x22e6ef,null))[_0xbccb('0x28')](handleError(_0x22e6ef,null));};exports[_0xbccb('0x151')]=function(_0x36b011,_0xd52b8,_0x4b25ad){var _0x23af60={};var _0x30ba48={};var _0x1aefa7;var _0x1fdb0f;return db[_0xbccb('0x45')]['findOne']({'where':{'id':_0x36b011[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0xd52b8,null))[_0xbccb('0x35')](function(_0x2292af){if(_0x2292af){_0x1aefa7=_0x2292af;_0x30ba48['model']=_[_0xbccb('0x4c')](db[_0xbccb('0x152')][_0xbccb('0x46')]);_0x30ba48[_0xbccb('0x4b')]=_['keys'](_0x36b011[_0xbccb('0x4b')]);_0x30ba48[_0xbccb('0x4d')]=_[_0xbccb('0x4e')](_0x30ba48[_0xbccb('0x49')],_0x30ba48['query']);_0x23af60[_0xbccb('0x50')]=_[_0xbccb('0x4e')](_0x30ba48['model'],qs[_0xbccb('0x4f')](_0x36b011[_0xbccb('0x4b')][_0xbccb('0x4f')]));_0x23af60['attributes']=_0x23af60[_0xbccb('0x50')]['length']?_0x23af60[_0xbccb('0x50')]:_0x30ba48[_0xbccb('0x49')];_0x23af60[_0xbccb('0x53')]=qs[_0xbccb('0x54')](_0x36b011[_0xbccb('0x4b')][_0xbccb('0x54')]);_0x23af60[_0xbccb('0x55')]=qs[_0xbccb('0x4d')](_[_0xbccb('0xdc')](_0x36b011[_0xbccb('0x4b')],_0x30ba48[_0xbccb('0x4d')]));if(_0x36b011['query'][_0xbccb('0x56')]){_0x23af60[_0xbccb('0x55')]=_[_0xbccb('0x57')](_0x23af60[_0xbccb('0x55')],{'$or':_[_0xbccb('0x3d')](_0x23af60['attributes'],function(_0x3f3e57){var _0x3964aa={};_0x3964aa[_0x3f3e57]={'$like':'%'+_0x36b011[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'};return _0x3964aa;})});}_0x23af60=_['merge']({},_0x23af60,_0x36b011[_0xbccb('0x5c')]);return _0x1aefa7[_0xbccb('0x151')](_0x23af60);}})[_0xbccb('0x35')](function(_0x20d461){if(_0x20d461){_0x1fdb0f=_0x20d461[_0xbccb('0x51')];if(!_0x36b011[_0xbccb('0x4b')]['hasOwnProperty'](_0xbccb('0x52'))){_0x23af60[_0xbccb('0x2e')]=qs[_0xbccb('0x2e')](_0x36b011[_0xbccb('0x4b')][_0xbccb('0x2e')]);_0x23af60[_0xbccb('0x30')]=qs[_0xbccb('0x30')](_0x36b011['query'][_0xbccb('0x30')]);}return _0x1aefa7[_0xbccb('0x151')](_0x23af60);}})[_0xbccb('0x35')](function(_0x3325ad){if(_0x3325ad){return _0x3325ad?{'count':_0x1fdb0f,'rows':_0x3325ad}:null;}})[_0xbccb('0x35')](respondWithResult(_0xd52b8,null))[_0xbccb('0x28')](handleError(_0xd52b8,null));};exports[_0xbccb('0x153')]=function(_0x332ef4,_0x3020dd,_0x58bf93){var _0x28994c={};var _0x56a006={};var _0x4208c2;var _0x554093;return db[_0xbccb('0x45')]['findOne']({'where':{'id':_0x332ef4['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x3020dd,null))[_0xbccb('0x35')](function(_0x17d868){if(_0x17d868){_0x4208c2=_0x17d868;_0x56a006[_0xbccb('0x49')]=_[_0xbccb('0x4c')](db[_0xbccb('0x154')][_0xbccb('0x46')]);_0x56a006[_0xbccb('0x4b')]=_['keys'](_0x332ef4[_0xbccb('0x4b')]);_0x56a006[_0xbccb('0x4d')]=_['intersection'](_0x56a006[_0xbccb('0x49')],_0x56a006[_0xbccb('0x4b')]);_0x28994c[_0xbccb('0x50')]=_[_0xbccb('0x4e')](_0x56a006[_0xbccb('0x49')],qs[_0xbccb('0x4f')](_0x332ef4[_0xbccb('0x4b')][_0xbccb('0x4f')]));_0x28994c['attributes']=_0x28994c[_0xbccb('0x50')]['length']?_0x28994c[_0xbccb('0x50')]:_0x56a006[_0xbccb('0x49')];_0x28994c[_0xbccb('0x53')]=qs['sort'](_0x332ef4[_0xbccb('0x4b')][_0xbccb('0x54')]);_0x28994c[_0xbccb('0x55')]=qs['filters'](_[_0xbccb('0xdc')](_0x332ef4[_0xbccb('0x4b')],_0x56a006[_0xbccb('0x4d')]));if(_0x332ef4['query'][_0xbccb('0x56')]){_0x28994c[_0xbccb('0x55')]=_[_0xbccb('0x57')](_0x28994c[_0xbccb('0x55')],{'$or':_[_0xbccb('0x3d')](_0x28994c['attributes'],function(_0x5e8ab9){var _0x14e216={};_0x14e216[_0x5e8ab9]={'$like':'%'+_0x332ef4[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'};return _0x14e216;})});}_0x28994c=_[_0xbccb('0x57')]({},_0x28994c,_0x332ef4[_0xbccb('0x5c')]);return _0x4208c2[_0xbccb('0x153')](_0x28994c);}})[_0xbccb('0x35')](function(_0x13d314){if(_0x13d314){_0x554093=_0x13d314['length'];if(!_0x332ef4['query'][_0xbccb('0xe2')]('nolimit')){_0x28994c[_0xbccb('0x2e')]=qs['limit'](_0x332ef4['query']['limit']);_0x28994c[_0xbccb('0x30')]=qs['offset'](_0x332ef4[_0xbccb('0x4b')][_0xbccb('0x30')]);}return _0x4208c2[_0xbccb('0x153')](_0x28994c);}})[_0xbccb('0x35')](function(_0x2a278d){if(_0x2a278d){return _0x2a278d?{'count':_0x554093,'rows':_0x2a278d}:null;}})['then'](respondWithResult(_0x3020dd,null))['catch'](handleError(_0x3020dd,null));};exports['addFaxAccounts']=function(_0xe7cbc4,_0x232fff,_0x313890){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0xe7cbc4['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x232fff,null))[_0xbccb('0x35')](function(_0x29b0c8){if(_0x29b0c8){return _0x29b0c8[_0xbccb('0x155')](_0xe7cbc4['body'][_0xbccb('0x72')],_[_0xbccb('0x73')](_0xe7cbc4[_0xbccb('0x6f')],[_0xbccb('0x72'),'id'])||{});}})[_0xbccb('0x35')](respondWithResult(_0x232fff,null))[_0xbccb('0x28')](handleError(_0x232fff,null));};exports[_0xbccb('0x156')]=function(_0xd8658,_0x3a4dac,_0x562067){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0xd8658[_0xbccb('0x6b')]['id']}})['then'](handleEntityNotFound(_0x3a4dac,null))[_0xbccb('0x35')](function(_0x2fe005){if(_0x2fe005){return _0x2fe005['removeFaxAccounts'](_0xd8658['query'][_0xbccb('0x72')]);}})[_0xbccb('0x35')](respondWithStatusCode(_0x3a4dac,null))[_0xbccb('0x28')](handleError(_0x3a4dac,null));};exports[_0xbccb('0x157')]=function(_0x2acc4d,_0x59ba23,_0x284596){var _0x2b58fb={};var _0x17f322={};var _0x318c4e;var _0x3c7a19;return db['User'][_0xbccb('0xa6')]({'where':{'id':_0x2acc4d[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x59ba23,null))[_0xbccb('0x35')](function(_0x3a95c9){if(_0x3a95c9){_0x318c4e=_0x3a95c9;_0x17f322[_0xbccb('0x49')]=_[_0xbccb('0x4c')](db['MailAccount'][_0xbccb('0x46')]);_0x17f322[_0xbccb('0x4b')]=_[_0xbccb('0x4c')](_0x2acc4d['query']);_0x17f322[_0xbccb('0x4d')]=_[_0xbccb('0x4e')](_0x17f322[_0xbccb('0x49')],_0x17f322[_0xbccb('0x4b')]);_0x2b58fb[_0xbccb('0x50')]=_['intersection'](_0x17f322['model'],qs['fields'](_0x2acc4d[_0xbccb('0x4b')][_0xbccb('0x4f')]));_0x2b58fb[_0xbccb('0x50')]=_0x2b58fb[_0xbccb('0x50')]['length']?_0x2b58fb[_0xbccb('0x50')]:_0x17f322[_0xbccb('0x49')];_0x2b58fb['order']=qs[_0xbccb('0x54')](_0x2acc4d[_0xbccb('0x4b')]['sort']);_0x2b58fb['where']=qs[_0xbccb('0x4d')](_['pick'](_0x2acc4d[_0xbccb('0x4b')],_0x17f322[_0xbccb('0x4d')]));if(_0x2acc4d[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x2b58fb[_0xbccb('0x55')]=_[_0xbccb('0x57')](_0x2b58fb['where'],{'$or':_[_0xbccb('0x3d')](_0x2b58fb['attributes'],function(_0x5ef640){var _0x1f5050={};_0x1f5050[_0x5ef640]={'$like':'%'+_0x2acc4d[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'};return _0x1f5050;})});}_0x2b58fb=_[_0xbccb('0x57')]({},_0x2b58fb,_0x2acc4d[_0xbccb('0x5c')]);return _0x318c4e['getMailAccounts'](_0x2b58fb);}})[_0xbccb('0x35')](function(_0x53cca7){if(_0x53cca7){_0x3c7a19=_0x53cca7[_0xbccb('0x51')];if(!_0x2acc4d[_0xbccb('0x4b')][_0xbccb('0xe2')](_0xbccb('0x52'))){_0x2b58fb[_0xbccb('0x2e')]=qs[_0xbccb('0x2e')](_0x2acc4d['query'][_0xbccb('0x2e')]);_0x2b58fb[_0xbccb('0x30')]=qs[_0xbccb('0x30')](_0x2acc4d[_0xbccb('0x4b')][_0xbccb('0x30')]);}return _0x318c4e[_0xbccb('0x157')](_0x2b58fb);}})['then'](function(_0x55a1fa){if(_0x55a1fa){return _0x55a1fa?{'count':_0x3c7a19,'rows':_0x55a1fa}:null;}})[_0xbccb('0x35')](respondWithResult(_0x59ba23,null))['catch'](handleError(_0x59ba23,null));};exports[_0xbccb('0x158')]=function(_0x1ad7fa,_0x2be5d8,_0x22d3dd){return db[_0xbccb('0x45')]['find']({'where':{'id':_0x1ad7fa['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x2be5d8,null))[_0xbccb('0x35')](function(_0x3bb072){if(_0x3bb072){return _0x3bb072[_0xbccb('0x158')](_0x1ad7fa[_0xbccb('0x6f')][_0xbccb('0x72')],_['omit'](_0x1ad7fa['body'],['ids','id'])||{});}})[_0xbccb('0x35')](respondWithResult(_0x2be5d8,null))['catch'](handleError(_0x2be5d8,null));};exports['removeMailAccounts']=function(_0x5cb30b,_0x24cb17,_0x565fda){return db['User'][_0xbccb('0x3f')]({'where':{'id':_0x5cb30b['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x24cb17,null))['then'](function(_0x8dea90){if(_0x8dea90){return _0x8dea90[_0xbccb('0x159')](_0x5cb30b[_0xbccb('0x4b')][_0xbccb('0x72')]);}})[_0xbccb('0x35')](respondWithStatusCode(_0x24cb17,null))[_0xbccb('0x28')](handleError(_0x24cb17,null));};exports[_0xbccb('0x15a')]=function(_0x20bf1c,_0x1acd37,_0x1c5696){var _0x39229a={};var _0xbbb72={};var _0x55a59c;var _0x2d5781;return db['User'][_0xbccb('0xa6')]({'where':{'id':_0x20bf1c['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x1acd37,null))[_0xbccb('0x35')](function(_0x2a34a4){if(_0x2a34a4){_0x55a59c=_0x2a34a4;_0xbbb72['model']=_[_0xbccb('0x4c')](db[_0xbccb('0x15b')]['rawAttributes']);_0xbbb72[_0xbccb('0x4b')]=_[_0xbccb('0x4c')](_0x20bf1c[_0xbccb('0x4b')]);_0xbbb72[_0xbccb('0x4d')]=_[_0xbccb('0x4e')](_0xbbb72['model'],_0xbbb72['query']);_0x39229a['attributes']=_[_0xbccb('0x4e')](_0xbbb72[_0xbccb('0x49')],qs['fields'](_0x20bf1c[_0xbccb('0x4b')][_0xbccb('0x4f')]));_0x39229a['attributes']=_0x39229a[_0xbccb('0x50')]['length']?_0x39229a[_0xbccb('0x50')]:_0xbbb72[_0xbccb('0x49')];_0x39229a['order']=qs['sort'](_0x20bf1c[_0xbccb('0x4b')][_0xbccb('0x54')]);_0x39229a[_0xbccb('0x55')]=qs[_0xbccb('0x4d')](_['pick'](_0x20bf1c['query'],_0xbbb72['filters']));if(_0x20bf1c[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x39229a[_0xbccb('0x55')]=_[_0xbccb('0x57')](_0x39229a[_0xbccb('0x55')],{'$or':_[_0xbccb('0x3d')](_0x39229a[_0xbccb('0x50')],function(_0x249686){var _0x899ba2={};_0x899ba2[_0x249686]={'$like':'%'+_0x20bf1c[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'};return _0x899ba2;})});}_0x39229a=_[_0xbccb('0x57')]({},_0x39229a,_0x20bf1c[_0xbccb('0x5c')]);return _0x55a59c['getOpenchannelAccounts'](_0x39229a);}})[_0xbccb('0x35')](function(_0x462ef2){if(_0x462ef2){_0x2d5781=_0x462ef2[_0xbccb('0x51')];if(!_0x20bf1c[_0xbccb('0x4b')][_0xbccb('0xe2')](_0xbccb('0x52'))){_0x39229a[_0xbccb('0x2e')]=qs['limit'](_0x20bf1c['query'][_0xbccb('0x2e')]);_0x39229a[_0xbccb('0x30')]=qs[_0xbccb('0x30')](_0x20bf1c[_0xbccb('0x4b')][_0xbccb('0x30')]);}return _0x55a59c[_0xbccb('0x15a')](_0x39229a);}})[_0xbccb('0x35')](function(_0x563967){if(_0x563967){return _0x563967?{'count':_0x2d5781,'rows':_0x563967}:null;}})[_0xbccb('0x35')](respondWithResult(_0x1acd37,null))[_0xbccb('0x28')](handleError(_0x1acd37,null));};exports[_0xbccb('0x15c')]=function(_0x352418,_0x32115f,_0x45bcc4){return db['User'][_0xbccb('0x3f')]({'where':{'id':_0x352418[_0xbccb('0x6b')]['id']}})['then'](handleEntityNotFound(_0x32115f,null))[_0xbccb('0x35')](function(_0xb05dae){if(_0xb05dae){return _0xb05dae[_0xbccb('0x15c')](_0x352418['body']['ids'],_[_0xbccb('0x73')](_0x352418[_0xbccb('0x6f')],[_0xbccb('0x72'),'id'])||{});}})[_0xbccb('0x35')](respondWithResult(_0x32115f,null))[_0xbccb('0x28')](handleError(_0x32115f,null));};exports['removeOpenchannelAccounts']=function(_0x5ea3ac,_0x501530,_0x8e5c93){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0x5ea3ac['params']['id']}})['then'](handleEntityNotFound(_0x501530,null))['then'](function(_0x3257cc){if(_0x3257cc){return _0x3257cc[_0xbccb('0x15d')](_0x5ea3ac[_0xbccb('0x4b')][_0xbccb('0x72')]);}})[_0xbccb('0x35')](respondWithStatusCode(_0x501530,null))[_0xbccb('0x28')](handleError(_0x501530,null));};exports['getSmsAccounts']=function(_0x46b90e,_0x749c7a,_0x33400c){var _0x5e5eb7={};var _0x33c03e={};var _0x48b2ae;var _0x22159d;return db[_0xbccb('0x45')]['findOne']({'where':{'id':_0x46b90e['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x749c7a,null))['then'](function(_0x2caa79){if(_0x2caa79){_0x48b2ae=_0x2caa79;_0x33c03e[_0xbccb('0x49')]=_[_0xbccb('0x4c')](db[_0xbccb('0x15e')]['rawAttributes']);_0x33c03e['query']=_['keys'](_0x46b90e[_0xbccb('0x4b')]);_0x33c03e['filters']=_[_0xbccb('0x4e')](_0x33c03e[_0xbccb('0x49')],_0x33c03e[_0xbccb('0x4b')]);_0x5e5eb7['attributes']=_['intersection'](_0x33c03e[_0xbccb('0x49')],qs[_0xbccb('0x4f')](_0x46b90e[_0xbccb('0x4b')]['fields']));_0x5e5eb7['attributes']=_0x5e5eb7[_0xbccb('0x50')]['length']?_0x5e5eb7[_0xbccb('0x50')]:_0x33c03e[_0xbccb('0x49')];_0x5e5eb7[_0xbccb('0x53')]=qs[_0xbccb('0x54')](_0x46b90e[_0xbccb('0x4b')]['sort']);_0x5e5eb7[_0xbccb('0x55')]=qs['filters'](_[_0xbccb('0xdc')](_0x46b90e[_0xbccb('0x4b')],_0x33c03e[_0xbccb('0x4d')]));if(_0x46b90e[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x5e5eb7[_0xbccb('0x55')]=_['merge'](_0x5e5eb7['where'],{'$or':_['map'](_0x5e5eb7['attributes'],function(_0x36f400){var _0x4a8618={};_0x4a8618[_0x36f400]={'$like':'%'+_0x46b90e['query'][_0xbccb('0x56')]+'%'};return _0x4a8618;})});}_0x5e5eb7=_['merge']({},_0x5e5eb7,_0x46b90e['options']);return _0x48b2ae[_0xbccb('0x15f')](_0x5e5eb7);}})[_0xbccb('0x35')](function(_0x558c59){if(_0x558c59){_0x22159d=_0x558c59['length'];if(!_0x46b90e[_0xbccb('0x4b')][_0xbccb('0xe2')](_0xbccb('0x52'))){_0x5e5eb7['limit']=qs[_0xbccb('0x2e')](_0x46b90e['query'][_0xbccb('0x2e')]);_0x5e5eb7[_0xbccb('0x30')]=qs[_0xbccb('0x30')](_0x46b90e['query'][_0xbccb('0x30')]);}return _0x48b2ae[_0xbccb('0x15f')](_0x5e5eb7);}})[_0xbccb('0x35')](function(_0x420d35){if(_0x420d35){return _0x420d35?{'count':_0x22159d,'rows':_0x420d35}:null;}})[_0xbccb('0x35')](respondWithResult(_0x749c7a,null))[_0xbccb('0x28')](handleError(_0x749c7a,null));};exports[_0xbccb('0x160')]=function(_0x2d9663,_0x16a6f5,_0x177d96){return db[_0xbccb('0x45')]['find']({'where':{'id':_0x2d9663[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x16a6f5,null))['then'](function(_0x53869a){if(_0x53869a){return _0x53869a[_0xbccb('0x160')](_0x2d9663[_0xbccb('0x6f')][_0xbccb('0x72')],_[_0xbccb('0x73')](_0x2d9663['body'],[_0xbccb('0x72'),'id'])||{});}})['then'](respondWithResult(_0x16a6f5,null))[_0xbccb('0x28')](handleError(_0x16a6f5,null));};exports['removeSmsAccounts']=function(_0xc42b5e,_0x550e9c,_0x393e92){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0xc42b5e['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x550e9c,null))[_0xbccb('0x35')](function(_0x3d9a5d){if(_0x3d9a5d){return _0x3d9a5d[_0xbccb('0x161')](_0xc42b5e[_0xbccb('0x4b')][_0xbccb('0x72')]);}})[_0xbccb('0x35')](respondWithStatusCode(_0x550e9c,null))[_0xbccb('0x28')](handleError(_0x550e9c,null));};exports['getChatWebsites']=function(_0xc28e28,_0x2e1cc3,_0x40204d){var _0x42abf8={};var _0x33231d={};var _0x31b8d0;var _0x42f8d9;return db[_0xbccb('0x45')]['findOne']({'where':{'id':_0xc28e28[_0xbccb('0x6b')]['id']}})['then'](handleEntityNotFound(_0x2e1cc3,null))['then'](function(_0xfc6f4c){if(_0xfc6f4c){_0x31b8d0=_0xfc6f4c;_0x33231d['model']=_[_0xbccb('0x4c')](db['ChatWebsite'][_0xbccb('0x46')]);_0x33231d[_0xbccb('0x4b')]=_[_0xbccb('0x4c')](_0xc28e28['query']);_0x33231d[_0xbccb('0x4d')]=_[_0xbccb('0x4e')](_0x33231d[_0xbccb('0x49')],_0x33231d[_0xbccb('0x4b')]);_0x42abf8['attributes']=_[_0xbccb('0x4e')](_0x33231d['model'],qs['fields'](_0xc28e28['query'][_0xbccb('0x4f')]));_0x42abf8[_0xbccb('0x50')]=_0x42abf8[_0xbccb('0x50')][_0xbccb('0x51')]?_0x42abf8[_0xbccb('0x50')]:_0x33231d[_0xbccb('0x49')];_0x42abf8[_0xbccb('0x53')]=qs[_0xbccb('0x54')](_0xc28e28['query']['sort']);_0x42abf8['where']=qs[_0xbccb('0x4d')](_[_0xbccb('0xdc')](_0xc28e28['query'],_0x33231d['filters']));if(_0xc28e28[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x42abf8['where']=_[_0xbccb('0x57')](_0x42abf8[_0xbccb('0x55')],{'$or':_[_0xbccb('0x3d')](_0x42abf8[_0xbccb('0x50')],function(_0x4fdec1){var _0x2369fc={};_0x2369fc[_0x4fdec1]={'$like':'%'+_0xc28e28[_0xbccb('0x4b')]['filter']+'%'};return _0x2369fc;})});}_0x42abf8=_[_0xbccb('0x57')]({},_0x42abf8,_0xc28e28[_0xbccb('0x5c')]);return _0x31b8d0[_0xbccb('0x162')](_0x42abf8);}})[_0xbccb('0x35')](function(_0x34b4b1){if(_0x34b4b1){_0x42f8d9=_0x34b4b1['length'];if(!_0xc28e28[_0xbccb('0x4b')][_0xbccb('0xe2')](_0xbccb('0x52'))){_0x42abf8[_0xbccb('0x2e')]=qs[_0xbccb('0x2e')](_0xc28e28[_0xbccb('0x4b')]['limit']);_0x42abf8[_0xbccb('0x30')]=qs['offset'](_0xc28e28['query'][_0xbccb('0x30')]);}return _0x31b8d0[_0xbccb('0x162')](_0x42abf8);}})[_0xbccb('0x35')](function(_0x336249){if(_0x336249){return _0x336249?{'count':_0x42f8d9,'rows':_0x336249}:null;}})[_0xbccb('0x35')](respondWithResult(_0x2e1cc3,null))['catch'](handleError(_0x2e1cc3,null));};exports[_0xbccb('0x163')]=function(_0x4e8a62,_0x5695fd,_0x44c31f){return db['User'][_0xbccb('0x3f')]({'where':{'id':_0x4e8a62['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x5695fd,null))[_0xbccb('0x35')](function(_0x30c2f2){if(_0x30c2f2){return _0x30c2f2[_0xbccb('0x163')](_0x4e8a62[_0xbccb('0x6f')][_0xbccb('0x72')],_[_0xbccb('0x73')](_0x4e8a62[_0xbccb('0x6f')],[_0xbccb('0x72'),'id'])||{});}})[_0xbccb('0x35')](respondWithResult(_0x5695fd,null))[_0xbccb('0x28')](handleError(_0x5695fd,null));};exports[_0xbccb('0x164')]=function(_0x5c8c62,_0x102f81,_0x329253){return db[_0xbccb('0x45')]['find']({'where':{'id':_0x5c8c62[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x102f81,null))[_0xbccb('0x35')](function(_0xbfb9f){if(_0xbfb9f){return _0xbfb9f[_0xbccb('0x164')](_0x5c8c62[_0xbccb('0x4b')][_0xbccb('0x72')]);}})['then'](respondWithStatusCode(_0x102f81,null))[_0xbccb('0x28')](handleError(_0x102f81,null));};exports[_0xbccb('0x165')]=function(_0x41cde7,_0x5824ed,_0x36258b){var _0x4fafdc={};var _0x33b6d2={};var _0x50b9ee;var _0x2320d8;return db[_0xbccb('0x45')][_0xbccb('0xa6')]({'where':{'id':_0x41cde7[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x5824ed,null))[_0xbccb('0x35')](function(_0x547e75){if(_0x547e75){_0x50b9ee=_0x547e75;_0x33b6d2['model']=_[_0xbccb('0x4c')](db['WhatsappAccount']['rawAttributes']);_0x33b6d2['query']=_[_0xbccb('0x4c')](_0x41cde7[_0xbccb('0x4b')]);_0x33b6d2[_0xbccb('0x4d')]=_[_0xbccb('0x4e')](_0x33b6d2[_0xbccb('0x49')],_0x33b6d2[_0xbccb('0x4b')]);_0x4fafdc[_0xbccb('0x50')]=_['intersection'](_0x33b6d2['model'],qs[_0xbccb('0x4f')](_0x41cde7['query'][_0xbccb('0x4f')]));_0x4fafdc[_0xbccb('0x50')]=_0x4fafdc[_0xbccb('0x50')][_0xbccb('0x51')]?_0x4fafdc[_0xbccb('0x50')]:_0x33b6d2[_0xbccb('0x49')];_0x4fafdc[_0xbccb('0x53')]=qs[_0xbccb('0x54')](_0x41cde7[_0xbccb('0x4b')][_0xbccb('0x54')]);_0x4fafdc[_0xbccb('0x55')]=qs[_0xbccb('0x4d')](_['pick'](_0x41cde7[_0xbccb('0x4b')],_0x33b6d2[_0xbccb('0x4d')]));if(_0x41cde7[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x4fafdc[_0xbccb('0x55')]=_[_0xbccb('0x57')](_0x4fafdc['where'],{'$or':_[_0xbccb('0x3d')](_0x4fafdc[_0xbccb('0x50')],function(_0x10e405){var _0x3b2837={};_0x3b2837[_0x10e405]={'$like':'%'+_0x41cde7['query'][_0xbccb('0x56')]+'%'};return _0x3b2837;})});}_0x4fafdc=_[_0xbccb('0x57')]({},_0x4fafdc,_0x41cde7[_0xbccb('0x5c')]);return _0x50b9ee['getWhatsappAccounts'](_0x4fafdc);}})['then'](function(_0x164de1){if(_0x164de1){_0x2320d8=_0x164de1['length'];if(!_0x41cde7[_0xbccb('0x4b')][_0xbccb('0xe2')](_0xbccb('0x52'))){_0x4fafdc['limit']=qs['limit'](_0x41cde7[_0xbccb('0x4b')][_0xbccb('0x2e')]);_0x4fafdc[_0xbccb('0x30')]=qs['offset'](_0x41cde7[_0xbccb('0x4b')][_0xbccb('0x30')]);}return _0x50b9ee['getWhatsappAccounts'](_0x4fafdc);}})[_0xbccb('0x35')](function(_0x4c8f2b){if(_0x4c8f2b){return _0x4c8f2b?{'count':_0x2320d8,'rows':_0x4c8f2b}:null;}})[_0xbccb('0x35')](respondWithResult(_0x5824ed,null))[_0xbccb('0x28')](handleError(_0x5824ed,null));};exports['addWhatsappAccounts']=function(_0x528af6,_0x433e67,_0x389d03){return db['User']['find']({'where':{'id':_0x528af6[_0xbccb('0x6b')]['id']}})['then'](handleEntityNotFound(_0x433e67,null))[_0xbccb('0x35')](function(_0x605599){if(_0x605599){return _0x605599[_0xbccb('0x166')](_0x528af6[_0xbccb('0x6f')]['ids'],_[_0xbccb('0x73')](_0x528af6[_0xbccb('0x6f')],['ids','id'])||{});}})['then'](respondWithResult(_0x433e67,null))[_0xbccb('0x28')](handleError(_0x433e67,null));};exports['removeWhatsappAccounts']=function(_0x4bc11f,_0x59ac35,_0x56e317){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0x4bc11f['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x59ac35,null))[_0xbccb('0x35')](function(_0x426225){if(_0x426225){return _0x426225[_0xbccb('0x167')](_0x4bc11f[_0xbccb('0x4b')]['ids']);}})[_0xbccb('0x35')](respondWithStatusCode(_0x59ac35,null))[_0xbccb('0x28')](handleError(_0x59ac35,null));};exports[_0xbccb('0x168')]=function(_0x3ff169,_0x5750a3,_0x257c35){var _0x360bbe={};var _0x17d55e={};var _0x2e0a44;var _0x4e1d9d;return db[_0xbccb('0x45')][_0xbccb('0xa6')]({'where':{'id':_0x3ff169[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x5750a3,null))[_0xbccb('0x35')](function(_0x3910ea){if(_0x3910ea){_0x2e0a44=_0x3910ea;_0x17d55e[_0xbccb('0x49')]=_['keys'](db[_0xbccb('0x169')]['rawAttributes']);_0x17d55e['query']=_['keys'](_0x3ff169[_0xbccb('0x4b')]);_0x17d55e['filters']=_[_0xbccb('0x4e')](_0x17d55e[_0xbccb('0x49')],_0x17d55e[_0xbccb('0x4b')]);_0x360bbe[_0xbccb('0x50')]=_[_0xbccb('0x4e')](_0x17d55e[_0xbccb('0x49')],qs[_0xbccb('0x4f')](_0x3ff169['query'][_0xbccb('0x4f')]));_0x360bbe[_0xbccb('0x50')]=_0x360bbe[_0xbccb('0x50')]['length']?_0x360bbe['attributes']:_0x17d55e[_0xbccb('0x49')];_0x360bbe['order']=qs[_0xbccb('0x54')](_0x3ff169['query'][_0xbccb('0x54')]);_0x360bbe[_0xbccb('0x55')]=qs[_0xbccb('0x4d')](_[_0xbccb('0xdc')](_0x3ff169['query'],_0x17d55e['filters']));if(_0x3ff169[_0xbccb('0x4b')][_0xbccb('0x56')]){_0x360bbe[_0xbccb('0x55')]=_[_0xbccb('0x57')](_0x360bbe[_0xbccb('0x55')],{'$or':_[_0xbccb('0x3d')](_0x360bbe[_0xbccb('0x50')],function(_0x3e1eae){var _0x4ee69b={};_0x4ee69b[_0x3e1eae]={'$like':'%'+_0x3ff169[_0xbccb('0x4b')]['filter']+'%'};return _0x4ee69b;})});}_0x360bbe=_[_0xbccb('0x57')]({},_0x360bbe,_0x3ff169[_0xbccb('0x5c')]);return _0x2e0a44['getSquareProjects'](_0x360bbe);}})[_0xbccb('0x35')](function(_0x2a40aa){if(_0x2a40aa){_0x4e1d9d=_0x2a40aa['length'];if(!_0x3ff169[_0xbccb('0x4b')]['hasOwnProperty']('nolimit')){_0x360bbe[_0xbccb('0x2e')]=qs[_0xbccb('0x2e')](_0x3ff169[_0xbccb('0x4b')][_0xbccb('0x2e')]);_0x360bbe[_0xbccb('0x30')]=qs[_0xbccb('0x30')](_0x3ff169['query'][_0xbccb('0x30')]);}return _0x2e0a44['getSquareProjects'](_0x360bbe);}})[_0xbccb('0x35')](function(_0x4fca6f){if(_0x4fca6f){return _0x4fca6f?{'count':_0x4e1d9d,'rows':_0x4fca6f}:null;}})['then'](respondWithResult(_0x5750a3,null))[_0xbccb('0x28')](handleError(_0x5750a3,null));};exports['addSquareProjects']=function(_0x458a32,_0x514ebd,_0x2c9121){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0x458a32[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x514ebd,null))[_0xbccb('0x35')](function(_0x38affa){if(_0x38affa){return _0x38affa[_0xbccb('0x16a')](_0x458a32['body'][_0xbccb('0x72')],_[_0xbccb('0x73')](_0x458a32[_0xbccb('0x6f')],[_0xbccb('0x72'),'id'])||{});}})[_0xbccb('0x35')](respondWithResult(_0x514ebd,null))['catch'](handleError(_0x514ebd,null));};exports[_0xbccb('0x16b')]=function(_0x1708ce,_0x5b16ad,_0x12a57c){return db[_0xbccb('0x45')]['find']({'where':{'id':_0x1708ce[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x5b16ad,null))[_0xbccb('0x35')](function(_0xad01b8){if(_0xad01b8){return _0xad01b8[_0xbccb('0x16b')](_0x1708ce[_0xbccb('0x4b')][_0xbccb('0x72')]);}})['then'](respondWithStatusCode(_0x5b16ad,null))['catch'](handleError(_0x5b16ad,null));};exports[_0xbccb('0x16c')]=function(_0x278d6e,_0x2fdf9b){var _0x1d115b={},_0x6faf63={},_0x56abff={'count':0x0,'rows':[]};var _0x114140=db[_0xbccb('0x16d')][_0xbccb('0x46')];_0x6faf63[_0xbccb('0x49')]=_[_0xbccb('0x4c')](_0x114140);_0x6faf63[_0xbccb('0x4b')]=_[_0xbccb('0x4c')](_0x278d6e[_0xbccb('0x4b')]);_0x6faf63['filters']=_[_0xbccb('0x4e')](_0x6faf63[_0xbccb('0x49')],_0x6faf63[_0xbccb('0x4b')]);_0x6faf63[_0xbccb('0x4d')]=_[_0xbccb('0x16e')](_0x6faf63['filters'],['$and',_0xbccb('0x16f'),_0xbccb('0x170'),_0xbccb('0x171'),'$lt',_0xbccb('0x172'),_0xbccb('0x173'),_0xbccb('0x174'),_0xbccb('0x175'),_0xbccb('0x176'),_0xbccb('0x177'),_0xbccb('0x178'),'$notIn',_0xbccb('0x179'),_0xbccb('0x17a'),_0xbccb('0x17b'),_0xbccb('0x17c'),_0xbccb('0x179'),_0xbccb('0x17d'),_0xbccb('0x17e'),_0xbccb('0x17f'),_0xbccb('0x180')]);_0x1d115b[_0xbccb('0x50')]=_[_0xbccb('0x4e')](_0x6faf63['model'],qs[_0xbccb('0x4f')](_0x278d6e[_0xbccb('0x4b')][_0xbccb('0x4f')]));_0x1d115b[_0xbccb('0x50')]=_0x1d115b[_0xbccb('0x50')][_0xbccb('0x51')]?_0x1d115b['attributes']:_0x6faf63['model'];if(!_0x278d6e[_0xbccb('0x4b')][_0xbccb('0xe2')](_0xbccb('0x52'))){_0x1d115b[_0xbccb('0x2e')]=qs[_0xbccb('0x2e')](_0x278d6e['query']['limit']);_0x1d115b[_0xbccb('0x30')]=qs['offset'](_0x278d6e[_0xbccb('0x4b')][_0xbccb('0x30')]);}_0x1d115b['order']=qs['sort'](_0x278d6e['query'][_0xbccb('0x54')]);_0x1d115b[_0xbccb('0x55')]=qs[_0xbccb('0x4d')](_[_0xbccb('0xdc')](_0x278d6e[_0xbccb('0x4b')],_0x6faf63[_0xbccb('0x4d')]));if(_0x278d6e['query'][_0xbccb('0x56')]){_0x1d115b[_0xbccb('0x55')]=_['merge'](_0x1d115b[_0xbccb('0x55')],{'$or':_[_0xbccb('0x3d')](_0x1d115b[_0xbccb('0x50')],function(_0x40beed){var _0x438e08={};_0x438e08[_0x40beed]={'$like':'%'+_0x278d6e[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'};return _0x438e08;})});}_0x1d115b['where']={'$and':[_0x1d115b[_0xbccb('0x55')],{'$or':[{'UserId':_0x278d6e[_0xbccb('0x6b')]['id']},{'OwnerId':_0x278d6e[_0xbccb('0x6b')]['id']}]}]};_0x1d115b=_[_0xbccb('0x57')]({},_0x1d115b,_0x278d6e[_0xbccb('0x5c')]);var _0x3bd803={'where':_0x1d115b[_0xbccb('0x55')]};return db[_0xbccb('0x16d')]['count'](_0x3bd803)[_0xbccb('0x35')](function(_0xcaa485){_0x56abff[_0xbccb('0x2f')]=_0xcaa485;if(_0x278d6e['query'][_0xbccb('0x5d')]){_0x1d115b[_0xbccb('0x5e')]=[{'attributes':['id',_0xbccb('0x181'),_0xbccb('0x182'),_0xbccb('0xfa')],'model':db[_0xbccb('0xdb')],'as':'Contact'},{'attributes':['id',_0xbccb('0x40'),_0xbccb('0x183')],'model':db[_0xbccb('0xba')],'as':_0xbccb('0xe5')}];}return db[_0xbccb('0x16d')][_0xbccb('0x61')](_0x1d115b);})[_0xbccb('0x35')](function(_0x4f3073){_0x56abff['rows']=_0x4f3073;return _0x56abff;})['then'](respondWithFilteredResult(_0x2fdf9b,_0x1d115b))[_0xbccb('0x28')](handleError(_0x2fdf9b,null));};exports[_0xbccb('0x184')]=function(_0x2a2116,_0x13580e,_0x308039){if(!_[_0xbccb('0x78')](_0x2a2116[_0xbccb('0x3a')]['id'])&&(_0x2a2116['user'][_0xbccb('0x38')]==_0xbccb('0x39')||_0x2a2116[_0xbccb('0x3a')][_0xbccb('0x38')]==_0xbccb('0x3a'))){return db[_0xbccb('0x45')][_0xbccb('0xa6')]({'where':{'id':_0x2a2116[_0xbccb('0x6b')]['id']},'raw':!![]})[_0xbccb('0x35')](function(_0x67607d){return authService[_0xbccb('0x185')](_0x67607d);})[_0xbccb('0x35')](function(_0xdee116){if(_0xdee116){return _0x13580e[_0xbccb('0x2a')](0xc8)[_0xbccb('0x2c')]({'api_key':_0xdee116[_0xbccb('0x186')]});}else{return _0x13580e[_0xbccb('0x2a')](0xcc)[_0xbccb('0x2c')]({'message':'No\x20API\x20access\x20key\x20found!'});}})['catch'](handleError(_0x13580e,0x193));}else{return _0x13580e['status'](0x191)[_0xbccb('0x2c')]({'message':_0xbccb('0x187')});}};exports['createApiKey']=function(_0x490e5c,_0x3e6db7,_0x4231d6){if(!_['isNil'](_0x490e5c[_0xbccb('0x3a')]['id'])&&(_0x490e5c[_0xbccb('0x3a')][_0xbccb('0x38')]==_0xbccb('0x39')||_0x490e5c[_0xbccb('0x3a')]['role']=='user')){return db[_0xbccb('0x45')][_0xbccb('0x3f')]({'where':{'id':_0x490e5c[_0xbccb('0x6b')]['id']}})[_0xbccb('0x35')](function(_0x1903c8){return authService[_0xbccb('0x188')](_0x1903c8);})[_0xbccb('0x35')](function(_0x198efa){return db[_0xbccb('0x45')][_0xbccb('0x34')]({'apiKeyIat':_0x198efa[_0xbccb('0x189')],'apiKeyNonce':_0x198efa[_0xbccb('0x18a')]},{'where':{'id':_0x490e5c['params']['id']}})[_0xbccb('0x35')](function(){return _0x3e6db7[_0xbccb('0x2a')](0xc8)[_0xbccb('0x2c')]({'api_key':_0x198efa[_0xbccb('0x186')]});});})[_0xbccb('0x28')](handleError(_0x3e6db7,0x193));}else{return _0x3e6db7['status'](0x191)[_0xbccb('0x2c')]({'message':'You\x20don\x27t\x20have\x20sufficient\x20privileges\x20to\x20access\x20this\x20resource.'});}};exports[_0xbccb('0x18b')]=function(_0x14ba9c,_0x244be9,_0x499608){if(!_[_0xbccb('0x78')](_0x14ba9c[_0xbccb('0x3a')]['id'])&&(_0x14ba9c[_0xbccb('0x3a')][_0xbccb('0x38')]==_0xbccb('0x39')||_0x14ba9c[_0xbccb('0x3a')][_0xbccb('0x38')]=='user')){return db['User']['find']({'where':{'id':_0x14ba9c['params']['id']}})[_0xbccb('0x35')](handleEntityNotFound(_0x244be9,null))[_0xbccb('0x35')](function(_0x391c64){if(_0x391c64&&_0x391c64[_0xbccb('0x18c')]&&_0x391c64[_0xbccb('0x18d')])return _0x391c64;else throw{'message':_0xbccb('0x18e')};})[_0xbccb('0x35')](function(_0x20347e){return db[_0xbccb('0x45')]['update']({'apiKeyNonce':null,'apiKeyIat':null},{'where':{'id':_0x14ba9c['params']['id']}});})[_0xbccb('0x35')](respondWithStatusCode(_0x244be9,0xc8))[_0xbccb('0x28')](handleError(_0x244be9,0x193));}else{return _0x244be9[_0xbccb('0x2a')](0x191)[_0xbccb('0x2c')]({'message':_0xbccb('0x187')});}};exports['whoami']=function(_0x27130d,_0x3b0377){var _0x5e5362=_0x27130d[_0xbccb('0x3a')][_0xbccb('0x37')]({'plain':!![]});if(!_0x5e5362){return _0x3b0377[_0xbccb('0x2a')](0x191)[_0xbccb('0x43')]('Unable\x20to\x20retrieve\x20the\x20current\x20user');}else{return _0x3b0377[_0xbccb('0x2a')](0xc8)[_0xbccb('0x2c')](_0x5e5362);}};exports[_0xbccb('0x18f')]=function(_0x5f5535,_0x99ee6a){var _0x422572={'offset':0x0},_0x495240={'count':0x0,'rows':[]};Promise[_0xbccb('0x113')]()[_0xbccb('0x35')](function(){if(!_0x5f5535[_0xbccb('0x4b')]['filter']&&!_0x5f5535[_0xbccb('0x4b')][_0xbccb('0x190')]&&!_0x5f5535[_0xbccb('0x4b')][_0xbccb('0x191')])return[];return Promise[_0xbccb('0x113')]()[_0xbccb('0x35')](function(){var _0x26d1f0=[];if(!_[_0xbccb('0x9a')](_0x5f5535[_0xbccb('0x4b')][_0xbccb('0x190')])){_0x26d1f0[_0xbccb('0x60')](db[_0xbccb('0x126')]['findAll']({'attributes':['id',_0xbccb('0x40')],'where':{'id':_0x5f5535[_0xbccb('0x4b')]['teams']}}));}if(!_['isEmpty'](_0x5f5535[_0xbccb('0x4b')][_0xbccb('0x191')])){_0x26d1f0[_0xbccb('0x60')](db[_0xbccb('0xba')][_0xbccb('0x61')]({'attributes':['id','name'],'type':_0xbccb('0x192'),'where':{'id':_0x5f5535[_0xbccb('0x4b')]['queues']}}));}return Promise[_0xbccb('0x6a')](_0x26d1f0);})[_0xbccb('0x35')](function(_0x2e00f2){var _0x5845b9=_[_0xbccb('0x138')](_0x2e00f2)[_0xbccb('0x3d')](function(_0x48d760){return _0x48d760[_0xbccb('0x13a')]({'attributes':['id',_0xbccb('0x40'),_0xbccb('0x77'),_0xbccb('0xad')],'raw':!![]});});return Promise[_0xbccb('0x6a')](_0x5845b9);})[_0xbccb('0x35')](function(_0xd90e35){var _0x379f65=_[_0xbccb('0x138')](_0xd90e35);if(!_0x5f5535[_0xbccb('0x4b')][_0xbccb('0x56')])return _0x379f65;if(_[_0xbccb('0x9a')](_0x379f65)){return db[_0xbccb('0x45')][_0xbccb('0x61')]({'attributes':['id',_0xbccb('0x40'),_0xbccb('0x77'),_0xbccb('0xad')],'where':{'role':_0xbccb('0x92'),'$or':[db[_0xbccb('0x5a')][_0xbccb('0x55')](db['sequelize']['fn']('lower',db[_0xbccb('0x5a')][_0xbccb('0x193')](_0xbccb('0x40'))),{'$like':'%'+_0x5f5535[_0xbccb('0x4b')][_0xbccb('0x56')][_0xbccb('0xb3')]()+'%'}),{'internal':{'$like':'%'+_0x5f5535[_0xbccb('0x4b')][_0xbccb('0x56')]+'%'}}]},'raw':!![]});}else{return _(_0x379f65)[_0xbccb('0x138')]()[_0xbccb('0x56')](function(_0x35f7ab){return _0x35f7ab[_0xbccb('0x40')][_0xbccb('0xb3')]()[_0xbccb('0x5f')](_0x5f5535[_0xbccb('0x4b')][_0xbccb('0x56')]['toLowerCase']())||_0x35f7ab[_0xbccb('0x77')][_0xbccb('0x194')]()[_0xbccb('0x5f')](_0x5f5535['query'][_0xbccb('0x56')]);})[_0xbccb('0x3e')]();}})[_0xbccb('0x35')](function(_0x3cc7f9){var _0x3db8a9=_0xbccb('0x40');var _0x3735eb=_0xbccb('0x195');if(_0x5f5535[_0xbccb('0x4b')][_0xbccb('0x54')]){var _0x3735eb=_0x5f5535[_0xbccb('0x4b')][_0xbccb('0x54')][0x0]==='-'?_0xbccb('0x196'):_0xbccb('0x195');var _0x3db8a9=_0x3735eb==='asc'?_0x5f5535[_0xbccb('0x4b')][_0xbccb('0x54')]:_0x5f5535['query'][_0xbccb('0x54')][_0xbccb('0x197')](0x1);}return _(_0x3cc7f9)[_0xbccb('0x198')]('id')['orderBy']([function(_0x4a9f15){return _0x3db8a9===_0xbccb('0x40')?_0x4a9f15[_0x3db8a9]['toLowerCase']():_0x4a9f15[_0x3db8a9];}],[_0x3735eb])['map'](function(_0x466499){return _[_0xbccb('0xdc')](_0x466499,['id',_0xbccb('0x40'),_0xbccb('0x77'),_0xbccb('0xad')]);})[_0xbccb('0x3e')]();})['then'](function(_0x3aea97){return client[_0xbccb('0x1f')]('Agents',_0x5f5535)[_0xbccb('0x35')](function(_0x21bd4b){if(_0x21bd4b[_0xbccb('0x24')])throw new Error(_0xbccb('0x199'));var _0xef06cf=_0x21bd4b['result'];var _0x1643ba=jayson[_0xbccb('0x19a')]['http']({'port':0x232c});return _0x1643ba[_0xbccb('0x1f')](_0xbccb('0x93'),_0x5f5535)['then'](function(_0x4c197f){if(_0x4c197f[_0xbccb('0x24')])throw new Error(_0xbccb('0x19b'));var _0x33c1e5=_0x4c197f[_0xbccb('0x27')];return _[_0xbccb('0x57')]({},_0x33c1e5,_0xef06cf);});})[_0xbccb('0x35')](function(_0x3b445a){return _[_0xbccb('0x3d')](_0x3aea97,function(_0x468d11){var _0x65cb06=_[_0xbccb('0x3f')](_0x3b445a['rows'],['id',_0x468d11['id']]);if(!_0x65cb06||!_0x468d11[_0xbccb('0xad')]){_0x468d11[_0xbccb('0x2a')]=_0xbccb('0x19c');}else if(_0x65cb06[_0xbccb('0xae')]){_0x468d11[_0xbccb('0x2a')]='pause';}else{_0x468d11[_0xbccb('0x2a')]=_['includes']([_0xbccb('0x19d'),_0xbccb('0x19e'),_0xbccb('0x19f'),_0xbccb('0x1a0'),null,undefined],_0x65cb06['voiceStatus'])?'online':_0xbccb('0x1a1');}return _0x468d11;});});});})[_0xbccb('0x35')](function(_0x574f75){if(!_0x5f5535[_0xbccb('0x4b')][_0xbccb('0xe2')](_0xbccb('0x52'))){_0x422572[_0xbccb('0x2e')]=qs['limit'](_0x5f5535['query']['limit']||0xa);_0x422572['offset']=qs[_0xbccb('0x30')](_0x5f5535[_0xbccb('0x4b')][_0xbccb('0x30')]);}_0x495240['count']=_0x574f75[_0xbccb('0x51')];_0x495240[_0xbccb('0x62')]=_0x422572[_0xbccb('0x2e')]?_0x574f75[_0xbccb('0x1a2')](_0x422572[_0xbccb('0x30')],_0x422572[_0xbccb('0x30')]+_0x422572['limit']):_0x574f75;return _0x495240;})[_0xbccb('0x35')](respondWithFilteredResult(_0x99ee6a,_0x422572))[_0xbccb('0x28')](handleError(_0x99ee6a,null));};function get_open_tabs(_0x497247,_0x571a13){var _0x5b969e=_0x497247['charAt'](0x0)[_0xbccb('0x1a3')]()+_0x497247[_0xbccb('0x1a2')](0x1);var _0x45781a={'type':db[_0xbccb('0x9f')][_0xbccb('0x7b')]['SELECT'],'raw':!![]};return new BPromise(function(_0x4c4249,_0x31f029){var _0x582dd2=squel[_0xbccb('0x1a4')]()['field'](_0xbccb('0x1a5')+_0x5b969e+_0xbccb('0x1a6'),'id')[_0xbccb('0x1a7')](_0xbccb('0x1a8'))['from']('user_has_'+_0x497247+_0xbccb('0x1a9'),'ui')['where'](_0xbccb('0x1aa'),_0x571a13['id']);return db['sequelize'][_0xbccb('0x4b')](_0x582dd2[_0xbccb('0x194')](),_0x45781a)['then'](function(_0x5ecae3){_0x571a13[_0x5b969e+'OpenTabs']=_0x5ecae3;_0x4c4249(_0x5ecae3);})['catch'](function(_0x446700){_0x31f029(_0x446700);});});};