Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / api / user / user.rpc.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 _0xcc3b=['ShowUser','PauseUser','find','name','role','internal','interface','format','params','update','MemberReport','findAll','PAUSE','length','getChannels','forEach','SIP/%s','DEFAULT\x20PAUSE','body','uniqueid','bulkCreate','type','YYYY-MM-DD\x20HH:mm:ss','UnpauseUser','channel','isValidChannel','Channel\x20parameter\x20%s\x20is\x20invalid','online','mailPause','chatPause','faxPause','openchannelPause','smsPause','lastPauseAt','User\x20with\x20id\x20%s\x20not\x20found','unpause','system','LogoutUser','findOne','UserVoiceQueueRt','push','all','mobile','phone','loginInPause','count','agent','../../config/license/util','agents','Maximum\x20login\x20has\x20been\x20reached','getVoiceQueues','upsert','LOGIN','callysquare','merge','concat','LOGININPAUSE','lodash','util','moment','bluebird','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','redis','defaults','socket.io-emitter','GetUser','User','options','raw','where','include','map','model','attributes','then','info','debug','stringify','catch','error','message'];(function(_0x262f0d,_0x51e151){var _0x21dc30=function(_0x49857c){while(--_0x49857c){_0x262f0d['push'](_0x262f0d['shift']());}};_0x21dc30(++_0x51e151);}(_0xcc3b,0x138));var _0xbcc3=function(_0x2641f9,_0x26715f){_0x2641f9=_0x2641f9-0x0;var _0x585741=_0xcc3b[_0x2641f9];return _0x585741;};'use strict';var _=require(_0xbcc3('0x0'));var util=require(_0xbcc3('0x1'));var moment=require(_0xbcc3('0x2'));var BPromise=require(_0xbcc3('0x3'));var Redis=require(_0xbcc3('0x4'));var db=require(_0xbcc3('0x5'))['db'];var utils=require(_0xbcc3('0x6'));var logger=require(_0xbcc3('0x7'))(_0xbcc3('0x8'));var config=require('../../config/environment');config[_0xbcc3('0x9')]=_[_0xbcc3('0xa')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xbcc3('0xb'))(new Redis(config[_0xbcc3('0x9')]));require('./user.socket')['register'](socket);exports[_0xbcc3('0xc')]=function(_0x2179b8){var _0x713bf9=this;return new Promise(function(_0x3599df,_0x1cae3c){return db[_0xbcc3('0xd')]['findAll']({'raw':_0x2179b8['options']?_0x2179b8[_0xbcc3('0xe')][_0xbcc3('0xf')]===undefined?!![]:![]:!![],'where':_0x2179b8[_0xbcc3('0xe')]?_0x2179b8[_0xbcc3('0xe')][_0xbcc3('0x10')]||null:null,'attributes':_0x2179b8[_0xbcc3('0xe')]?_0x2179b8[_0xbcc3('0xe')]['attributes']||null:null,'limit':_0x2179b8['options']?_0x2179b8[_0xbcc3('0xe')]['limit']||null:null,'include':_0x2179b8[_0xbcc3('0xe')]?_0x2179b8[_0xbcc3('0xe')][_0xbcc3('0x11')]?_[_0xbcc3('0x12')](_0x2179b8[_0xbcc3('0xe')][_0xbcc3('0x11')],function(_0x21f964){return{'model':db[_0x21f964[_0xbcc3('0x13')]],'as':_0x21f964['as'],'attributes':_0x21f964['attributes'],'include':_0x21f964[_0xbcc3('0x11')]?_['map'](_0x21f964[_0xbcc3('0x11')],function(_0x77b73b){return{'model':db[_0x77b73b[_0xbcc3('0x13')]],'as':_0x77b73b['as'],'attributes':_0x77b73b[_0xbcc3('0x14')],'include':_0x77b73b[_0xbcc3('0x11')]?_['map'](_0x77b73b[_0xbcc3('0x11')],function(_0x4c0abd){return{'model':db[_0x4c0abd[_0xbcc3('0x13')]],'as':_0x4c0abd['as'],'attributes':_0x4c0abd[_0xbcc3('0x14')]};}):[]};}):[]};}):[]:[]})[_0xbcc3('0x15')](function(_0x41cc03){logger[_0xbcc3('0x16')](_0xbcc3('0xc'),_0x2179b8);logger[_0xbcc3('0x17')](_0xbcc3('0xc'),_0x2179b8,JSON[_0xbcc3('0x18')](_0x41cc03));_0x3599df(_0x41cc03);})[_0xbcc3('0x19')](function(_0x516a3d){logger[_0xbcc3('0x1a')](_0xbcc3('0xc'),_0x516a3d['message'],_0x2179b8);_0x1cae3c(_0x713bf9['error'](0x1f4,_0x516a3d[_0xbcc3('0x1b')]));});});};exports['ShowUser']=function(_0xe74801){var _0x5eac6e=this;return new Promise(function(_0x4d02fd,_0x25d513){return db[_0xbcc3('0xd')]['find']({'raw':_0xe74801[_0xbcc3('0xe')]?_0xe74801['options'][_0xbcc3('0xf')]===undefined?!![]:![]:!![],'where':_0xe74801['options']?_0xe74801[_0xbcc3('0xe')][_0xbcc3('0x10')]||null:null,'attributes':_0xe74801[_0xbcc3('0xe')]?_0xe74801['options'][_0xbcc3('0x14')]||null:null,'include':_0xe74801['options']?_0xe74801[_0xbcc3('0xe')][_0xbcc3('0x11')]?_[_0xbcc3('0x12')](_0xe74801[_0xbcc3('0xe')][_0xbcc3('0x11')],function(_0x2cc33f){return{'model':db[_0x2cc33f[_0xbcc3('0x13')]],'as':_0x2cc33f['as'],'attributes':_0x2cc33f[_0xbcc3('0x14')],'include':_0x2cc33f[_0xbcc3('0x11')]?_[_0xbcc3('0x12')](_0x2cc33f[_0xbcc3('0x11')],function(_0x1fd734){return{'model':db[_0x1fd734[_0xbcc3('0x13')]],'as':_0x1fd734['as'],'attributes':_0x1fd734['attributes'],'include':_0x1fd734['include']?_[_0xbcc3('0x12')](_0x1fd734[_0xbcc3('0x11')],function(_0x246f68){return{'model':db[_0x246f68['model']],'as':_0x246f68['as'],'attributes':_0x246f68[_0xbcc3('0x14')]};}):[]};}):[]};}):[]:[]})[_0xbcc3('0x15')](function(_0x31470d){logger[_0xbcc3('0x16')](_0xbcc3('0x1c'),_0xe74801);logger[_0xbcc3('0x17')](_0xbcc3('0x1c'),_0xe74801,JSON['stringify'](_0x31470d));_0x4d02fd(_0x31470d);})['catch'](function(_0x474e3a){logger['error'](_0xbcc3('0x1c'),_0x474e3a[_0xbcc3('0x1b')],_0xe74801);_0x25d513(_0x5eac6e[_0xbcc3('0x1a')](0x1f4,_0x474e3a['message']));});});};exports[_0xbcc3('0x1d')]=function(_0x5e9d40){var _0x405f53;return db[_0xbcc3('0xd')][_0xbcc3('0x1e')]({'where':_0x5e9d40[_0xbcc3('0xe')][_0xbcc3('0x10')]||{},'attributes':['id',_0xbcc3('0x1f'),_0xbcc3('0x20'),_0xbcc3('0x21'),_0xbcc3('0x22')]})[_0xbcc3('0x15')](function(_0x151581){if(!_0x151581){throw new Error(util[_0xbcc3('0x23')]('User\x20with\x20id\x20%s\x20not\x20found',_0x5e9d40[_0xbcc3('0x24')]['id']));}_0x405f53=_0x151581;return db['UserVoiceQueueRt'][_0xbcc3('0x25')]({'paused':0x1},{'where':{'UserId':_0x405f53['id']},'individualHooks':!![]});})[_0xbcc3('0x15')](function(){return db[_0xbcc3('0x26')][_0xbcc3('0x27')]({'where':{'membername':_0x405f53[_0xbcc3('0x1f')],'type':_0xbcc3('0x28'),'exitAt':null}});})['then'](function(_0x31632a){if(_0x31632a&&_0x31632a[_0xbcc3('0x29')]){var _0x210a2c=moment()[_0xbcc3('0x23')]('YYYY-MM-DD\x20HH:mm:ss');for(var _0x524c83=0x0,_0x865b2c=_0x31632a[_0xbcc3('0x29')];_0x524c83<_0x865b2c;_0x524c83++){_0x31632a[_0x524c83]['updateAttributes']({'exitAt':_0x210a2c});}}})['then'](function(){var _0x2db50f=[];var _0x149641=utils[_0xbcc3('0x2a')]();_0x149641[_0xbcc3('0x2b')](function(_0x3f5060){_0x2db50f['push']({'channel':_0x3f5060,'membername':_0x405f53[_0xbcc3('0x1f')],'interface':_['isNil'](_0x405f53[_0xbcc3('0x22')])?util[_0xbcc3('0x23')](_0xbcc3('0x2c'),_0x405f53[_0xbcc3('0x1f')]):_0x405f53[_0xbcc3('0x22')],'type':_0xbcc3('0x28'),'enterAt':moment()[_0xbcc3('0x23')]('YYYY-MM-DD\x20HH:mm:ss'),'data1':_0x5e9d40['body']['type']||_0xbcc3('0x2d'),'role':_0x405f53[_0xbcc3('0x20')],'internal':_0x405f53['internal'],'uniqueid':_0x5e9d40[_0xbcc3('0x2e')][_0xbcc3('0x2f')]||null});});return db[_0xbcc3('0x26')][_0xbcc3('0x30')](_0x2db50f,{'individualHooks':!![]});})['then'](function(){return _0x405f53['update']({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'whatsappPause':!![],'pauseType':_0x5e9d40['body'][_0xbcc3('0x31')]||_0xbcc3('0x2d'),'lastPauseAt':moment()[_0xbcc3('0x23')](_0xbcc3('0x32'))});})['catch'](function(_0x476cf1){throw _0x476cf1;});};exports[_0xbcc3('0x33')]=function(_0x1638e7){return Promise['resolve']()[_0xbcc3('0x15')](function(){if(_0x1638e7[_0xbcc3('0x2e')][_0xbcc3('0x34')]&&!utils[_0xbcc3('0x35')](_0x1638e7[_0xbcc3('0x2e')][_0xbcc3('0x34')])){throw new Error(util[_0xbcc3('0x23')](_0xbcc3('0x36'),_0x1638e7[_0xbcc3('0x2e')][_0xbcc3('0x34')]));}return db[_0xbcc3('0xd')]['findOne']({'where':_0x1638e7['options'][_0xbcc3('0x10')]||{},'attributes':['id',_0xbcc3('0x1f'),_0xbcc3('0x20'),_0xbcc3('0x21'),_0xbcc3('0x22'),_0xbcc3('0x37'),'voicePause',_0xbcc3('0x38'),_0xbcc3('0x39'),_0xbcc3('0x3a'),_0xbcc3('0x3b'),_0xbcc3('0x3c'),'whatsappPause','pauseType',_0xbcc3('0x3d')]});})[_0xbcc3('0x15')](function(_0x59ef0a){if(!_0x59ef0a){throw new Error(util[_0xbcc3('0x23')](_0xbcc3('0x3e'),_0x1638e7[_0xbcc3('0x24')]['id']));}return _0x59ef0a[_0xbcc3('0x3f')](_0x1638e7[_0xbcc3('0x2e')][_0xbcc3('0x34')],_0xbcc3('0x40'));})['catch'](function(_0x14e1d2){throw _0x14e1d2;});};exports[_0xbcc3('0x41')]=function(_0x255e7e){var _0x5cd714=this;return new Promise(function(_0x53c773,_0x37b9bc){var _0xc89cc8;return db[_0xbcc3('0xd')][_0xbcc3('0x42')]({'where':_0x255e7e[_0xbcc3('0xe')][_0xbcc3('0x10')]||{},'attributes':['id','name']})[_0xbcc3('0x15')](function(_0xc890c6){if(_0xc890c6){_0xc89cc8=_0xc890c6;return db[_0xbcc3('0x43')]['destroy']({'where':{'membername':_0xc89cc8[_0xbcc3('0x1f')]},'individualHooks':!![]});}})['then'](function(){if(_0xc89cc8){return db[_0xbcc3('0x26')][_0xbcc3('0x27')]({'where':{'membername':_0xc89cc8[_0xbcc3('0x1f')],'exitAt':null}});}})['then'](function(_0x3c46d8){if(_0xc89cc8){if(_0x3c46d8&&_0x3c46d8[_0xbcc3('0x29')]){var _0x4c50fe=[];_0x3c46d8[_0xbcc3('0x2b')](function(_0x343bef){_0x4c50fe[_0xbcc3('0x44')](_0x343bef[_0xbcc3('0x25')]({'exitAt':moment()[_0xbcc3('0x23')](_0xbcc3('0x32'))}));});return BPromise[_0xbcc3('0x45')](_0x4c50fe);}}})[_0xbcc3('0x15')](function(){if(_0xc89cc8){return _0xc89cc8[_0xbcc3('0x25')]({'online':![],'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})[_0xbcc3('0x15')](function(_0x52e049){_0x53c773(_0x52e049);})['catch'](function(_0x3160b3){_0x37b9bc(_0x5cd714[_0xbcc3('0x1a')](0x1f4,_0x3160b3['message']));});});};exports['LoginUser']=function(_0x129493){var _0x1b0cb9=this;return new Promise(function(_0x1d336a,_0x33e526){var _0x4e06dc;var _0x3149dd;var _0x572b57;var _0x5b0b60;return db[_0xbcc3('0xd')]['findOne']({'where':_0x129493[_0xbcc3('0xe')]['where']||{},'attributes':['id',_0xbcc3('0x1f'),_0xbcc3('0x20'),_0xbcc3('0x46'),_0xbcc3('0x47'),_0xbcc3('0x21'),_0xbcc3('0x48'),_0xbcc3('0x22')]})[_0xbcc3('0x15')](function(_0x3a5e2c){if(_0x3a5e2c){_0x4e06dc=_0x3a5e2c;_0x5b0b60=_0x129493[_0xbcc3('0x2e')][_0xbcc3('0x22')]?_0x129493[_0xbcc3('0x2e')][_0xbcc3('0x22')]:util[_0xbcc3('0x23')](_0xbcc3('0x2c'),_0x4e06dc['name']);return db['User'][_0xbcc3('0x49')]({'where':{'role':_0xbcc3('0x4a'),'online':!![],'id':{'$ne':_0x4e06dc['id']}}});}})[_0xbcc3('0x15')](function(_0x3af28e){if(_0x3af28e){_0x572b57=_0x3af28e;return require(_0xbcc3('0x4b'))['getLicense']();}})[_0xbcc3('0x15')](function(_0x1b1a89){if(_0x1b1a89&&_0x1b1a89[_0xbcc3('0x4c')]&&_0x572b57>=_0x1b1a89[_0xbcc3('0x4c')]){throw new Error(_0xbcc3('0x4d'));}})['then'](function(){if(_0x4e06dc){return db[_0xbcc3('0x43')]['destroy']({'where':{'membername':_0x4e06dc[_0xbcc3('0x1f')]},'individualHooks':!![]});}})[_0xbcc3('0x15')](function(){if(_0x4e06dc){return _0x4e06dc[_0xbcc3('0x4e')]({'raw':!![]});}})[_0xbcc3('0x15')](function(_0x2e95d3){if(_0x4e06dc){if(_0x2e95d3){var _0x2aaaa6=[];_0x3149dd=_0x2e95d3;if(_0x3149dd[_0xbcc3('0x29')]){for(var _0x3918ad=0x0;_0x3918ad<_0x3149dd[_0xbcc3('0x29')];_0x3918ad++){_0x2aaaa6[_0xbcc3('0x44')](db[_0xbcc3('0x43')][_0xbcc3('0x4f')]({'membername':_0x4e06dc[_0xbcc3('0x1f')],'UserId':_0x4e06dc['id'],'queue_name':_0x3149dd[_0x3918ad][_0xbcc3('0x1f')],'VoiceQueueId':_0x3149dd[_0x3918ad]['id'],'interface':_0x5b0b60,'paused':_0x4e06dc[_0xbcc3('0x48')]||![],'penalty':_0x3149dd[_0x3918ad]['UserVoiceQueue.penalty']||0x0}));}return BPromise['all'](_0x2aaaa6);}}}})[_0xbcc3('0x15')](function(){if(_0x4e06dc){return db['MemberReport']['findAll']({'where':{'membername':_0x4e06dc['name'],'exitAt':null}});}})[_0xbcc3('0x15')](function(_0x2f219b){if(_0x4e06dc){if(_0x2f219b&&_0x2f219b[_0xbcc3('0x29')]){var _0x593527=[];_0x2f219b[_0xbcc3('0x2b')](function(_0x4e8b30){_0x593527[_0xbcc3('0x44')](_0x4e8b30['update']({'exitAt':moment()[_0xbcc3('0x23')]('YYYY-MM-DD\x20HH:mm:ss')}));});return BPromise[_0xbcc3('0x45')](_0x593527);}}})[_0xbcc3('0x15')](function(){if(_0x4e06dc){var _0x55151d=[];var _0x2db77e=[];var _0x34de57=utils[_0xbcc3('0x2a')]();var _0x1937f0={'membername':_0x4e06dc['name'],'interface':_0x5b0b60,'enterAt':moment()[_0xbcc3('0x23')]('YYYY-MM-DD\x20HH:mm:ss'),'role':_0x4e06dc[_0xbcc3('0x20')],'internal':_0x4e06dc[_0xbcc3('0x21')]};_0x34de57[_0xbcc3('0x2b')](function(_0x13ba6c){_0x55151d['push'](_['merge']({'channel':_0x13ba6c,'type':_0xbcc3('0x50'),'data1':_0xbcc3('0x51'),'data2':_0x5b0b60},_0x1937f0));if(_0x4e06dc[_0xbcc3('0x48')]){_0x2db77e[_0xbcc3('0x44')](_[_0xbcc3('0x52')]({'channel':_0x13ba6c,'type':_0xbcc3('0x28'),'data1':'LOGININPAUSE'},_0x1937f0));}});return db[_0xbcc3('0x26')][_0xbcc3('0x30')](_0x55151d[_0xbcc3('0x53')](_0x2db77e),{'individualHooks':!![]});}})['then'](function(){if(_0x4e06dc){return _0x4e06dc['update']({'online':!![],'lastLoginAt':moment()[_0xbcc3('0x23')]('YYYY-MM-DD\x20HH:mm:ss'),'voicePause':_0x4e06dc['loginInPause']||![],'mailPause':_0x4e06dc[_0xbcc3('0x48')]||![],'chatPause':_0x4e06dc[_0xbcc3('0x48')]||![],'faxPause':_0x4e06dc[_0xbcc3('0x48')]||![],'smsPause':_0x4e06dc[_0xbcc3('0x48')]||![],'openchannelPause':_0x4e06dc[_0xbcc3('0x48')]||![],'pauseType':_0x4e06dc[_0xbcc3('0x48')]?_0xbcc3('0x54'):null,'lastPauseAt':moment()[_0xbcc3('0x23')](_0xbcc3('0x32')),'interface':_0x5b0b60});}})[_0xbcc3('0x15')](function(_0x104d3a){_0x1d336a(_0x104d3a);})[_0xbcc3('0x19')](function(_0x2202de){_0x33e526(_0x1b0cb9[_0xbcc3('0x1a')](0x1f4,_0x2202de[_0xbcc3('0x1b')]));});});};