19f234dd42dec72eaa33d7333acfcdefcf6b0b51
[motion-next.git] / server / api / faxAccount / faxAccount.rpc.js
1 const a189_0x52c2=['create','mapKey','findAll','FaxAccount,\x20%s,\x20%s','result','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','then','unmanaged','FaxAccount,\x20%s,\x20%s,\x20%s','limit','../../rediscache','FaxApplication','options','UserId','Contact\x20not\x20found','ListId','raw','*,*,*,*','from','stringify','client','includes','push','List','ContactId','Contacts','updatedAt','unshift','isNil','include','CmContact','error','../../mysqldb','created','message','applications','get','attributes','request','CmList','FaxAccount','list','./faxAccount.socket','findOne','Applications','jayson/promise','name','where','catch','difference','defaults','no\x20available\x20attributes','NotifyFaxAccount','length','interaction','code','map','register','Start','debug','orderBy','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','account','close','sequelize','http','User','from\x20is\x20mandatory','body','asc','../../config/logger','priority','FaxMessage','keys','waitForTheAssignedAgent','request\x20sent','createdAt','fax','startRouting','model','DESC','GetFaxAccount','FaxInteraction'];(function(_0x59fa25,_0x52c281){const _0xeaa481=function(_0x13e41f){while(--_0x13e41f){_0x59fa25['push'](_0x59fa25['shift']());}};_0xeaa481(++_0x52c281);}(a189_0x52c2,0x114));const a189_0xeaa4=function(_0x59fa25,_0x52c281){_0x59fa25=_0x59fa25-0x0;let _0xeaa481=a189_0x52c2[_0x59fa25];return _0xeaa481;};const _0x1e1b8a=a189_0xeaa4;'use strict';const _=require('lodash'),db=require(_0x1e1b8a('0x5'))['db'],{ValidationError}=require(_0x1e1b8a('0x25')),logger=require(_0x1e1b8a('0x2b'))('rpc'),{getSocket}=require(_0x1e1b8a('0x42')),socket=getSocket(),jayson=require(_0x1e1b8a('0x12')),client=jayson[_0x1e1b8a('0x4c')][_0x1e1b8a('0x26')]({'port':0x232c});require(_0x1e1b8a('0xf'))[_0x1e1b8a('0x1e')](socket);function respondWithRpcPromise(_0x13e41f,_0x440711,_0x16ffaa){return new Promise(function(_0x97ffee,_0x33ecd7){const _0x2c3f15=a189_0xeaa4;return client[_0x2c3f15('0xb')](_0x13e41f,_0x16ffaa)[_0x2c3f15('0x3e')](function(_0x12e407){const _0x268cbc=_0x2c3f15;logger['info'](_0x268cbc('0x3b'),_0x440711,_0x268cbc('0x30')),logger[_0x268cbc('0x20')](_0x268cbc('0x40'),_0x440711,_0x268cbc('0x30'),JSON[_0x268cbc('0x4b')](_0x12e407));if(_0x12e407[_0x268cbc('0x4')]){if(_0x12e407['error'][_0x268cbc('0x1c')]===0x1f4)return logger['error'](_0x268cbc('0x3b'),_0x440711,_0x12e407[_0x268cbc('0x4')][_0x268cbc('0x7')]),_0x33ecd7(_0x12e407[_0x268cbc('0x4')]['message']);return logger[_0x268cbc('0x4')](_0x268cbc('0x3b'),_0x440711,_0x12e407[_0x268cbc('0x4')][_0x268cbc('0x7')]),_0x97ffee(_0x12e407[_0x268cbc('0x4')][_0x268cbc('0x7')]);}else logger['info'](_0x268cbc('0x3b'),_0x440711,_0x268cbc('0x30')),_0x97ffee(_0x12e407[_0x268cbc('0x3c')][_0x268cbc('0x7')]);})['catch'](function(_0x193e76){const _0x1b3088=_0x2c3f15;logger[_0x1b3088('0x4')](_0x1b3088('0x3b'),_0x440711,_0x193e76),_0x33ecd7(_0x193e76);});});}exports[_0x1e1b8a('0x36')]=function(_0x2d7bc7){const _0x40da33=this;return new Promise(function(_0x4a8594,_0x230789){const _0x19a959=a189_0xeaa4;return db['FaxAccount'][_0x19a959('0x3a')]({'raw':_0x2d7bc7[_0x19a959('0x44')]?_0x2d7bc7['options'][_0x19a959('0x48')]===undefined?!![]:![]:!![],'where':_0x2d7bc7['options']?_0x2d7bc7[_0x19a959('0x44')][_0x19a959('0x14')]||null:null,'attributes':_0x2d7bc7['options']?_0x2d7bc7[_0x19a959('0x44')]['attributes']||null:null,'limit':_0x2d7bc7[_0x19a959('0x44')]?_0x2d7bc7['options'][_0x19a959('0x41')]||null:null,'include':_0x2d7bc7['options']?_0x2d7bc7[_0x19a959('0x44')][_0x19a959('0x2')]?_[_0x19a959('0x1d')](_0x2d7bc7[_0x19a959('0x44')]['include'],function(_0x5c7c84){const _0x2f3e45=_0x19a959;return{'model':db[_0x5c7c84['model']],'as':_0x5c7c84['as'],'attributes':_0x5c7c84['attributes'],'include':_0x5c7c84[_0x2f3e45('0x2')]?_[_0x2f3e45('0x1d')](_0x5c7c84[_0x2f3e45('0x2')],function(_0x5edb68){const _0x216c5d=_0x2f3e45;return{'model':db[_0x5edb68['model']],'as':_0x5edb68['as'],'attributes':_0x5edb68[_0x216c5d('0xa')],'include':_0x5edb68[_0x216c5d('0x2')]?_[_0x216c5d('0x1d')](_0x5edb68[_0x216c5d('0x2')],function(_0x50214c){const _0xed9dbd=_0x216c5d;return{'model':db[_0x50214c[_0xed9dbd('0x34')]],'as':_0x50214c['as'],'attributes':_0x50214c['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x180f43){const _0x52d80a=_0x19a959;logger['info']('GetFaxAccount',_0x2d7bc7),logger[_0x52d80a('0x20')](_0x52d80a('0x36'),_0x2d7bc7,JSON[_0x52d80a('0x4b')](_0x180f43)),_0x4a8594(_0x180f43);})['catch'](function(_0x1b5a0b){const _0x21bf62=_0x19a959;logger[_0x21bf62('0x4')](_0x21bf62('0x36'),_0x1b5a0b['message'],_0x2d7bc7),_0x230789(_0x40da33[_0x21bf62('0x4')](0x1f4,_0x1b5a0b[_0x21bf62('0x7')]));});});},exports[_0x1e1b8a('0x19')]=function(_0x2371a0){const _0xc161c8=this;return new Promise(function(_0x27e304,_0x2daf8f){const _0x1d17d9=a189_0xeaa4,_0x128772={'body':_0x2371a0[_0x1d17d9('0x29')],'channel':'fax'};let _0x1ba2b1=[],_0x223cd4=[];const _0x1916e4={};return db[_0x1d17d9('0x3')]['describe']()[_0x1d17d9('0x3e')](function(_0x1123f1){const _0x20bcd4=_0x1d17d9;if(!_0x1123f1)throw new ValidationError(_0x20bcd4('0x18'));_0x1ba2b1=_[_0x20bcd4('0x16')](_[_0x20bcd4('0x2e')](_0x1123f1),['createdAt','updatedAt']),_0x223cd4=_[_0x20bcd4('0x16')](_[_0x20bcd4('0x2e')](_0x1123f1),[_0x20bcd4('0x31'),_0x20bcd4('0x52'),'CompanyId',_0x20bcd4('0x47')]);_0x2371a0[_0x20bcd4('0x29')]['id']&&delete _0x2371a0[_0x20bcd4('0x29')]['id'];if(_[_0x20bcd4('0x1')](_0x2371a0[_0x20bcd4('0x29')][_0x20bcd4('0x4a')]))throw new ValidationError(_0x20bcd4('0x28'));if(_[_0x20bcd4('0x1')](_0x2371a0[_0x20bcd4('0x29')][_0x20bcd4('0x29')])||_0x2371a0[_0x20bcd4('0x29')][_0x20bcd4('0x29')]==='')throw new ValidationError('body\x20is\x20mandatory\x20and\x20not\x20empty');if(_[_0x20bcd4('0x1')](_0x2371a0[_0x20bcd4('0x29')][_0x20bcd4('0x39')]))throw new ValidationError(_0x20bcd4('0x3d')+_0x223cd4);if(!_[_0x20bcd4('0x4d')](_0x223cd4,_0x2371a0[_0x20bcd4('0x29')]['mapKey']))throw new ValidationError(_0x20bcd4('0x22')+_0x223cd4);_0x1916e4[_0x2371a0[_0x20bcd4('0x29')][_0x20bcd4('0x39')]]=_0x2371a0[_0x20bcd4('0x29')][_0x20bcd4('0x4a')];})[_0x1d17d9('0x3e')](function(){const _0x1cb20b=_0x1d17d9;return db[_0x1cb20b('0xd')][_0x1cb20b('0x10')]({'where':{'id':_0x2371a0[_0x1cb20b('0x23')]['id']},'include':[{'model':db[_0x1cb20b('0xc')],'as':_0x1cb20b('0x4f'),'include':[{'model':db[_0x1cb20b('0x3')],'as':'Contacts','where':_0x1916e4,'limit':0x1,'order':[['updatedAt',_0x1cb20b('0x35')]]}]},{'model':db[_0x1cb20b('0x43')],'as':_0x1cb20b('0x11')}]});})[_0x1d17d9('0x3e')](function(_0x424792){const _0x5a3d51=_0x1d17d9;if(_0x424792&&_0x424792[_0x5a3d51('0x4f')]){const _0x122e73=_0x424792[_0x5a3d51('0x9')]({'plain':!![]});_0x128772['account']=_0x122e73,_0x128772[_0x5a3d51('0x8')]=_0x122e73['Applications'],_0x128772[_0x5a3d51('0xe')]=_0x122e73['List'],_0x128772[_0x5a3d51('0x8')]=_[_0x5a3d51('0x21')](_0x128772[_0x5a3d51('0x8')],[_0x5a3d51('0x2c')],[_0x5a3d51('0x2a')]);_0x128772[_0x5a3d51('0x23')]['Applications']&&delete _0x128772[_0x5a3d51('0x23')][_0x5a3d51('0x11')];if(_0x128772[_0x5a3d51('0x23')][_0x5a3d51('0x4f')]&&_0x128772['account'][_0x5a3d51('0x4f')]['Contacts'][_0x5a3d51('0x1a')])return _0x128772['account'][_0x5a3d51('0x4f')][_0x5a3d51('0x51')][0x0];const _0x4abb84=_[_0x5a3d51('0x17')](_0x2371a0[_0x5a3d51('0x29')],{'firstName':_0x2371a0['body'][_0x5a3d51('0x4a')],'ListId':_0x122e73[_0x5a3d51('0x47')]});return _0x4abb84[_0x2371a0[_0x5a3d51('0x29')][_0x5a3d51('0x39')]]=_0x2371a0[_0x5a3d51('0x29')][_0x5a3d51('0x4a')],db[_0x5a3d51('0x3')][_0x5a3d51('0x38')](_0x4abb84,{'fields':_0x1ba2b1,'raw':!![]});}})[_0x1d17d9('0x3e')](function(_0x5242fa){const _0x138a10=_0x1d17d9;_0x128772['contact']=_0x5242fa;if(_0x5242fa){const _0x3f40b9={'ContactId':_0x5242fa['id'],'FaxAccountId':_0x2371a0[_0x138a10('0x23')]['id'],'fax':_0x5242fa[_0x138a10('0x32')]};return db[_0x138a10('0x37')][_0x138a10('0x10')]({'where':{'ContactId':_0x5242fa['id'],'closed':![],'FaxAccountId':_0x2371a0[_0x138a10('0x23')]['id']}})[_0x138a10('0x3e')](function(_0x183492){const _0x5cbcce=_0x138a10;if(_0x183492)return[_0x183492,![]];return db['FaxInteraction']['create'](_0x3f40b9)[_0x5cbcce('0x3e')](function(_0x433d32){return[_0x433d32,!![]];});});}else throw new Error(_0x138a10('0x46'));})['then'](function([_0x4570be,_0x25464d]){const _0x47e299=_0x1d17d9,_0x28627c=_0x4570be[_0x47e299('0x9')]({'plain':!![]});return _0x25464d?(_0x128772['account']['autoclose']&&_0x128772[_0x47e299('0x8')][_0x47e299('0x4e')]({'id':0x0,'priority':_0x128772[_0x47e299('0x8')][_0x47e299('0x1a')]+0x1,'app':_0x47e299('0x24'),'appdata':_0x47e299('0x3f'),'interval':_0x47e299('0x49')}),_0x28627c[_0x47e299('0x6')]=!![]):_0x28627c[_0x47e299('0x6')]=![],_0x128772[_0x47e299('0x1b')]=_0x28627c,db[_0x47e299('0x2d')][_0x47e299('0x38')]({'body':_0x2371a0['body']['body'],'FaxAccountId':_0x2371a0['account']['id'],'FaxInteractionId':_0x4570be['id'],'direction':'in','ContactId':_0x4570be[_0x47e299('0x50')],'AttachmentId':_0x2371a0[_0x47e299('0x29')]['AttachmentId']});})['then'](function(_0xe42e95){const _0x48b8e6=_0x1d17d9;_0x128772[_0x48b8e6('0x7')]=_0xe42e95;if(_0x128772[_0x48b8e6('0x1b')][_0x48b8e6('0x45')])return db[_0x48b8e6('0x27')][_0x48b8e6('0x10')]({'attributes':['id',_0x48b8e6('0x13')],'where':{'id':_0x128772['interaction'][_0x48b8e6('0x45')]}})[_0x48b8e6('0x3e')](function(_0x2029ef){const _0x4760d9=_0x48b8e6;return _0x2029ef&&_0x128772['applications'][_0x4760d9('0x0')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x2029ef['name']+','+(_0x128772['account'][_0x4760d9('0x2f')]||0xa),'interval':_0x4760d9('0x49')}),respondWithRpcPromise(_0x4760d9('0x1f'),_0x4760d9('0x33'),_0x128772);});return respondWithRpcPromise(_0x48b8e6('0x1f'),'startRouting',_0x128772);})['then'](function(_0x397498){_0x27e304(_0x397498);})[_0x1d17d9('0x15')](function(_0x247be1){const _0x36de7f=_0x1d17d9;_0x2daf8f(_0xc161c8['error'](0x1f4,_0x247be1[_0x36de7f('0x7')]));});});};