Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / api / faxAccount / faxAccount.controller.js
index bf8cc23..29c96d6 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xde89=['createdAt','TrunkId','ListId','findById','getMessages','FaxMessage','$gte','format','YYYY-MM-DD\x20HH:mm:ss','List','Contacts','DESC','attachments','join','root','server/files/attachments','CheckAfterSend','isNil','from','\x22%s\x22\x20<%s>','fax','CmContact','List\x20not\x20found','user','out','filename','Messages','Contact\x20not\x20found','spread','ContactId','dataValues','SendFax','SendFaxRpc,\x20%s','isArray','userFaxAccount:remove','emit','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','register','jayson/promise','client','http','then','FaxAccount,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','info','catch','sendStatus','end','status','json','offset','undefined','limit','count','set','Content-Range','apply','update','destroy','FaxAccounts','name','Pause','mandatoryDispositionPause','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','filter','merge','options','FaxAccount','includeAll','findAll','rows','params','include','find','create','body','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','FaxAccountId','Disposition','getDispositions','findOne','pick','removeDispositions','ids','addAnswer','getAnswers','CannedAnswer','nolimit','removeAnswers','addInteraction','FaxInteraction','getInteractions','Contact','User','Owner','Tag','Tags','color','tag','sequelize','transaction','Transaction','READ_COMMITTED','FaxApplication','findAndCountAll','stack','finally','send','getApplications','context','from-voip-provider','exten','localstationid','app','system','description','Fax\x20Extension','priority','appdata','push','Answer','CDR(type)=inbound-fax','Set','ecm','headerinfo','maxrate','minrate','modem','t38timeout','FAXOPT(','Wait','/var/opt/motion2/server/files/attachments/fax-${CALLERID(num)}-${CUT(UNIQUEID,.,1)}-${CUT(UNIQUEID,.,2)}-${STRFTIME(,,%C%y%m%d%H%M%S)}-rx.tif,d','ReceiveFax','VoiceExtension','updateAccountApplications','bulkCreate'];(function(_0x8f6906,_0x1c4fe6){var _0x493cd9=function(_0x48bff6){while(--_0x48bff6){_0x8f6906['push'](_0x8f6906['shift']());}};_0x493cd9(++_0x1c4fe6);}(_0xde89,0x1ad));var _0x9de8=function(_0x30bd4d,_0x50eb60){_0x30bd4d=_0x30bd4d-0x0;var _0x306915=_0xde89[_0x30bd4d];return _0x306915;};'use strict';var emlformat=require(_0x9de8('0x0'));var rimraf=require(_0x9de8('0x1'));var zipdir=require(_0x9de8('0x2'));var jsonpatch=require(_0x9de8('0x3'));var rp=require('request-promise');var moment=require(_0x9de8('0x4'));var BPromise=require(_0x9de8('0x5'));var Mustache=require(_0x9de8('0x6'));var util=require(_0x9de8('0x7'));var path=require(_0x9de8('0x8'));var sox=require(_0x9de8('0x9'));var csv=require(_0x9de8('0xa'));var ejs=require(_0x9de8('0xb'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x9de8('0xc'));var squel=require(_0x9de8('0xd'));var crypto=require(_0x9de8('0xe'));var jsforce=require(_0x9de8('0xf'));var deskjs=require('desk.js');var toCsv=require(_0x9de8('0xa'));var querystring=require(_0x9de8('0x10'));var Papa=require(_0x9de8('0x11'));var Redis=require(_0x9de8('0x12'));var authService=require(_0x9de8('0x13'));var qs=require(_0x9de8('0x14'));var as=require(_0x9de8('0x15'));var hardwareService=require(_0x9de8('0x16'));var logger=require(_0x9de8('0x17'))('api');var utils=require(_0x9de8('0x18'));var config=require(_0x9de8('0x19'));var licenseUtil=require(_0x9de8('0x1a'));var db=require(_0x9de8('0x1b'))['db'];config[_0x9de8('0x1c')]=_[_0x9de8('0x1d')](config[_0x9de8('0x1c')],{'host':_0x9de8('0x1e'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x9de8('0x1c')]));require('./faxAccount.socket')[_0x9de8('0x1f')](socket);var jayson=require(_0x9de8('0x20'));var client=jayson[_0x9de8('0x21')][_0x9de8('0x22')]({'port':0x232c});var client9002=jayson[_0x9de8('0x21')]['http']({'port':0x232a});function respondWithRpcPromise(_0xc569fe,_0x4a96c6,_0x455f2f,_0x538d14){return new BPromise(function(_0x59be01,_0x474c7c){var _0x2694f6=_0x538d14||client;return _0x2694f6['request'](_0xc569fe,_0x455f2f)[_0x9de8('0x23')](function(_0x59be93){logger['info'](_0x9de8('0x24'),_0x4a96c6,_0x9de8('0x25'));logger[_0x9de8('0x26')]('FaxAccount,\x20%s,\x20%s,\x20%s',_0x4a96c6,_0x9de8('0x25'),JSON[_0x9de8('0x27')](_0x59be93));if(_0x59be93[_0x9de8('0x28')]){if(_0x59be93[_0x9de8('0x28')][_0x9de8('0x29')]===0x1f4){logger['error'](_0x9de8('0x24'),_0x4a96c6,_0x59be93['error']['message']);return _0x474c7c(_0x59be93[_0x9de8('0x28')][_0x9de8('0x2a')]);}logger['error'](_0x9de8('0x24'),_0x4a96c6,_0x59be93[_0x9de8('0x28')][_0x9de8('0x2a')]);return _0x59be01(_0x59be93[_0x9de8('0x28')][_0x9de8('0x2a')]);}else{logger[_0x9de8('0x2b')]('FaxAccount,\x20%s,\x20%s',_0x4a96c6,_0x9de8('0x25'));_0x59be01(_0x59be93['result']['message']);}})[_0x9de8('0x2c')](function(_0x105fbd){logger[_0x9de8('0x28')](_0x9de8('0x24'),_0x4a96c6,_0x105fbd);_0x474c7c(_0x105fbd);});});}function respondWithStatusCode(_0x1f9a38,_0x5e8c5b){_0x5e8c5b=_0x5e8c5b||0xcc;return function(_0xf2fa11){if(_0xf2fa11){return _0x1f9a38[_0x9de8('0x2d')](_0x5e8c5b);}return _0x1f9a38['status'](_0x5e8c5b)[_0x9de8('0x2e')]();};}function respondWithResult(_0x4bec5d,_0x2c174c){_0x2c174c=_0x2c174c||0xc8;return function(_0x11c3ad){if(_0x11c3ad){return _0x4bec5d[_0x9de8('0x2f')](_0x2c174c)[_0x9de8('0x30')](_0x11c3ad);}};}function respondWithFilteredResult(_0x329d1a,_0xf4ecec){return function(_0x51803d){if(_0x51803d){var _0x1b1faf=typeof _0xf4ecec[_0x9de8('0x31')]===_0x9de8('0x32')&&typeof _0xf4ecec[_0x9de8('0x33')]===_0x9de8('0x32');var _0x993bfc=_0x51803d[_0x9de8('0x34')];var _0x2eced5=_0x1b1faf?0x0:_0xf4ecec[_0x9de8('0x31')];var _0x2556a8=_0x1b1faf?_0x51803d[_0x9de8('0x34')]:_0xf4ecec[_0x9de8('0x31')]+_0xf4ecec[_0x9de8('0x33')];var _0x5deb2d;if(_0x2556a8>=_0x993bfc){_0x2556a8=_0x993bfc;_0x5deb2d=0xc8;}else{_0x5deb2d=0xce;}_0x329d1a['status'](_0x5deb2d);return _0x329d1a[_0x9de8('0x35')](_0x9de8('0x36'),_0x2eced5+'-'+_0x2556a8+'/'+_0x993bfc)[_0x9de8('0x30')](_0x51803d);}return null;};}function patchUpdates(_0x33a8dd){return function(_0x4346da){try{jsonpatch[_0x9de8('0x37')](_0x4346da,_0x33a8dd,!![]);}catch(_0x28177d){return BPromise['reject'](_0x28177d);}return _0x4346da['save']();};}function saveUpdates(_0x4d55fe,_0x18b5ef){return function(_0x143bdc){if(_0x143bdc){return _0x143bdc[_0x9de8('0x38')](_0x4d55fe)[_0x9de8('0x23')](function(_0x57dc6c){return _0x57dc6c;});}return null;};}function removeEntity(_0x27b112,_0x38958a){return function(_0x549b66){if(_0x549b66){return _0x549b66[_0x9de8('0x39')]()['then'](function(){var _0x5603e5=_0x549b66['get']({'plain':!![]});var _0x2c77ed=_0x9de8('0x3a');return db['UserProfileResource'][_0x9de8('0x39')]({'where':{'type':_0x2c77ed,'resourceId':_0x5603e5['id']}})[_0x9de8('0x23')](function(){return _0x549b66;});})['then'](function(){_0x27b112[_0x9de8('0x2f')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3a6cc9,_0x260212){return function(_0x1b6abe){if(!_0x1b6abe){_0x3a6cc9[_0x9de8('0x2d')](0x194);}return _0x1b6abe;};}function handleError(_0xa85e62,_0x54061b){_0x54061b=_0x54061b||0x1f4;return function(_0x59c282){logger['error'](_0x59c282['stack']);if(_0x59c282[_0x9de8('0x3b')]){delete _0x59c282[_0x9de8('0x3b')];}_0xa85e62['status'](_0x54061b)['send'](_0x59c282);};}exports['index']=function(_0x16af3a,_0x23b910){var _0x1e1442={'include':[{'model':db[_0x9de8('0x3c')],'as':_0x9de8('0x3d')}]},_0x36e143={},_0x503f17={'count':0x0,'rows':[]};var _0xbdce6d=_[_0x9de8('0x3e')](db['FaxAccount'][_0x9de8('0x3f')],function(_0x37c348){return{'name':_0x37c348[_0x9de8('0x40')],'type':_0x37c348[_0x9de8('0x41')][_0x9de8('0x42')]};});_0x36e143[_0x9de8('0x43')]=_['map'](_0xbdce6d,_0x9de8('0x3b'));_0x36e143[_0x9de8('0x44')]=_[_0x9de8('0x45')](_0x16af3a[_0x9de8('0x44')]);_0x36e143[_0x9de8('0x46')]=_[_0x9de8('0x47')](_0x36e143[_0x9de8('0x43')],_0x36e143[_0x9de8('0x44')]);_0x1e1442[_0x9de8('0x48')]=_[_0x9de8('0x47')](_0x36e143[_0x9de8('0x43')],qs[_0x9de8('0x49')](_0x16af3a[_0x9de8('0x44')][_0x9de8('0x49')]));_0x1e1442[_0x9de8('0x48')]=_0x1e1442[_0x9de8('0x48')][_0x9de8('0x4a')]?_0x1e1442[_0x9de8('0x48')]:_0x36e143[_0x9de8('0x43')];if(!_0x16af3a[_0x9de8('0x44')][_0x9de8('0x4b')]('nolimit')){_0x1e1442[_0x9de8('0x33')]=qs['limit'](_0x16af3a[_0x9de8('0x44')]['limit']);_0x1e1442[_0x9de8('0x31')]=qs[_0x9de8('0x31')](_0x16af3a[_0x9de8('0x44')][_0x9de8('0x31')]);}_0x1e1442[_0x9de8('0x4c')]=qs[_0x9de8('0x4d')](_0x16af3a[_0x9de8('0x44')][_0x9de8('0x4d')]);_0x1e1442[_0x9de8('0x4e')]=qs['filters'](_['pick'](_0x16af3a['query'],_0x36e143['filters']),_0xbdce6d);if(_0x16af3a[_0x9de8('0x44')][_0x9de8('0x4f')]){_0x1e1442[_0x9de8('0x4e')]=_[_0x9de8('0x50')](_0x1e1442['where'],{'$or':_[_0x9de8('0x3e')](_0xbdce6d,function(_0x4328da){if(_0x4328da[_0x9de8('0x41')]!=='VIRTUAL'){var _0x4ecef9={};_0x4ecef9[_0x4328da[_0x9de8('0x3b')]]={'$like':'%'+_0x16af3a['query'][_0x9de8('0x4f')]+'%'};return _0x4ecef9;}})});}_0x1e1442=_[_0x9de8('0x50')]({},_0x1e1442,_0x16af3a[_0x9de8('0x51')]);var _0x29787a={'where':_0x1e1442['where']};return db[_0x9de8('0x52')]['count'](_0x29787a)['then'](function(_0x4cb304){_0x503f17['count']=_0x4cb304;if(_0x16af3a[_0x9de8('0x44')][_0x9de8('0x53')]){_0x1e1442['include']=[{'all':!![]}];}return db[_0x9de8('0x52')][_0x9de8('0x54')](_0x1e1442);})[_0x9de8('0x23')](function(_0x498f24){_0x503f17[_0x9de8('0x55')]=_0x498f24;return _0x503f17;})['then'](respondWithFilteredResult(_0x23b910,_0x1e1442))[_0x9de8('0x2c')](handleError(_0x23b910,null));};exports['show']=function(_0x41570c,_0x5c59a3){var _0x1c69d3={'raw':![],'where':{'id':_0x41570c[_0x9de8('0x56')]['id']},'include':[{'model':db[_0x9de8('0x3c')],'as':_0x9de8('0x3d')}]},_0x46ff15={};_0x46ff15['model']=_[_0x9de8('0x45')](db[_0x9de8('0x52')]['rawAttributes']);_0x46ff15[_0x9de8('0x44')]=_[_0x9de8('0x45')](_0x41570c[_0x9de8('0x44')]);_0x46ff15['filters']=_[_0x9de8('0x47')](_0x46ff15[_0x9de8('0x43')],_0x46ff15['query']);_0x1c69d3[_0x9de8('0x48')]=_[_0x9de8('0x47')](_0x46ff15[_0x9de8('0x43')],qs['fields'](_0x41570c['query'][_0x9de8('0x49')]));_0x1c69d3[_0x9de8('0x48')]=_0x1c69d3[_0x9de8('0x48')]['length']?_0x1c69d3[_0x9de8('0x48')]:_0x46ff15[_0x9de8('0x43')];if(_0x41570c['query'][_0x9de8('0x53')]){_0x1c69d3[_0x9de8('0x57')]=[{'all':!![]}];}_0x1c69d3=_[_0x9de8('0x50')]({},_0x1c69d3,_0x41570c[_0x9de8('0x51')]);return db[_0x9de8('0x52')][_0x9de8('0x58')](_0x1c69d3)['then'](handleEntityNotFound(_0x5c59a3,null))[_0x9de8('0x23')](respondWithResult(_0x5c59a3,null))['catch'](handleError(_0x5c59a3,null));};exports['create']=function(_0x1763d4,_0x3b07ae){return db[_0x9de8('0x52')][_0x9de8('0x59')](_0x1763d4[_0x9de8('0x5a')],{})[_0x9de8('0x23')](function(_0x4af0c8){var _0x49ad96=_0x1763d4['user'][_0x9de8('0x5b')]({'plain':!![]});if(!_0x49ad96)throw new Error(_0x9de8('0x5c'));if(_0x49ad96[_0x9de8('0x5d')]==='user'){var _0x4bd7f1=_0x4af0c8[_0x9de8('0x5b')]({'plain':!![]});var _0x22b5ca=_0x9de8('0x3a');return db[_0x9de8('0x5e')]['find']({'where':{'name':_0x22b5ca,'userProfileId':_0x49ad96[_0x9de8('0x5f')]},'raw':!![]})[_0x9de8('0x23')](function(_0x38ac78){if(_0x38ac78&&_0x38ac78['autoAssociation']===0x0){return db[_0x9de8('0x60')][_0x9de8('0x59')]({'name':_0x4bd7f1[_0x9de8('0x3b')],'resourceId':_0x4bd7f1['id'],'type':_0x38ac78['name'],'sectionId':_0x38ac78['id']},{})[_0x9de8('0x23')](function(){return _0x4af0c8;});}else{return _0x4af0c8;}})['catch'](function(_0x50a435){logger[_0x9de8('0x28')](_0x9de8('0x61'),_0x50a435);throw _0x50a435;});}return _0x4af0c8;})[_0x9de8('0x23')](respondWithResult(_0x3b07ae,0xc9))[_0x9de8('0x2c')](handleError(_0x3b07ae,null));};exports[_0x9de8('0x38')]=function(_0x404af9,_0x5aae0d){if(_0x404af9[_0x9de8('0x5a')]['id']){delete _0x404af9[_0x9de8('0x5a')]['id'];}return db['FaxAccount'][_0x9de8('0x58')]({'where':{'id':_0x404af9[_0x9de8('0x56')]['id']},'include':[{'model':db[_0x9de8('0x3c')],'as':_0x9de8('0x3d')}]})[_0x9de8('0x23')](handleEntityNotFound(_0x5aae0d,null))['then'](saveUpdates(_0x404af9['body'],null))[_0x9de8('0x23')](respondWithResult(_0x5aae0d,null))['catch'](handleError(_0x5aae0d,null));};exports['destroy']=function(_0x337ea6,_0x29f452){return db[_0x9de8('0x52')][_0x9de8('0x58')]({'where':{'id':_0x337ea6[_0x9de8('0x56')]['id']}})[_0x9de8('0x23')](handleEntityNotFound(_0x29f452,null))[_0x9de8('0x23')](removeEntity(_0x29f452,null))[_0x9de8('0x2c')](handleError(_0x29f452,null));};exports['describe']=function(_0x5e537d,_0xb94cbf){return db[_0x9de8('0x52')][_0x9de8('0x62')]()[_0x9de8('0x23')](respondWithResult(_0xb94cbf,null))['catch'](handleError(_0xb94cbf,null));};exports[_0x9de8('0x63')]=function(_0x29dd75,_0x961cf3,_0x2f161){if(_0x29dd75[_0x9de8('0x5a')]['id']){delete _0x29dd75['body']['id'];}return db[_0x9de8('0x52')][_0x9de8('0x58')]({'where':{'id':_0x29dd75['params']['id']}})['then'](handleEntityNotFound(_0x961cf3,null))[_0x9de8('0x23')](function(_0x5ee8b3){if(_0x5ee8b3){_0x29dd75[_0x9de8('0x5a')][_0x9de8('0x64')]=_0x5ee8b3['id'];return db[_0x9de8('0x65')][_0x9de8('0x59')](_0x29dd75[_0x9de8('0x5a')]);}})[_0x9de8('0x23')](respondWithResult(_0x961cf3,null))[_0x9de8('0x2c')](handleError(_0x961cf3,null));};exports[_0x9de8('0x66')]=function(_0x57d122,_0x2b20c7,_0x47f664){var _0x48195a={'raw':![],'where':{}};var _0xc28d5={};var _0x3b3445={'count':0x0,'rows':[]};return db[_0x9de8('0x52')][_0x9de8('0x67')]({'where':{'id':_0x57d122[_0x9de8('0x56')]['id']}})[_0x9de8('0x23')](handleEntityNotFound(_0x2b20c7,null))['then'](function(_0x4331b8){if(_0x4331b8){_0xc28d5[_0x9de8('0x43')]=_['keys'](db['Disposition']['rawAttributes']);_0xc28d5[_0x9de8('0x44')]=_[_0x9de8('0x45')](_0x57d122['query']);_0xc28d5[_0x9de8('0x46')]=_[_0x9de8('0x47')](_0xc28d5[_0x9de8('0x43')],_0xc28d5[_0x9de8('0x44')]);_0x48195a[_0x9de8('0x48')]=_[_0x9de8('0x47')](_0xc28d5[_0x9de8('0x43')],qs[_0x9de8('0x49')](_0x57d122['query'][_0x9de8('0x49')]));_0x48195a[_0x9de8('0x48')]=_0x48195a[_0x9de8('0x48')][_0x9de8('0x4a')]?_0x48195a['attributes']:_0xc28d5[_0x9de8('0x43')];if(!_0x57d122[_0x9de8('0x44')][_0x9de8('0x4b')]('nolimit')){_0x48195a[_0x9de8('0x33')]=qs[_0x9de8('0x33')](_0x57d122['query'][_0x9de8('0x33')]);_0x48195a['offset']=qs['offset'](_0x57d122[_0x9de8('0x44')][_0x9de8('0x31')]);}_0x48195a[_0x9de8('0x4c')]=qs[_0x9de8('0x4d')](_0x57d122['query']['sort']);_0x48195a[_0x9de8('0x4e')]=qs[_0x9de8('0x46')](_[_0x9de8('0x68')](_0x57d122[_0x9de8('0x44')],_0xc28d5[_0x9de8('0x46')]));_0x48195a[_0x9de8('0x4e')][_0x9de8('0x64')]=_0x4331b8['id'];if(_0x57d122['query'][_0x9de8('0x4f')]){_0x48195a['where']=_['merge'](_0x48195a[_0x9de8('0x4e')],{'$or':_[_0x9de8('0x3e')](_0x48195a[_0x9de8('0x48')],function(_0x13eb65){var _0x4e72c9={};_0x4e72c9[_0x13eb65]={'$like':'%'+_0x57d122['query'][_0x9de8('0x4f')]+'%'};return _0x4e72c9;})});}_0x48195a=_['merge']({},_0x48195a,_0x57d122[_0x9de8('0x51')]);return db['Disposition']['count']({'where':_0x48195a['where']})[_0x9de8('0x23')](function(_0x2768af){_0x3b3445[_0x9de8('0x34')]=_0x2768af;if(_0x57d122[_0x9de8('0x44')]['includeAll']){_0x48195a[_0x9de8('0x57')]=[{'all':!![]}];}return db[_0x9de8('0x65')][_0x9de8('0x54')](_0x48195a);})[_0x9de8('0x23')](function(_0x575a85){_0x3b3445[_0x9de8('0x55')]=_0x575a85;return _0x3b3445;});}})['then'](respondWithFilteredResult(_0x2b20c7,_0x48195a))['catch'](handleError(_0x2b20c7,null));};exports[_0x9de8('0x69')]=function(_0x224ba3,_0x42bff1,_0x204f81){return db[_0x9de8('0x52')]['find']({'where':{'id':_0x224ba3['params']['id']}})[_0x9de8('0x23')](handleEntityNotFound(_0x42bff1,null))[_0x9de8('0x23')](function(_0x1fe23){if(_0x1fe23){return _0x1fe23[_0x9de8('0x69')](_0x224ba3[_0x9de8('0x44')][_0x9de8('0x6a')]);}})[_0x9de8('0x23')](respondWithStatusCode(_0x42bff1,null))[_0x9de8('0x2c')](handleError(_0x42bff1,null));};exports[_0x9de8('0x6b')]=function(_0x5647cb,_0x2be5f2,_0x557a1e){if(_0x5647cb['body']['id']){delete _0x5647cb[_0x9de8('0x5a')]['id'];}return db[_0x9de8('0x52')][_0x9de8('0x58')]({'where':{'id':_0x5647cb[_0x9de8('0x56')]['id']}})[_0x9de8('0x23')](handleEntityNotFound(_0x2be5f2,null))['then'](function(_0x4b7f7c){if(_0x4b7f7c){_0x5647cb[_0x9de8('0x5a')]['FaxAccountId']=_0x4b7f7c['id'];return db['CannedAnswer'][_0x9de8('0x59')](_0x5647cb[_0x9de8('0x5a')]);}})[_0x9de8('0x23')](respondWithResult(_0x2be5f2,null))[_0x9de8('0x2c')](handleError(_0x2be5f2,null));};exports[_0x9de8('0x6c')]=function(_0x2263ad,_0x8cb041,_0x3c9ee0){var _0x52edd0={'raw':![],'where':{}};var _0x861371={};var _0x1f0b8a={'count':0x0,'rows':[]};return db['FaxAccount'][_0x9de8('0x67')]({'where':{'id':_0x2263ad[_0x9de8('0x56')]['id']}})[_0x9de8('0x23')](handleEntityNotFound(_0x8cb041,null))[_0x9de8('0x23')](function(_0x325844){if(_0x325844){_0x861371[_0x9de8('0x43')]=_[_0x9de8('0x45')](db[_0x9de8('0x6d')][_0x9de8('0x3f')]);_0x861371[_0x9de8('0x44')]=_[_0x9de8('0x45')](_0x2263ad[_0x9de8('0x44')]);_0x861371[_0x9de8('0x46')]=_['intersection'](_0x861371['model'],_0x861371[_0x9de8('0x44')]);_0x52edd0['attributes']=_[_0x9de8('0x47')](_0x861371[_0x9de8('0x43')],qs[_0x9de8('0x49')](_0x2263ad['query']['fields']));_0x52edd0[_0x9de8('0x48')]=_0x52edd0[_0x9de8('0x48')][_0x9de8('0x4a')]?_0x52edd0[_0x9de8('0x48')]:_0x861371[_0x9de8('0x43')];if(!_0x2263ad[_0x9de8('0x44')][_0x9de8('0x4b')](_0x9de8('0x6e'))){_0x52edd0['limit']=qs[_0x9de8('0x33')](_0x2263ad[_0x9de8('0x44')][_0x9de8('0x33')]);_0x52edd0['offset']=qs[_0x9de8('0x31')](_0x2263ad[_0x9de8('0x44')][_0x9de8('0x31')]);}_0x52edd0[_0x9de8('0x4c')]=qs[_0x9de8('0x4d')](_0x2263ad[_0x9de8('0x44')][_0x9de8('0x4d')]);_0x52edd0[_0x9de8('0x4e')]=qs['filters'](_[_0x9de8('0x68')](_0x2263ad[_0x9de8('0x44')],_0x861371[_0x9de8('0x46')]));_0x52edd0[_0x9de8('0x4e')][_0x9de8('0x64')]=_0x325844['id'];if(_0x2263ad[_0x9de8('0x44')]['filter']){_0x52edd0[_0x9de8('0x4e')]=_[_0x9de8('0x50')](_0x52edd0[_0x9de8('0x4e')],{'$or':_[_0x9de8('0x3e')](_0x52edd0[_0x9de8('0x48')],function(_0x1d6de1){var _0x5b1961={};_0x5b1961[_0x1d6de1]={'$like':'%'+_0x2263ad[_0x9de8('0x44')][_0x9de8('0x4f')]+'%'};return _0x5b1961;})});}_0x52edd0=_[_0x9de8('0x50')]({},_0x52edd0,_0x2263ad[_0x9de8('0x51')]);return db[_0x9de8('0x6d')]['count']({'where':_0x52edd0[_0x9de8('0x4e')]})['then'](function(_0x3fd6ff){_0x1f0b8a[_0x9de8('0x34')]=_0x3fd6ff;if(_0x2263ad[_0x9de8('0x44')]['includeAll']){_0x52edd0[_0x9de8('0x57')]=[{'all':!![]}];}return db[_0x9de8('0x6d')][_0x9de8('0x54')](_0x52edd0);})['then'](function(_0x30c890){_0x1f0b8a[_0x9de8('0x55')]=_0x30c890;return _0x1f0b8a;});}})[_0x9de8('0x23')](respondWithFilteredResult(_0x8cb041,_0x52edd0))[_0x9de8('0x2c')](handleError(_0x8cb041,null));};exports[_0x9de8('0x6f')]=function(_0x3bc93f,_0x24dbc2,_0x128cd6){return db[_0x9de8('0x52')][_0x9de8('0x58')]({'where':{'id':_0x3bc93f['params']['id']}})[_0x9de8('0x23')](handleEntityNotFound(_0x24dbc2,null))[_0x9de8('0x23')](function(_0x19bfdd){if(_0x19bfdd){return _0x19bfdd[_0x9de8('0x6f')](_0x3bc93f[_0x9de8('0x44')]['ids']);}})['then'](respondWithStatusCode(_0x24dbc2,null))[_0x9de8('0x2c')](handleError(_0x24dbc2,null));};exports[_0x9de8('0x70')]=function(_0x417854,_0x1a7d46,_0x53dfb9){return db[_0x9de8('0x71')][_0x9de8('0x58')]({'where':{'id':_0x417854[_0x9de8('0x56')]['id']}})[_0x9de8('0x23')](handleEntityNotFound(_0x1a7d46,null))[_0x9de8('0x23')](function(_0x5a9c06){if(_0x5a9c06){return _0x5a9c06[_0x9de8('0x70')](_0x417854[_0x9de8('0x5a')][_0x9de8('0x6a')],_['omit'](_0x417854[_0x9de8('0x5a')],[_0x9de8('0x6a'),'id'])||{});}})[_0x9de8('0x23')](respondWithResult(_0x1a7d46,null))[_0x9de8('0x2c')](handleError(_0x1a7d46,null));};exports[_0x9de8('0x72')]=function(_0xf4f384,_0x1822ed,_0x6f4dbe){var _0x534cc3={'raw':![],'where':{}};var _0x4cd26b={};var _0x498237={'count':0x0,'rows':[]};return db[_0x9de8('0x52')][_0x9de8('0x67')]({'where':{'id':_0xf4f384['params']['id']}})[_0x9de8('0x23')](handleEntityNotFound(_0x1822ed,null))[_0x9de8('0x23')](function(_0x276456){if(_0x276456){_0x4cd26b['model']=_[_0x9de8('0x45')](db['FaxInteraction'][_0x9de8('0x3f')]);_0x4cd26b['query']=_['keys'](_0xf4f384[_0x9de8('0x44')]);_0x4cd26b['filters']=_[_0x9de8('0x47')](_0x4cd26b[_0x9de8('0x43')],_0x4cd26b[_0x9de8('0x44')]);_0x534cc3[_0x9de8('0x48')]=_['intersection'](_0x4cd26b[_0x9de8('0x43')],qs[_0x9de8('0x49')](_0xf4f384['query'][_0x9de8('0x49')]));_0x534cc3[_0x9de8('0x48')]=_0x534cc3['attributes'][_0x9de8('0x4a')]?_0x534cc3[_0x9de8('0x48')]:_0x4cd26b[_0x9de8('0x43')];if(!_0xf4f384[_0x9de8('0x44')][_0x9de8('0x4b')]('nolimit')){_0x534cc3['limit']=qs[_0x9de8('0x33')](_0xf4f384[_0x9de8('0x44')][_0x9de8('0x33')]);_0x534cc3[_0x9de8('0x31')]=qs[_0x9de8('0x31')](_0xf4f384[_0x9de8('0x44')]['offset']);}_0x534cc3['order']=qs[_0x9de8('0x4d')](_0xf4f384[_0x9de8('0x44')]['sort']);_0x534cc3[_0x9de8('0x4e')]=qs[_0x9de8('0x46')](_[_0x9de8('0x68')](_0xf4f384[_0x9de8('0x44')],_0x4cd26b['filters']));_0x534cc3[_0x9de8('0x4e')][_0x9de8('0x64')]=_0x276456['id'];if(_0xf4f384[_0x9de8('0x44')]['filter']){_0x534cc3[_0x9de8('0x4e')]=_[_0x9de8('0x50')](_0x534cc3[_0x9de8('0x4e')],{'$or':_[_0x9de8('0x3e')](_0x534cc3['attributes'],function(_0x25b4c0){var _0x523423={};_0x523423[_0x25b4c0]={'$like':'%'+_0xf4f384[_0x9de8('0x44')][_0x9de8('0x4f')]+'%'};return _0x523423;})});}_0x534cc3=_[_0x9de8('0x50')]({},_0x534cc3,_0xf4f384[_0x9de8('0x51')]);return db[_0x9de8('0x71')]['count']({'where':_0x534cc3[_0x9de8('0x4e')]})[_0x9de8('0x23')](function(_0x8afd00){_0x498237[_0x9de8('0x34')]=_0x8afd00;if(_0xf4f384[_0x9de8('0x44')][_0x9de8('0x53')]){_0x534cc3['include']=[{'model':db['CmContact'],'as':_0x9de8('0x73'),'required':![]},{'model':db[_0x9de8('0x74')],'as':_0x9de8('0x75'),'attributes':[_0x9de8('0x3b'),'fullname','internal'],'required':![]},{'model':db[_0x9de8('0x76')],'as':_0x9de8('0x77'),'attributes':['id',_0x9de8('0x3b'),_0x9de8('0x78')],'where':_0xf4f384['query'][_0x9de8('0x79')]?{'id':_0xf4f384['query'][_0x9de8('0x79')]}:undefined,'required':_0xf4f384['query'][_0x9de8('0x79')]?!![]:![]}];}return db[_0x9de8('0x71')]['findAll'](_0x534cc3);})['then'](function(_0x37de87){_0x498237[_0x9de8('0x55')]=_0x37de87;return _0x498237;});}})[_0x9de8('0x23')](respondWithFilteredResult(_0x1822ed,_0x534cc3))[_0x9de8('0x2c')](handleError(_0x1822ed,null));};exports['addApplications']=function(_0x26bcee,_0x195f48){var _0x2d5d39=_0x26bcee[_0x9de8('0x56')]['id'];var _0xcb60f9=_0x26bcee[_0x9de8('0x5a')];var _0x9295f8=0xc8;var _0x1dbb1f=null;return db[_0x9de8('0x7a')][_0x9de8('0x7b')]({'isolationLevel':db[_0x9de8('0x7a')][_0x9de8('0x7c')]['ISOLATION_LEVELS'][_0x9de8('0x7d')]},function(_0x42c648){return db['FaxAccount'][_0x9de8('0x67')]({'where':{'id':_0x2d5d39},'transaction':_0x42c648})[_0x9de8('0x23')](function(_0x5d18f2){if(_0x5d18f2){return db[_0x9de8('0x7e')][_0x9de8('0x39')]({'where':{'FaxAccountId':_0x2d5d39},'transaction':_0x42c648})[_0x9de8('0x23')](function(){var _0x5472cc=_[_0x9de8('0x3e')](_0xcb60f9,function(_0x31453b){_0x31453b[_0x9de8('0x64')]=_0x2d5d39;return _0x31453b;});return db[_0x9de8('0x7e')]['bulkCreate'](_0x5472cc,{'transaction':_0x42c648});});}else{_0x9295f8=0x194;_0x1dbb1f=[];}});})[_0x9de8('0x23')](function(){if(_0x9295f8!==0x194){return db[_0x9de8('0x7e')][_0x9de8('0x7f')]({'where':{'FaxAccountId':_0x2d5d39},'order':'priority'})[_0x9de8('0x23')](function(_0x412b43){_0x1dbb1f=_0x412b43;});}})[_0x9de8('0x2c')](function(_0x39b5a0){_0x9295f8=0x1f4;logger[_0x9de8('0x28')](_0x39b5a0[_0x9de8('0x80')]);if(_0x39b5a0['name']){delete _0x39b5a0[_0x9de8('0x3b')];}_0x1dbb1f=_0x39b5a0;})[_0x9de8('0x81')](function(){if(_0x1dbb1f===null){_0x195f48[_0x9de8('0x2d')](_0x9295f8);}else{if(_0x9295f8===0x1f4){_0x195f48[_0x9de8('0x2f')](_0x9295f8)[_0x9de8('0x82')](_0x1dbb1f);}else{_0x195f48[_0x9de8('0x2f')](_0x9295f8)['json'](_0x1dbb1f);}}});};exports[_0x9de8('0x83')]=function(_0x4be769,_0x4f5a64,_0x259e39){var _0x4eb079={};var _0x9e1738={};var _0xd32c8b;var _0x533748;return db[_0x9de8('0x52')][_0x9de8('0x67')]({'where':{'id':_0x4be769[_0x9de8('0x56')]['id']}})['then'](handleEntityNotFound(_0x4f5a64,null))[_0x9de8('0x23')](function(_0x16edf5){if(_0x16edf5){_0xd32c8b=_0x16edf5;_0x9e1738[_0x9de8('0x43')]=_['keys'](db['FaxApplication'][_0x9de8('0x3f')]);_0x9e1738[_0x9de8('0x44')]=_[_0x9de8('0x45')](_0x4be769['query']);_0x9e1738[_0x9de8('0x46')]=_[_0x9de8('0x47')](_0x9e1738[_0x9de8('0x43')],_0x9e1738[_0x9de8('0x44')]);_0x4eb079[_0x9de8('0x48')]=_[_0x9de8('0x47')](_0x9e1738[_0x9de8('0x43')],qs[_0x9de8('0x49')](_0x4be769[_0x9de8('0x44')][_0x9de8('0x49')]));_0x4eb079[_0x9de8('0x48')]=_0x4eb079[_0x9de8('0x48')][_0x9de8('0x4a')]?_0x4eb079[_0x9de8('0x48')]:_0x9e1738[_0x9de8('0x43')];_0x4eb079['order']=qs[_0x9de8('0x4d')](_0x4be769['query'][_0x9de8('0x4d')]);_0x4eb079[_0x9de8('0x4e')]=qs[_0x9de8('0x46')](_[_0x9de8('0x68')](_0x4be769['query'],_0x9e1738[_0x9de8('0x46')]));if(_0x4be769[_0x9de8('0x44')]['filter']){_0x4eb079[_0x9de8('0x4e')]=_[_0x9de8('0x50')](_0x4eb079[_0x9de8('0x4e')],{'$or':_['map'](_0x4eb079[_0x9de8('0x48')],function(_0x429683){var _0x4f5230={};_0x4f5230[_0x429683]={'$like':'%'+_0x4be769[_0x9de8('0x44')][_0x9de8('0x4f')]+'%'};return _0x4f5230;})});}_0x4eb079=_[_0x9de8('0x50')]({},_0x4eb079,_0x4be769[_0x9de8('0x51')]);return _0xd32c8b[_0x9de8('0x83')](_0x4eb079);}})[_0x9de8('0x23')](function(_0x5703e4){if(_0x5703e4){_0x533748=_0x5703e4['length'];if(!_0x4be769[_0x9de8('0x44')]['hasOwnProperty'](_0x9de8('0x6e'))){_0x4eb079[_0x9de8('0x33')]=qs[_0x9de8('0x33')](_0x4be769[_0x9de8('0x44')][_0x9de8('0x33')]);_0x4eb079[_0x9de8('0x31')]=qs['offset'](_0x4be769['query'][_0x9de8('0x31')]);}return _0xd32c8b[_0x9de8('0x83')](_0x4eb079);}})['then'](function(_0x40e1f0){if(_0x40e1f0){return _0x40e1f0?{'count':_0x533748,'rows':_0x40e1f0}:null;}})[_0x9de8('0x23')](respondWithResult(_0x4f5a64,null))[_0x9de8('0x2c')](handleError(_0x4f5a64,null));};function Extension(_0x3b8005,_0x3ab4c3,_0x3e2921,_0x4135e5){this[_0x9de8('0x84')]=_0x9de8('0x85');this[_0x9de8('0x86')]=_0x3b8005[_0x9de8('0x87')];this[_0x9de8('0x88')]=_0x4135e5;this[_0x9de8('0x41')]=_0x9de8('0x89');this[_0x9de8('0x8a')]=_0x9de8('0x8b');this[_0x9de8('0x64')]=_0x3b8005['id'];this[_0x9de8('0x8c')]=_0x3ab4c3;this[_0x9de8('0x8d')]=_0x3e2921;}function createExtensionsReciveFax(_0xe05227){var _0x50a969=0x1;var _0x1bd7a3=[];_0x1bd7a3[_0x9de8('0x8e')](new Extension(_0xe05227,_0x50a969,'',_0x9de8('0x8f')));_0x50a969+=0x1;_0x1bd7a3[_0x9de8('0x8e')](new Extension(_0xe05227,_0x50a969,_0x9de8('0x90'),_0x9de8('0x91')));_0x50a969+=0x1;for(var _0x438b7c in _0xe05227){if(_0xe05227[_0x9de8('0x4b')](_0x438b7c)&&(_0x438b7c===_0x9de8('0x92')||_0x438b7c===_0x9de8('0x87')||_0x438b7c==='gateway'||_0x438b7c==='faxdetect'||_0x438b7c===_0x9de8('0x93')||_0x438b7c===_0x9de8('0x94')||_0x438b7c===_0x9de8('0x95')||_0x438b7c===_0x9de8('0x96')||_0x438b7c===_0x9de8('0x97'))){_0x1bd7a3[_0x9de8('0x8e')](new Extension(_0xe05227,_0x50a969,_0x9de8('0x98')+_0x438b7c+')='+_0xe05227[_0x438b7c],_0x9de8('0x91')));_0x50a969+=0x1;}}_0x1bd7a3[_0x9de8('0x8e')](new Extension(_0xe05227,_0x50a969,'6',_0x9de8('0x99')));_0x50a969+=0x1;_0x1bd7a3['push'](new Extension(_0xe05227,_0x50a969,_0x9de8('0x9a'),_0x9de8('0x9b')));_0x50a969=0x0;return _0x1bd7a3;}exports['addAccountApplications']=function(_0x5725ab,_0x193718,_0x34d765){var _0x2b1d28;return db[_0x9de8('0x7a')][_0x9de8('0x7b')](function(_0x726cc5){return db[_0x9de8('0x52')][_0x9de8('0x59')](_0x5725ab[_0x9de8('0x5a')],{'transaction':_0x726cc5})[_0x9de8('0x23')](function(_0x1f2fec){_0x2b1d28=_0x1f2fec[_0x9de8('0x5b')]({'plain':!![]});return db[_0x9de8('0x9c')]['bulkCreate'](createExtensionsReciveFax(_0x2b1d28),{'transaction':_0x726cc5});});})['then'](function(){return _0x2b1d28;})['then'](respondWithResult(_0x193718,null))['catch'](handleError(_0x193718,null));};exports[_0x9de8('0x9d')]=function(_0x19a41d,_0x35fda4,_0x5d0640){var _0x463e38;return db[_0x9de8('0x7a')][_0x9de8('0x7b')](function(_0x2ca9ce){return db['FaxAccount']['update'](_0x19a41d[_0x9de8('0x5a')],{'where':{'id':_0x19a41d['body']['id']},'transaction':_0x2ca9ce})[_0x9de8('0x23')](function(_0x28fd26){return db['VoiceExtension']['destroy']({'where':{'FaxAccountId':_0x19a41d['body']['id']},'transaction':_0x2ca9ce})[_0x9de8('0x23')](function(_0x4f758b){return db['VoiceExtension'][_0x9de8('0x9e')](createExtensionsReciveFax(_['omit'](_0x19a41d[_0x9de8('0x5a')],['tech',_0x9de8('0x42'),_0x9de8('0x9f'),'updatedAt',_0x9de8('0xa0'),_0x9de8('0xa1')])),{'transaction':_0x2ca9ce});});});})[_0x9de8('0x23')](function(){return db[_0x9de8('0x52')][_0x9de8('0xa2')](_0x19a41d[_0x9de8('0x5a')]['id']);})[_0x9de8('0x23')](respondWithResult(_0x35fda4,null))[_0x9de8('0x2c')](handleError(_0x35fda4,null));};exports[_0x9de8('0xa3')]=function(_0x944f01,_0x57a318,_0xf18657){var _0x3bd72e={'raw':!![],'where':{}};var _0x130987={};var _0x1dd4bf={'count':0x0,'rows':[]};return db[_0x9de8('0x52')][_0x9de8('0x67')]({'where':{'id':_0x944f01[_0x9de8('0x56')]['id']}})[_0x9de8('0x23')](handleEntityNotFound(_0x57a318,null))[_0x9de8('0x23')](function(_0xcd857a){if(_0xcd857a){_0x130987[_0x9de8('0x43')]=_[_0x9de8('0x45')](db[_0x9de8('0xa4')][_0x9de8('0x3f')]);_0x130987[_0x9de8('0x44')]=_[_0x9de8('0x45')](_0x944f01[_0x9de8('0x44')]);_0x130987[_0x9de8('0x46')]=_['intersection'](_0x130987['model'],_0x130987[_0x9de8('0x44')]);_0x3bd72e[_0x9de8('0x48')]=_['intersection'](_0x130987[_0x9de8('0x43')],qs[_0x9de8('0x49')](_0x944f01[_0x9de8('0x44')][_0x9de8('0x49')]));_0x3bd72e[_0x9de8('0x48')]=_0x3bd72e[_0x9de8('0x48')][_0x9de8('0x4a')]?_0x3bd72e[_0x9de8('0x48')]:_0x130987[_0x9de8('0x43')];if(!_0x944f01[_0x9de8('0x44')][_0x9de8('0x4b')](_0x9de8('0x6e'))){_0x3bd72e[_0x9de8('0x33')]=qs[_0x9de8('0x33')](_0x944f01[_0x9de8('0x44')]['limit']);_0x3bd72e[_0x9de8('0x31')]=qs[_0x9de8('0x31')](_0x944f01[_0x9de8('0x44')][_0x9de8('0x31')]);}_0x3bd72e[_0x9de8('0x4c')]=qs[_0x9de8('0x4d')](_0x944f01[_0x9de8('0x44')][_0x9de8('0x4d')]);_0x3bd72e[_0x9de8('0x4e')]=qs[_0x9de8('0x46')](_[_0x9de8('0x68')](_0x944f01[_0x9de8('0x44')],_0x130987['filters']));_0x3bd72e[_0x9de8('0x4e')]['FaxAccountId']=_0xcd857a['id'];if(_0x944f01[_0x9de8('0x44')][_0x9de8('0x4f')]){_0x3bd72e[_0x9de8('0x4e')]=_[_0x9de8('0x50')](_0x3bd72e[_0x9de8('0x4e')],{'$or':_[_0x9de8('0x3e')](_0x3bd72e['attributes'],function(_0x3032b1){var _0x3dbb65={};_0x3dbb65[_0x3032b1]={'$like':'%'+_0x944f01[_0x9de8('0x44')]['filter']+'%'};return _0x3dbb65;})});}if(_0x944f01['query'][_0x9de8('0xa5')]){var _0x3f060d=_0x944f01[_0x9de8('0x44')][_0x9de8('0xa5')]['split'](',');var _0x1b773d={};_0x1b773d[_0x3f060d[0x0]]={'$gte':moment(_0x3f060d[0x1])[_0x9de8('0xa6')](_0x9de8('0xa7'))};_0x3bd72e[_0x9de8('0x4e')]=_['merge'](_0x3bd72e[_0x9de8('0x4e')],_0x1b773d);}_0x3bd72e=_[_0x9de8('0x50')]({},_0x3bd72e,_0x944f01[_0x9de8('0x51')]);return db[_0x9de8('0xa4')][_0x9de8('0x34')]({'where':_0x3bd72e[_0x9de8('0x4e')]})[_0x9de8('0x23')](function(_0x323079){_0x1dd4bf[_0x9de8('0x34')]=_0x323079;if(_0x944f01[_0x9de8('0x44')][_0x9de8('0x53')]){_0x3bd72e[_0x9de8('0x57')]=[{'all':!![]}];}return db[_0x9de8('0xa4')][_0x9de8('0x54')](_0x3bd72e);})[_0x9de8('0x23')](function(_0x2a6968){_0x1dd4bf['rows']=_0x2a6968;return _0x1dd4bf;});}})[_0x9de8('0x23')](respondWithFilteredResult(_0x57a318,_0x3bd72e))[_0x9de8('0x2c')](handleError(_0x57a318,null));};exports[_0x9de8('0x82')]=function(_0x45ed93,_0x82cd96,_0x4dfad9){var _0x4fbeca,_0xe1f1a5={},_0x22c932;if(_0x45ed93['body']['to']){_0x22c932=_0x45ed93[_0x9de8('0x5a')]['to'][0x0];}return db[_0x9de8('0x52')]['find']({'where':{'id':_0x45ed93['params']['id']},'include':[{'model':db['CmList'],'as':_0x9de8('0xa8'),'include':[{'model':db['CmContact'],'as':_0x9de8('0xa9'),'where':{'fax':_0x22c932},'limit':0x1,'order':[['updatedAt',_0x9de8('0xaa')]]}]}]})['then'](handleEntityNotFound(_0x82cd96,null))[_0x9de8('0x23')](function(_0x389f8c){_0x4fbeca=_0x389f8c;if(_0x45ed93[_0x9de8('0x5a')][_0x9de8('0xab')]&&_0x45ed93[_0x9de8('0x5a')][_0x9de8('0xab')][_0x9de8('0x4a')]){for(var _0x33651f=0x0;_0x33651f<_0x45ed93['body']['attachments'][_0x9de8('0x4a')];_0x33651f+=0x1){_0x45ed93[_0x9de8('0x5a')][_0x9de8('0xab')][_0x33651f]={'filename':_0x45ed93['body'][_0x9de8('0xab')][_0x33651f][_0x9de8('0x3b')],'id':_0x45ed93[_0x9de8('0x5a')][_0x9de8('0xab')][_0x33651f]['id'],'path':path[_0x9de8('0xac')](config[_0x9de8('0xad')],_0x9de8('0xae'),_0x45ed93[_0x9de8('0x5a')]['attachments'][_0x33651f]['basename'])};}}return respondWithRpcPromise('CheckAfterSend',_0x9de8('0xaf'),{'FaxAccountId':_[_0x9de8('0xb0')](_0x45ed93['params']['id'])?undefined:_0x45ed93['params']['id'],'path':_[_0x9de8('0xb0')](_0x45ed93[_0x9de8('0x5a')][_0x9de8('0xab')][0x0][_0x9de8('0x8')])?undefined:_0x45ed93[_0x9de8('0x5a')]['attachments'][0x0][_0x9de8('0x8')],'fax':_[_0x9de8('0xb0')](_0x45ed93[_0x9de8('0x5a')]['to'][0x0])?undefined:_0x45ed93['body']['to'][0x0]},client9002);})['then'](function(){if(_0x4fbeca){if(_[_0x9de8('0xb0')](_0x45ed93[_0x9de8('0x5a')][_0x9de8('0xb1')])){_0x45ed93[_0x9de8('0x5a')][_0x9de8('0xb1')]=util[_0x9de8('0xa6')](_0x9de8('0xb2'),_0x4fbeca['name'],_0x4fbeca[_0x9de8('0xb3')]);}if(_0x4fbeca[_0x9de8('0xa8')]){if(_0x4fbeca[_0x9de8('0xa8')][_0x9de8('0xa9')][_0x9de8('0x4a')]){return _0x4fbeca['List']['Contacts'][0x0];}else{return db[_0x9de8('0xb4')][_0x9de8('0x59')](_[_0x9de8('0x1d')](_0x45ed93[_0x9de8('0x5a')],{'firstName':_0x45ed93[_0x9de8('0x5a')]['to'][0x0],'phone':_0x45ed93[_0x9de8('0x5a')]['to'][0x0],'fax':_0x45ed93[_0x9de8('0x5a')]['to'][0x0],'ListId':_0x4fbeca[_0x9de8('0xa1')]}));}}else{throw new Error(_0x9de8('0xb5'));}}else{throw new Error('Send\x20Fax\x20failed');}})['then'](function(_0x165308){if(_0x165308){return db[_0x9de8('0x71')][_0x9de8('0x58')]({'where':{'ContactId':_0x165308['id'],'closed':![],'FaxAccountId':_0x4fbeca['id']}})[_0x9de8('0x23')](function(_0xec1c3e){if(_0xec1c3e){return[_0xec1c3e,![]];}return db[_0x9de8('0x71')]['create']({'UserId':_0x45ed93[_0x9de8('0xb6')]['id'],'ContactId':_0x165308['id'],'FaxAccountId':_0x4fbeca['id'],'fax':_0x45ed93[_0x9de8('0x5a')]['to'][0x0],'firstMsgDirection':_0x9de8('0xb7'),'Messages':[_['merge'](_0x45ed93[_0x9de8('0x5a')],{'read':![],'body':_0x45ed93[_0x9de8('0x5a')][_0x9de8('0xab')][0x0][_0x9de8('0xb8')],'FaxAccountId':_0x4fbeca['id'],'UserId':_0x45ed93['user']['id'],'ContactId':_0x165308['id'],'AttachmentId':_0x45ed93['body'][_0x9de8('0xab')][0x0]['id']})]},{'include':[{'model':db[_0x9de8('0xa4')],'as':_0x9de8('0xb9')}]})[_0x9de8('0x23')](function(_0x4fff99){return[_0x4fff99,!![]];});});}else{throw new Error(_0x9de8('0xba'));}})[_0x9de8('0xbb')](function(_0x59d4e2,_0x16b5d8){if(_0x16b5d8){return _0x59d4e2;}return db[_0x9de8('0xa4')][_0x9de8('0x59')]({'direction':'out','read':![],'body':_0x45ed93[_0x9de8('0x5a')]['attachments'][0x0]['filename'],'FaxAccountId':_0x4fbeca['id'],'FaxInteractionId':_0x59d4e2['id'],'UserId':_0x45ed93['user']['id'],'ContactId':_0x59d4e2[_0x9de8('0xbc')],'AttachmentId':_0x45ed93[_0x9de8('0x5a')][_0x9de8('0xab')][0x0]['id']})['then'](function(_0x448bec){_0x59d4e2[_0x9de8('0xbd')][_0x9de8('0xb9')]=[];_0x59d4e2[_0x9de8('0xbd')][_0x9de8('0xb9')][_0x9de8('0x8e')](_0x448bec[_0x9de8('0xbd')]);return _0x59d4e2;});})[_0x9de8('0x23')](function(_0x3916cb){respondWithRpcPromise(_0x9de8('0xbe'),'SendFax',{'FaxAccountId':_['isNil'](_0x45ed93[_0x9de8('0x56')]['id'])?undefined:_0x45ed93[_0x9de8('0x56')]['id'],'path':_['isNil'](_0x45ed93[_0x9de8('0x5a')][_0x9de8('0xab')][0x0][_0x9de8('0x8')])?undefined:_0x45ed93[_0x9de8('0x5a')][_0x9de8('0xab')][0x0]['path'],'fax':_['isNil'](_0x45ed93[_0x9de8('0x5a')]['to'][0x0])?undefined:_0x45ed93[_0x9de8('0x5a')]['to'][0x0],'AttachmentId':_0x45ed93[_0x9de8('0x5a')]['attachments'][0x0]['id']},client9002)[_0x9de8('0x23')](function(_0x3ca236){logger[_0x9de8('0x2b')]('SendFaxRpc,\x20%s',_0x3ca236);})[_0x9de8('0x2c')](function(_0x486e1e){logger[_0x9de8('0x2b')](_0x9de8('0xbf'),_0x486e1e);});return _0x3916cb;})[_0x9de8('0x23')](respondWithResult(_0x82cd96,null))['catch'](handleError(_0x82cd96,null));};exports['addAgents']=function(_0x2d38b1,_0x3d5bf0,_0x504eb6){return db['FaxAccount']['find']({'where':{'id':_0x2d38b1[_0x9de8('0x56')]['id']}})[_0x9de8('0x23')](handleEntityNotFound(_0x3d5bf0,null))[_0x9de8('0x23')](function(_0x28675a){if(_0x28675a){return _0x28675a['addAgents'](_0x2d38b1['body']['ids'],_['omit'](_0x2d38b1[_0x9de8('0x5a')],['ids','id'])||{})[_0x9de8('0xbb')](function(_0x32e0a2){for(var _0x66124d=0x0;_0x66124d<_0x2d38b1[_0x9de8('0x5a')]['ids'][_0x9de8('0x4a')];_0x66124d+=0x1){socket['emit']('userFaxAccount:save',{'UserId':Number(_0x2d38b1[_0x9de8('0x5a')][_0x9de8('0x6a')][_0x66124d]),'FaxAccountId':Number(_0x2d38b1[_0x9de8('0x56')]['id'])});}return _0x32e0a2;});}})[_0x9de8('0x23')](respondWithResult(_0x3d5bf0,null))[_0x9de8('0x2c')](handleError(_0x3d5bf0,null));};exports['removeAgents']=function(_0x1e134a,_0x338039,_0x27a1fc){return db[_0x9de8('0x52')][_0x9de8('0x58')]({'where':{'id':_0x1e134a[_0x9de8('0x56')]['id']}})[_0x9de8('0x23')](handleEntityNotFound(_0x338039,null))[_0x9de8('0x23')](function(_0x5595b7){if(_0x5595b7){return _0x5595b7['removeAgents'](_0x1e134a[_0x9de8('0x44')][_0x9de8('0x6a')])[_0x9de8('0x23')](function(){if(_[_0x9de8('0xc0')](_0x1e134a[_0x9de8('0x44')][_0x9de8('0x6a')])){for(var _0x5e5ce1=0x0;_0x5e5ce1<_0x1e134a[_0x9de8('0x44')][_0x9de8('0x6a')][_0x9de8('0x4a')];_0x5e5ce1+=0x1){socket['emit'](_0x9de8('0xc1'),{'UserId':Number(_0x1e134a['query'][_0x9de8('0x6a')][_0x5e5ce1]),'FaxAccountId':Number(_0x1e134a[_0x9de8('0x56')]['id'])});}}else{socket[_0x9de8('0xc2')]('userFaxAccount:remove',{'UserId':Number(_0x1e134a[_0x9de8('0x44')][_0x9de8('0x6a')]),'FaxAccountId':Number(_0x1e134a['params']['id'])});}});}})['then'](respondWithStatusCode(_0x338039,null))[_0x9de8('0x2c')](handleError(_0x338039,null));};exports['getAgents']=function(_0x60f35,_0xae2f72,_0x5e0dd4){var _0x5b60bd={};var _0x1fa4d9={};var _0x970797;var _0xa5b112;return db[_0x9de8('0x52')][_0x9de8('0x67')]({'where':{'id':_0x60f35[_0x9de8('0x56')]['id']}})['then'](handleEntityNotFound(_0xae2f72,null))[_0x9de8('0x23')](function(_0x46836a){if(_0x46836a){_0x970797=_0x46836a;_0x1fa4d9[_0x9de8('0x43')]=_[_0x9de8('0x45')](db[_0x9de8('0x74')][_0x9de8('0x3f')]);_0x1fa4d9[_0x9de8('0x44')]=_[_0x9de8('0x45')](_0x60f35[_0x9de8('0x44')]);_0x1fa4d9[_0x9de8('0x46')]=_[_0x9de8('0x47')](_0x1fa4d9[_0x9de8('0x43')],_0x1fa4d9['query']);_0x5b60bd[_0x9de8('0x48')]=_[_0x9de8('0x47')](_0x1fa4d9[_0x9de8('0x43')],qs[_0x9de8('0x49')](_0x60f35[_0x9de8('0x44')][_0x9de8('0x49')]));_0x5b60bd['attributes']=_0x5b60bd[_0x9de8('0x48')][_0x9de8('0x4a')]?_0x5b60bd['attributes']:_0x1fa4d9[_0x9de8('0x43')];_0x5b60bd[_0x9de8('0x4c')]=qs[_0x9de8('0x4d')](_0x60f35[_0x9de8('0x44')][_0x9de8('0x4d')]);_0x5b60bd[_0x9de8('0x4e')]=qs[_0x9de8('0x46')](_['pick'](_0x60f35['query'],_0x1fa4d9[_0x9de8('0x46')]));if(_0x60f35[_0x9de8('0x44')][_0x9de8('0x4f')]){_0x5b60bd[_0x9de8('0x4e')]=_[_0x9de8('0x50')](_0x5b60bd[_0x9de8('0x4e')],{'$or':_[_0x9de8('0x3e')](_0x5b60bd['attributes'],function(_0x43c243){var _0x28281f={};_0x28281f[_0x43c243]={'$like':'%'+_0x60f35[_0x9de8('0x44')][_0x9de8('0x4f')]+'%'};return _0x28281f;})});}_0x5b60bd=_[_0x9de8('0x50')]({},_0x5b60bd,_0x60f35['options']);return _0x970797[_0x9de8('0xc3')](_0x5b60bd);}})['then'](function(_0xb68f37){if(_0xb68f37){_0xa5b112=_0xb68f37[_0x9de8('0x4a')];if(!_0x60f35[_0x9de8('0x44')][_0x9de8('0x4b')]('nolimit')){_0x5b60bd[_0x9de8('0x33')]=qs[_0x9de8('0x33')](_0x60f35[_0x9de8('0x44')]['limit']);_0x5b60bd[_0x9de8('0x31')]=qs[_0x9de8('0x31')](_0x60f35[_0x9de8('0x44')]['offset']);}return _0x970797[_0x9de8('0xc3')](_0x5b60bd);}})[_0x9de8('0x23')](function(_0x2e8222){if(_0x2e8222){return _0x2e8222?{'count':_0xa5b112,'rows':_0x2e8222}:null;}})[_0x9de8('0x23')](respondWithResult(_0xae2f72,null))[_0x9de8('0x2c')](handleError(_0xae2f72,null));};
\ No newline at end of file
+var _0xb41d=['filter','merge','where','VIRTUAL','findAll','rows','show','params','Pause','length','includeAll','include','options','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','userProfileId','autoAssociation','update','addDisposition','FaxAccountId','getDispositions','findOne','Disposition','removeDispositions','ids','CannedAnswer','getAnswers','removeAnswers','addInteraction','FaxInteraction','omit','CmContact','Owner','fullname','internal','Tag','Tags','color','tag','addApplications','sequelize','transaction','Transaction','FaxApplication','bulkCreate','findAndCountAll','priority','finally','getApplications','from-voip-provider','exten','localstationid','app','system','description','Fax\x20Extension','appdata','push','Answer','ecm','gateway','faxdetect','headerinfo','maxrate','minrate','t38timeout','/var/opt/motion2/server/files/attachments/fax-${CALLERID(num)}-${CUT(UNIQUEID,.,1)}-${CUT(UNIQUEID,.,2)}-${STRFTIME(,,%C%y%m%d%H%M%S)}-rx.tif,d','ReceiveFax','addAccountApplications','VoiceExtension','updateAccountApplications','createdAt','updatedAt','ListId','findById','getMessages','FaxMessage','$gte','YYYY-MM-DD\x20HH:mm:ss','CmList','List','attachments','join','root','server/files/attachments','basename','CheckAfterSend','isNil','format','fax','Contacts','List\x20not\x20found','Send\x20Fax\x20failed','out','filename','Messages','Contact\x20not\x20found','spread','dataValues','SendFax','SendFaxRpc,\x20%s','emit','removeAgents','userFaxAccount:remove','User','getAgents','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./faxAccount.socket','jayson/promise','http','client','request','then','info','FaxAccount,\x20%s,\x20%s','request\x20sent','debug','FaxAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','end','status','json','offset','undefined','limit','count','Content-Range','reject','save','destroy','get','FaxAccounts','UserProfileResource','stack','name','send','index','mandatoryDispositionPause','FaxAccount','rawAttributes','fieldName','type','key','model','map','keys','query','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','filters','pick'];(function(_0x58c456,_0x5804a6){var _0x5555c0=function(_0x20f9c1){while(--_0x20f9c1){_0x58c456['push'](_0x58c456['shift']());}};_0x5555c0(++_0x5804a6);}(_0xb41d,0x6f));var _0xdb41=function(_0x256b72,_0x340985){_0x256b72=_0x256b72-0x0;var _0x2183e3=_0xb41d[_0x256b72];return _0x2183e3;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xdb41('0x0'));var zipdir=require(_0xdb41('0x1'));var jsonpatch=require(_0xdb41('0x2'));var rp=require(_0xdb41('0x3'));var moment=require(_0xdb41('0x4'));var BPromise=require(_0xdb41('0x5'));var Mustache=require(_0xdb41('0x6'));var util=require('util');var path=require(_0xdb41('0x7'));var sox=require(_0xdb41('0x8'));var csv=require(_0xdb41('0x9'));var ejs=require(_0xdb41('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xdb41('0xb'));var squel=require(_0xdb41('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xdb41('0xd'));var toCsv=require(_0xdb41('0x9'));var querystring=require(_0xdb41('0xe'));var Papa=require(_0xdb41('0xf'));var Redis=require('ioredis');var authService=require(_0xdb41('0x10'));var qs=require(_0xdb41('0x11'));var as=require(_0xdb41('0x12'));var hardwareService=require(_0xdb41('0x13'));var logger=require(_0xdb41('0x14'))(_0xdb41('0x15'));var utils=require('../../config/utils');var config=require(_0xdb41('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0xdb41('0x17'))['db'];config[_0xdb41('0x18')]=_[_0xdb41('0x19')](config[_0xdb41('0x18')],{'host':_0xdb41('0x1a'),'port':0x18eb});var socket=require(_0xdb41('0x1b'))(new Redis(config[_0xdb41('0x18')]));require(_0xdb41('0x1c'))['register'](socket);var jayson=require(_0xdb41('0x1d'));var client=jayson['client'][_0xdb41('0x1e')]({'port':0x232c});var client9002=jayson[_0xdb41('0x1f')][_0xdb41('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x570240,_0x241238,_0xc31d8f,_0x5bdaad){return new BPromise(function(_0x413325,_0x4dba8a){var _0x76ed79=_0x5bdaad||client;return _0x76ed79[_0xdb41('0x20')](_0x570240,_0xc31d8f)[_0xdb41('0x21')](function(_0x306fae){logger[_0xdb41('0x22')](_0xdb41('0x23'),_0x241238,_0xdb41('0x24'));logger[_0xdb41('0x25')](_0xdb41('0x26'),_0x241238,_0xdb41('0x24'),JSON[_0xdb41('0x27')](_0x306fae));if(_0x306fae[_0xdb41('0x28')]){if(_0x306fae[_0xdb41('0x28')][_0xdb41('0x29')]===0x1f4){logger['error']('FaxAccount,\x20%s,\x20%s',_0x241238,_0x306fae[_0xdb41('0x28')][_0xdb41('0x2a')]);return _0x4dba8a(_0x306fae[_0xdb41('0x28')][_0xdb41('0x2a')]);}logger[_0xdb41('0x28')](_0xdb41('0x23'),_0x241238,_0x306fae[_0xdb41('0x28')]['message']);return _0x413325(_0x306fae[_0xdb41('0x28')][_0xdb41('0x2a')]);}else{logger['info'](_0xdb41('0x23'),_0x241238,_0xdb41('0x24'));_0x413325(_0x306fae[_0xdb41('0x2b')][_0xdb41('0x2a')]);}})[_0xdb41('0x2c')](function(_0x660d04){logger[_0xdb41('0x28')](_0xdb41('0x23'),_0x241238,_0x660d04);_0x4dba8a(_0x660d04);});});}function respondWithStatusCode(_0x36108c,_0x4e6410){_0x4e6410=_0x4e6410||0xcc;return function(_0x21ea64){if(_0x21ea64){return _0x36108c[_0xdb41('0x2d')](_0x4e6410);}return _0x36108c['status'](_0x4e6410)[_0xdb41('0x2e')]();};}function respondWithResult(_0x41b8e3,_0x29e425){_0x29e425=_0x29e425||0xc8;return function(_0x5d9e98){if(_0x5d9e98){return _0x41b8e3[_0xdb41('0x2f')](_0x29e425)[_0xdb41('0x30')](_0x5d9e98);}};}function respondWithFilteredResult(_0x5c087b,_0x4e5e6f){return function(_0x40ae01){if(_0x40ae01){var _0x1f2ae9=typeof _0x4e5e6f[_0xdb41('0x31')]===_0xdb41('0x32')&&typeof _0x4e5e6f[_0xdb41('0x33')]===_0xdb41('0x32');var _0x417e23=_0x40ae01[_0xdb41('0x34')];var _0x624f0c=_0x1f2ae9?0x0:_0x4e5e6f['offset'];var _0x35d8e0=_0x1f2ae9?_0x40ae01['count']:_0x4e5e6f['offset']+_0x4e5e6f[_0xdb41('0x33')];var _0x443be8;if(_0x35d8e0>=_0x417e23){_0x35d8e0=_0x417e23;_0x443be8=0xc8;}else{_0x443be8=0xce;}_0x5c087b[_0xdb41('0x2f')](_0x443be8);return _0x5c087b['set'](_0xdb41('0x35'),_0x624f0c+'-'+_0x35d8e0+'/'+_0x417e23)[_0xdb41('0x30')](_0x40ae01);}return null;};}function patchUpdates(_0x1986a9){return function(_0x33d3c3){try{jsonpatch['apply'](_0x33d3c3,_0x1986a9,!![]);}catch(_0x3bf877){return BPromise[_0xdb41('0x36')](_0x3bf877);}return _0x33d3c3[_0xdb41('0x37')]();};}function saveUpdates(_0x173f06,_0x463a7e){return function(_0x20541b){if(_0x20541b){return _0x20541b['update'](_0x173f06)[_0xdb41('0x21')](function(_0x40f1f0){return _0x40f1f0;});}return null;};}function removeEntity(_0x55203e,_0x392f8d){return function(_0x115a08){if(_0x115a08){return _0x115a08[_0xdb41('0x38')]()[_0xdb41('0x21')](function(){var _0x3d1586=_0x115a08[_0xdb41('0x39')]({'plain':!![]});var _0xad4782=_0xdb41('0x3a');return db[_0xdb41('0x3b')][_0xdb41('0x38')]({'where':{'type':_0xad4782,'resourceId':_0x3d1586['id']}})['then'](function(){return _0x115a08;});})['then'](function(){_0x55203e['status'](0xcc)[_0xdb41('0x2e')]();});}};}function handleEntityNotFound(_0x54f7f3,_0x5e71cf){return function(_0x51536a){if(!_0x51536a){_0x54f7f3[_0xdb41('0x2d')](0x194);}return _0x51536a;};}function handleError(_0x5d4c35,_0x4dbcba){_0x4dbcba=_0x4dbcba||0x1f4;return function(_0x20b9a1){logger[_0xdb41('0x28')](_0x20b9a1[_0xdb41('0x3c')]);if(_0x20b9a1[_0xdb41('0x3d')]){delete _0x20b9a1[_0xdb41('0x3d')];}_0x5d4c35[_0xdb41('0x2f')](_0x4dbcba)[_0xdb41('0x3e')](_0x20b9a1);};}exports[_0xdb41('0x3f')]=function(_0x4240d9,_0x728cf3){var _0x3191fc={'include':[{'model':db['Pause'],'as':_0xdb41('0x40')}]},_0x4ebd08={},_0x71811b={'count':0x0,'rows':[]};var _0x265435=_['map'](db[_0xdb41('0x41')][_0xdb41('0x42')],function(_0xc29d34){return{'name':_0xc29d34[_0xdb41('0x43')],'type':_0xc29d34[_0xdb41('0x44')][_0xdb41('0x45')]};});_0x4ebd08[_0xdb41('0x46')]=_[_0xdb41('0x47')](_0x265435,'name');_0x4ebd08['query']=_[_0xdb41('0x48')](_0x4240d9[_0xdb41('0x49')]);_0x4ebd08['filters']=_[_0xdb41('0x4a')](_0x4ebd08[_0xdb41('0x46')],_0x4ebd08[_0xdb41('0x49')]);_0x3191fc['attributes']=_[_0xdb41('0x4a')](_0x4ebd08[_0xdb41('0x46')],qs[_0xdb41('0x4b')](_0x4240d9[_0xdb41('0x49')][_0xdb41('0x4b')]));_0x3191fc['attributes']=_0x3191fc[_0xdb41('0x4c')]['length']?_0x3191fc[_0xdb41('0x4c')]:_0x4ebd08[_0xdb41('0x46')];if(!_0x4240d9[_0xdb41('0x49')][_0xdb41('0x4d')](_0xdb41('0x4e'))){_0x3191fc[_0xdb41('0x33')]=qs[_0xdb41('0x33')](_0x4240d9['query'][_0xdb41('0x33')]);_0x3191fc[_0xdb41('0x31')]=qs[_0xdb41('0x31')](_0x4240d9[_0xdb41('0x49')][_0xdb41('0x31')]);}_0x3191fc[_0xdb41('0x4f')]=qs[_0xdb41('0x50')](_0x4240d9[_0xdb41('0x49')][_0xdb41('0x50')]);_0x3191fc['where']=qs[_0xdb41('0x51')](_[_0xdb41('0x52')](_0x4240d9[_0xdb41('0x49')],_0x4ebd08['filters']),_0x265435);if(_0x4240d9[_0xdb41('0x49')][_0xdb41('0x53')]){_0x3191fc['where']=_[_0xdb41('0x54')](_0x3191fc[_0xdb41('0x55')],{'$or':_[_0xdb41('0x47')](_0x265435,function(_0x33ae0b){if(_0x33ae0b[_0xdb41('0x44')]!==_0xdb41('0x56')){var _0x1658d3={};_0x1658d3[_0x33ae0b[_0xdb41('0x3d')]]={'$like':'%'+_0x4240d9[_0xdb41('0x49')]['filter']+'%'};return _0x1658d3;}})});}_0x3191fc=_[_0xdb41('0x54')]({},_0x3191fc,_0x4240d9['options']);var _0x4f20e7={'where':_0x3191fc[_0xdb41('0x55')]};return db['FaxAccount'][_0xdb41('0x34')](_0x4f20e7)['then'](function(_0x524a01){_0x71811b[_0xdb41('0x34')]=_0x524a01;if(_0x4240d9[_0xdb41('0x49')]['includeAll']){_0x3191fc['include']=[{'all':!![]}];}return db[_0xdb41('0x41')][_0xdb41('0x57')](_0x3191fc);})[_0xdb41('0x21')](function(_0x4e66e7){_0x71811b[_0xdb41('0x58')]=_0x4e66e7;return _0x71811b;})[_0xdb41('0x21')](respondWithFilteredResult(_0x728cf3,_0x3191fc))[_0xdb41('0x2c')](handleError(_0x728cf3,null));};exports[_0xdb41('0x59')]=function(_0x57aaf0,_0x5cfdad){var _0x57ca15={'raw':![],'where':{'id':_0x57aaf0[_0xdb41('0x5a')]['id']},'include':[{'model':db[_0xdb41('0x5b')],'as':'mandatoryDispositionPause'}]},_0x99f69c={};_0x99f69c[_0xdb41('0x46')]=_[_0xdb41('0x48')](db['FaxAccount'][_0xdb41('0x42')]);_0x99f69c['query']=_[_0xdb41('0x48')](_0x57aaf0[_0xdb41('0x49')]);_0x99f69c['filters']=_[_0xdb41('0x4a')](_0x99f69c[_0xdb41('0x46')],_0x99f69c[_0xdb41('0x49')]);_0x57ca15[_0xdb41('0x4c')]=_[_0xdb41('0x4a')](_0x99f69c[_0xdb41('0x46')],qs['fields'](_0x57aaf0[_0xdb41('0x49')][_0xdb41('0x4b')]));_0x57ca15[_0xdb41('0x4c')]=_0x57ca15[_0xdb41('0x4c')][_0xdb41('0x5c')]?_0x57ca15[_0xdb41('0x4c')]:_0x99f69c['model'];if(_0x57aaf0[_0xdb41('0x49')][_0xdb41('0x5d')]){_0x57ca15[_0xdb41('0x5e')]=[{'all':!![]}];}_0x57ca15=_[_0xdb41('0x54')]({},_0x57ca15,_0x57aaf0[_0xdb41('0x5f')]);return db['FaxAccount']['find'](_0x57ca15)[_0xdb41('0x21')](handleEntityNotFound(_0x5cfdad,null))[_0xdb41('0x21')](respondWithResult(_0x5cfdad,null))['catch'](handleError(_0x5cfdad,null));};exports[_0xdb41('0x60')]=function(_0x282162,_0x428457){return db[_0xdb41('0x41')][_0xdb41('0x60')](_0x282162[_0xdb41('0x61')],{})[_0xdb41('0x21')](function(_0x5006b5){var _0x1f7608=_0x282162[_0xdb41('0x62')][_0xdb41('0x39')]({'plain':!![]});if(!_0x1f7608)throw new Error(_0xdb41('0x63'));if(_0x1f7608[_0xdb41('0x64')]==='user'){var _0x38dc33=_0x5006b5[_0xdb41('0x39')]({'plain':!![]});var _0x494b3b=_0xdb41('0x3a');return db[_0xdb41('0x65')][_0xdb41('0x66')]({'where':{'name':_0x494b3b,'userProfileId':_0x1f7608[_0xdb41('0x67')]},'raw':!![]})[_0xdb41('0x21')](function(_0x282c8c){if(_0x282c8c&&_0x282c8c[_0xdb41('0x68')]===0x0){return db[_0xdb41('0x3b')][_0xdb41('0x60')]({'name':_0x38dc33[_0xdb41('0x3d')],'resourceId':_0x38dc33['id'],'type':_0x282c8c['name'],'sectionId':_0x282c8c['id']},{})['then'](function(){return _0x5006b5;});}else{return _0x5006b5;}})[_0xdb41('0x2c')](function(_0x1de5f8){logger[_0xdb41('0x28')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x1de5f8);throw _0x1de5f8;});}return _0x5006b5;})[_0xdb41('0x21')](respondWithResult(_0x428457,0xc9))['catch'](handleError(_0x428457,null));};exports[_0xdb41('0x69')]=function(_0x161d3c,_0x460fc1){if(_0x161d3c[_0xdb41('0x61')]['id']){delete _0x161d3c['body']['id'];}return db[_0xdb41('0x41')][_0xdb41('0x66')]({'where':{'id':_0x161d3c[_0xdb41('0x5a')]['id']},'include':[{'model':db[_0xdb41('0x5b')],'as':_0xdb41('0x40')}]})[_0xdb41('0x21')](handleEntityNotFound(_0x460fc1,null))[_0xdb41('0x21')](saveUpdates(_0x161d3c[_0xdb41('0x61')],null))[_0xdb41('0x21')](respondWithResult(_0x460fc1,null))[_0xdb41('0x2c')](handleError(_0x460fc1,null));};exports[_0xdb41('0x38')]=function(_0x2b9bc3,_0x5a972d){return db[_0xdb41('0x41')][_0xdb41('0x66')]({'where':{'id':_0x2b9bc3[_0xdb41('0x5a')]['id']}})[_0xdb41('0x21')](handleEntityNotFound(_0x5a972d,null))['then'](removeEntity(_0x5a972d,null))[_0xdb41('0x2c')](handleError(_0x5a972d,null));};exports['describe']=function(_0x269a61,_0x6871ab){return db[_0xdb41('0x41')]['describe']()[_0xdb41('0x21')](respondWithResult(_0x6871ab,null))[_0xdb41('0x2c')](handleError(_0x6871ab,null));};exports[_0xdb41('0x6a')]=function(_0x863c8c,_0x254a51,_0x335086){if(_0x863c8c[_0xdb41('0x61')]['id']){delete _0x863c8c[_0xdb41('0x61')]['id'];}return db[_0xdb41('0x41')][_0xdb41('0x66')]({'where':{'id':_0x863c8c[_0xdb41('0x5a')]['id']}})[_0xdb41('0x21')](handleEntityNotFound(_0x254a51,null))['then'](function(_0x576cd2){if(_0x576cd2){_0x863c8c['body'][_0xdb41('0x6b')]=_0x576cd2['id'];return db['Disposition'][_0xdb41('0x60')](_0x863c8c[_0xdb41('0x61')]);}})[_0xdb41('0x21')](respondWithResult(_0x254a51,null))[_0xdb41('0x2c')](handleError(_0x254a51,null));};exports[_0xdb41('0x6c')]=function(_0x58b7d8,_0x4657cd,_0x154ea6){var _0x4efcd9={'raw':![],'where':{}};var _0x49258d={};var _0x14e33e={'count':0x0,'rows':[]};return db[_0xdb41('0x41')][_0xdb41('0x6d')]({'where':{'id':_0x58b7d8[_0xdb41('0x5a')]['id']}})[_0xdb41('0x21')](handleEntityNotFound(_0x4657cd,null))[_0xdb41('0x21')](function(_0x5191dd){if(_0x5191dd){_0x49258d[_0xdb41('0x46')]=_['keys'](db[_0xdb41('0x6e')][_0xdb41('0x42')]);_0x49258d[_0xdb41('0x49')]=_[_0xdb41('0x48')](_0x58b7d8[_0xdb41('0x49')]);_0x49258d[_0xdb41('0x51')]=_[_0xdb41('0x4a')](_0x49258d[_0xdb41('0x46')],_0x49258d[_0xdb41('0x49')]);_0x4efcd9['attributes']=_[_0xdb41('0x4a')](_0x49258d[_0xdb41('0x46')],qs[_0xdb41('0x4b')](_0x58b7d8['query'][_0xdb41('0x4b')]));_0x4efcd9[_0xdb41('0x4c')]=_0x4efcd9[_0xdb41('0x4c')][_0xdb41('0x5c')]?_0x4efcd9[_0xdb41('0x4c')]:_0x49258d[_0xdb41('0x46')];if(!_0x58b7d8[_0xdb41('0x49')][_0xdb41('0x4d')](_0xdb41('0x4e'))){_0x4efcd9[_0xdb41('0x33')]=qs['limit'](_0x58b7d8[_0xdb41('0x49')][_0xdb41('0x33')]);_0x4efcd9[_0xdb41('0x31')]=qs[_0xdb41('0x31')](_0x58b7d8[_0xdb41('0x49')]['offset']);}_0x4efcd9[_0xdb41('0x4f')]=qs[_0xdb41('0x50')](_0x58b7d8[_0xdb41('0x49')][_0xdb41('0x50')]);_0x4efcd9['where']=qs[_0xdb41('0x51')](_[_0xdb41('0x52')](_0x58b7d8['query'],_0x49258d[_0xdb41('0x51')]));_0x4efcd9[_0xdb41('0x55')][_0xdb41('0x6b')]=_0x5191dd['id'];if(_0x58b7d8['query'][_0xdb41('0x53')]){_0x4efcd9['where']=_[_0xdb41('0x54')](_0x4efcd9[_0xdb41('0x55')],{'$or':_[_0xdb41('0x47')](_0x4efcd9[_0xdb41('0x4c')],function(_0x4ca9cb){var _0x468c9b={};_0x468c9b[_0x4ca9cb]={'$like':'%'+_0x58b7d8[_0xdb41('0x49')][_0xdb41('0x53')]+'%'};return _0x468c9b;})});}_0x4efcd9=_[_0xdb41('0x54')]({},_0x4efcd9,_0x58b7d8[_0xdb41('0x5f')]);return db[_0xdb41('0x6e')][_0xdb41('0x34')]({'where':_0x4efcd9[_0xdb41('0x55')]})[_0xdb41('0x21')](function(_0x2f7517){_0x14e33e[_0xdb41('0x34')]=_0x2f7517;if(_0x58b7d8[_0xdb41('0x49')][_0xdb41('0x5d')]){_0x4efcd9[_0xdb41('0x5e')]=[{'all':!![]}];}return db['Disposition']['findAll'](_0x4efcd9);})[_0xdb41('0x21')](function(_0x1e0d29){_0x14e33e['rows']=_0x1e0d29;return _0x14e33e;});}})[_0xdb41('0x21')](respondWithFilteredResult(_0x4657cd,_0x4efcd9))[_0xdb41('0x2c')](handleError(_0x4657cd,null));};exports[_0xdb41('0x6f')]=function(_0x1dea70,_0x26837d,_0x587a40){return db['FaxAccount'][_0xdb41('0x66')]({'where':{'id':_0x1dea70[_0xdb41('0x5a')]['id']}})[_0xdb41('0x21')](handleEntityNotFound(_0x26837d,null))[_0xdb41('0x21')](function(_0x39917a){if(_0x39917a){return _0x39917a['removeDispositions'](_0x1dea70['query'][_0xdb41('0x70')]);}})[_0xdb41('0x21')](respondWithStatusCode(_0x26837d,null))['catch'](handleError(_0x26837d,null));};exports['addAnswer']=function(_0xeaffa4,_0x332aa2,_0x28dcfc){if(_0xeaffa4[_0xdb41('0x61')]['id']){delete _0xeaffa4[_0xdb41('0x61')]['id'];}return db[_0xdb41('0x41')]['find']({'where':{'id':_0xeaffa4[_0xdb41('0x5a')]['id']}})['then'](handleEntityNotFound(_0x332aa2,null))[_0xdb41('0x21')](function(_0x3b154c){if(_0x3b154c){_0xeaffa4['body'][_0xdb41('0x6b')]=_0x3b154c['id'];return db[_0xdb41('0x71')][_0xdb41('0x60')](_0xeaffa4[_0xdb41('0x61')]);}})[_0xdb41('0x21')](respondWithResult(_0x332aa2,null))[_0xdb41('0x2c')](handleError(_0x332aa2,null));};exports[_0xdb41('0x72')]=function(_0x5f3e38,_0xef45e3,_0x21b8ff){var _0x177c02={'raw':![],'where':{}};var _0x3e7b58={};var _0x3dcdcd={'count':0x0,'rows':[]};return db[_0xdb41('0x41')][_0xdb41('0x6d')]({'where':{'id':_0x5f3e38[_0xdb41('0x5a')]['id']}})['then'](handleEntityNotFound(_0xef45e3,null))['then'](function(_0x587298){if(_0x587298){_0x3e7b58[_0xdb41('0x46')]=_['keys'](db[_0xdb41('0x71')][_0xdb41('0x42')]);_0x3e7b58[_0xdb41('0x49')]=_['keys'](_0x5f3e38[_0xdb41('0x49')]);_0x3e7b58[_0xdb41('0x51')]=_[_0xdb41('0x4a')](_0x3e7b58[_0xdb41('0x46')],_0x3e7b58[_0xdb41('0x49')]);_0x177c02[_0xdb41('0x4c')]=_[_0xdb41('0x4a')](_0x3e7b58[_0xdb41('0x46')],qs[_0xdb41('0x4b')](_0x5f3e38['query']['fields']));_0x177c02[_0xdb41('0x4c')]=_0x177c02[_0xdb41('0x4c')][_0xdb41('0x5c')]?_0x177c02[_0xdb41('0x4c')]:_0x3e7b58[_0xdb41('0x46')];if(!_0x5f3e38['query'][_0xdb41('0x4d')]('nolimit')){_0x177c02[_0xdb41('0x33')]=qs[_0xdb41('0x33')](_0x5f3e38[_0xdb41('0x49')][_0xdb41('0x33')]);_0x177c02[_0xdb41('0x31')]=qs[_0xdb41('0x31')](_0x5f3e38['query'][_0xdb41('0x31')]);}_0x177c02['order']=qs['sort'](_0x5f3e38['query'][_0xdb41('0x50')]);_0x177c02[_0xdb41('0x55')]=qs[_0xdb41('0x51')](_[_0xdb41('0x52')](_0x5f3e38['query'],_0x3e7b58[_0xdb41('0x51')]));_0x177c02[_0xdb41('0x55')][_0xdb41('0x6b')]=_0x587298['id'];if(_0x5f3e38['query'][_0xdb41('0x53')]){_0x177c02['where']=_[_0xdb41('0x54')](_0x177c02[_0xdb41('0x55')],{'$or':_[_0xdb41('0x47')](_0x177c02[_0xdb41('0x4c')],function(_0x3e8950){var _0x1cba97={};_0x1cba97[_0x3e8950]={'$like':'%'+_0x5f3e38[_0xdb41('0x49')][_0xdb41('0x53')]+'%'};return _0x1cba97;})});}_0x177c02=_[_0xdb41('0x54')]({},_0x177c02,_0x5f3e38['options']);return db['CannedAnswer'][_0xdb41('0x34')]({'where':_0x177c02['where']})[_0xdb41('0x21')](function(_0x334d39){_0x3dcdcd[_0xdb41('0x34')]=_0x334d39;if(_0x5f3e38[_0xdb41('0x49')][_0xdb41('0x5d')]){_0x177c02[_0xdb41('0x5e')]=[{'all':!![]}];}return db[_0xdb41('0x71')][_0xdb41('0x57')](_0x177c02);})[_0xdb41('0x21')](function(_0x1e3246){_0x3dcdcd[_0xdb41('0x58')]=_0x1e3246;return _0x3dcdcd;});}})[_0xdb41('0x21')](respondWithFilteredResult(_0xef45e3,_0x177c02))[_0xdb41('0x2c')](handleError(_0xef45e3,null));};exports[_0xdb41('0x73')]=function(_0x18c8e9,_0x3bcea7,_0x33d78f){return db[_0xdb41('0x41')][_0xdb41('0x66')]({'where':{'id':_0x18c8e9['params']['id']}})[_0xdb41('0x21')](handleEntityNotFound(_0x3bcea7,null))[_0xdb41('0x21')](function(_0x4954d3){if(_0x4954d3){return _0x4954d3[_0xdb41('0x73')](_0x18c8e9[_0xdb41('0x49')][_0xdb41('0x70')]);}})[_0xdb41('0x21')](respondWithStatusCode(_0x3bcea7,null))[_0xdb41('0x2c')](handleError(_0x3bcea7,null));};exports[_0xdb41('0x74')]=function(_0x1f6b40,_0x18f109,_0x4cfa05){return db[_0xdb41('0x75')][_0xdb41('0x66')]({'where':{'id':_0x1f6b40[_0xdb41('0x5a')]['id']}})[_0xdb41('0x21')](handleEntityNotFound(_0x18f109,null))['then'](function(_0xc35202){if(_0xc35202){return _0xc35202[_0xdb41('0x74')](_0x1f6b40[_0xdb41('0x61')][_0xdb41('0x70')],_[_0xdb41('0x76')](_0x1f6b40[_0xdb41('0x61')],[_0xdb41('0x70'),'id'])||{});}})[_0xdb41('0x21')](respondWithResult(_0x18f109,null))[_0xdb41('0x2c')](handleError(_0x18f109,null));};exports['getInteractions']=function(_0x5e3eec,_0x5f0dc2,_0x3f7060){var _0x2ebcff={'raw':![],'where':{}};var _0x4b3dda={};var _0x42c700={'count':0x0,'rows':[]};return db['FaxAccount']['findOne']({'where':{'id':_0x5e3eec['params']['id']}})[_0xdb41('0x21')](handleEntityNotFound(_0x5f0dc2,null))[_0xdb41('0x21')](function(_0x11c6f8){if(_0x11c6f8){_0x4b3dda[_0xdb41('0x46')]=_['keys'](db[_0xdb41('0x75')][_0xdb41('0x42')]);_0x4b3dda['query']=_[_0xdb41('0x48')](_0x5e3eec[_0xdb41('0x49')]);_0x4b3dda[_0xdb41('0x51')]=_[_0xdb41('0x4a')](_0x4b3dda[_0xdb41('0x46')],_0x4b3dda[_0xdb41('0x49')]);_0x2ebcff[_0xdb41('0x4c')]=_[_0xdb41('0x4a')](_0x4b3dda[_0xdb41('0x46')],qs['fields'](_0x5e3eec[_0xdb41('0x49')][_0xdb41('0x4b')]));_0x2ebcff[_0xdb41('0x4c')]=_0x2ebcff[_0xdb41('0x4c')]['length']?_0x2ebcff[_0xdb41('0x4c')]:_0x4b3dda[_0xdb41('0x46')];if(!_0x5e3eec[_0xdb41('0x49')][_0xdb41('0x4d')](_0xdb41('0x4e'))){_0x2ebcff[_0xdb41('0x33')]=qs[_0xdb41('0x33')](_0x5e3eec[_0xdb41('0x49')]['limit']);_0x2ebcff[_0xdb41('0x31')]=qs[_0xdb41('0x31')](_0x5e3eec[_0xdb41('0x49')]['offset']);}_0x2ebcff['order']=qs[_0xdb41('0x50')](_0x5e3eec['query']['sort']);_0x2ebcff[_0xdb41('0x55')]=qs['filters'](_[_0xdb41('0x52')](_0x5e3eec[_0xdb41('0x49')],_0x4b3dda[_0xdb41('0x51')]));_0x2ebcff[_0xdb41('0x55')][_0xdb41('0x6b')]=_0x11c6f8['id'];if(_0x5e3eec[_0xdb41('0x49')][_0xdb41('0x53')]){_0x2ebcff[_0xdb41('0x55')]=_[_0xdb41('0x54')](_0x2ebcff[_0xdb41('0x55')],{'$or':_['map'](_0x2ebcff['attributes'],function(_0x17edf9){var _0x12fd65={};_0x12fd65[_0x17edf9]={'$like':'%'+_0x5e3eec[_0xdb41('0x49')][_0xdb41('0x53')]+'%'};return _0x12fd65;})});}_0x2ebcff=_[_0xdb41('0x54')]({},_0x2ebcff,_0x5e3eec[_0xdb41('0x5f')]);return db['FaxInteraction']['count']({'where':_0x2ebcff[_0xdb41('0x55')]})[_0xdb41('0x21')](function(_0x4a7a91){_0x42c700[_0xdb41('0x34')]=_0x4a7a91;if(_0x5e3eec[_0xdb41('0x49')][_0xdb41('0x5d')]){_0x2ebcff['include']=[{'model':db[_0xdb41('0x77')],'as':'Contact','required':![]},{'model':db['User'],'as':_0xdb41('0x78'),'attributes':[_0xdb41('0x3d'),_0xdb41('0x79'),_0xdb41('0x7a')],'required':![]},{'model':db[_0xdb41('0x7b')],'as':_0xdb41('0x7c'),'attributes':['id','name',_0xdb41('0x7d')],'where':_0x5e3eec['query'][_0xdb41('0x7e')]?{'id':_0x5e3eec[_0xdb41('0x49')]['tag']}:undefined,'required':_0x5e3eec[_0xdb41('0x49')][_0xdb41('0x7e')]?!![]:![]}];}return db[_0xdb41('0x75')][_0xdb41('0x57')](_0x2ebcff);})[_0xdb41('0x21')](function(_0x1d3deb){_0x42c700[_0xdb41('0x58')]=_0x1d3deb;return _0x42c700;});}})[_0xdb41('0x21')](respondWithFilteredResult(_0x5f0dc2,_0x2ebcff))[_0xdb41('0x2c')](handleError(_0x5f0dc2,null));};exports[_0xdb41('0x7f')]=function(_0x132bd5,_0x316865){var _0x565485=_0x132bd5[_0xdb41('0x5a')]['id'];var _0x487c8f=_0x132bd5[_0xdb41('0x61')];var _0x371a34=0xc8;var _0x46611a=null;return db[_0xdb41('0x80')][_0xdb41('0x81')]({'isolationLevel':db['sequelize'][_0xdb41('0x82')]['ISOLATION_LEVELS']['READ_COMMITTED']},function(_0x41bcfb){return db[_0xdb41('0x41')][_0xdb41('0x6d')]({'where':{'id':_0x565485},'transaction':_0x41bcfb})[_0xdb41('0x21')](function(_0x3bb35d){if(_0x3bb35d){return db[_0xdb41('0x83')][_0xdb41('0x38')]({'where':{'FaxAccountId':_0x565485},'transaction':_0x41bcfb})['then'](function(){var _0x3390d9=_[_0xdb41('0x47')](_0x487c8f,function(_0x54efd5){_0x54efd5['FaxAccountId']=_0x565485;return _0x54efd5;});return db['FaxApplication'][_0xdb41('0x84')](_0x3390d9,{'transaction':_0x41bcfb});});}else{_0x371a34=0x194;_0x46611a=[];}});})[_0xdb41('0x21')](function(){if(_0x371a34!==0x194){return db[_0xdb41('0x83')][_0xdb41('0x85')]({'where':{'FaxAccountId':_0x565485},'order':_0xdb41('0x86')})['then'](function(_0x16bc45){_0x46611a=_0x16bc45;});}})[_0xdb41('0x2c')](function(_0x58ccbe){_0x371a34=0x1f4;logger[_0xdb41('0x28')](_0x58ccbe[_0xdb41('0x3c')]);if(_0x58ccbe['name']){delete _0x58ccbe['name'];}_0x46611a=_0x58ccbe;})[_0xdb41('0x87')](function(){if(_0x46611a===null){_0x316865[_0xdb41('0x2d')](_0x371a34);}else{if(_0x371a34===0x1f4){_0x316865[_0xdb41('0x2f')](_0x371a34)[_0xdb41('0x3e')](_0x46611a);}else{_0x316865[_0xdb41('0x2f')](_0x371a34)['json'](_0x46611a);}}});};exports['getApplications']=function(_0x5e6318,_0x3535cd,_0x598d10){var _0x2df6ea={};var _0x51995e={};var _0x382880;var _0x240dbe;return db[_0xdb41('0x41')][_0xdb41('0x6d')]({'where':{'id':_0x5e6318[_0xdb41('0x5a')]['id']}})['then'](handleEntityNotFound(_0x3535cd,null))['then'](function(_0x1cc364){if(_0x1cc364){_0x382880=_0x1cc364;_0x51995e[_0xdb41('0x46')]=_[_0xdb41('0x48')](db[_0xdb41('0x83')][_0xdb41('0x42')]);_0x51995e[_0xdb41('0x49')]=_['keys'](_0x5e6318[_0xdb41('0x49')]);_0x51995e[_0xdb41('0x51')]=_[_0xdb41('0x4a')](_0x51995e[_0xdb41('0x46')],_0x51995e['query']);_0x2df6ea[_0xdb41('0x4c')]=_[_0xdb41('0x4a')](_0x51995e['model'],qs[_0xdb41('0x4b')](_0x5e6318[_0xdb41('0x49')]['fields']));_0x2df6ea[_0xdb41('0x4c')]=_0x2df6ea['attributes']['length']?_0x2df6ea[_0xdb41('0x4c')]:_0x51995e[_0xdb41('0x46')];_0x2df6ea[_0xdb41('0x4f')]=qs[_0xdb41('0x50')](_0x5e6318['query'][_0xdb41('0x50')]);_0x2df6ea[_0xdb41('0x55')]=qs[_0xdb41('0x51')](_['pick'](_0x5e6318[_0xdb41('0x49')],_0x51995e[_0xdb41('0x51')]));if(_0x5e6318[_0xdb41('0x49')][_0xdb41('0x53')]){_0x2df6ea[_0xdb41('0x55')]=_[_0xdb41('0x54')](_0x2df6ea[_0xdb41('0x55')],{'$or':_[_0xdb41('0x47')](_0x2df6ea['attributes'],function(_0x2ed864){var _0x3d047f={};_0x3d047f[_0x2ed864]={'$like':'%'+_0x5e6318[_0xdb41('0x49')]['filter']+'%'};return _0x3d047f;})});}_0x2df6ea=_['merge']({},_0x2df6ea,_0x5e6318[_0xdb41('0x5f')]);return _0x382880[_0xdb41('0x88')](_0x2df6ea);}})[_0xdb41('0x21')](function(_0x4993a2){if(_0x4993a2){_0x240dbe=_0x4993a2[_0xdb41('0x5c')];if(!_0x5e6318['query'][_0xdb41('0x4d')]('nolimit')){_0x2df6ea[_0xdb41('0x33')]=qs[_0xdb41('0x33')](_0x5e6318[_0xdb41('0x49')][_0xdb41('0x33')]);_0x2df6ea[_0xdb41('0x31')]=qs[_0xdb41('0x31')](_0x5e6318[_0xdb41('0x49')][_0xdb41('0x31')]);}return _0x382880[_0xdb41('0x88')](_0x2df6ea);}})[_0xdb41('0x21')](function(_0x296390){if(_0x296390){return _0x296390?{'count':_0x240dbe,'rows':_0x296390}:null;}})['then'](respondWithResult(_0x3535cd,null))['catch'](handleError(_0x3535cd,null));};function Extension(_0x153108,_0x21a7e6,_0x1967ae,_0x4288c0){this['context']=_0xdb41('0x89');this[_0xdb41('0x8a')]=_0x153108[_0xdb41('0x8b')];this[_0xdb41('0x8c')]=_0x4288c0;this[_0xdb41('0x44')]=_0xdb41('0x8d');this[_0xdb41('0x8e')]=_0xdb41('0x8f');this['FaxAccountId']=_0x153108['id'];this['priority']=_0x21a7e6;this[_0xdb41('0x90')]=_0x1967ae;}function createExtensionsReciveFax(_0x5d90a0){var _0xa2c7bd=0x1;var _0x367576=[];_0x367576[_0xdb41('0x91')](new Extension(_0x5d90a0,_0xa2c7bd,'',_0xdb41('0x92')));_0xa2c7bd+=0x1;_0x367576['push'](new Extension(_0x5d90a0,_0xa2c7bd,'CDR(type)=inbound-fax','Set'));_0xa2c7bd+=0x1;for(var _0x51b8de in _0x5d90a0){if(_0x5d90a0[_0xdb41('0x4d')](_0x51b8de)&&(_0x51b8de===_0xdb41('0x93')||_0x51b8de==='localstationid'||_0x51b8de===_0xdb41('0x94')||_0x51b8de===_0xdb41('0x95')||_0x51b8de===_0xdb41('0x96')||_0x51b8de===_0xdb41('0x97')||_0x51b8de===_0xdb41('0x98')||_0x51b8de==='modem'||_0x51b8de===_0xdb41('0x99'))){_0x367576[_0xdb41('0x91')](new Extension(_0x5d90a0,_0xa2c7bd,'FAXOPT('+_0x51b8de+')='+_0x5d90a0[_0x51b8de],'Set'));_0xa2c7bd+=0x1;}}_0x367576[_0xdb41('0x91')](new Extension(_0x5d90a0,_0xa2c7bd,'6','Wait'));_0xa2c7bd+=0x1;_0x367576[_0xdb41('0x91')](new Extension(_0x5d90a0,_0xa2c7bd,_0xdb41('0x9a'),_0xdb41('0x9b')));_0xa2c7bd=0x0;return _0x367576;}exports[_0xdb41('0x9c')]=function(_0x429092,_0x1167f5,_0x46a793){var _0x23eddd;return db[_0xdb41('0x80')][_0xdb41('0x81')](function(_0x41165a){return db[_0xdb41('0x41')][_0xdb41('0x60')](_0x429092[_0xdb41('0x61')],{'transaction':_0x41165a})['then'](function(_0x3e51cb){_0x23eddd=_0x3e51cb[_0xdb41('0x39')]({'plain':!![]});return db[_0xdb41('0x9d')]['bulkCreate'](createExtensionsReciveFax(_0x23eddd),{'transaction':_0x41165a});});})[_0xdb41('0x21')](function(){return _0x23eddd;})[_0xdb41('0x21')](respondWithResult(_0x1167f5,null))[_0xdb41('0x2c')](handleError(_0x1167f5,null));};exports[_0xdb41('0x9e')]=function(_0x3fbf7f,_0x3f74a0,_0x199bf7){var _0xd93ec0;return db[_0xdb41('0x80')][_0xdb41('0x81')](function(_0x385452){return db[_0xdb41('0x41')]['update'](_0x3fbf7f[_0xdb41('0x61')],{'where':{'id':_0x3fbf7f[_0xdb41('0x61')]['id']},'transaction':_0x385452})[_0xdb41('0x21')](function(_0x4aabb1){return db[_0xdb41('0x9d')][_0xdb41('0x38')]({'where':{'FaxAccountId':_0x3fbf7f[_0xdb41('0x61')]['id']},'transaction':_0x385452})[_0xdb41('0x21')](function(_0x3f5a17){return db[_0xdb41('0x9d')]['bulkCreate'](createExtensionsReciveFax(_[_0xdb41('0x76')](_0x3fbf7f[_0xdb41('0x61')],['tech',_0xdb41('0x45'),_0xdb41('0x9f'),_0xdb41('0xa0'),'TrunkId',_0xdb41('0xa1')])),{'transaction':_0x385452});});});})['then'](function(){return db[_0xdb41('0x41')][_0xdb41('0xa2')](_0x3fbf7f['body']['id']);})[_0xdb41('0x21')](respondWithResult(_0x3f74a0,null))['catch'](handleError(_0x3f74a0,null));};exports[_0xdb41('0xa3')]=function(_0x45fdf8,_0x674676,_0x71fec2){var _0x2d0cdf={'raw':!![],'where':{}};var _0x4be083={};var _0x5abfa8={'count':0x0,'rows':[]};return db[_0xdb41('0x41')]['findOne']({'where':{'id':_0x45fdf8[_0xdb41('0x5a')]['id']}})[_0xdb41('0x21')](handleEntityNotFound(_0x674676,null))[_0xdb41('0x21')](function(_0x14b6f3){if(_0x14b6f3){_0x4be083[_0xdb41('0x46')]=_[_0xdb41('0x48')](db[_0xdb41('0xa4')]['rawAttributes']);_0x4be083['query']=_['keys'](_0x45fdf8[_0xdb41('0x49')]);_0x4be083[_0xdb41('0x51')]=_[_0xdb41('0x4a')](_0x4be083[_0xdb41('0x46')],_0x4be083[_0xdb41('0x49')]);_0x2d0cdf['attributes']=_['intersection'](_0x4be083[_0xdb41('0x46')],qs[_0xdb41('0x4b')](_0x45fdf8['query'][_0xdb41('0x4b')]));_0x2d0cdf[_0xdb41('0x4c')]=_0x2d0cdf['attributes'][_0xdb41('0x5c')]?_0x2d0cdf['attributes']:_0x4be083[_0xdb41('0x46')];if(!_0x45fdf8['query']['hasOwnProperty']('nolimit')){_0x2d0cdf['limit']=qs[_0xdb41('0x33')](_0x45fdf8[_0xdb41('0x49')][_0xdb41('0x33')]);_0x2d0cdf[_0xdb41('0x31')]=qs[_0xdb41('0x31')](_0x45fdf8['query']['offset']);}_0x2d0cdf[_0xdb41('0x4f')]=qs[_0xdb41('0x50')](_0x45fdf8['query'][_0xdb41('0x50')]);_0x2d0cdf['where']=qs['filters'](_[_0xdb41('0x52')](_0x45fdf8['query'],_0x4be083[_0xdb41('0x51')]));_0x2d0cdf[_0xdb41('0x55')][_0xdb41('0x6b')]=_0x14b6f3['id'];if(_0x45fdf8[_0xdb41('0x49')][_0xdb41('0x53')]){_0x2d0cdf[_0xdb41('0x55')]=_[_0xdb41('0x54')](_0x2d0cdf['where'],{'$or':_['map'](_0x2d0cdf['attributes'],function(_0xd07c7c){var _0xf9ee0f={};_0xf9ee0f[_0xd07c7c]={'$like':'%'+_0x45fdf8[_0xdb41('0x49')][_0xdb41('0x53')]+'%'};return _0xf9ee0f;})});}if(_0x45fdf8[_0xdb41('0x49')][_0xdb41('0xa5')]){var _0x2b7630=_0x45fdf8[_0xdb41('0x49')][_0xdb41('0xa5')]['split'](',');var _0x4752de={};_0x4752de[_0x2b7630[0x0]]={'$gte':moment(_0x2b7630[0x1])['format'](_0xdb41('0xa6'))};_0x2d0cdf['where']=_[_0xdb41('0x54')](_0x2d0cdf[_0xdb41('0x55')],_0x4752de);}_0x2d0cdf=_[_0xdb41('0x54')]({},_0x2d0cdf,_0x45fdf8[_0xdb41('0x5f')]);return db['FaxMessage'][_0xdb41('0x34')]({'where':_0x2d0cdf[_0xdb41('0x55')]})[_0xdb41('0x21')](function(_0x2d2037){_0x5abfa8[_0xdb41('0x34')]=_0x2d2037;if(_0x45fdf8[_0xdb41('0x49')]['includeAll']){_0x2d0cdf[_0xdb41('0x5e')]=[{'all':!![]}];}return db['FaxMessage'][_0xdb41('0x57')](_0x2d0cdf);})[_0xdb41('0x21')](function(_0x23f2cc){_0x5abfa8[_0xdb41('0x58')]=_0x23f2cc;return _0x5abfa8;});}})[_0xdb41('0x21')](respondWithFilteredResult(_0x674676,_0x2d0cdf))[_0xdb41('0x2c')](handleError(_0x674676,null));};exports[_0xdb41('0x3e')]=function(_0x51467c,_0x18fe92,_0x10b500){var _0x5b2076,_0x4f611d={},_0x9c0315;if(_0x51467c[_0xdb41('0x61')]['to']){_0x9c0315=_0x51467c[_0xdb41('0x61')]['to'][0x0];}return db[_0xdb41('0x41')][_0xdb41('0x66')]({'where':{'id':_0x51467c[_0xdb41('0x5a')]['id']},'include':[{'model':db[_0xdb41('0xa7')],'as':_0xdb41('0xa8'),'include':[{'model':db[_0xdb41('0x77')],'as':'Contacts','where':{'fax':_0x9c0315},'limit':0x1,'order':[[_0xdb41('0xa0'),'DESC']]}]}]})[_0xdb41('0x21')](handleEntityNotFound(_0x18fe92,null))[_0xdb41('0x21')](function(_0x1551e5){_0x5b2076=_0x1551e5;if(_0x51467c['body'][_0xdb41('0xa9')]&&_0x51467c[_0xdb41('0x61')][_0xdb41('0xa9')][_0xdb41('0x5c')]){for(var _0x14c4bf=0x0;_0x14c4bf<_0x51467c['body']['attachments'][_0xdb41('0x5c')];_0x14c4bf+=0x1){_0x51467c[_0xdb41('0x61')][_0xdb41('0xa9')][_0x14c4bf]={'filename':_0x51467c[_0xdb41('0x61')][_0xdb41('0xa9')][_0x14c4bf][_0xdb41('0x3d')],'id':_0x51467c['body'][_0xdb41('0xa9')][_0x14c4bf]['id'],'path':path[_0xdb41('0xaa')](config[_0xdb41('0xab')],_0xdb41('0xac'),_0x51467c[_0xdb41('0x61')][_0xdb41('0xa9')][_0x14c4bf][_0xdb41('0xad')])};}}return respondWithRpcPromise('CheckAfterSend',_0xdb41('0xae'),{'FaxAccountId':_[_0xdb41('0xaf')](_0x51467c[_0xdb41('0x5a')]['id'])?undefined:_0x51467c['params']['id'],'path':_['isNil'](_0x51467c[_0xdb41('0x61')][_0xdb41('0xa9')][0x0]['path'])?undefined:_0x51467c[_0xdb41('0x61')][_0xdb41('0xa9')][0x0]['path'],'fax':_[_0xdb41('0xaf')](_0x51467c[_0xdb41('0x61')]['to'][0x0])?undefined:_0x51467c['body']['to'][0x0]},client9002);})[_0xdb41('0x21')](function(){if(_0x5b2076){if(_[_0xdb41('0xaf')](_0x51467c[_0xdb41('0x61')]['from'])){_0x51467c[_0xdb41('0x61')]['from']=util[_0xdb41('0xb0')]('\x22%s\x22\x20<%s>',_0x5b2076['name'],_0x5b2076[_0xdb41('0xb1')]);}if(_0x5b2076['List']){if(_0x5b2076[_0xdb41('0xa8')][_0xdb41('0xb2')][_0xdb41('0x5c')]){return _0x5b2076[_0xdb41('0xa8')][_0xdb41('0xb2')][0x0];}else{return db[_0xdb41('0x77')][_0xdb41('0x60')](_[_0xdb41('0x19')](_0x51467c[_0xdb41('0x61')],{'firstName':_0x51467c['body']['to'][0x0],'phone':_0x51467c[_0xdb41('0x61')]['to'][0x0],'fax':_0x51467c[_0xdb41('0x61')]['to'][0x0],'ListId':_0x5b2076[_0xdb41('0xa1')]}));}}else{throw new Error(_0xdb41('0xb3'));}}else{throw new Error(_0xdb41('0xb4'));}})[_0xdb41('0x21')](function(_0x1141df){if(_0x1141df){return db['FaxInteraction'][_0xdb41('0x66')]({'where':{'ContactId':_0x1141df['id'],'closed':![],'FaxAccountId':_0x5b2076['id']}})[_0xdb41('0x21')](function(_0x5f613c){if(_0x5f613c){return[_0x5f613c,![]];}return db['FaxInteraction'][_0xdb41('0x60')]({'UserId':_0x51467c[_0xdb41('0x62')]['id'],'ContactId':_0x1141df['id'],'FaxAccountId':_0x5b2076['id'],'fax':_0x51467c[_0xdb41('0x61')]['to'][0x0],'firstMsgDirection':_0xdb41('0xb5'),'Messages':[_[_0xdb41('0x54')](_0x51467c[_0xdb41('0x61')],{'read':![],'body':_0x51467c[_0xdb41('0x61')][_0xdb41('0xa9')][0x0][_0xdb41('0xb6')],'FaxAccountId':_0x5b2076['id'],'UserId':_0x51467c['user']['id'],'ContactId':_0x1141df['id'],'AttachmentId':_0x51467c[_0xdb41('0x61')][_0xdb41('0xa9')][0x0]['id']})]},{'include':[{'model':db[_0xdb41('0xa4')],'as':_0xdb41('0xb7')}]})[_0xdb41('0x21')](function(_0x3b12e6){return[_0x3b12e6,!![]];});});}else{throw new Error(_0xdb41('0xb8'));}})[_0xdb41('0xb9')](function(_0x267768,_0x4b30d8){if(_0x4b30d8){return _0x267768;}return db[_0xdb41('0xa4')][_0xdb41('0x60')]({'direction':_0xdb41('0xb5'),'read':![],'body':_0x51467c[_0xdb41('0x61')]['attachments'][0x0]['filename'],'FaxAccountId':_0x5b2076['id'],'FaxInteractionId':_0x267768['id'],'UserId':_0x51467c['user']['id'],'ContactId':_0x267768['ContactId'],'AttachmentId':_0x51467c[_0xdb41('0x61')][_0xdb41('0xa9')][0x0]['id']})[_0xdb41('0x21')](function(_0xa7ccb9){_0x267768['dataValues'][_0xdb41('0xb7')]=[];_0x267768['dataValues'][_0xdb41('0xb7')][_0xdb41('0x91')](_0xa7ccb9[_0xdb41('0xba')]);return _0x267768;});})[_0xdb41('0x21')](function(_0x16196b){respondWithRpcPromise('SendFax',_0xdb41('0xbb'),{'FaxAccountId':_[_0xdb41('0xaf')](_0x51467c['params']['id'])?undefined:_0x51467c['params']['id'],'path':_[_0xdb41('0xaf')](_0x51467c[_0xdb41('0x61')][_0xdb41('0xa9')][0x0][_0xdb41('0x7')])?undefined:_0x51467c['body'][_0xdb41('0xa9')][0x0][_0xdb41('0x7')],'fax':_[_0xdb41('0xaf')](_0x51467c[_0xdb41('0x61')]['to'][0x0])?undefined:_0x51467c['body']['to'][0x0],'AttachmentId':_0x51467c[_0xdb41('0x61')][_0xdb41('0xa9')][0x0]['id']},client9002)['then'](function(_0x1dcf2e){logger['info'](_0xdb41('0xbc'),_0x1dcf2e);})[_0xdb41('0x2c')](function(_0x1234e7){logger[_0xdb41('0x22')](_0xdb41('0xbc'),_0x1234e7);});return _0x16196b;})[_0xdb41('0x21')](respondWithResult(_0x18fe92,null))['catch'](handleError(_0x18fe92,null));};exports['addAgents']=function(_0x276c45,_0x2e8868,_0x57ac01){return db[_0xdb41('0x41')][_0xdb41('0x66')]({'where':{'id':_0x276c45[_0xdb41('0x5a')]['id']}})[_0xdb41('0x21')](handleEntityNotFound(_0x2e8868,null))['then'](function(_0x5edc33){if(_0x5edc33){return _0x5edc33['addAgents'](_0x276c45[_0xdb41('0x61')][_0xdb41('0x70')],_[_0xdb41('0x76')](_0x276c45[_0xdb41('0x61')],[_0xdb41('0x70'),'id'])||{})[_0xdb41('0xb9')](function(_0x4b84de){for(var _0x5d18bb=0x0;_0x5d18bb<_0x276c45[_0xdb41('0x61')][_0xdb41('0x70')][_0xdb41('0x5c')];_0x5d18bb+=0x1){socket[_0xdb41('0xbd')]('userFaxAccount:save',{'UserId':Number(_0x276c45[_0xdb41('0x61')][_0xdb41('0x70')][_0x5d18bb]),'FaxAccountId':Number(_0x276c45[_0xdb41('0x5a')]['id'])});}return _0x4b84de;});}})[_0xdb41('0x21')](respondWithResult(_0x2e8868,null))[_0xdb41('0x2c')](handleError(_0x2e8868,null));};exports[_0xdb41('0xbe')]=function(_0x8f1edd,_0xf0cc1,_0x432c9c){return db[_0xdb41('0x41')]['find']({'where':{'id':_0x8f1edd[_0xdb41('0x5a')]['id']}})[_0xdb41('0x21')](handleEntityNotFound(_0xf0cc1,null))[_0xdb41('0x21')](function(_0x485a7d){if(_0x485a7d){return _0x485a7d[_0xdb41('0xbe')](_0x8f1edd['query'][_0xdb41('0x70')])[_0xdb41('0x21')](function(){if(_['isArray'](_0x8f1edd[_0xdb41('0x49')][_0xdb41('0x70')])){for(var _0x5d4451=0x0;_0x5d4451<_0x8f1edd['query'][_0xdb41('0x70')][_0xdb41('0x5c')];_0x5d4451+=0x1){socket[_0xdb41('0xbd')](_0xdb41('0xbf'),{'UserId':Number(_0x8f1edd[_0xdb41('0x49')][_0xdb41('0x70')][_0x5d4451]),'FaxAccountId':Number(_0x8f1edd[_0xdb41('0x5a')]['id'])});}}else{socket[_0xdb41('0xbd')]('userFaxAccount:remove',{'UserId':Number(_0x8f1edd[_0xdb41('0x49')][_0xdb41('0x70')]),'FaxAccountId':Number(_0x8f1edd[_0xdb41('0x5a')]['id'])});}});}})[_0xdb41('0x21')](respondWithStatusCode(_0xf0cc1,null))[_0xdb41('0x2c')](handleError(_0xf0cc1,null));};exports['getAgents']=function(_0x4ece90,_0x42b292,_0x5845f0){var _0x546e18={};var _0x13c354={};var _0x4eed66;var _0x412f95;return db[_0xdb41('0x41')][_0xdb41('0x6d')]({'where':{'id':_0x4ece90['params']['id']}})[_0xdb41('0x21')](handleEntityNotFound(_0x42b292,null))[_0xdb41('0x21')](function(_0x440780){if(_0x440780){_0x4eed66=_0x440780;_0x13c354[_0xdb41('0x46')]=_[_0xdb41('0x48')](db[_0xdb41('0xc0')][_0xdb41('0x42')]);_0x13c354[_0xdb41('0x49')]=_[_0xdb41('0x48')](_0x4ece90['query']);_0x13c354[_0xdb41('0x51')]=_[_0xdb41('0x4a')](_0x13c354[_0xdb41('0x46')],_0x13c354['query']);_0x546e18[_0xdb41('0x4c')]=_['intersection'](_0x13c354[_0xdb41('0x46')],qs[_0xdb41('0x4b')](_0x4ece90[_0xdb41('0x49')][_0xdb41('0x4b')]));_0x546e18[_0xdb41('0x4c')]=_0x546e18['attributes'][_0xdb41('0x5c')]?_0x546e18[_0xdb41('0x4c')]:_0x13c354[_0xdb41('0x46')];_0x546e18[_0xdb41('0x4f')]=qs[_0xdb41('0x50')](_0x4ece90[_0xdb41('0x49')][_0xdb41('0x50')]);_0x546e18[_0xdb41('0x55')]=qs[_0xdb41('0x51')](_[_0xdb41('0x52')](_0x4ece90[_0xdb41('0x49')],_0x13c354[_0xdb41('0x51')]));if(_0x4ece90['query'][_0xdb41('0x53')]){_0x546e18['where']=_[_0xdb41('0x54')](_0x546e18[_0xdb41('0x55')],{'$or':_[_0xdb41('0x47')](_0x546e18['attributes'],function(_0x46829e){var _0xf876e={};_0xf876e[_0x46829e]={'$like':'%'+_0x4ece90['query'][_0xdb41('0x53')]+'%'};return _0xf876e;})});}_0x546e18=_[_0xdb41('0x54')]({},_0x546e18,_0x4ece90[_0xdb41('0x5f')]);return _0x4eed66['getAgents'](_0x546e18);}})[_0xdb41('0x21')](function(_0x1ffea8){if(_0x1ffea8){_0x412f95=_0x1ffea8[_0xdb41('0x5c')];if(!_0x4ece90['query'][_0xdb41('0x4d')](_0xdb41('0x4e'))){_0x546e18[_0xdb41('0x33')]=qs[_0xdb41('0x33')](_0x4ece90['query'][_0xdb41('0x33')]);_0x546e18['offset']=qs[_0xdb41('0x31')](_0x4ece90[_0xdb41('0x49')]['offset']);}return _0x4eed66[_0xdb41('0xc1')](_0x546e18);}})[_0xdb41('0x21')](function(_0x47bd01){if(_0x47bd01){return _0x47bd01?{'count':_0x412f95,'rows':_0x47bd01}:null;}})[_0xdb41('0x21')](respondWithResult(_0x42b292,null))[_0xdb41('0x2c')](handleError(_0x42b292,null));};
\ No newline at end of file