f15a6b83b7f03ddd86ac45dc8f54120ed718a239
[motion2.git] / server / api / voicePrefix / voicePrefix.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 _0x5f66=['map','rawAttributes','fieldName','key','model','name','query','keys','filters','intersection','fields','attributes','length','nolimit','order','sort','where','pick','filter','merge','type','VIRTUAL','options','VoicePrefix','count','includeAll','include','findAll','rows','catch','find','destroy','describe','create','transaction','body','VoiceExtension','VoiceExtensionId','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','context','from-sip','exten','system','description','Voice\x20Prefix\x20Extension','appdata','NoOp','Voice\x20Prefix','VoicePrefixId','bulkCreate','Extensions\x20creation\x20failed','prefix','Set','CDR(prefix)=','callerIdAll','push','PREFIX-CALLERIDALL=','goto','charAt','system-','findById','params','addAgents','ids','spread','userVoicePrefix:save','removeAgents','isArray','emit','userVoicePrefix:remove','findOne','getAgents','hasOwnProperty','getTeams','Team','online','voicePause','interface','flatMap','Agents','sequelize','addTeams','each','TeamVoicePrefix','upsert','UserVoicePrefix','findOrCreate','forEach','removeTeams','User','select','from','team_has_voice_prefixes','join','user_has_teams','clone','toString','QueryTypes','every','TeamId','includes','all','union','compact','value','isEmpty','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','path','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/license/util','redis','localhost','socket.io-emitter','./voicePrefix.socket','register','sendStatus','end','status','json','offset','undefined','limit','set','Content-Range','reject','update','get','VoicePrefixes','UserProfileResource','then','error','stack','send'];(function(_0x4233a2,_0x478e28){var _0x1c420e=function(_0x10b59e){while(--_0x10b59e){_0x4233a2['push'](_0x4233a2['shift']());}};_0x1c420e(++_0x478e28);}(_0x5f66,0x1a0));var _0x65f6=function(_0x432682,_0x253044){_0x432682=_0x432682-0x0;var _0x463d05=_0x5f66[_0x432682];return _0x463d05;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x65f6('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x65f6('0x1'));var rp=require(_0x65f6('0x2'));var moment=require(_0x65f6('0x3'));var BPromise=require(_0x65f6('0x4'));var Mustache=require(_0x65f6('0x5'));var util=require('util');var path=require(_0x65f6('0x6'));var sox=require('sox');var csv=require(_0x65f6('0x7'));var ejs=require(_0x65f6('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x65f6('0x9'));var crypto=require(_0x65f6('0xa'));var jsforce=require(_0x65f6('0xb'));var deskjs=require(_0x65f6('0xc'));var toCsv=require(_0x65f6('0x7'));var querystring=require(_0x65f6('0xd'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x65f6('0xe'));var qs=require(_0x65f6('0xf'));var as=require(_0x65f6('0x10'));var hardwareService=require(_0x65f6('0x11'));var logger=require('../../config/logger')(_0x65f6('0x12'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x65f6('0x13'));var db=require('../../mysqldb')['db'];config[_0x65f6('0x14')]=_['defaults'](config[_0x65f6('0x14')],{'host':_0x65f6('0x15'),'port':0x18eb});var socket=require(_0x65f6('0x16'))(new Redis(config[_0x65f6('0x14')]));require(_0x65f6('0x17'))[_0x65f6('0x18')](socket);function respondWithStatusCode(_0x44144b,_0xb1d40a){_0xb1d40a=_0xb1d40a||0xcc;return function(_0x46dbc6){if(_0x46dbc6){return _0x44144b[_0x65f6('0x19')](_0xb1d40a);}return _0x44144b['status'](_0xb1d40a)[_0x65f6('0x1a')]();};}function respondWithResult(_0x49a913,_0x5dd324){_0x5dd324=_0x5dd324||0xc8;return function(_0x1693e6){if(_0x1693e6){return _0x49a913[_0x65f6('0x1b')](_0x5dd324)[_0x65f6('0x1c')](_0x1693e6);}};}function respondWithFilteredResult(_0x1c955c,_0x1b1cbb){return function(_0x1f974c){if(_0x1f974c){var _0xc8660c=typeof _0x1b1cbb[_0x65f6('0x1d')]==='undefined'&&typeof _0x1b1cbb['limit']===_0x65f6('0x1e');var _0x5b4055=_0x1f974c['count'];var _0x5c5b91=_0xc8660c?0x0:_0x1b1cbb[_0x65f6('0x1d')];var _0x21ea88=_0xc8660c?_0x1f974c['count']:_0x1b1cbb[_0x65f6('0x1d')]+_0x1b1cbb[_0x65f6('0x1f')];var _0xbee6a4;if(_0x21ea88>=_0x5b4055){_0x21ea88=_0x5b4055;_0xbee6a4=0xc8;}else{_0xbee6a4=0xce;}_0x1c955c[_0x65f6('0x1b')](_0xbee6a4);return _0x1c955c[_0x65f6('0x20')](_0x65f6('0x21'),_0x5c5b91+'-'+_0x21ea88+'/'+_0x5b4055)['json'](_0x1f974c);}return null;};}function patchUpdates(_0x197a49){return function(_0x4bb39e){try{jsonpatch['apply'](_0x4bb39e,_0x197a49,!![]);}catch(_0x212247){return BPromise[_0x65f6('0x22')](_0x212247);}return _0x4bb39e['save']();};}function saveUpdates(_0x1eeaaa,_0x471a33){return function(_0x2317ce){if(_0x2317ce){return _0x2317ce[_0x65f6('0x23')](_0x1eeaaa)['then'](function(_0x9d7bb0){return _0x9d7bb0;});}return null;};}function removeEntity(_0x59ea32,_0x20a161){return function(_0x5963e0){if(_0x5963e0){return _0x5963e0['destroy']()['then'](function(){var _0x29abdb=_0x5963e0[_0x65f6('0x24')]({'plain':!![]});var _0x4b2292=_0x65f6('0x25');return db[_0x65f6('0x26')]['destroy']({'where':{'type':_0x4b2292,'resourceId':_0x29abdb['id']}})[_0x65f6('0x27')](function(){return _0x5963e0;});})[_0x65f6('0x27')](function(){_0x59ea32[_0x65f6('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4ac04b,_0x488d36){return function(_0x266cfe){if(!_0x266cfe){_0x4ac04b[_0x65f6('0x19')](0x194);}return _0x266cfe;};}function handleError(_0x4344b3,_0x408ccc){_0x408ccc=_0x408ccc||0x1f4;return function(_0x518cac){logger[_0x65f6('0x28')](_0x518cac[_0x65f6('0x29')]);if(_0x518cac['name']){delete _0x518cac['name'];}_0x4344b3[_0x65f6('0x1b')](_0x408ccc)[_0x65f6('0x2a')](_0x518cac);};}exports['index']=function(_0x4e50c0,_0x10b368){var _0x1ce43c={},_0x11fe3b={},_0xc53cb7={'count':0x0,'rows':[]};var _0x1217fd=_[_0x65f6('0x2b')](db['VoicePrefix'][_0x65f6('0x2c')],function(_0x38f3c6){return{'name':_0x38f3c6[_0x65f6('0x2d')],'type':_0x38f3c6['type'][_0x65f6('0x2e')]};});_0x11fe3b[_0x65f6('0x2f')]=_[_0x65f6('0x2b')](_0x1217fd,_0x65f6('0x30'));_0x11fe3b[_0x65f6('0x31')]=_[_0x65f6('0x32')](_0x4e50c0['query']);_0x11fe3b[_0x65f6('0x33')]=_[_0x65f6('0x34')](_0x11fe3b['model'],_0x11fe3b[_0x65f6('0x31')]);_0x1ce43c['attributes']=_[_0x65f6('0x34')](_0x11fe3b['model'],qs[_0x65f6('0x35')](_0x4e50c0[_0x65f6('0x31')]['fields']));_0x1ce43c[_0x65f6('0x36')]=_0x1ce43c[_0x65f6('0x36')][_0x65f6('0x37')]?_0x1ce43c['attributes']:_0x11fe3b['model'];if(!_0x4e50c0[_0x65f6('0x31')]['hasOwnProperty'](_0x65f6('0x38'))){_0x1ce43c['limit']=qs[_0x65f6('0x1f')](_0x4e50c0[_0x65f6('0x31')]['limit']);_0x1ce43c[_0x65f6('0x1d')]=qs['offset'](_0x4e50c0['query'][_0x65f6('0x1d')]);}_0x1ce43c[_0x65f6('0x39')]=qs[_0x65f6('0x3a')](_0x4e50c0[_0x65f6('0x31')][_0x65f6('0x3a')]);_0x1ce43c[_0x65f6('0x3b')]=qs[_0x65f6('0x33')](_[_0x65f6('0x3c')](_0x4e50c0['query'],_0x11fe3b[_0x65f6('0x33')]),_0x1217fd);if(_0x4e50c0['query'][_0x65f6('0x3d')]){_0x1ce43c[_0x65f6('0x3b')]=_[_0x65f6('0x3e')](_0x1ce43c[_0x65f6('0x3b')],{'$or':_['map'](_0x1217fd,function(_0x32148f){if(_0x32148f[_0x65f6('0x3f')]!==_0x65f6('0x40')){var _0x3fb1c6={};_0x3fb1c6[_0x32148f[_0x65f6('0x30')]]={'$like':'%'+_0x4e50c0[_0x65f6('0x31')][_0x65f6('0x3d')]+'%'};return _0x3fb1c6;}})});}_0x1ce43c=_[_0x65f6('0x3e')]({},_0x1ce43c,_0x4e50c0[_0x65f6('0x41')]);var _0x5d8e48={'where':_0x1ce43c[_0x65f6('0x3b')]};return db[_0x65f6('0x42')][_0x65f6('0x43')](_0x5d8e48)[_0x65f6('0x27')](function(_0x83e2d9){_0xc53cb7[_0x65f6('0x43')]=_0x83e2d9;if(_0x4e50c0[_0x65f6('0x31')][_0x65f6('0x44')]){_0x1ce43c[_0x65f6('0x45')]=[{'all':!![]}];}return db[_0x65f6('0x42')][_0x65f6('0x46')](_0x1ce43c);})[_0x65f6('0x27')](function(_0x6c4d94){_0xc53cb7[_0x65f6('0x47')]=_0x6c4d94;return _0xc53cb7;})[_0x65f6('0x27')](respondWithFilteredResult(_0x10b368,_0x1ce43c))[_0x65f6('0x48')](handleError(_0x10b368,null));};exports['show']=function(_0x2dd16c,_0x37cd36){var _0x2d8c45={'raw':![],'where':{'id':_0x2dd16c['params']['id']}},_0x3828c9={};_0x3828c9[_0x65f6('0x2f')]=_[_0x65f6('0x32')](db[_0x65f6('0x42')]['rawAttributes']);_0x3828c9[_0x65f6('0x31')]=_[_0x65f6('0x32')](_0x2dd16c[_0x65f6('0x31')]);_0x3828c9[_0x65f6('0x33')]=_['intersection'](_0x3828c9[_0x65f6('0x2f')],_0x3828c9['query']);_0x2d8c45[_0x65f6('0x36')]=_[_0x65f6('0x34')](_0x3828c9['model'],qs[_0x65f6('0x35')](_0x2dd16c['query'][_0x65f6('0x35')]));_0x2d8c45[_0x65f6('0x36')]=_0x2d8c45[_0x65f6('0x36')][_0x65f6('0x37')]?_0x2d8c45[_0x65f6('0x36')]:_0x3828c9[_0x65f6('0x2f')];if(_0x2dd16c['query']['includeAll']){_0x2d8c45[_0x65f6('0x45')]=[{'all':!![]}];}_0x2d8c45=_[_0x65f6('0x3e')]({},_0x2d8c45,_0x2dd16c[_0x65f6('0x41')]);return db[_0x65f6('0x42')][_0x65f6('0x49')](_0x2d8c45)[_0x65f6('0x27')](handleEntityNotFound(_0x37cd36,null))[_0x65f6('0x27')](respondWithResult(_0x37cd36,null))[_0x65f6('0x48')](handleError(_0x37cd36,null));};exports[_0x65f6('0x4a')]=function(_0x517a47,_0x1f16cf){return db[_0x65f6('0x42')][_0x65f6('0x49')]({'where':{'id':_0x517a47['params']['id']}})[_0x65f6('0x27')](handleEntityNotFound(_0x1f16cf,null))[_0x65f6('0x27')](removeEntity(_0x1f16cf,null))['catch'](handleError(_0x1f16cf,null));};exports[_0x65f6('0x4b')]=function(_0x253d52,_0x57eb04){return db[_0x65f6('0x42')]['describe']()[_0x65f6('0x27')](respondWithResult(_0x57eb04,null))[_0x65f6('0x48')](handleError(_0x57eb04,null));};exports[_0x65f6('0x4c')]=function(_0x4b9f0a,_0x1646c5){var _0x43a52e;return db['sequelize'][_0x65f6('0x4d')](function(_0x34312c){return db['VoicePrefix'][_0x65f6('0x4c')](_0x4b9f0a[_0x65f6('0x4e')],{'transaction':_0x34312c})[_0x65f6('0x27')](function(_0x25d504){_0x43a52e=_0x25d504[_0x65f6('0x24')]({'plain':!![]});return db[_0x65f6('0x4f')][_0x65f6('0x49')]({'where':{'id':_0x43a52e[_0x65f6('0x50')]},'raw':!![]})['then'](function(_0x52c5a4){return createVoicePrefixExtensions(_0x43a52e,_0x52c5a4,_0x34312c);});});})['then'](function(){var _0x19f40c=_0x4b9f0a[_0x65f6('0x51')][_0x65f6('0x24')]({'plain':!![]});if(!_0x19f40c)throw new Error(_0x65f6('0x52'));if(_0x19f40c['role']===_0x65f6('0x51')){var _0x2032b9=_0x43a52e;return db[_0x65f6('0x53')]['find']({'where':{'name':_0x65f6('0x25'),'userProfileId':_0x19f40c[_0x65f6('0x54')]},'raw':!![]})[_0x65f6('0x27')](function(_0x4e289e){if(_0x4e289e&&_0x4e289e['autoAssociation']===0x0){return db[_0x65f6('0x26')][_0x65f6('0x4c')]({'name':_0x2032b9[_0x65f6('0x30')],'resourceId':_0x2032b9['id'],'type':_0x4e289e[_0x65f6('0x30')],'sectionId':_0x4e289e['id']},{})[_0x65f6('0x27')](function(){return _0x43a52e;});}else{return _0x43a52e;}})[_0x65f6('0x48')](function(_0x35d77f){logger[_0x65f6('0x28')](_0x65f6('0x55'),_0x35d77f);throw _0x35d77f;});}return _0x43a52e;})[_0x65f6('0x27')](respondWithResult(_0x1646c5,null))[_0x65f6('0x48')](handleError(_0x1646c5,null));};function Extension(_0x141fcc,_0x30adee,_0x3e3143,_0x5ba9c6){this[_0x65f6('0x56')]=_0x65f6('0x57');this[_0x65f6('0x58')]=_0x141fcc;this['app']=_0x3e3143;this[_0x65f6('0x3f')]=_0x65f6('0x59');this[_0x65f6('0x5a')]=_0x65f6('0x5b');this['priority']=_0x30adee;this[_0x65f6('0x5c')]=_0x5ba9c6;}function createVoicePrefixExtensions(_0x4227f5,_0xe5fc65,_0x3e0d8b){return new BPromise(function(_0x553ff0,_0x2923ff){var _0x2fc20f=new Extension(formatPrefixName(_0x4227f5['prefix']),0x1,_0x65f6('0x5d'),_0x65f6('0x5e'));_0x2fc20f[_0x65f6('0x5f')]=_0x4227f5['id'];return db['VoiceExtension'][_0x65f6('0x4c')](_0x2fc20f,{'transaction':_0x3e0d8b})[_0x65f6('0x27')](function(_0x3974ef){var _0x3c23e3=_0x3974ef[_0x65f6('0x24')]({'plain':!![]});var _0x334fa1=_['map'](addVoicePrefixExtensions(_0x4227f5,_0xe5fc65),function(_0x4ee8bd){_0x4ee8bd['VoiceExtensionId']=_0x3c23e3['id'];_0x4ee8bd[_0x65f6('0x5f')]=_0x4227f5['id'];return _0x4ee8bd;});return db[_0x65f6('0x4f')][_0x65f6('0x60')](_0x334fa1,{'transaction':_0x3e0d8b})[_0x65f6('0x27')](function(_0xab6f0){if(!_0xab6f0){return _0x2923ff(_0x65f6('0x61'));}else{return _0x553ff0(_0xab6f0);}})['catch'](function(_0xfbfebc){return _0x2923ff(_0xfbfebc);});});;});};function addVoicePrefixExtensions(_0x1d1532,_0x54b569){var _0x225aeb=[];var _0x39c244=formatPrefixName(_0x1d1532[_0x65f6('0x62')]);_0x225aeb['push'](new Extension(_0x39c244,0x2,_0x65f6('0x63'),_0x65f6('0x64')+_0x1d1532['name']));if(_0x1d1532[_0x65f6('0x65')]){_0x225aeb[_0x65f6('0x66')](new Extension(_0x39c244,0x3,_0x65f6('0x63'),_0x65f6('0x67')+_0x1d1532[_0x65f6('0x65')]));}else{_0x225aeb[_0x65f6('0x66')](new Extension(_0x39c244,0x3,_0x65f6('0x5d'),'No\x20callerid\x20available'));}_0x225aeb['push'](new Extension(_0x39c244,0x4,_0x65f6('0x68'),_0x54b569[_0x65f6('0x56')]+','+'${EXTEN:'+(0x8+_0x1d1532[_0x65f6('0x30')]['length'])+'}'+','+0x1));return _0x225aeb;}function formatPrefixName(_0x3a483b){var _0x4e0450='_';for(var _0x440df1=0x0;_0x440df1<_0x3a483b[_0x65f6('0x37')];_0x440df1++){if(_0x3a483b[_0x65f6('0x69')](_0x440df1)=='-'){_0x4e0450+=_0x3a483b[_0x65f6('0x69')](_0x440df1);}else{_0x4e0450+='['+_0x3a483b[_0x65f6('0x69')](_0x440df1)+']';}}_0x4e0450+='.';return _0x4e0450;}exports[_0x65f6('0x23')]=function(_0x1aaf75,_0x1cc66a,_0x2405a7){var _0x4b7ecd=_0x1aaf75['body'];_0x4b7ecd[_0x65f6('0x62')]=_0x65f6('0x6a')+_0x4b7ecd[_0x65f6('0x30')]+'-';return db['sequelize']['transaction'](function(_0x2dbec2){return db[_0x65f6('0x42')][_0x65f6('0x23')](_0x4b7ecd,{'where':{'id':_0x4b7ecd['id']},'transaction':_0x2dbec2})[_0x65f6('0x27')](function(){return db[_0x65f6('0x4f')][_0x65f6('0x4a')]({'where':{'VoicePrefixId':_0x4b7ecd['id']},'transaction':_0x2dbec2})['then'](function(){return db['VoiceExtension'][_0x65f6('0x49')]({'where':{'id':_0x4b7ecd[_0x65f6('0x50')]},'raw':!![]})['then'](function(_0x219bf8){return createVoicePrefixExtensions(_0x4b7ecd,_0x219bf8,_0x2dbec2);});});});})['then'](function(){return db[_0x65f6('0x42')][_0x65f6('0x6b')](_0x4b7ecd['id']);})[_0x65f6('0x27')](respondWithResult(_0x1cc66a,null))[_0x65f6('0x48')](handleError(_0x1cc66a,null));};exports['addAgents']=function(_0x34ab7b,_0x351d43,_0x11411c){return db['VoicePrefix']['find']({'where':{'id':_0x34ab7b[_0x65f6('0x6c')]['id']}})['then'](handleEntityNotFound(_0x351d43,null))[_0x65f6('0x27')](function(_0xf6de){if(_0xf6de){return _0xf6de[_0x65f6('0x6d')](_0x34ab7b[_0x65f6('0x4e')]['ids'],_['omit'](_0x34ab7b['body'],[_0x65f6('0x6e'),'id'])||{})[_0x65f6('0x6f')](function(_0x161fb2){for(var _0x57464e=0x0;_0x57464e<_0x34ab7b[_0x65f6('0x4e')][_0x65f6('0x6e')][_0x65f6('0x37')];_0x57464e+=0x1){socket['emit'](_0x65f6('0x70'),{'UserId':Number(_0x34ab7b[_0x65f6('0x4e')]['ids'][_0x57464e]),'VoicePrefixId':Number(_0x34ab7b[_0x65f6('0x6c')]['id'])});}return _0x161fb2;});}})[_0x65f6('0x27')](respondWithResult(_0x351d43,null))['catch'](handleError(_0x351d43,null));};exports[_0x65f6('0x71')]=function(_0x5ef825,_0xe8449b,_0x55ea91){return db[_0x65f6('0x42')][_0x65f6('0x49')]({'where':{'id':_0x5ef825['params']['id']}})[_0x65f6('0x27')](handleEntityNotFound(_0xe8449b,null))[_0x65f6('0x27')](function(_0x2a700b){if(_0x2a700b){return _0x2a700b[_0x65f6('0x71')](_0x5ef825[_0x65f6('0x31')][_0x65f6('0x6e')])[_0x65f6('0x27')](function(){if(_[_0x65f6('0x72')](_0x5ef825[_0x65f6('0x31')][_0x65f6('0x6e')])){for(var _0x288eb0=0x0;_0x288eb0<_0x5ef825['query'][_0x65f6('0x6e')][_0x65f6('0x37')];_0x288eb0+=0x1){socket[_0x65f6('0x73')](_0x65f6('0x74'),{'UserId':Number(_0x5ef825['query'][_0x65f6('0x6e')][_0x288eb0]),'VoicePrefixId':Number(_0x5ef825[_0x65f6('0x6c')]['id'])});}}else{socket['emit'](_0x65f6('0x74'),{'UserId':Number(_0x5ef825['query'][_0x65f6('0x6e')]),'VoicePrefixId':Number(_0x5ef825['params']['id'])});}});}})[_0x65f6('0x27')](respondWithStatusCode(_0xe8449b,null))[_0x65f6('0x48')](handleError(_0xe8449b,null));};exports['getAgents']=function(_0x4946c7,_0xa4a742,_0x413c21){var _0x5158c9={};var _0x2d86c8={};var _0x3b3bd5;var _0x73d359;return db['VoicePrefix'][_0x65f6('0x75')]({'where':{'id':_0x4946c7[_0x65f6('0x6c')]['id']}})['then'](handleEntityNotFound(_0xa4a742,null))[_0x65f6('0x27')](function(_0x504b39){if(_0x504b39){_0x3b3bd5=_0x504b39;_0x2d86c8[_0x65f6('0x2f')]=_['keys'](db['User'][_0x65f6('0x2c')]);_0x2d86c8[_0x65f6('0x31')]=_[_0x65f6('0x32')](_0x4946c7[_0x65f6('0x31')]);_0x2d86c8[_0x65f6('0x33')]=_[_0x65f6('0x34')](_0x2d86c8[_0x65f6('0x2f')],_0x2d86c8[_0x65f6('0x31')]);_0x5158c9['attributes']=_['intersection'](_0x2d86c8[_0x65f6('0x2f')],qs['fields'](_0x4946c7[_0x65f6('0x31')][_0x65f6('0x35')]));_0x5158c9[_0x65f6('0x36')]=_0x5158c9[_0x65f6('0x36')][_0x65f6('0x37')]?_0x5158c9['attributes']:_0x2d86c8[_0x65f6('0x2f')];_0x5158c9[_0x65f6('0x39')]=qs[_0x65f6('0x3a')](_0x4946c7['query'][_0x65f6('0x3a')]);_0x5158c9[_0x65f6('0x3b')]=qs[_0x65f6('0x33')](_[_0x65f6('0x3c')](_0x4946c7[_0x65f6('0x31')],_0x2d86c8[_0x65f6('0x33')]));if(_0x4946c7['query']['filter']){_0x5158c9[_0x65f6('0x3b')]=_[_0x65f6('0x3e')](_0x5158c9[_0x65f6('0x3b')],{'$or':_[_0x65f6('0x2b')](_0x5158c9['attributes'],function(_0x4bda86){var _0x336076={};_0x336076[_0x4bda86]={'$like':'%'+_0x4946c7[_0x65f6('0x31')][_0x65f6('0x3d')]+'%'};return _0x336076;})});}_0x5158c9=_[_0x65f6('0x3e')]({},_0x5158c9,_0x4946c7[_0x65f6('0x41')]);return _0x3b3bd5[_0x65f6('0x76')](_0x5158c9);}})['then'](function(_0x4d607a){if(_0x4d607a){_0x73d359=_0x4d607a['length'];if(!_0x4946c7[_0x65f6('0x31')][_0x65f6('0x77')](_0x65f6('0x38'))){_0x5158c9[_0x65f6('0x1f')]=qs['limit'](_0x4946c7['query'][_0x65f6('0x1f')]);_0x5158c9[_0x65f6('0x1d')]=qs['offset'](_0x4946c7[_0x65f6('0x31')]['offset']);}return _0x3b3bd5[_0x65f6('0x76')](_0x5158c9);}})['then'](function(_0x3a30ed){if(_0x3a30ed){return _0x3a30ed?{'count':_0x73d359,'rows':_0x3a30ed}:null;}})[_0x65f6('0x27')](respondWithResult(_0xa4a742,null))['catch'](handleError(_0xa4a742,null));};exports[_0x65f6('0x78')]=function(_0x330e18,_0x13c03b,_0x9f6e0c){var _0xec6a56={};var _0x144db0={};var _0x584ea4;var _0x45b3e6;return db['VoicePrefix'][_0x65f6('0x75')]({'where':{'id':_0x330e18['params']['id']}})[_0x65f6('0x27')](handleEntityNotFound(_0x13c03b,null))[_0x65f6('0x27')](function(_0xdf396c){if(_0xdf396c){_0x584ea4=_0xdf396c;_0x144db0[_0x65f6('0x2f')]=_['keys'](db[_0x65f6('0x79')][_0x65f6('0x2c')]);_0x144db0[_0x65f6('0x31')]=_['keys'](_0x330e18['query']);_0x144db0[_0x65f6('0x33')]=_[_0x65f6('0x34')](_0x144db0['model'],_0x144db0[_0x65f6('0x31')]);_0xec6a56[_0x65f6('0x36')]=_[_0x65f6('0x34')](_0x144db0['model'],qs[_0x65f6('0x35')](_0x330e18[_0x65f6('0x31')]['fields']));_0xec6a56[_0x65f6('0x36')]=_0xec6a56[_0x65f6('0x36')][_0x65f6('0x37')]?_0xec6a56['attributes']:_0x144db0[_0x65f6('0x2f')];_0xec6a56[_0x65f6('0x39')]=qs[_0x65f6('0x3a')](_0x330e18['query'][_0x65f6('0x3a')]);_0xec6a56['where']=qs[_0x65f6('0x33')](_[_0x65f6('0x3c')](_0x330e18[_0x65f6('0x31')],_0x144db0[_0x65f6('0x33')]));if(_0x330e18[_0x65f6('0x31')][_0x65f6('0x3d')]){_0xec6a56['where']=_[_0x65f6('0x3e')](_0xec6a56[_0x65f6('0x3b')],{'$or':_[_0x65f6('0x2b')](_0xec6a56[_0x65f6('0x36')],function(_0x207d15){var _0x59407d={};_0x59407d[_0x207d15]={'$like':'%'+_0x330e18['query']['filter']+'%'};return _0x59407d;})});}_0xec6a56=_[_0x65f6('0x3e')]({},_0xec6a56,_0x330e18[_0x65f6('0x41')]);return _0x584ea4[_0x65f6('0x78')](_0xec6a56);}})['then'](function(_0x151cee){if(_0x151cee){_0x45b3e6=_0x151cee['length'];if(!_0x330e18['query'][_0x65f6('0x77')](_0x65f6('0x38'))){_0xec6a56['limit']=qs[_0x65f6('0x1f')](_0x330e18[_0x65f6('0x31')][_0x65f6('0x1f')]);_0xec6a56[_0x65f6('0x1d')]=qs[_0x65f6('0x1d')](_0x330e18[_0x65f6('0x31')][_0x65f6('0x1d')]);}return _0x584ea4[_0x65f6('0x78')](_0xec6a56);}})[_0x65f6('0x27')](function(_0x350641){if(_0x350641){return _0x350641?{'count':_0x45b3e6,'rows':_0x350641}:null;}})[_0x65f6('0x27')](respondWithResult(_0x13c03b,null))[_0x65f6('0x48')](handleError(_0x13c03b,null));};exports['addTeams']=function(_0x349af7,_0x52dc75,_0x55355f){var _0x24d524=_0x349af7[_0x65f6('0x4e')][_0x65f6('0x6e')];var _0x3727f9;return db['Team'][_0x65f6('0x46')]({'where':{'id':_0x24d524},'attributes':['id'],'include':[{'model':db['User'],'as':'Agents','attributes':['id',_0x65f6('0x30'),_0x65f6('0x7a'),_0x65f6('0x7b'),_0x65f6('0x7c')],'raw':!![]}]})[_0x65f6('0x27')](function(_0xcdfebe){if(_0xcdfebe){_0x3727f9=_0xcdfebe;var _0x5a33cf=_[_0x65f6('0x7d')](_0xcdfebe,function(_0x56bf49){var _0x1ef2a0=_0x56bf49[_0x65f6('0x24')]({'plain':!![]});return _0x1ef2a0[_0x65f6('0x7e')];});return db['VoicePrefix'][_0x65f6('0x49')]({'where':{'id':_0x349af7['params']['id']}})['then'](function(_0x377d5e){return db[_0x65f6('0x7f')][_0x65f6('0x4d')](function(_0xf364a9){return _0x377d5e[_0x65f6('0x80')](_0x24d524,{'transaction':_0xf364a9})['then'](function(){return BPromise[_0x65f6('0x81')](_0x3727f9,function(_0x400633){return db[_0x65f6('0x82')][_0x65f6('0x83')]({'TeamId':_0x400633['id'],'VoicePrefixId':_0x349af7['params']['id']},{'transaction':_0xf364a9});});})[_0x65f6('0x27')](function(){return BPromise[_0x65f6('0x81')](_0x5a33cf,function(_0x344163){return db[_0x65f6('0x84')][_0x65f6('0x85')]({'where':{'UserId':_0x344163['id'],'VoicePrefixId':_0x349af7[_0x65f6('0x6c')]['id']},'transaction':_0xf364a9});});})[_0x65f6('0x27')](function(){_0x5a33cf[_0x65f6('0x86')](function(_0x558410){socket[_0x65f6('0x73')](_0x65f6('0x70'),{'UserId':_0x558410['id'],'VoicePrefixId':_0x377d5e['id']});});});});});}})[_0x65f6('0x27')](respondWithStatusCode(_0x52dc75,null))[_0x65f6('0x48')](handleError(_0x52dc75,null));};exports[_0x65f6('0x87')]=function(_0x4171a1,_0x57667e,_0x3fd6ee){return db[_0x65f6('0x79')]['findAll']({'where':{'id':_0x4171a1[_0x65f6('0x31')]['ids']},'attributes':['id'],'include':[{'model':db[_0x65f6('0x88')],'as':_0x65f6('0x7e'),'attributes':['id'],'raw':!![]}]})[_0x65f6('0x27')](handleEntityNotFound(_0x57667e,null))[_0x65f6('0x27')](function(_0x2177f1){var _0x55c9bd=_[_0x65f6('0x2b')](_0x2177f1,'id');var _0x395642=[];var _0x2394eb=[];var _0x31870f=squel[_0x65f6('0x89')]();_0x31870f['field']('tq.TeamId')[_0x65f6('0x8a')](_0x65f6('0x8b'),'tq')[_0x65f6('0x8c')](_0x65f6('0x8d'),'ut','ut.TeamId\x20=\x20tq.TeamId')['where']('VoicePrefixId\x20=\x20?',_0x4171a1[_0x65f6('0x6c')]['id']);for(var _0x3b0a97=0x0;_0x3b0a97<_0x2177f1[_0x65f6('0x37')];_0x3b0a97+=0x1){let _0x50e159=_0x2177f1[_0x3b0a97];for(var _0x12730b=0x0;_0x12730b<_0x50e159[_0x65f6('0x7e')][_0x65f6('0x37')];_0x12730b+=0x1){let _0x18c6a8=_0x50e159[_0x65f6('0x7e')][_0x12730b];var _0x54e258=_0x31870f[_0x65f6('0x8e')]();_0x54e258[_0x65f6('0x3b')]('ut.UserId\x20=\x20?',_0x18c6a8['id']);_0x2394eb['push'](db[_0x65f6('0x7f')][_0x65f6('0x31')](_0x54e258[_0x65f6('0x8f')](),{'type':db[_0x65f6('0x7f')][_0x65f6('0x90')]['SELECT']})[_0x65f6('0x27')](function(_0x4b080a){if(_0x4b080a[_0x65f6('0x37')]===0x1){return _0x18c6a8['id'];}else{var _0x5d181a=_[_0x65f6('0x91')](_['map'](_0x4b080a,_0x65f6('0x92')),function(_0x48a9df){return _[_0x65f6('0x93')](_0x55c9bd,_0x48a9df);});if(_0x5d181a){return _0x18c6a8['id'];}}}));}}return BPromise[_0x65f6('0x94')](_0x2394eb)['then'](function(_0x4f2f43){_0x395642=_(_0x395642)[_0x65f6('0x95')](_0x4f2f43)[_0x65f6('0x96')]()[_0x65f6('0x97')]();return db[_0x65f6('0x42')][_0x65f6('0x49')]({'where':{'id':_0x4171a1[_0x65f6('0x6c')]['id']}})[_0x65f6('0x27')](function(_0x1b5957){return db[_0x65f6('0x7f')][_0x65f6('0x4d')](function(_0x4a90e3){return _0x1b5957[_0x65f6('0x87')](_0x4171a1[_0x65f6('0x31')][_0x65f6('0x6e')],{'transaction':_0x4a90e3})[_0x65f6('0x27')](function(){if(!_[_0x65f6('0x98')](_0x395642)){return _0x1b5957[_0x65f6('0x71')](_0x395642,{'transaction':_0x4a90e3});}})['then'](function(){_0x395642[_0x65f6('0x86')](function(_0x91d7bf){socket[_0x65f6('0x73')](_0x65f6('0x74'),{'UserId':_0x91d7bf,'VoicePrefixId':_0x1b5957['id']});});});});});});})[_0x65f6('0x27')](respondWithStatusCode(_0x57667e,null))[_0x65f6('0x48')](handleError(_0x57667e,null));};