ddf3cffa885b4006158702c5097856c18d75c04f
[motion-next.git] / server / api / faxMessage / faxMessage.controller.js
1 const a205_0x1525=['[FAXMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','fields','message','event','channel','VIRTUAL','fax-interactions','FaxAccountId','type','FaxMessage','ContactId','interface','FaxInteraction','catch','/var/opt/motion2/server/files/attachments/%s','FaxMessage,\x20%s,\x20%s,\x20%s','basename','../../config/logger','body','includeAll','rawAttributes','key','stack','offset','moment','Content-Range','register','undefined','util','then','SIP/%s','keys','create','path','error','intersection','get','merge','../../mysqldb','root','model','YYYY-MM-DD\x20HH:mm:ss','filters','download','send','client','sequelize','include','params','reject','result','CmContact','limit','role','sort','update','attributes','Attachment','map','status','read','Contact','server','user','rejectmessage','fieldName','fax','code','debug','interaction','attachments','where','findOne','AttachmentId','nolimit','./faxMessage.socket','request\x20sent','count','accept','[FAXMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','format','like','UserId','options','rows','files','end','findAll','http','manual','stringify','FaxInteractionId','sendStatus','info','request','FaxMessage,\x20%s,\x20%s','query','lodash','isNil','acceptmessage','destroy','AcceptMessage','join','SendFax','name','length','null','EventManager','order','describe','json'];(function(_0x50d6d,_0x1525ae){const _0x14066c=function(_0x489f60){while(--_0x489f60){_0x50d6d['push'](_0x50d6d['shift']());}};_0x14066c(++_0x1525ae);}(a205_0x1525,0x15c));const a205_0x1406=function(_0x50d6d,_0x1525ae){_0x50d6d=_0x50d6d-0x0;let _0x14066c=a205_0x1525[_0x50d6d];return _0x14066c;};const _0x13b4d4=a205_0x1406;'use strict';const moment=require(_0x13b4d4('0x9')),util=require(_0x13b4d4('0xd')),path=require(_0x13b4d4('0x12')),_=require(_0x13b4d4('0x52')),{getSocket}=require('../../rediscache'),socket=getSocket(),qs=require('../../components/parsers/qs'),logger=require(_0x13b4d4('0x2'))('api'),config=require('../../config/environment'),interaction_log=require('../../config/logger')(_0x13b4d4('0x66')),db=require(_0x13b4d4('0x17'))['db'],{Op}=require(_0x13b4d4('0x1f'));require(_0x13b4d4('0x3c'))[_0x13b4d4('0xb')](socket);const jayson=require('jayson/promise'),client=jayson[_0x13b4d4('0x1e')][_0x13b4d4('0x49')]({'port':0x232c}),client9002=jayson[_0x13b4d4('0x1e')]['http']({'port':0x232a});function respondWithRpcPromise(_0x489f60,_0x2ed453,_0x2c6aac,_0x55dbab){return new Promise(function(_0x1b0c87,_0x2a4f8f){const _0x3486a7=a205_0x1406,_0x1b38f7=_0x55dbab||client;return _0x1b38f7[_0x3486a7('0x4f')](_0x489f60,_0x2c6aac)[_0x3486a7('0xe')](function(_0x38a8f4){const _0x4600cf=_0x3486a7;logger['info'](_0x4600cf('0x50'),_0x2ed453,_0x4600cf('0x3d')),logger[_0x4600cf('0x35')](_0x4600cf('0x0'),_0x2ed453,'request\x20sent',JSON[_0x4600cf('0x4b')](_0x38a8f4));if(_0x38a8f4[_0x4600cf('0x13')]){if(_0x38a8f4[_0x4600cf('0x13')][_0x4600cf('0x34')]===0x1f4)return logger[_0x4600cf('0x13')](_0x4600cf('0x50'),_0x2ed453,_0x38a8f4[_0x4600cf('0x13')][_0x4600cf('0x62')]),_0x2a4f8f(_0x38a8f4[_0x4600cf('0x13')][_0x4600cf('0x62')]);return logger['error']('FaxMessage,\x20%s,\x20%s',_0x2ed453,_0x38a8f4[_0x4600cf('0x13')][_0x4600cf('0x62')]),_0x1b0c87(_0x38a8f4[_0x4600cf('0x13')][_0x4600cf('0x62')]);}else logger[_0x4600cf('0x4e')](_0x4600cf('0x50'),_0x2ed453,_0x4600cf('0x3d')),_0x1b0c87(_0x38a8f4[_0x4600cf('0x23')]['message']);})[_0x3486a7('0x6d')](function(_0x5ef23a){const _0x52a252=_0x3486a7;logger[_0x52a252('0x13')]('FaxMessage,\x20%s,\x20%s',_0x2ed453,_0x5ef23a),_0x2a4f8f(_0x5ef23a);});});}function respondWithResult(_0x54a106,_0xfeddaa){return _0xfeddaa=_0xfeddaa||0xc8,function(_0x4f5dc0){const _0x2db554=a205_0x1406;if(_0x4f5dc0)return _0x54a106[_0x2db554('0x2c')](_0xfeddaa)['json'](_0x4f5dc0);};}function respondWithFilteredResult(_0x165ecd,_0x3038f2){return function(_0x4293bb){const _0x29c401=a205_0x1406;if(_0x4293bb){const _0x1e3d40=_0x4293bb['count'],_0x574bb1=_0x3038f2[_0x29c401('0x8')];let _0x3bcf21=_0x3038f2[_0x29c401('0x8')]+_0x3038f2[_0x29c401('0x25')],_0x195a12;return _0x3bcf21>=_0x1e3d40?(_0x3bcf21=_0x1e3d40,_0x195a12=0xc8):_0x195a12=0xce,_0x165ecd[_0x29c401('0x2c')](_0x195a12),_0x165ecd['set'](_0x29c401('0xa'),_0x574bb1+'-'+_0x3bcf21+'/'+_0x1e3d40)[_0x29c401('0x5f')](_0x4293bb);}return null;};}function saveUpdates(_0x5d1265){return function(_0x292322){const _0xfd2f2c=a205_0x1406;if(_0x292322)return _0x292322[_0xfd2f2c('0x28')](_0x5d1265)[_0xfd2f2c('0xe')](function(_0x58e665){return _0x58e665;});return null;};}function removeEntity(_0x1a406d){return function(_0x50525f){const _0x7c817f=a205_0x1406;if(_0x50525f)return _0x50525f[_0x7c817f('0x55')]()[_0x7c817f('0xe')](function(){const _0x3af509=_0x7c817f;_0x1a406d[_0x3af509('0x2c')](0xcc)[_0x3af509('0x47')]();});};}function handleEntityNotFound(_0x26b0bf){return function(_0x395721){const _0x1031a3=a205_0x1406;return!_0x395721&&_0x26b0bf[_0x1031a3('0x4d')](0x194),_0x395721;};}function handleError(_0x494fbf,_0x519ff7){return _0x519ff7=_0x519ff7||0x1f4,function(_0x1828c6){const _0x16cebc=a205_0x1406;logger['error'](_0x1828c6[_0x16cebc('0x7')]),_0x1828c6[_0x16cebc('0x59')]&&delete _0x1828c6[_0x16cebc('0x59')],_0x494fbf[_0x16cebc('0x2c')](_0x519ff7)[_0x16cebc('0x1d')](_0x1828c6);};}exports['index']=function(_0x3ea635,_0x353933){const _0x7b2103=_0x13b4d4;let _0x4a269d={};const _0xd7289c={},_0x496a2f={'count':0x0,'rows':[]},_0x1b1bda=_[_0x7b2103('0x2b')](db[_0x7b2103('0x69')][_0x7b2103('0x5')],function(_0x2bb60d){const _0x2a07fd=_0x7b2103;return{'name':_0x2bb60d[_0x2a07fd('0x32')],'type':_0x2bb60d[_0x2a07fd('0x68')][_0x2a07fd('0x6')]};});_0xd7289c[_0x7b2103('0x19')]=_[_0x7b2103('0x2b')](_0x1b1bda,_0x7b2103('0x59')),_0xd7289c[_0x7b2103('0x51')]=_[_0x7b2103('0x10')](_0x3ea635['query']),_0xd7289c['filters']=_['intersection'](_0xd7289c[_0x7b2103('0x19')],_0xd7289c['query']),_0x4a269d['attributes']=_['intersection'](_0xd7289c[_0x7b2103('0x19')],qs[_0x7b2103('0x61')](_0x3ea635[_0x7b2103('0x51')][_0x7b2103('0x61')])),_0x4a269d[_0x7b2103('0x29')]=_0x4a269d[_0x7b2103('0x29')][_0x7b2103('0x5a')]?_0x4a269d[_0x7b2103('0x29')]:_0xd7289c[_0x7b2103('0x19')];typeof _0x3ea635['query'][_0x7b2103('0x3b')]===_0x7b2103('0xc')&&(_0x4a269d[_0x7b2103('0x25')]=qs[_0x7b2103('0x25')](_0x3ea635[_0x7b2103('0x51')][_0x7b2103('0x25')]),_0x4a269d[_0x7b2103('0x8')]=qs[_0x7b2103('0x8')](_0x3ea635[_0x7b2103('0x51')][_0x7b2103('0x8')]));_0x4a269d[_0x7b2103('0x5d')]=qs[_0x7b2103('0x27')](_0x3ea635[_0x7b2103('0x51')]['sort']),_0x4a269d['where']=qs[_0x7b2103('0x1b')](_['pick'](_0x3ea635[_0x7b2103('0x51')],_0xd7289c['filters']),_0x1b1bda);_0x3ea635[_0x7b2103('0x51')]['filter']&&(_0x4a269d[_0x7b2103('0x38')]=_['merge'](_0x4a269d[_0x7b2103('0x38')],{[Op['or']]:_[_0x7b2103('0x2b')](_0x1b1bda,function(_0x5edeeb){const _0x53f440=_0x7b2103;if(_0x5edeeb[_0x53f440('0x68')]!==_0x53f440('0x65')){const _0x2e2167={};return _0x2e2167[_0x5edeeb[_0x53f440('0x59')]]={[Op[_0x53f440('0x42')]]:'%'+_0x3ea635[_0x53f440('0x51')]['filter']+'%'},_0x2e2167;}})}));_0x4a269d=_[_0x7b2103('0x16')]({},_0x4a269d,_0x3ea635[_0x7b2103('0x44')]);const _0x4ac42c={'where':_0x4a269d[_0x7b2103('0x38')]};return db[_0x7b2103('0x69')][_0x7b2103('0x3e')](_0x4ac42c)[_0x7b2103('0xe')](function(_0x594c64){const _0x170bf8=_0x7b2103;return _0x496a2f[_0x170bf8('0x3e')]=_0x594c64,_0x3ea635[_0x170bf8('0x51')][_0x170bf8('0x4')]&&(_0x4a269d[_0x170bf8('0x20')]=[{'all':!![]}]),db['FaxMessage'][_0x170bf8('0x48')](_0x4a269d);})[_0x7b2103('0xe')](function(_0x564692){const _0x381184=_0x7b2103;return _0x496a2f[_0x381184('0x45')]=_0x564692,_0x496a2f;})[_0x7b2103('0xe')](respondWithFilteredResult(_0x353933,_0x4a269d))['catch'](handleError(_0x353933,null));},exports['show']=function(_0xb715b3,_0x29fe56){const _0x4566e3=_0x13b4d4;let _0x1bbd58={'raw':!![],'where':{'id':_0xb715b3[_0x4566e3('0x21')]['id']}};const _0x41b864={};return _0x41b864[_0x4566e3('0x19')]=_[_0x4566e3('0x10')](db[_0x4566e3('0x69')][_0x4566e3('0x5')]),_0x41b864[_0x4566e3('0x51')]=_[_0x4566e3('0x10')](_0xb715b3[_0x4566e3('0x51')]),_0x41b864[_0x4566e3('0x1b')]=_[_0x4566e3('0x14')](_0x41b864[_0x4566e3('0x19')],_0x41b864[_0x4566e3('0x51')]),_0x1bbd58['attributes']=_[_0x4566e3('0x14')](_0x41b864['model'],qs['fields'](_0xb715b3[_0x4566e3('0x51')][_0x4566e3('0x61')])),_0x1bbd58['attributes']=_0x1bbd58[_0x4566e3('0x29')][_0x4566e3('0x5a')]?_0x1bbd58[_0x4566e3('0x29')]:_0x41b864[_0x4566e3('0x19')],_0xb715b3[_0x4566e3('0x51')][_0x4566e3('0x4')]&&(_0x1bbd58[_0x4566e3('0x20')]=[{'all':!![]}]),_0x1bbd58=_[_0x4566e3('0x16')]({},_0x1bbd58,_0xb715b3['options']),db[_0x4566e3('0x69')][_0x4566e3('0x39')](_0x1bbd58)['then'](handleEntityNotFound(_0x29fe56,null))[_0x4566e3('0xe')](respondWithResult(_0x29fe56,null))['catch'](handleError(_0x29fe56,null));},exports['update']=function(_0x29d57c,_0xf4385a){const _0x2b25a2=_0x13b4d4;return _0x29d57c[_0x2b25a2('0x3')]['id']&&delete _0x29d57c[_0x2b25a2('0x3')]['id'],db[_0x2b25a2('0x69')]['findOne']({'where':{'id':_0x29d57c[_0x2b25a2('0x21')]['id']}})[_0x2b25a2('0xe')](handleEntityNotFound(_0xf4385a,null))[_0x2b25a2('0xe')](saveUpdates(_0x29d57c['body'],null))[_0x2b25a2('0xe')](respondWithResult(_0xf4385a,null))[_0x2b25a2('0x6d')](handleError(_0xf4385a,null));},exports[_0x13b4d4('0x55')]=function(_0x21a364,_0x4e7b7b){const _0x380799=_0x13b4d4;return db[_0x380799('0x69')]['findOne']({'where':{'id':_0x21a364['params']['id']}})[_0x380799('0xe')](handleEntityNotFound(_0x4e7b7b,null))[_0x380799('0xe')](removeEntity(_0x4e7b7b,null))['catch'](handleError(_0x4e7b7b,null));},exports[_0x13b4d4('0x5e')]=function(_0x8e89e1,_0x4044ad){const _0x46c8d2=_0x13b4d4;return db[_0x46c8d2('0x69')][_0x46c8d2('0x5e')]()[_0x46c8d2('0xe')](respondWithResult(_0x4044ad,null))[_0x46c8d2('0x6d')](handleError(_0x4044ad,null));},exports[_0x13b4d4('0x3f')]=function(_0x5b471a,_0x501be1){const _0x41f87d=_0x13b4d4,_0x44deb7={'channel':_0x41f87d('0x33')};return _0x5b471a['body']['id']&&delete _0x5b471a[_0x41f87d('0x3')]['id'],_0x5b471a[_0x41f87d('0x3')][_0x41f87d('0x2d')]=!![],_0x5b471a[_0x41f87d('0x3')]['readAt']=moment()[_0x41f87d('0x41')]('YYYY-MM-DD\x20HH:mm:ss'),_0x5b471a[_0x41f87d('0x3')]['UserId']=_0x5b471a[_0x41f87d('0x3')]['UserId']||_0x5b471a[_0x41f87d('0x30')]['id'],db['FaxMessage'][_0x41f87d('0x39')]({'where':{'id':_0x5b471a['params']['id'],'UserId':null},'include':[{'model':db[_0x41f87d('0x24')],'as':_0x41f87d('0x2e')}]})[_0x41f87d('0xe')](handleEntityNotFound(_0x501be1,null))[_0x41f87d('0xe')](saveUpdates(_0x5b471a[_0x41f87d('0x3')],null))['then'](function(_0xe8f840){const _0x13a222=_0x41f87d;if(_0xe8f840)return _0x44deb7[_0x13a222('0x62')]=_0xe8f840[_0x13a222('0x15')]({'plain':!![]}),db[_0x13a222('0x6c')][_0x13a222('0x39')]({'where':{'id':_0xe8f840[_0x13a222('0x4c')]}});return null;})[_0x41f87d('0xe')](handleEntityNotFound(_0x501be1,null))[_0x41f87d('0xe')](function(_0x4076e8){const _0x48b0aa=_0x41f87d;if(_0x4076e8)return _0x4076e8['update']({'UserId':_0x5b471a[_0x48b0aa('0x3')][_0x48b0aa('0x43')],'read1stAt':_['isNil'](_0x4076e8['read1stAt'])?moment()[_0x48b0aa('0x41')](_0x48b0aa('0x1a')):undefined});return null;})['then'](function(_0x3aa554){const _0x20b94e=_0x41f87d;if(_0x3aa554)return _0x44deb7['interaction']=_0x3aa554[_0x20b94e('0x15')]({'plain':!![]}),interaction_log['info'](_0x20b94e('0x40'),_0x5b471a[_0x20b94e('0x30')]['id'],_0x5b471a[_0x20b94e('0x30')][_0x20b94e('0x59')],_0x5b471a[_0x20b94e('0x30')][_0x20b94e('0x26')],_0x44deb7[_0x20b94e('0x36')]['id'],_0x5b471a['body']?JSON[_0x20b94e('0x4b')](_0x5b471a[_0x20b94e('0x3')]):_0x20b94e('0x5b')),respondWithRpcPromise(_0x20b94e('0x56'),'acceptMessage',_0x44deb7);return null;})[_0x41f87d('0xe')](function(_0x4fe0d4){const _0x3338c2=_0x41f87d;if(_0x4fe0d4){if(_0x5b471a[_0x3338c2('0x3')][_0x3338c2('0x4a')])return _0x44deb7[_0x3338c2('0x62')][_0x3338c2('0x6b')]=util['format'](_0x3338c2('0xf'),_0x5b471a[_0x3338c2('0x30')][_0x3338c2('0x59')]),_0x44deb7[_0x3338c2('0x62')][_0x3338c2('0x64')]=_0x44deb7[_0x3338c2('0x64')],_0x44deb7[_0x3338c2('0x62')][_0x3338c2('0x63')]=_0x3338c2('0x3f'),respondWithRpcPromise('EventManager',_0x3338c2('0x5c'),{'event':_0x3338c2('0x54'),'message':_0x44deb7[_0x3338c2('0x62')]},client9002)[_0x3338c2('0xe')](function(){return _0x44deb7;});return _0x44deb7;}return null;})[_0x41f87d('0xe')](respondWithResult(_0x501be1,null))['catch'](handleError(_0x501be1,null));},exports['reject']=function(_0x25a1c5,_0x9b3b64){const _0x1e2c5f=_0x13b4d4,_0x676bcd={'agent':{},'channel':'fax'};return _0x25a1c5['body']['id']&&delete _0x25a1c5[_0x1e2c5f('0x3')]['id'],_0x25a1c5['body'][_0x1e2c5f('0x43')]=_0x25a1c5[_0x1e2c5f('0x3')][_0x1e2c5f('0x43')]||_0x25a1c5[_0x1e2c5f('0x30')]['id'],_0x676bcd['agent']['id']=_0x25a1c5['body'][_0x1e2c5f('0x43')],db[_0x1e2c5f('0x69')][_0x1e2c5f('0x39')]({'where':{'id':_0x25a1c5[_0x1e2c5f('0x21')]['id'],'UserId':null}})[_0x1e2c5f('0xe')](handleEntityNotFound(_0x9b3b64,null))[_0x1e2c5f('0xe')](function(_0x28d075){const _0x269a29=_0x1e2c5f;if(_0x28d075)return _0x676bcd[_0x269a29('0x62')]=_0x28d075[_0x269a29('0x15')]({'plain':!![]}),db[_0x269a29('0x6c')][_0x269a29('0x39')]({'where':{'id':_0x28d075[_0x269a29('0x4c')]}});return null;})[_0x1e2c5f('0xe')](handleEntityNotFound(_0x9b3b64,null))[_0x1e2c5f('0xe')](function(_0x12bdb6){const _0x2760b7=_0x1e2c5f;if(_0x12bdb6)return _0x676bcd[_0x2760b7('0x36')]=_0x12bdb6[_0x2760b7('0x15')]({'plain':!![]}),interaction_log[_0x2760b7('0x4e')](_0x2760b7('0x60'),_0x25a1c5[_0x2760b7('0x30')]['id'],_0x25a1c5['user']['name'],_0x25a1c5[_0x2760b7('0x30')][_0x2760b7('0x26')],_0x676bcd[_0x2760b7('0x36')]['id'],_0x25a1c5[_0x2760b7('0x3')]?JSON['stringify'](_0x25a1c5[_0x2760b7('0x3')]):_0x2760b7('0x5b')),respondWithRpcPromise('RejectMessage','rejectMessage',_0x676bcd);return null;})['then'](function(_0x59f3a3){const _0x846206=_0x1e2c5f;if(_0x59f3a3)return _0x59f3a3[_0x846206('0x62')]['interface']=util[_0x846206('0x41')](_0x846206('0xf'),_0x25a1c5[_0x846206('0x30')][_0x846206('0x59')]),_0x59f3a3['message'][_0x846206('0x64')]=_0x676bcd['channel'],_0x59f3a3['message'][_0x846206('0x63')]=_0x846206('0x22'),respondWithRpcPromise(_0x846206('0x5c'),'EventManager',{'event':_0x846206('0x31'),'message':_0x59f3a3[_0x846206('0x62')]},client9002),_0x676bcd;return null;})['then'](respondWithResult(_0x9b3b64,null))[_0x1e2c5f('0x6d')](handleError(_0x9b3b64,null));},exports[_0x13b4d4('0x11')]=function(_0x3aac24,_0x39ca18){const _0x233897=_0x13b4d4;let _0x1a1a07;return db[_0x233897('0x69')][_0x233897('0x11')](_0x3aac24[_0x233897('0x3')],{})[_0x233897('0xe')](function(_0x3b5b9e){const _0x3c5a8b=_0x233897;return _0x1a1a07=_0x3b5b9e,db[_0x3c5a8b('0x24')][_0x3c5a8b('0x39')]({'where':{'id':_0x1a1a07[_0x3c5a8b('0x6a')]}});})[_0x233897('0xe')](function(_0xae901){const _0x107566=_0x233897;if(_['isNil'](_0xae901))return;else return _0x1a1a07[_0x107566('0x33')]=_0xae901[_0x107566('0x33')],db[_0x107566('0x2a')][_0x107566('0x39')]({'where':{'id':_0x1a1a07[_0x107566('0x3a')]}});})[_0x233897('0xe')](function(_0x34b249){const _0x531ca5=_0x233897;return respondWithRpcPromise(_0x531ca5('0x58'),_0x531ca5('0x58'),{'FaxAccountId':_[_0x531ca5('0x53')](_0x3aac24[_0x531ca5('0x3')])?undefined:_0x3aac24[_0x531ca5('0x3')][_0x531ca5('0x67')],'path':_['isNil'](_0x34b249)?undefined:util['format'](_0x531ca5('0x6e'),_0x34b249['basename']),'fax':_[_0x531ca5('0x53')](_0x1a1a07[_0x531ca5('0x33')])?undefined:_0x1a1a07[_0x531ca5('0x33')],'AttachmentId':_0x1a1a07['AttachmentId']},client9002);})[_0x233897('0xe')](respondWithResult(_0x39ca18,0xc9))[_0x233897('0x6d')](handleError(_0x39ca18,null));},exports[_0x13b4d4('0x1c')]=function(_0x348045,_0x461b9f){const _0x314a92=_0x13b4d4,_0x5b33a3=path[_0x314a92('0x57')](config[_0x314a92('0x18')],_0x314a92('0x2f'),_0x314a92('0x46'),_0x314a92('0x37'));return db[_0x314a92('0x69')][_0x314a92('0x39')]({'where':{'id':_0x348045['params']['id']},'include':[{'model':db[_0x314a92('0x2a')],'as':_0x314a92('0x2a')}]})[_0x314a92('0xe')](handleEntityNotFound(_0x461b9f,null))['then'](function(_0x213000){const _0x925fcb=_0x314a92;if(_0x213000)return _0x461b9f[_0x925fcb('0x1c')](path[_0x925fcb('0x57')](_0x5b33a3,_0x213000[_0x925fcb('0x2a')][_0x925fcb('0x1')]));})[_0x314a92('0x6d')](handleError(_0x461b9f,null));};