Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / api / user / user.rpc.js
index c9f6900..3bbd5c3 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x659c=['include','model','attributes','GetUser','ShowUser','User','find','PauseUser','name','role','interface','UserVoiceQueueRt','MemberReport','findAll','PAUSE','YYYY-MM-DD\x20HH:mm:ss','length','updateAttributes','getChannels','forEach','push','isNil','format','SIP/%s','body','type','DEFAULT\x20PAUSE','internal','uniqueid','update','UnpauseUser','findOne','channel','Unknown\x20channel','voice','system','mail','chat','fax','sms','openchannel','whatsapp','set','%s%s','Pause','all','LogoutUser','LoginUser','loginInPause','count','../../config/license/util','getLicense','agents','Maximum\x20login\x20has\x20been\x20reached','destroy','getVoiceQueues','UserVoiceQueue.penalty','merge','LOGIN','callysquare','LOGININPAUSE','bulkCreate','lodash','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/environment','jayson/promise','client','http','redis','defaults','socket.io-emitter','request','then','User,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','info','result','catch','options','raw','where','limit','map'];(function(_0xc74b25,_0x4e6a58){var _0x4e9b9d=function(_0x382b1a){while(--_0x382b1a){_0xc74b25['push'](_0xc74b25['shift']());}};_0x4e9b9d(++_0x4e6a58);}(_0x659c,0x1aa));var _0xc659=function(_0x280f4a,_0x2ed8d6){_0x280f4a=_0x280f4a-0x0;var _0x1bb157=_0x659c[_0x280f4a];return _0x1bb157;};'use strict';var _=require(_0xc659('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0xc659('0x1'));var rs=require(_0xc659('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xc659('0x3'))['db'];var utils=require(_0xc659('0x4'));var logger=require('../../config/logger')('rpc');var config=require(_0xc659('0x5'));var jayson=require(_0xc659('0x6'));var client=jayson[_0xc659('0x7')][_0xc659('0x8')]({'port':0x232a});config[_0xc659('0x9')]=_[_0xc659('0xa')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xc659('0xb'))(new Redis(config['redis']));require('./user.socket')['register'](socket);function respondWithRpcPromise(_0x29a052,_0x2ea975,_0x422e00){return new BPromise(function(_0x35a046,_0x3f6f5a){return client[_0xc659('0xc')](_0x29a052,_0x422e00)[_0xc659('0xd')](function(_0x4267f3){logger['info'](_0xc659('0xe'),_0x2ea975,_0xc659('0xf'));logger[_0xc659('0x10')]('User,\x20%s,\x20%s,\x20%s',_0x2ea975,'request\x20sent',JSON[_0xc659('0x11')](_0x4267f3));if(_0x4267f3[_0xc659('0x12')]){if(_0x4267f3['error'][_0xc659('0x13')]===0x1f4){logger[_0xc659('0x12')](_0xc659('0xe'),_0x2ea975,_0x4267f3[_0xc659('0x12')][_0xc659('0x14')]);return _0x3f6f5a(_0x4267f3[_0xc659('0x12')][_0xc659('0x14')]);}logger[_0xc659('0x12')](_0xc659('0xe'),_0x2ea975,_0x4267f3[_0xc659('0x12')]['message']);return _0x35a046(_0x4267f3[_0xc659('0x12')][_0xc659('0x14')]);}else{logger[_0xc659('0x15')](_0xc659('0xe'),_0x2ea975,_0xc659('0xf'));_0x35a046(_0x4267f3[_0xc659('0x16')]['message']);}})[_0xc659('0x17')](function(_0x33e118){logger[_0xc659('0x12')]('User,\x20%s,\x20%s',_0x2ea975,_0x33e118);_0x3f6f5a(_0x33e118);});});}exports['GetUser']=function(_0x163064){var _0x6af6f9=this;return new Promise(function(_0x48be52,_0x463dc1){return db['User']['findAll']({'raw':_0x163064['options']?_0x163064[_0xc659('0x18')][_0xc659('0x19')]===undefined?!![]:![]:!![],'where':_0x163064[_0xc659('0x18')]?_0x163064[_0xc659('0x18')][_0xc659('0x1a')]||null:null,'attributes':_0x163064[_0xc659('0x18')]?_0x163064['options']['attributes']||null:null,'limit':_0x163064['options']?_0x163064[_0xc659('0x18')][_0xc659('0x1b')]||null:null,'include':_0x163064['options']?_0x163064[_0xc659('0x18')]['include']?_[_0xc659('0x1c')](_0x163064[_0xc659('0x18')][_0xc659('0x1d')],function(_0x36e194){return{'model':db[_0x36e194[_0xc659('0x1e')]],'as':_0x36e194['as'],'attributes':_0x36e194[_0xc659('0x1f')],'include':_0x36e194[_0xc659('0x1d')]?_[_0xc659('0x1c')](_0x36e194[_0xc659('0x1d')],function(_0x27efe0){return{'model':db[_0x27efe0[_0xc659('0x1e')]],'as':_0x27efe0['as'],'attributes':_0x27efe0[_0xc659('0x1f')],'include':_0x27efe0['include']?_[_0xc659('0x1c')](_0x27efe0[_0xc659('0x1d')],function(_0x5deee1){return{'model':db[_0x5deee1['model']],'as':_0x5deee1['as'],'attributes':_0x5deee1[_0xc659('0x1f')]};}):[]};}):[]};}):[]:[]})[_0xc659('0xd')](function(_0x2770d6){logger[_0xc659('0x15')]('GetUser',_0x163064);logger[_0xc659('0x10')](_0xc659('0x20'),_0x163064,JSON[_0xc659('0x11')](_0x2770d6));_0x48be52(_0x2770d6);})['catch'](function(_0x39eec1){logger[_0xc659('0x12')]('GetUser',_0x39eec1['message'],_0x163064);_0x463dc1(_0x6af6f9[_0xc659('0x12')](0x1f4,_0x39eec1['message']));});});};exports[_0xc659('0x21')]=function(_0x290c99){var _0x55dca5=this;return new Promise(function(_0x5181bb,_0x1e1dd0){return db[_0xc659('0x22')][_0xc659('0x23')]({'raw':_0x290c99['options']?_0x290c99[_0xc659('0x18')][_0xc659('0x19')]===undefined?!![]:![]:!![],'where':_0x290c99['options']?_0x290c99[_0xc659('0x18')]['where']||null:null,'attributes':_0x290c99[_0xc659('0x18')]?_0x290c99['options'][_0xc659('0x1f')]||null:null,'include':_0x290c99['options']?_0x290c99[_0xc659('0x18')][_0xc659('0x1d')]?_[_0xc659('0x1c')](_0x290c99[_0xc659('0x18')][_0xc659('0x1d')],function(_0x2596f1){return{'model':db[_0x2596f1[_0xc659('0x1e')]],'as':_0x2596f1['as'],'attributes':_0x2596f1[_0xc659('0x1f')],'include':_0x2596f1[_0xc659('0x1d')]?_[_0xc659('0x1c')](_0x2596f1['include'],function(_0x54b04c){return{'model':db[_0x54b04c[_0xc659('0x1e')]],'as':_0x54b04c['as'],'attributes':_0x54b04c[_0xc659('0x1f')],'include':_0x54b04c[_0xc659('0x1d')]?_['map'](_0x54b04c[_0xc659('0x1d')],function(_0x20d36d){return{'model':db[_0x20d36d[_0xc659('0x1e')]],'as':_0x20d36d['as'],'attributes':_0x20d36d[_0xc659('0x1f')]};}):[]};}):[]};}):[]:[]})[_0xc659('0xd')](function(_0x82c490){logger['info']('ShowUser',_0x290c99);logger[_0xc659('0x10')](_0xc659('0x21'),_0x290c99,JSON[_0xc659('0x11')](_0x82c490));_0x5181bb(_0x82c490);})['catch'](function(_0x286843){logger['error']('ShowUser',_0x286843[_0xc659('0x14')],_0x290c99);_0x1e1dd0(_0x55dca5[_0xc659('0x12')](0x1f4,_0x286843[_0xc659('0x14')]));});});};exports[_0xc659('0x24')]=function(_0xbc35d2){var _0x29c249=this;return new Promise(function(_0x5f4fbd,_0x2dfa9c){var _0x2cb6f2;return db[_0xc659('0x22')][_0xc659('0x23')]({'where':_0xbc35d2[_0xc659('0x18')]['where']||{},'attributes':['id',_0xc659('0x25'),_0xc659('0x26'),'internal',_0xc659('0x27')]})['then'](function(_0x5a97e6){if(_0x5a97e6){_0x2cb6f2=_0x5a97e6;return db[_0xc659('0x28')]['update']({'paused':0x1},{'where':{'UserId':_0x2cb6f2['id']},'individualHooks':!![]});}})[_0xc659('0xd')](function(){if(_0x2cb6f2){return db[_0xc659('0x29')][_0xc659('0x2a')]({'where':{'membername':_0x2cb6f2[_0xc659('0x25')],'type':_0xc659('0x2b'),'exitAt':null}});}})['then'](function(_0x3bb7e4){if(_0x2cb6f2){if(_0x3bb7e4&&_0x3bb7e4['length']){var _0x4b799b=moment()['format'](_0xc659('0x2c'));for(var _0x268194=0x0,_0x3a27e2=_0x3bb7e4[_0xc659('0x2d')];_0x268194<_0x3a27e2;_0x268194++){_0x3bb7e4[_0x268194][_0xc659('0x2e')]({'exitAt':_0x4b799b});}}}})[_0xc659('0xd')](function(){if(_0x2cb6f2){var _0x4c80df=[];var _0x2a53bf=utils[_0xc659('0x2f')]();_0x2a53bf[_0xc659('0x30')](function(_0x5b6933){_0x4c80df[_0xc659('0x31')]({'channel':_0x5b6933,'membername':_0x2cb6f2[_0xc659('0x25')],'interface':_[_0xc659('0x32')](_0x2cb6f2['interface'])?util[_0xc659('0x33')](_0xc659('0x34'),_0x2cb6f2[_0xc659('0x25')]):_0x2cb6f2[_0xc659('0x27')],'type':'PAUSE','enterAt':moment()[_0xc659('0x33')](_0xc659('0x2c')),'data1':_0xbc35d2[_0xc659('0x35')][_0xc659('0x36')]||_0xc659('0x37'),'role':_0x2cb6f2[_0xc659('0x26')],'internal':_0x2cb6f2[_0xc659('0x38')],'uniqueid':_0xbc35d2[_0xc659('0x35')][_0xc659('0x39')]||null});});return db[_0xc659('0x29')]['bulkCreate'](_0x4c80df,{'individualHooks':!![]});}})['then'](function(){if(_0x2cb6f2){return _0x2cb6f2[_0xc659('0x3a')]({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'whatsappPause':!![],'pauseType':_0xbc35d2[_0xc659('0x35')][_0xc659('0x36')]||_0xc659('0x37'),'lastPauseAt':moment()[_0xc659('0x33')](_0xc659('0x2c'))});}})['then'](function(_0x45f65c){_0x5f4fbd(_0x45f65c);})[_0xc659('0x17')](function(_0x2f1ac2){_0x2dfa9c(_0x29c249[_0xc659('0x12')](0x1f4,_0x2f1ac2['message']));});});};exports[_0xc659('0x3b')]=function(_0x5bc99f){var _0x1bd163=this;return new Promise(function(_0x4298b1,_0x1b09c3){var _0x108fd2;return db[_0xc659('0x22')][_0xc659('0x3c')]({'where':_0x5bc99f[_0xc659('0x18')][_0xc659('0x1a')]||{},'attributes':['id',_0xc659('0x25')]})['then'](function(_0x30e545){if(_0x30e545){_0x108fd2=_0x30e545;if(_0x5bc99f[_0xc659('0x35')][_0xc659('0x3d')]&&!utils['isValidChannel'](_0x5bc99f[_0xc659('0x35')][_0xc659('0x3d')])){throw new Error(_0xc659('0x3e'));}switch(_0x5bc99f[_0xc659('0x35')][_0xc659('0x3d')]){case _0xc659('0x3f'):return db[_0xc659('0x28')][_0xc659('0x3a')]({'paused':0x0},{'where':{'UserId':_0x108fd2['id']}})[_0xc659('0xd')](function(){return db['MemberReport'][_0xc659('0x23')]({'where':{'channel':_0x5bc99f['body'][_0xc659('0x3d')],'membername':_0x108fd2[_0xc659('0x25')],'type':_0xc659('0x2b'),'exitAt':null}});})[_0xc659('0xd')](function(_0x27908c){if(_0x27908c){return _0x27908c[_0xc659('0x3a')]({'exitAt':moment()[_0xc659('0x33')](_0xc659('0x2c')),'data2':_0xc659('0x40')},{'individualHooks':!![]});}return null;})['then'](function(){return _0x108fd2[_0xc659('0x3a')]({'voicePause':![]});});case _0xc659('0x41'):case _0xc659('0x42'):case _0xc659('0x43'):case _0xc659('0x44'):case _0xc659('0x45'):case _0xc659('0x46'):return db[_0xc659('0x29')][_0xc659('0x23')]({'where':{'channel':_0x5bc99f[_0xc659('0x35')][_0xc659('0x3d')],'membername':_0x108fd2[_0xc659('0x25')],'type':'PAUSE','exitAt':null}})[_0xc659('0xd')](function(_0x3c7c8f){return _0x3c7c8f['update']({'exitAt':moment()[_0xc659('0x33')](_0xc659('0x2c')),'data2':_0xc659('0x40')},{'individualHooks':!![]});})[_0xc659('0xd')](function(){var _0x3fbb29={};_[_0xc659('0x47')](_0x3fbb29,util[_0xc659('0x33')](_0xc659('0x48'),_0x5bc99f[_0xc659('0x35')]['channel'],_0xc659('0x49')),![]);return _0x108fd2[_0xc659('0x3a')](_0x3fbb29);});default:return db[_0xc659('0x28')]['update']({'paused':0x0},{'where':{'UserId':_0x108fd2['id']}})[_0xc659('0xd')](function(){return db[_0xc659('0x29')][_0xc659('0x2a')]({'where':{'membername':_0x108fd2[_0xc659('0x25')],'type':_0xc659('0x2b'),'exitAt':null}});})[_0xc659('0xd')](function(_0x296163){var _0x539b4f=[];_0x296163[_0xc659('0x30')](function(_0x1bd6eb){_0x539b4f[_0xc659('0x31')](_0x1bd6eb['update']({'exitAt':moment()[_0xc659('0x33')](_0xc659('0x2c')),'data2':_0xc659('0x40')}));});return BPromise[_0xc659('0x4a')](_0x539b4f);})[_0xc659('0xd')](function(){return _0x108fd2['update']({'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![],'whatsappPause':![]});});}}})[_0xc659('0xd')](function(_0x4ce242){_0x4298b1(_0x4ce242);})[_0xc659('0x17')](function(_0x31033f){_0x1b09c3(_0x1bd163[_0xc659('0x12')](0x1f4,_0x31033f[_0xc659('0x14')]));});});};exports[_0xc659('0x4b')]=function(_0x1c6127){var _0x34b10f=this;return new Promise(function(_0x3cb663,_0x437118){var _0xb31f2d;return db[_0xc659('0x22')][_0xc659('0x3c')]({'where':_0x1c6127[_0xc659('0x18')][_0xc659('0x1a')]||{},'attributes':['id',_0xc659('0x25')]})[_0xc659('0xd')](function(_0x4e117b){if(_0x4e117b){_0xb31f2d=_0x4e117b;return db[_0xc659('0x28')]['destroy']({'where':{'membername':_0xb31f2d[_0xc659('0x25')]},'individualHooks':!![]});}})[_0xc659('0xd')](function(){if(_0xb31f2d){return db[_0xc659('0x29')][_0xc659('0x2a')]({'where':{'membername':_0xb31f2d[_0xc659('0x25')],'exitAt':null}});}})[_0xc659('0xd')](function(_0x58ddbb){if(_0xb31f2d){if(_0x58ddbb&&_0x58ddbb[_0xc659('0x2d')]){var _0x1b4e6b=[];_0x58ddbb[_0xc659('0x30')](function(_0x23b577){_0x1b4e6b[_0xc659('0x31')](_0x23b577[_0xc659('0x3a')]({'exitAt':moment()['format'](_0xc659('0x2c'))}));});return BPromise[_0xc659('0x4a')](_0x1b4e6b);}}})[_0xc659('0xd')](function(){if(_0xb31f2d){return _0xb31f2d['update']({'online':![],'lastLoginAt':null,'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})[_0xc659('0xd')](function(_0x186e8f){_0x3cb663(_0x186e8f);})['catch'](function(_0x3b58f7){_0x437118(_0x34b10f[_0xc659('0x12')](0x1f4,_0x3b58f7[_0xc659('0x14')]));});});};exports[_0xc659('0x4c')]=function(_0x1ff5ab){var _0x1be4be=this;return new Promise(function(_0x40f32d,_0x5386d5){var _0x3b3067;var _0x2a6ed9;var _0x483767;var _0x840b5f;return db['User'][_0xc659('0x3c')]({'where':_0x1ff5ab[_0xc659('0x18')]['where']||{},'attributes':['id',_0xc659('0x25'),_0xc659('0x26'),'mobile','phone',_0xc659('0x38'),_0xc659('0x4d'),_0xc659('0x27')]})[_0xc659('0xd')](function(_0x2ab917){if(_0x2ab917){_0x3b3067=_0x2ab917;_0x840b5f=_0x1ff5ab[_0xc659('0x35')]['interface']?_0x1ff5ab['body']['interface']:util[_0xc659('0x33')](_0xc659('0x34'),_0x3b3067[_0xc659('0x25')]);return db[_0xc659('0x22')][_0xc659('0x4e')]({'where':{'role':'agent','online':!![],'id':{'$ne':_0x3b3067['id']}}});}})[_0xc659('0xd')](function(_0x561848){if(_0x561848){_0x483767=_0x561848;return require(_0xc659('0x4f'))[_0xc659('0x50')]();}})[_0xc659('0xd')](function(_0x2e8bd6){if(_0x2e8bd6&&_0x2e8bd6[_0xc659('0x51')]&&_0x483767>=_0x2e8bd6[_0xc659('0x51')]){throw new Error(_0xc659('0x52'));}})['then'](function(){if(_0x3b3067){return db['UserVoiceQueueRt'][_0xc659('0x53')]({'where':{'membername':_0x3b3067['name']},'individualHooks':!![]});}})['then'](function(){if(_0x3b3067){return _0x3b3067[_0xc659('0x54')]({'raw':!![]});}})[_0xc659('0xd')](function(_0x42dc6f){if(_0x3b3067){if(_0x42dc6f){var _0x1938a7=[];_0x2a6ed9=_0x42dc6f;if(_0x2a6ed9[_0xc659('0x2d')]){for(var _0x340ee4=0x0;_0x340ee4<_0x2a6ed9[_0xc659('0x2d')];_0x340ee4++){_0x1938a7['push'](db[_0xc659('0x28')]['upsert']({'membername':_0x3b3067[_0xc659('0x25')],'UserId':_0x3b3067['id'],'queue_name':_0x2a6ed9[_0x340ee4][_0xc659('0x25')],'VoiceQueueId':_0x2a6ed9[_0x340ee4]['id'],'interface':_0x840b5f,'paused':_0x3b3067[_0xc659('0x4d')]||![],'penalty':_0x2a6ed9[_0x340ee4][_0xc659('0x55')]||0x0}));}return BPromise[_0xc659('0x4a')](_0x1938a7);}}}})['then'](function(){if(_0x3b3067){return db[_0xc659('0x29')][_0xc659('0x2a')]({'where':{'membername':_0x3b3067[_0xc659('0x25')],'exitAt':null}});}})[_0xc659('0xd')](function(_0x230a0f){if(_0x3b3067){if(_0x230a0f&&_0x230a0f[_0xc659('0x2d')]){var _0x30addf=[];_0x230a0f[_0xc659('0x30')](function(_0x30094c){_0x30addf[_0xc659('0x31')](_0x30094c[_0xc659('0x3a')]({'exitAt':moment()[_0xc659('0x33')](_0xc659('0x2c'))}));});return BPromise['all'](_0x30addf);}}})[_0xc659('0xd')](function(_0x54f4b1){if(_0x3b3067){var _0x58f229=[];var _0x5c1edf=[];var _0x3d32d0=utils[_0xc659('0x2f')]();var _0x598571={'membername':_0x3b3067[_0xc659('0x25')],'interface':_0x840b5f,'enterAt':moment()[_0xc659('0x33')](_0xc659('0x2c')),'role':_0x3b3067[_0xc659('0x26')],'internal':_0x3b3067[_0xc659('0x38')]};_0x3d32d0[_0xc659('0x30')](function(_0x382041){_0x58f229[_0xc659('0x31')](_[_0xc659('0x56')]({'channel':_0x382041,'type':_0xc659('0x57'),'data1':_0xc659('0x58'),'data2':_0x840b5f},_0x598571));if(_0x3b3067[_0xc659('0x4d')]){_0x5c1edf['push'](_[_0xc659('0x56')]({'channel':_0x382041,'type':'PAUSE','data1':_0xc659('0x59')},_0x598571));}});return db[_0xc659('0x29')][_0xc659('0x5a')](_0x58f229['concat'](_0x5c1edf),{'individualHooks':!![]});}})[_0xc659('0xd')](function(){if(_0x3b3067){return _0x3b3067[_0xc659('0x3a')]({'online':!![],'lastLoginAt':moment()[_0xc659('0x33')]('YYYY-MM-DD\x20HH:mm:ss'),'voicePause':_0x3b3067[_0xc659('0x4d')]||![],'mailPause':_0x3b3067[_0xc659('0x4d')]||![],'chatPause':_0x3b3067[_0xc659('0x4d')]||![],'faxPause':_0x3b3067[_0xc659('0x4d')]||![],'smsPause':_0x3b3067['loginInPause']||![],'openchannelPause':_0x3b3067[_0xc659('0x4d')]||![],'pauseType':_0x3b3067[_0xc659('0x4d')]?_0xc659('0x59'):null,'lastPauseAt':moment()[_0xc659('0x33')](_0xc659('0x2c')),'interface':_0x840b5f});}})[_0xc659('0xd')](function(_0x36901c){_0x40f32d(_0x36901c);})[_0xc659('0x17')](function(_0x5b894b){_0x5386d5(_0x1be4be['error'](0x1f4,_0x5b894b['message']));});});};
\ No newline at end of file
+var _0xedd3=['mailPause','chatPause','faxPause','openchannelPause','pauseType','lastPauseAt','system','LogoutUser','findOne','destroy','LoginUser','mobile','loginInPause','count','agent','../../config/license/util','getLicense','agents','Maximum\x20login\x20has\x20been\x20reached','getVoiceQueues','upsert','UserVoiceQueue.penalty','all','forEach','merge','LOGIN','callysquare','concat','lodash','util','moment','bluebird','../../mysqldb','../../config/utils','../../config/logger','rpc','defaults','redis','localhost','socket.io-emitter','./user.socket','register','User','findAll','options','raw','where','limit','include','attributes','map','model','then','info','GetUser','debug','error','find','ShowUser','stringify','message','name','interface','User\x20with\x20id\x20%s\x20not\x20found','params','UserVoiceQueueRt','update','MemberReport','PAUSE','length','format','YYYY-MM-DD\x20HH:mm:ss','updateAttributes','getChannels','push','SIP/%s','body','type','DEFAULT\x20PAUSE','role','internal','uniqueid','catch','resolve','channel','isValidChannel','online','voicePause'];(function(_0x499f8c,_0x5a332c){var _0x5a630c=function(_0x161ec1){while(--_0x161ec1){_0x499f8c['push'](_0x499f8c['shift']());}};_0x5a630c(++_0x5a332c);}(_0xedd3,0x74));var _0x3edd=function(_0x4d613c,_0x55f220){_0x4d613c=_0x4d613c-0x0;var _0x301fe3=_0xedd3[_0x4d613c];return _0x301fe3;};'use strict';var _=require(_0x3edd('0x0'));var util=require(_0x3edd('0x1'));var moment=require(_0x3edd('0x2'));var BPromise=require(_0x3edd('0x3'));var Redis=require('ioredis');var db=require(_0x3edd('0x4'))['db'];var utils=require(_0x3edd('0x5'));var logger=require(_0x3edd('0x6'))(_0x3edd('0x7'));var config=require('../../config/environment');config['redis']=_[_0x3edd('0x8')](config[_0x3edd('0x9')],{'host':_0x3edd('0xa'),'port':0x18eb});var socket=require(_0x3edd('0xb'))(new Redis(config[_0x3edd('0x9')]));require(_0x3edd('0xc'))[_0x3edd('0xd')](socket);exports['GetUser']=function(_0x1e8e58){var _0x5272ec=this;return new Promise(function(_0x1f5735,_0x247dd7){return db[_0x3edd('0xe')][_0x3edd('0xf')]({'raw':_0x1e8e58[_0x3edd('0x10')]?_0x1e8e58[_0x3edd('0x10')][_0x3edd('0x11')]===undefined?!![]:![]:!![],'where':_0x1e8e58[_0x3edd('0x10')]?_0x1e8e58[_0x3edd('0x10')][_0x3edd('0x12')]||null:null,'attributes':_0x1e8e58[_0x3edd('0x10')]?_0x1e8e58['options']['attributes']||null:null,'limit':_0x1e8e58[_0x3edd('0x10')]?_0x1e8e58[_0x3edd('0x10')][_0x3edd('0x13')]||null:null,'include':_0x1e8e58[_0x3edd('0x10')]?_0x1e8e58[_0x3edd('0x10')]['include']?_['map'](_0x1e8e58[_0x3edd('0x10')][_0x3edd('0x14')],function(_0x7eb48b){return{'model':db[_0x7eb48b['model']],'as':_0x7eb48b['as'],'attributes':_0x7eb48b[_0x3edd('0x15')],'include':_0x7eb48b[_0x3edd('0x14')]?_[_0x3edd('0x16')](_0x7eb48b[_0x3edd('0x14')],function(_0x33878d){return{'model':db[_0x33878d['model']],'as':_0x33878d['as'],'attributes':_0x33878d[_0x3edd('0x15')],'include':_0x33878d['include']?_[_0x3edd('0x16')](_0x33878d[_0x3edd('0x14')],function(_0x5b2b98){return{'model':db[_0x5b2b98[_0x3edd('0x17')]],'as':_0x5b2b98['as'],'attributes':_0x5b2b98[_0x3edd('0x15')]};}):[]};}):[]};}):[]:[]})[_0x3edd('0x18')](function(_0x370858){logger[_0x3edd('0x19')](_0x3edd('0x1a'),_0x1e8e58);logger[_0x3edd('0x1b')](_0x3edd('0x1a'),_0x1e8e58,JSON['stringify'](_0x370858));_0x1f5735(_0x370858);})['catch'](function(_0x56e54a){logger['error'](_0x3edd('0x1a'),_0x56e54a['message'],_0x1e8e58);_0x247dd7(_0x5272ec[_0x3edd('0x1c')](0x1f4,_0x56e54a['message']));});});};exports['ShowUser']=function(_0x1cfba5){var _0x34dab2=this;return new Promise(function(_0x1cf4b1,_0x4a88ab){return db[_0x3edd('0xe')][_0x3edd('0x1d')]({'raw':_0x1cfba5[_0x3edd('0x10')]?_0x1cfba5['options'][_0x3edd('0x11')]===undefined?!![]:![]:!![],'where':_0x1cfba5['options']?_0x1cfba5[_0x3edd('0x10')][_0x3edd('0x12')]||null:null,'attributes':_0x1cfba5[_0x3edd('0x10')]?_0x1cfba5['options'][_0x3edd('0x15')]||null:null,'include':_0x1cfba5[_0x3edd('0x10')]?_0x1cfba5[_0x3edd('0x10')][_0x3edd('0x14')]?_[_0x3edd('0x16')](_0x1cfba5['options'][_0x3edd('0x14')],function(_0xd0a34d){return{'model':db[_0xd0a34d[_0x3edd('0x17')]],'as':_0xd0a34d['as'],'attributes':_0xd0a34d[_0x3edd('0x15')],'include':_0xd0a34d[_0x3edd('0x14')]?_[_0x3edd('0x16')](_0xd0a34d['include'],function(_0x34c49c){return{'model':db[_0x34c49c['model']],'as':_0x34c49c['as'],'attributes':_0x34c49c[_0x3edd('0x15')],'include':_0x34c49c[_0x3edd('0x14')]?_[_0x3edd('0x16')](_0x34c49c[_0x3edd('0x14')],function(_0x1827cd){return{'model':db[_0x1827cd[_0x3edd('0x17')]],'as':_0x1827cd['as'],'attributes':_0x1827cd['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x4f9ca8){logger[_0x3edd('0x19')](_0x3edd('0x1e'),_0x1cfba5);logger[_0x3edd('0x1b')](_0x3edd('0x1e'),_0x1cfba5,JSON[_0x3edd('0x1f')](_0x4f9ca8));_0x1cf4b1(_0x4f9ca8);})['catch'](function(_0x391b79){logger[_0x3edd('0x1c')](_0x3edd('0x1e'),_0x391b79[_0x3edd('0x20')],_0x1cfba5);_0x4a88ab(_0x34dab2[_0x3edd('0x1c')](0x1f4,_0x391b79[_0x3edd('0x20')]));});});};exports['PauseUser']=function(_0x447223){var _0x20b70c;return db[_0x3edd('0xe')]['find']({'where':_0x447223[_0x3edd('0x10')]['where']||{},'attributes':['id',_0x3edd('0x21'),'role','internal',_0x3edd('0x22')]})[_0x3edd('0x18')](function(_0x18e001){if(!_0x18e001){throw new Error(util['format'](_0x3edd('0x23'),_0x447223[_0x3edd('0x24')]['id']));}_0x20b70c=_0x18e001;return db[_0x3edd('0x25')][_0x3edd('0x26')]({'paused':0x1},{'where':{'UserId':_0x20b70c['id']},'individualHooks':!![]});})['then'](function(){return db[_0x3edd('0x27')][_0x3edd('0xf')]({'where':{'membername':_0x20b70c[_0x3edd('0x21')],'type':_0x3edd('0x28'),'exitAt':null}});})['then'](function(_0x244e68){if(_0x244e68&&_0x244e68[_0x3edd('0x29')]){var _0x3ac693=moment()[_0x3edd('0x2a')](_0x3edd('0x2b'));for(var _0x3674e6=0x0,_0x1637fb=_0x244e68[_0x3edd('0x29')];_0x3674e6<_0x1637fb;_0x3674e6++){_0x244e68[_0x3674e6][_0x3edd('0x2c')]({'exitAt':_0x3ac693});}}})[_0x3edd('0x18')](function(){var _0x339ab3=[];var _0x5afb6d=utils[_0x3edd('0x2d')]();_0x5afb6d['forEach'](function(_0x3b99ca){_0x339ab3[_0x3edd('0x2e')]({'channel':_0x3b99ca,'membername':_0x20b70c['name'],'interface':_['isNil'](_0x20b70c[_0x3edd('0x22')])?util[_0x3edd('0x2a')](_0x3edd('0x2f'),_0x20b70c[_0x3edd('0x21')]):_0x20b70c[_0x3edd('0x22')],'type':_0x3edd('0x28'),'enterAt':moment()[_0x3edd('0x2a')]('YYYY-MM-DD\x20HH:mm:ss'),'data1':_0x447223[_0x3edd('0x30')][_0x3edd('0x31')]||_0x3edd('0x32'),'role':_0x20b70c[_0x3edd('0x33')],'internal':_0x20b70c[_0x3edd('0x34')],'uniqueid':_0x447223[_0x3edd('0x30')][_0x3edd('0x35')]||null});});return db[_0x3edd('0x27')]['bulkCreate'](_0x339ab3,{'individualHooks':!![]});})[_0x3edd('0x18')](function(){return _0x20b70c[_0x3edd('0x26')]({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'whatsappPause':!![],'pauseType':_0x447223[_0x3edd('0x30')][_0x3edd('0x31')]||'DEFAULT\x20PAUSE','lastPauseAt':moment()[_0x3edd('0x2a')](_0x3edd('0x2b'))});})[_0x3edd('0x36')](function(_0x2ab1e2){throw _0x2ab1e2;});};exports['UnpauseUser']=function(_0xc55857){return Promise[_0x3edd('0x37')]()[_0x3edd('0x18')](function(){if(_0xc55857[_0x3edd('0x30')][_0x3edd('0x38')]&&!utils[_0x3edd('0x39')](_0xc55857['body'][_0x3edd('0x38')])){throw new Error(util['format']('Channel\x20parameter\x20%s\x20is\x20invalid',_0xc55857['body'][_0x3edd('0x38')]));}return db[_0x3edd('0xe')]['findOne']({'where':_0xc55857[_0x3edd('0x10')][_0x3edd('0x12')]||{},'attributes':['id',_0x3edd('0x21'),_0x3edd('0x33'),_0x3edd('0x34'),'interface',_0x3edd('0x3a'),_0x3edd('0x3b'),_0x3edd('0x3c'),_0x3edd('0x3d'),_0x3edd('0x3e'),_0x3edd('0x3f'),'smsPause','whatsappPause',_0x3edd('0x40'),_0x3edd('0x41')]});})['then'](function(_0x48abe3){if(!_0x48abe3){throw new Error(util[_0x3edd('0x2a')]('User\x20with\x20id\x20%s\x20not\x20found',_0xc55857[_0x3edd('0x24')]['id']));}return _0x48abe3['unpause'](_0xc55857[_0x3edd('0x30')][_0x3edd('0x38')],_0x3edd('0x42'));})[_0x3edd('0x36')](function(_0x27aba8){throw _0x27aba8;});};exports[_0x3edd('0x43')]=function(_0x30a7cf){var _0x5f2e6b=this;return new Promise(function(_0x211d81,_0x1e115d){var _0x5126cb;return db['User'][_0x3edd('0x44')]({'where':_0x30a7cf[_0x3edd('0x10')][_0x3edd('0x12')]||{},'attributes':['id',_0x3edd('0x21')]})[_0x3edd('0x18')](function(_0x1ba97f){if(_0x1ba97f){_0x5126cb=_0x1ba97f;return db[_0x3edd('0x25')][_0x3edd('0x45')]({'where':{'membername':_0x5126cb[_0x3edd('0x21')]},'individualHooks':!![]});}})[_0x3edd('0x18')](function(){if(_0x5126cb){return db[_0x3edd('0x27')]['findAll']({'where':{'membername':_0x5126cb[_0x3edd('0x21')],'exitAt':null}});}})[_0x3edd('0x18')](function(_0x4ec501){if(_0x5126cb){if(_0x4ec501&&_0x4ec501[_0x3edd('0x29')]){var _0x2fc8a4=[];_0x4ec501['forEach'](function(_0x2c809e){_0x2fc8a4[_0x3edd('0x2e')](_0x2c809e[_0x3edd('0x26')]({'exitAt':moment()['format'](_0x3edd('0x2b'))}));});return BPromise['all'](_0x2fc8a4);}}})[_0x3edd('0x18')](function(){if(_0x5126cb){return _0x5126cb[_0x3edd('0x26')]({'online':![],'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})[_0x3edd('0x18')](function(_0x2c018c){_0x211d81(_0x2c018c);})['catch'](function(_0x3b078d){_0x1e115d(_0x5f2e6b['error'](0x1f4,_0x3b078d[_0x3edd('0x20')]));});});};exports[_0x3edd('0x46')]=function(_0x1965f2){var _0x4d1a28=this;return new Promise(function(_0x28f2af,_0x313eea){var _0x1e6976;var _0xa4a4da;var _0xd0be45;var _0x7dff7;return db[_0x3edd('0xe')]['findOne']({'where':_0x1965f2[_0x3edd('0x10')][_0x3edd('0x12')]||{},'attributes':['id',_0x3edd('0x21'),_0x3edd('0x33'),_0x3edd('0x47'),'phone','internal',_0x3edd('0x48'),_0x3edd('0x22')]})[_0x3edd('0x18')](function(_0x599ce0){if(_0x599ce0){_0x1e6976=_0x599ce0;_0x7dff7=_0x1965f2[_0x3edd('0x30')][_0x3edd('0x22')]?_0x1965f2[_0x3edd('0x30')][_0x3edd('0x22')]:util[_0x3edd('0x2a')](_0x3edd('0x2f'),_0x1e6976['name']);return db[_0x3edd('0xe')][_0x3edd('0x49')]({'where':{'role':_0x3edd('0x4a'),'online':!![],'id':{'$ne':_0x1e6976['id']}}});}})['then'](function(_0xcb440){if(_0xcb440){_0xd0be45=_0xcb440;return require(_0x3edd('0x4b'))[_0x3edd('0x4c')]();}})[_0x3edd('0x18')](function(_0x2b1160){if(_0x2b1160&&_0x2b1160[_0x3edd('0x4d')]&&_0xd0be45>=_0x2b1160['agents']){throw new Error(_0x3edd('0x4e'));}})[_0x3edd('0x18')](function(){if(_0x1e6976){return db['UserVoiceQueueRt'][_0x3edd('0x45')]({'where':{'membername':_0x1e6976[_0x3edd('0x21')]},'individualHooks':!![]});}})['then'](function(){if(_0x1e6976){return _0x1e6976[_0x3edd('0x4f')]({'raw':!![]});}})['then'](function(_0x4333d3){if(_0x1e6976){if(_0x4333d3){var _0x4fe1d2=[];_0xa4a4da=_0x4333d3;if(_0xa4a4da['length']){for(var _0x2b2f6c=0x0;_0x2b2f6c<_0xa4a4da[_0x3edd('0x29')];_0x2b2f6c++){_0x4fe1d2[_0x3edd('0x2e')](db['UserVoiceQueueRt'][_0x3edd('0x50')]({'membername':_0x1e6976['name'],'UserId':_0x1e6976['id'],'queue_name':_0xa4a4da[_0x2b2f6c][_0x3edd('0x21')],'VoiceQueueId':_0xa4a4da[_0x2b2f6c]['id'],'interface':_0x7dff7,'paused':_0x1e6976[_0x3edd('0x48')]||![],'penalty':_0xa4a4da[_0x2b2f6c][_0x3edd('0x51')]||0x0}));}return BPromise[_0x3edd('0x52')](_0x4fe1d2);}}}})[_0x3edd('0x18')](function(){if(_0x1e6976){return db[_0x3edd('0x27')][_0x3edd('0xf')]({'where':{'membername':_0x1e6976[_0x3edd('0x21')],'exitAt':null}});}})[_0x3edd('0x18')](function(_0x3dbf4e){if(_0x1e6976){if(_0x3dbf4e&&_0x3dbf4e[_0x3edd('0x29')]){var _0x2e8371=[];_0x3dbf4e[_0x3edd('0x53')](function(_0x798b04){_0x2e8371['push'](_0x798b04[_0x3edd('0x26')]({'exitAt':moment()['format'](_0x3edd('0x2b'))}));});return BPromise['all'](_0x2e8371);}}})['then'](function(){if(_0x1e6976){var _0xf5c0ca=[];var _0x2d157=[];var _0x40a2c6=utils['getChannels']();var _0x2f6898={'membername':_0x1e6976[_0x3edd('0x21')],'interface':_0x7dff7,'enterAt':moment()[_0x3edd('0x2a')](_0x3edd('0x2b')),'role':_0x1e6976[_0x3edd('0x33')],'internal':_0x1e6976['internal']};_0x40a2c6[_0x3edd('0x53')](function(_0x202e95){_0xf5c0ca[_0x3edd('0x2e')](_[_0x3edd('0x54')]({'channel':_0x202e95,'type':_0x3edd('0x55'),'data1':_0x3edd('0x56'),'data2':_0x7dff7},_0x2f6898));if(_0x1e6976['loginInPause']){_0x2d157[_0x3edd('0x2e')](_[_0x3edd('0x54')]({'channel':_0x202e95,'type':'PAUSE','data1':'LOGININPAUSE'},_0x2f6898));}});return db[_0x3edd('0x27')]['bulkCreate'](_0xf5c0ca[_0x3edd('0x57')](_0x2d157),{'individualHooks':!![]});}})[_0x3edd('0x18')](function(){if(_0x1e6976){return _0x1e6976[_0x3edd('0x26')]({'online':!![],'lastLoginAt':moment()['format'](_0x3edd('0x2b')),'voicePause':_0x1e6976['loginInPause']||![],'mailPause':_0x1e6976[_0x3edd('0x48')]||![],'chatPause':_0x1e6976['loginInPause']||![],'faxPause':_0x1e6976['loginInPause']||![],'smsPause':_0x1e6976[_0x3edd('0x48')]||![],'openchannelPause':_0x1e6976['loginInPause']||![],'pauseType':_0x1e6976[_0x3edd('0x48')]?'LOGININPAUSE':null,'lastPauseAt':moment()[_0x3edd('0x2a')](_0x3edd('0x2b')),'interface':_0x7dff7});}})['then'](function(_0x9bece4){_0x28f2af(_0x9bece4);})[_0x3edd('0x36')](function(_0x4cc3b9){_0x313eea(_0x4d1a28[_0x3edd('0x1c')](0x1f4,_0x4cc3b9['message']));});});};
\ No newline at end of file