Built motion from commit 4c579f6b.|2.5.32
[motion2.git] / server / api / faxAccount / faxAccount.controller.js
index 6a74aa9..22a0795 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x985b=['show','params','rawAttributes','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','describe','addDisposition','FaxAccountId','Disposition','getDispositions','findOne','hasOwnProperty','pick','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','FaxInteraction','omit','getInteractions','Contact','User','Owner','Tags','color','tag','sequelize','FaxApplication','bulkCreate','findAndCountAll','getApplications','context','from-voip-provider','exten','localstationid','system','description','Fax\x20Extension','priority','appdata','push','CDR(type)=inbound-fax','Set','ecm','gateway','faxdetect','headerinfo','maxrate','modem','t38timeout','FAXOPT(','addAccountApplications','transaction','VoiceExtension','tech','key','createdAt','updatedAt','ListId','getMessages','FaxMessage','$gte','format','YYYY-MM-DD\x20HH:mm:ss','CmList','List','CmContact','Contacts','attachments','join','root','server/files/attachments','basename','CheckAfterSend','isNil','from','fax','List\x20not\x20found','Send\x20Fax\x20failed','user','out','filename','Messages','Contact\x20not\x20found','spread','ContactId','dataValues','SendFax','SendFaxRpc,\x20%s','addAgents','emit','userFaxAccount:save','removeAgents','isArray','userFaxAccount:remove','getAgents','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./faxAccount.socket','jayson/promise','client','http','request','info','FaxAccount,\x20%s,\x20%s','request\x20sent','debug','FaxAccount,\x20%s,\x20%s,\x20%s','error','code','message','result','catch','sendStatus','status','end','json','limit','count','offset','set','Content-Range','apply','reject','update','then','destroy','get','FaxAccounts','UserProfileResource','stack','name','send','index','Pause','mandatoryDispositionPause','map','FaxAccount','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','nolimit','order','sort','where','filter','merge','options','includeAll','include','findAll','rows'];(function(_0x2656a4,_0x28dd1b){var _0x48ce85=function(_0x41d957){while(--_0x41d957){_0x2656a4['push'](_0x2656a4['shift']());}};_0x48ce85(++_0x28dd1b);}(_0x985b,0x129));var _0xb985=function(_0x4b85ab,_0x5c3fb3){_0x4b85ab=_0x4b85ab-0x0;var _0x280b51=_0x985b[_0x4b85ab];return _0x280b51;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xb985('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xb985('0x1'));var rp=require(_0xb985('0x2'));var moment=require(_0xb985('0x3'));var BPromise=require(_0xb985('0x4'));var Mustache=require(_0xb985('0x5'));var util=require('util');var path=require(_0xb985('0x6'));var sox=require(_0xb985('0x7'));var csv=require(_0xb985('0x8'));var ejs=require(_0xb985('0x9'));var fs=require('fs');var fs_extra=require(_0xb985('0xa'));var _=require(_0xb985('0xb'));var squel=require(_0xb985('0xc'));var crypto=require(_0xb985('0xd'));var jsforce=require(_0xb985('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xb985('0x8'));var querystring=require(_0xb985('0xf'));var Papa=require('papaparse');var Redis=require(_0xb985('0x10'));var authService=require('../../components/auth/service');var qs=require(_0xb985('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xb985('0x12'))(_0xb985('0x13'));var utils=require(_0xb985('0x14'));var config=require(_0xb985('0x15'));var licenseUtil=require(_0xb985('0x16'));var db=require(_0xb985('0x17'))['db'];config[_0xb985('0x18')]=_[_0xb985('0x19')](config[_0xb985('0x18')],{'host':_0xb985('0x1a'),'port':0x18eb});var socket=require(_0xb985('0x1b'))(new Redis(config[_0xb985('0x18')]));require(_0xb985('0x1c'))['register'](socket);var jayson=require(_0xb985('0x1d'));var client=jayson[_0xb985('0x1e')][_0xb985('0x1f')]({'port':0x232c});var client9002=jayson[_0xb985('0x1e')][_0xb985('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x5b841d,_0x3f0314,_0x4cc793,_0x5e1d1d){return new BPromise(function(_0x4e92f0,_0x2550ce){var _0x3cb6c8=_0x5e1d1d||client;return _0x3cb6c8[_0xb985('0x20')](_0x5b841d,_0x4cc793)['then'](function(_0x598a92){logger[_0xb985('0x21')](_0xb985('0x22'),_0x3f0314,_0xb985('0x23'));logger[_0xb985('0x24')](_0xb985('0x25'),_0x3f0314,_0xb985('0x23'),JSON['stringify'](_0x598a92));if(_0x598a92[_0xb985('0x26')]){if(_0x598a92[_0xb985('0x26')][_0xb985('0x27')]===0x1f4){logger['error'](_0xb985('0x22'),_0x3f0314,_0x598a92[_0xb985('0x26')][_0xb985('0x28')]);return _0x2550ce(_0x598a92[_0xb985('0x26')][_0xb985('0x28')]);}logger[_0xb985('0x26')](_0xb985('0x22'),_0x3f0314,_0x598a92[_0xb985('0x26')][_0xb985('0x28')]);return _0x4e92f0(_0x598a92[_0xb985('0x26')]['message']);}else{logger[_0xb985('0x21')](_0xb985('0x22'),_0x3f0314,_0xb985('0x23'));_0x4e92f0(_0x598a92[_0xb985('0x29')]['message']);}})[_0xb985('0x2a')](function(_0x482393){logger[_0xb985('0x26')](_0xb985('0x22'),_0x3f0314,_0x482393);_0x2550ce(_0x482393);});});}function respondWithStatusCode(_0x1daefa,_0x3c04d1){_0x3c04d1=_0x3c04d1||0xcc;return function(_0x525142){if(_0x525142){return _0x1daefa[_0xb985('0x2b')](_0x3c04d1);}return _0x1daefa[_0xb985('0x2c')](_0x3c04d1)[_0xb985('0x2d')]();};}function respondWithResult(_0x435be3,_0x1bd526){_0x1bd526=_0x1bd526||0xc8;return function(_0xff2d94){if(_0xff2d94){return _0x435be3[_0xb985('0x2c')](_0x1bd526)[_0xb985('0x2e')](_0xff2d94);}};}function respondWithFilteredResult(_0x56ca88,_0x425897){return function(_0x4b64e6){if(_0x4b64e6){var _0x5e4bd7=typeof _0x425897['offset']==='undefined'&&typeof _0x425897[_0xb985('0x2f')]==='undefined';var _0x16b231=_0x4b64e6[_0xb985('0x30')];var _0x119a4b=_0x5e4bd7?0x0:_0x425897[_0xb985('0x31')];var _0xec774e=_0x5e4bd7?_0x4b64e6[_0xb985('0x30')]:_0x425897[_0xb985('0x31')]+_0x425897[_0xb985('0x2f')];var _0x5e02e3;if(_0xec774e>=_0x16b231){_0xec774e=_0x16b231;_0x5e02e3=0xc8;}else{_0x5e02e3=0xce;}_0x56ca88[_0xb985('0x2c')](_0x5e02e3);return _0x56ca88[_0xb985('0x32')](_0xb985('0x33'),_0x119a4b+'-'+_0xec774e+'/'+_0x16b231)[_0xb985('0x2e')](_0x4b64e6);}return null;};}function patchUpdates(_0x4be9fc){return function(_0x4e1f87){try{jsonpatch[_0xb985('0x34')](_0x4e1f87,_0x4be9fc,!![]);}catch(_0x2844d5){return BPromise[_0xb985('0x35')](_0x2844d5);}return _0x4e1f87['save']();};}function saveUpdates(_0x315b3c,_0x21d533){return function(_0x3d2dbf){if(_0x3d2dbf){return _0x3d2dbf[_0xb985('0x36')](_0x315b3c)[_0xb985('0x37')](function(_0x1f68f3){return _0x1f68f3;});}return null;};}function removeEntity(_0xeaed2e,_0x46dd22){return function(_0x178227){if(_0x178227){return _0x178227[_0xb985('0x38')]()['then'](function(){var _0x4cc4f9=_0x178227[_0xb985('0x39')]({'plain':!![]});var _0x2668a5=_0xb985('0x3a');return db[_0xb985('0x3b')]['destroy']({'where':{'type':_0x2668a5,'resourceId':_0x4cc4f9['id']}})['then'](function(){return _0x178227;});})[_0xb985('0x37')](function(){_0xeaed2e[_0xb985('0x2c')](0xcc)[_0xb985('0x2d')]();});}};}function handleEntityNotFound(_0x3bd569,_0x4d6831){return function(_0x16677d){if(!_0x16677d){_0x3bd569['sendStatus'](0x194);}return _0x16677d;};}function handleError(_0x34a673,_0x22529d){_0x22529d=_0x22529d||0x1f4;return function(_0x4bf1b8){logger[_0xb985('0x26')](_0x4bf1b8[_0xb985('0x3c')]);if(_0x4bf1b8[_0xb985('0x3d')]){delete _0x4bf1b8['name'];}_0x34a673[_0xb985('0x2c')](_0x22529d)[_0xb985('0x3e')](_0x4bf1b8);};}exports[_0xb985('0x3f')]=function(_0x125a21,_0x1b0826){var _0x231eb3={'include':[{'model':db[_0xb985('0x40')],'as':_0xb985('0x41')}]},_0x447560={},_0x640aa8={'count':0x0,'rows':[]};var _0xc6246d=_[_0xb985('0x42')](db[_0xb985('0x43')]['rawAttributes'],function(_0x1411a0){return{'name':_0x1411a0[_0xb985('0x44')],'type':_0x1411a0[_0xb985('0x45')]['key']};});_0x447560[_0xb985('0x46')]=_[_0xb985('0x42')](_0xc6246d,_0xb985('0x3d'));_0x447560[_0xb985('0x47')]=_[_0xb985('0x48')](_0x125a21[_0xb985('0x47')]);_0x447560[_0xb985('0x49')]=_[_0xb985('0x4a')](_0x447560['model'],_0x447560[_0xb985('0x47')]);_0x231eb3[_0xb985('0x4b')]=_[_0xb985('0x4a')](_0x447560['model'],qs[_0xb985('0x4c')](_0x125a21[_0xb985('0x47')][_0xb985('0x4c')]));_0x231eb3[_0xb985('0x4b')]=_0x231eb3[_0xb985('0x4b')][_0xb985('0x4d')]?_0x231eb3[_0xb985('0x4b')]:_0x447560[_0xb985('0x46')];if(!_0x125a21['query']['hasOwnProperty'](_0xb985('0x4e'))){_0x231eb3['limit']=qs['limit'](_0x125a21['query'][_0xb985('0x2f')]);_0x231eb3[_0xb985('0x31')]=qs[_0xb985('0x31')](_0x125a21[_0xb985('0x47')][_0xb985('0x31')]);}_0x231eb3[_0xb985('0x4f')]=qs[_0xb985('0x50')](_0x125a21['query'][_0xb985('0x50')]);_0x231eb3[_0xb985('0x51')]=qs['filters'](_['pick'](_0x125a21[_0xb985('0x47')],_0x447560[_0xb985('0x49')]),_0xc6246d);if(_0x125a21[_0xb985('0x47')][_0xb985('0x52')]){_0x231eb3['where']=_[_0xb985('0x53')](_0x231eb3[_0xb985('0x51')],{'$or':_[_0xb985('0x42')](_0xc6246d,function(_0x385a73){if(_0x385a73[_0xb985('0x45')]!=='VIRTUAL'){var _0x27a191={};_0x27a191[_0x385a73['name']]={'$like':'%'+_0x125a21[_0xb985('0x47')][_0xb985('0x52')]+'%'};return _0x27a191;}})});}_0x231eb3=_[_0xb985('0x53')]({},_0x231eb3,_0x125a21[_0xb985('0x54')]);var _0x8d6b25={'where':_0x231eb3[_0xb985('0x51')]};return db[_0xb985('0x43')]['count'](_0x8d6b25)[_0xb985('0x37')](function(_0x5c67f1){_0x640aa8[_0xb985('0x30')]=_0x5c67f1;if(_0x125a21['query'][_0xb985('0x55')]){_0x231eb3[_0xb985('0x56')]=[{'all':!![]}];}return db[_0xb985('0x43')][_0xb985('0x57')](_0x231eb3);})[_0xb985('0x37')](function(_0x4cec29){_0x640aa8[_0xb985('0x58')]=_0x4cec29;return _0x640aa8;})[_0xb985('0x37')](respondWithFilteredResult(_0x1b0826,_0x231eb3))[_0xb985('0x2a')](handleError(_0x1b0826,null));};exports[_0xb985('0x59')]=function(_0x4f80e3,_0x500477){var _0x4f3c86={'raw':![],'where':{'id':_0x4f80e3[_0xb985('0x5a')]['id']},'include':[{'model':db[_0xb985('0x40')],'as':_0xb985('0x41')}]},_0x5565af={};_0x5565af['model']=_[_0xb985('0x48')](db['FaxAccount'][_0xb985('0x5b')]);_0x5565af['query']=_[_0xb985('0x48')](_0x4f80e3[_0xb985('0x47')]);_0x5565af[_0xb985('0x49')]=_[_0xb985('0x4a')](_0x5565af[_0xb985('0x46')],_0x5565af[_0xb985('0x47')]);_0x4f3c86[_0xb985('0x4b')]=_[_0xb985('0x4a')](_0x5565af[_0xb985('0x46')],qs['fields'](_0x4f80e3[_0xb985('0x47')][_0xb985('0x4c')]));_0x4f3c86[_0xb985('0x4b')]=_0x4f3c86[_0xb985('0x4b')][_0xb985('0x4d')]?_0x4f3c86[_0xb985('0x4b')]:_0x5565af[_0xb985('0x46')];if(_0x4f80e3[_0xb985('0x47')][_0xb985('0x55')]){_0x4f3c86[_0xb985('0x56')]=[{'all':!![]}];}_0x4f3c86=_['merge']({},_0x4f3c86,_0x4f80e3[_0xb985('0x54')]);return db['FaxAccount'][_0xb985('0x5c')](_0x4f3c86)[_0xb985('0x37')](handleEntityNotFound(_0x500477,null))['then'](respondWithResult(_0x500477,null))['catch'](handleError(_0x500477,null));};exports[_0xb985('0x5d')]=function(_0x42e608,_0x403ef6){return db[_0xb985('0x43')][_0xb985('0x5d')](_0x42e608[_0xb985('0x5e')],{})[_0xb985('0x37')](function(_0x5b49c2){var _0x1d9e5d=_0x42e608['user']['get']({'plain':!![]});if(!_0x1d9e5d)throw new Error(_0xb985('0x5f'));if(_0x1d9e5d[_0xb985('0x60')]==='user'){var _0x154a7a=_0x5b49c2[_0xb985('0x39')]({'plain':!![]});var _0x7b7ca6=_0xb985('0x3a');return db[_0xb985('0x61')][_0xb985('0x5c')]({'where':{'name':_0x7b7ca6,'userProfileId':_0x1d9e5d[_0xb985('0x62')]},'raw':!![]})[_0xb985('0x37')](function(_0x4adac3){if(_0x4adac3&&_0x4adac3[_0xb985('0x63')]===0x0){return db['UserProfileResource'][_0xb985('0x5d')]({'name':_0x154a7a['name'],'resourceId':_0x154a7a['id'],'type':_0x4adac3[_0xb985('0x3d')],'sectionId':_0x4adac3['id']},{})[_0xb985('0x37')](function(){return _0x5b49c2;});}else{return _0x5b49c2;}})['catch'](function(_0xf00b7d){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0xf00b7d);throw _0xf00b7d;});}return _0x5b49c2;})[_0xb985('0x37')](respondWithResult(_0x403ef6,0xc9))[_0xb985('0x2a')](handleError(_0x403ef6,null));};exports[_0xb985('0x36')]=function(_0x3c3645,_0x28b0c3){if(_0x3c3645[_0xb985('0x5e')]['id']){delete _0x3c3645[_0xb985('0x5e')]['id'];}return db[_0xb985('0x43')]['find']({'where':{'id':_0x3c3645[_0xb985('0x5a')]['id']},'include':[{'model':db[_0xb985('0x40')],'as':_0xb985('0x41')}]})[_0xb985('0x37')](handleEntityNotFound(_0x28b0c3,null))[_0xb985('0x37')](saveUpdates(_0x3c3645[_0xb985('0x5e')],null))['then'](respondWithResult(_0x28b0c3,null))['catch'](handleError(_0x28b0c3,null));};exports[_0xb985('0x38')]=function(_0x54dcf1,_0x1881d8){return db[_0xb985('0x43')][_0xb985('0x5c')]({'where':{'id':_0x54dcf1['params']['id']}})[_0xb985('0x37')](handleEntityNotFound(_0x1881d8,null))[_0xb985('0x37')](removeEntity(_0x1881d8,null))[_0xb985('0x2a')](handleError(_0x1881d8,null));};exports[_0xb985('0x64')]=function(_0x446604,_0x3bfd77){return db[_0xb985('0x43')][_0xb985('0x64')]()[_0xb985('0x37')](respondWithResult(_0x3bfd77,null))[_0xb985('0x2a')](handleError(_0x3bfd77,null));};exports[_0xb985('0x65')]=function(_0x17bf46,_0x253a04,_0x25fa98){if(_0x17bf46[_0xb985('0x5e')]['id']){delete _0x17bf46[_0xb985('0x5e')]['id'];}return db[_0xb985('0x43')][_0xb985('0x5c')]({'where':{'id':_0x17bf46[_0xb985('0x5a')]['id']}})[_0xb985('0x37')](handleEntityNotFound(_0x253a04,null))[_0xb985('0x37')](function(_0x9c12e9){if(_0x9c12e9){_0x17bf46['body'][_0xb985('0x66')]=_0x9c12e9['id'];return db[_0xb985('0x67')][_0xb985('0x5d')](_0x17bf46[_0xb985('0x5e')]);}})['then'](respondWithResult(_0x253a04,null))[_0xb985('0x2a')](handleError(_0x253a04,null));};exports[_0xb985('0x68')]=function(_0x463cb2,_0x13e09c,_0x1f1dcb){var _0x2351ec={'raw':![],'where':{}};var _0x26010c={};var _0x507912={'count':0x0,'rows':[]};return db['FaxAccount'][_0xb985('0x69')]({'where':{'id':_0x463cb2['params']['id']}})[_0xb985('0x37')](handleEntityNotFound(_0x13e09c,null))[_0xb985('0x37')](function(_0x29f55f){if(_0x29f55f){_0x26010c[_0xb985('0x46')]=_[_0xb985('0x48')](db[_0xb985('0x67')][_0xb985('0x5b')]);_0x26010c[_0xb985('0x47')]=_[_0xb985('0x48')](_0x463cb2[_0xb985('0x47')]);_0x26010c[_0xb985('0x49')]=_[_0xb985('0x4a')](_0x26010c[_0xb985('0x46')],_0x26010c['query']);_0x2351ec[_0xb985('0x4b')]=_['intersection'](_0x26010c[_0xb985('0x46')],qs[_0xb985('0x4c')](_0x463cb2[_0xb985('0x47')]['fields']));_0x2351ec[_0xb985('0x4b')]=_0x2351ec[_0xb985('0x4b')][_0xb985('0x4d')]?_0x2351ec['attributes']:_0x26010c['model'];if(!_0x463cb2[_0xb985('0x47')][_0xb985('0x6a')]('nolimit')){_0x2351ec[_0xb985('0x2f')]=qs[_0xb985('0x2f')](_0x463cb2[_0xb985('0x47')]['limit']);_0x2351ec[_0xb985('0x31')]=qs[_0xb985('0x31')](_0x463cb2['query'][_0xb985('0x31')]);}_0x2351ec['order']=qs['sort'](_0x463cb2[_0xb985('0x47')][_0xb985('0x50')]);_0x2351ec[_0xb985('0x51')]=qs[_0xb985('0x49')](_[_0xb985('0x6b')](_0x463cb2[_0xb985('0x47')],_0x26010c[_0xb985('0x49')]));_0x2351ec[_0xb985('0x51')]['FaxAccountId']=_0x29f55f['id'];if(_0x463cb2[_0xb985('0x47')][_0xb985('0x52')]){_0x2351ec[_0xb985('0x51')]=_[_0xb985('0x53')](_0x2351ec[_0xb985('0x51')],{'$or':_[_0xb985('0x42')](_0x2351ec['attributes'],function(_0x4882f8){var _0x16b673={};_0x16b673[_0x4882f8]={'$like':'%'+_0x463cb2['query'][_0xb985('0x52')]+'%'};return _0x16b673;})});}_0x2351ec=_[_0xb985('0x53')]({},_0x2351ec,_0x463cb2[_0xb985('0x54')]);return db[_0xb985('0x67')][_0xb985('0x30')]({'where':_0x2351ec['where']})[_0xb985('0x37')](function(_0x2fd8c6){_0x507912[_0xb985('0x30')]=_0x2fd8c6;if(_0x463cb2[_0xb985('0x47')][_0xb985('0x55')]){_0x2351ec['include']=[{'all':!![]}];}return db[_0xb985('0x67')][_0xb985('0x57')](_0x2351ec);})['then'](function(_0x2c8a14){_0x507912[_0xb985('0x58')]=_0x2c8a14;return _0x507912;});}})['then'](respondWithFilteredResult(_0x13e09c,_0x2351ec))[_0xb985('0x2a')](handleError(_0x13e09c,null));};exports[_0xb985('0x6c')]=function(_0x51c4cc,_0x5e60ea,_0x36eab0){return db[_0xb985('0x43')][_0xb985('0x5c')]({'where':{'id':_0x51c4cc[_0xb985('0x5a')]['id']}})[_0xb985('0x37')](handleEntityNotFound(_0x5e60ea,null))['then'](function(_0x5c8d21){if(_0x5c8d21){return _0x5c8d21[_0xb985('0x6c')](_0x51c4cc[_0xb985('0x47')][_0xb985('0x6d')]);}})['then'](respondWithStatusCode(_0x5e60ea,null))[_0xb985('0x2a')](handleError(_0x5e60ea,null));};exports[_0xb985('0x6e')]=function(_0x338fd4,_0x49c27a,_0xb72313){if(_0x338fd4[_0xb985('0x5e')]['id']){delete _0x338fd4['body']['id'];}return db[_0xb985('0x43')][_0xb985('0x5c')]({'where':{'id':_0x338fd4[_0xb985('0x5a')]['id']}})[_0xb985('0x37')](handleEntityNotFound(_0x49c27a,null))[_0xb985('0x37')](function(_0x3453ae){if(_0x3453ae){_0x338fd4[_0xb985('0x5e')][_0xb985('0x66')]=_0x3453ae['id'];return db[_0xb985('0x6f')]['create'](_0x338fd4[_0xb985('0x5e')]);}})[_0xb985('0x37')](respondWithResult(_0x49c27a,null))[_0xb985('0x2a')](handleError(_0x49c27a,null));};exports[_0xb985('0x70')]=function(_0x544598,_0x238238,_0x42420a){var _0xd0e9d8={'raw':![],'where':{}};var _0x1b0897={};var _0x584bfd={'count':0x0,'rows':[]};return db[_0xb985('0x43')][_0xb985('0x69')]({'where':{'id':_0x544598[_0xb985('0x5a')]['id']}})[_0xb985('0x37')](handleEntityNotFound(_0x238238,null))[_0xb985('0x37')](function(_0x4294df){if(_0x4294df){_0x1b0897[_0xb985('0x46')]=_['keys'](db[_0xb985('0x6f')]['rawAttributes']);_0x1b0897[_0xb985('0x47')]=_[_0xb985('0x48')](_0x544598[_0xb985('0x47')]);_0x1b0897[_0xb985('0x49')]=_[_0xb985('0x4a')](_0x1b0897[_0xb985('0x46')],_0x1b0897['query']);_0xd0e9d8[_0xb985('0x4b')]=_[_0xb985('0x4a')](_0x1b0897[_0xb985('0x46')],qs['fields'](_0x544598[_0xb985('0x47')][_0xb985('0x4c')]));_0xd0e9d8['attributes']=_0xd0e9d8[_0xb985('0x4b')][_0xb985('0x4d')]?_0xd0e9d8[_0xb985('0x4b')]:_0x1b0897[_0xb985('0x46')];if(!_0x544598[_0xb985('0x47')][_0xb985('0x6a')](_0xb985('0x4e'))){_0xd0e9d8[_0xb985('0x2f')]=qs[_0xb985('0x2f')](_0x544598[_0xb985('0x47')][_0xb985('0x2f')]);_0xd0e9d8[_0xb985('0x31')]=qs[_0xb985('0x31')](_0x544598['query'][_0xb985('0x31')]);}_0xd0e9d8[_0xb985('0x4f')]=qs[_0xb985('0x50')](_0x544598[_0xb985('0x47')]['sort']);_0xd0e9d8['where']=qs[_0xb985('0x49')](_[_0xb985('0x6b')](_0x544598[_0xb985('0x47')],_0x1b0897[_0xb985('0x49')]));_0xd0e9d8['where']['FaxAccountId']=_0x4294df['id'];if(_0x544598[_0xb985('0x47')][_0xb985('0x52')]){_0xd0e9d8['where']=_[_0xb985('0x53')](_0xd0e9d8[_0xb985('0x51')],{'$or':_['map'](_0xd0e9d8['attributes'],function(_0x5f052f){var _0x137cd3={};_0x137cd3[_0x5f052f]={'$like':'%'+_0x544598[_0xb985('0x47')][_0xb985('0x52')]+'%'};return _0x137cd3;})});}_0xd0e9d8=_['merge']({},_0xd0e9d8,_0x544598[_0xb985('0x54')]);return db[_0xb985('0x6f')][_0xb985('0x30')]({'where':_0xd0e9d8[_0xb985('0x51')]})[_0xb985('0x37')](function(_0x3fa68f){_0x584bfd[_0xb985('0x30')]=_0x3fa68f;if(_0x544598[_0xb985('0x47')][_0xb985('0x55')]){_0xd0e9d8['include']=[{'all':!![]}];}return db[_0xb985('0x6f')][_0xb985('0x57')](_0xd0e9d8);})['then'](function(_0x14062e){_0x584bfd[_0xb985('0x58')]=_0x14062e;return _0x584bfd;});}})[_0xb985('0x37')](respondWithFilteredResult(_0x238238,_0xd0e9d8))[_0xb985('0x2a')](handleError(_0x238238,null));};exports[_0xb985('0x71')]=function(_0x1dbd62,_0x3f06f0,_0x1f8f7a){return db[_0xb985('0x43')][_0xb985('0x5c')]({'where':{'id':_0x1dbd62[_0xb985('0x5a')]['id']}})[_0xb985('0x37')](handleEntityNotFound(_0x3f06f0,null))['then'](function(_0x27e680){if(_0x27e680){return _0x27e680[_0xb985('0x71')](_0x1dbd62['query']['ids']);}})['then'](respondWithStatusCode(_0x3f06f0,null))[_0xb985('0x2a')](handleError(_0x3f06f0,null));};exports['addInteraction']=function(_0x29fe3c,_0x1441f8,_0x1bbf79){return db[_0xb985('0x72')][_0xb985('0x5c')]({'where':{'id':_0x29fe3c['params']['id']}})[_0xb985('0x37')](handleEntityNotFound(_0x1441f8,null))[_0xb985('0x37')](function(_0x56e3ee){if(_0x56e3ee){return _0x56e3ee['addInteraction'](_0x29fe3c['body'][_0xb985('0x6d')],_[_0xb985('0x73')](_0x29fe3c['body'],[_0xb985('0x6d'),'id'])||{});}})[_0xb985('0x37')](respondWithResult(_0x1441f8,null))[_0xb985('0x2a')](handleError(_0x1441f8,null));};exports[_0xb985('0x74')]=function(_0x5bc170,_0x9429b8,_0x1a1b77){var _0x3c2ce4={'raw':![],'where':{}};var _0x2aa453={};var _0x381154={'count':0x0,'rows':[]};return db[_0xb985('0x43')][_0xb985('0x69')]({'where':{'id':_0x5bc170['params']['id']}})[_0xb985('0x37')](handleEntityNotFound(_0x9429b8,null))[_0xb985('0x37')](function(_0x1efc6e){if(_0x1efc6e){_0x2aa453[_0xb985('0x46')]=_[_0xb985('0x48')](db[_0xb985('0x72')][_0xb985('0x5b')]);_0x2aa453[_0xb985('0x47')]=_[_0xb985('0x48')](_0x5bc170[_0xb985('0x47')]);_0x2aa453[_0xb985('0x49')]=_[_0xb985('0x4a')](_0x2aa453['model'],_0x2aa453[_0xb985('0x47')]);_0x3c2ce4[_0xb985('0x4b')]=_[_0xb985('0x4a')](_0x2aa453['model'],qs['fields'](_0x5bc170[_0xb985('0x47')][_0xb985('0x4c')]));_0x3c2ce4[_0xb985('0x4b')]=_0x3c2ce4[_0xb985('0x4b')][_0xb985('0x4d')]?_0x3c2ce4[_0xb985('0x4b')]:_0x2aa453[_0xb985('0x46')];if(!_0x5bc170['query'][_0xb985('0x6a')]('nolimit')){_0x3c2ce4['limit']=qs['limit'](_0x5bc170[_0xb985('0x47')][_0xb985('0x2f')]);_0x3c2ce4['offset']=qs[_0xb985('0x31')](_0x5bc170['query'][_0xb985('0x31')]);}_0x3c2ce4[_0xb985('0x4f')]=qs[_0xb985('0x50')](_0x5bc170[_0xb985('0x47')][_0xb985('0x50')]);_0x3c2ce4[_0xb985('0x51')]=qs[_0xb985('0x49')](_[_0xb985('0x6b')](_0x5bc170['query'],_0x2aa453[_0xb985('0x49')]));_0x3c2ce4[_0xb985('0x51')]['FaxAccountId']=_0x1efc6e['id'];if(_0x5bc170[_0xb985('0x47')][_0xb985('0x52')]){_0x3c2ce4['where']=_[_0xb985('0x53')](_0x3c2ce4[_0xb985('0x51')],{'$or':_[_0xb985('0x42')](_0x3c2ce4['attributes'],function(_0x409c94){var _0x26f4bd={};_0x26f4bd[_0x409c94]={'$like':'%'+_0x5bc170[_0xb985('0x47')][_0xb985('0x52')]+'%'};return _0x26f4bd;})});}_0x3c2ce4=_[_0xb985('0x53')]({},_0x3c2ce4,_0x5bc170['options']);return db[_0xb985('0x72')][_0xb985('0x30')]({'where':_0x3c2ce4['where']})['then'](function(_0xf9530d){_0x381154['count']=_0xf9530d;if(_0x5bc170[_0xb985('0x47')]['includeAll']){_0x3c2ce4[_0xb985('0x56')]=[{'model':db['CmContact'],'as':_0xb985('0x75'),'required':![]},{'model':db[_0xb985('0x76')],'as':_0xb985('0x77'),'attributes':[_0xb985('0x3d'),'fullname','internal'],'required':![]},{'model':db['Tag'],'as':_0xb985('0x78'),'attributes':['id',_0xb985('0x3d'),_0xb985('0x79')],'where':_0x5bc170['query'][_0xb985('0x7a')]?{'id':_0x5bc170[_0xb985('0x47')][_0xb985('0x7a')]}:undefined,'required':_0x5bc170[_0xb985('0x47')]['tag']?!![]:![]}];}return db[_0xb985('0x72')][_0xb985('0x57')](_0x3c2ce4);})[_0xb985('0x37')](function(_0x4cc8bd){_0x381154[_0xb985('0x58')]=_0x4cc8bd;return _0x381154;});}})[_0xb985('0x37')](respondWithFilteredResult(_0x9429b8,_0x3c2ce4))['catch'](handleError(_0x9429b8,null));};exports['addApplications']=function(_0x13d60b,_0x8b43b0,_0x432945){return db['FaxAccount']['findOne']({'where':{'id':_0x13d60b['params']['id']}})[_0xb985('0x37')](handleEntityNotFound(_0x8b43b0,null))['then'](function(_0x177122){if(_0x177122){return db[_0xb985('0x7b')]['transaction'](function(_0x41c069){return db[_0xb985('0x7c')]['destroy']({'where':{'FaxAccountId':_0x13d60b[_0xb985('0x5a')]['id']},'transaction':_0x41c069})[_0xb985('0x37')](function(_0x25b4d2){var _0x5839c1=_[_0xb985('0x42')](_0x13d60b[_0xb985('0x5e')],function(_0x31ecb6){_0x31ecb6['FaxAccountId']=_0x13d60b[_0xb985('0x5a')]['id'];return _0x31ecb6;});return db['FaxApplication'][_0xb985('0x7d')](_0x5839c1,{'transaction':_0x41c069});});})[_0xb985('0x37')](function(){return db[_0xb985('0x7c')][_0xb985('0x7e')]({'where':{'FaxAccountId':_0x13d60b[_0xb985('0x5a')]['id']},'order':'priority'});});}})[_0xb985('0x37')](respondWithResult(_0x8b43b0,null))[_0xb985('0x2a')](handleError(_0x8b43b0,null));};exports[_0xb985('0x7f')]=function(_0x33224a,_0x5d607b,_0x435af8){var _0x528227={};var _0x1f41d1={};var _0x2dd43b;var _0x56193e;return db[_0xb985('0x43')][_0xb985('0x69')]({'where':{'id':_0x33224a[_0xb985('0x5a')]['id']}})['then'](handleEntityNotFound(_0x5d607b,null))['then'](function(_0x8bd05f){if(_0x8bd05f){_0x2dd43b=_0x8bd05f;_0x1f41d1['model']=_[_0xb985('0x48')](db[_0xb985('0x7c')]['rawAttributes']);_0x1f41d1[_0xb985('0x47')]=_[_0xb985('0x48')](_0x33224a['query']);_0x1f41d1[_0xb985('0x49')]=_[_0xb985('0x4a')](_0x1f41d1['model'],_0x1f41d1[_0xb985('0x47')]);_0x528227[_0xb985('0x4b')]=_['intersection'](_0x1f41d1[_0xb985('0x46')],qs[_0xb985('0x4c')](_0x33224a[_0xb985('0x47')][_0xb985('0x4c')]));_0x528227[_0xb985('0x4b')]=_0x528227[_0xb985('0x4b')][_0xb985('0x4d')]?_0x528227[_0xb985('0x4b')]:_0x1f41d1[_0xb985('0x46')];_0x528227[_0xb985('0x4f')]=qs[_0xb985('0x50')](_0x33224a[_0xb985('0x47')][_0xb985('0x50')]);_0x528227[_0xb985('0x51')]=qs['filters'](_[_0xb985('0x6b')](_0x33224a['query'],_0x1f41d1[_0xb985('0x49')]));if(_0x33224a[_0xb985('0x47')][_0xb985('0x52')]){_0x528227[_0xb985('0x51')]=_[_0xb985('0x53')](_0x528227[_0xb985('0x51')],{'$or':_[_0xb985('0x42')](_0x528227['attributes'],function(_0x609e1e){var _0x7b637={};_0x7b637[_0x609e1e]={'$like':'%'+_0x33224a[_0xb985('0x47')]['filter']+'%'};return _0x7b637;})});}_0x528227=_['merge']({},_0x528227,_0x33224a['options']);return _0x2dd43b[_0xb985('0x7f')](_0x528227);}})[_0xb985('0x37')](function(_0x52a5bc){if(_0x52a5bc){_0x56193e=_0x52a5bc[_0xb985('0x4d')];if(!_0x33224a['query'][_0xb985('0x6a')](_0xb985('0x4e'))){_0x528227['limit']=qs[_0xb985('0x2f')](_0x33224a[_0xb985('0x47')][_0xb985('0x2f')]);_0x528227[_0xb985('0x31')]=qs[_0xb985('0x31')](_0x33224a['query'][_0xb985('0x31')]);}return _0x2dd43b[_0xb985('0x7f')](_0x528227);}})[_0xb985('0x37')](function(_0x1f893b){if(_0x1f893b){return _0x1f893b?{'count':_0x56193e,'rows':_0x1f893b}:null;}})[_0xb985('0x37')](respondWithResult(_0x5d607b,null))['catch'](handleError(_0x5d607b,null));};function Extension(_0x18d6e9,_0x3817bc,_0x79f795,_0x14637f){this[_0xb985('0x80')]=_0xb985('0x81');this[_0xb985('0x82')]=_0x18d6e9[_0xb985('0x83')];this['app']=_0x14637f;this[_0xb985('0x45')]=_0xb985('0x84');this[_0xb985('0x85')]=_0xb985('0x86');this[_0xb985('0x66')]=_0x18d6e9['id'];this[_0xb985('0x87')]=_0x3817bc;this[_0xb985('0x88')]=_0x79f795;}function createExtensionsReciveFax(_0x1b7a0f){var _0x2bf58a=0x1;var _0x472e58=[];_0x472e58['push'](new Extension(_0x1b7a0f,_0x2bf58a,'','Answer'));_0x2bf58a+=0x1;_0x472e58[_0xb985('0x89')](new Extension(_0x1b7a0f,_0x2bf58a,_0xb985('0x8a'),_0xb985('0x8b')));_0x2bf58a+=0x1;for(var _0x34007b in _0x1b7a0f){if(_0x1b7a0f[_0xb985('0x6a')](_0x34007b)&&(_0x34007b===_0xb985('0x8c')||_0x34007b===_0xb985('0x83')||_0x34007b===_0xb985('0x8d')||_0x34007b===_0xb985('0x8e')||_0x34007b===_0xb985('0x8f')||_0x34007b===_0xb985('0x90')||_0x34007b==='minrate'||_0x34007b===_0xb985('0x91')||_0x34007b===_0xb985('0x92'))){_0x472e58[_0xb985('0x89')](new Extension(_0x1b7a0f,_0x2bf58a,_0xb985('0x93')+_0x34007b+')='+_0x1b7a0f[_0x34007b],_0xb985('0x8b')));_0x2bf58a+=0x1;}}_0x472e58[_0xb985('0x89')](new Extension(_0x1b7a0f,_0x2bf58a,'6','Wait'));_0x2bf58a+=0x1;_0x472e58[_0xb985('0x89')](new Extension(_0x1b7a0f,_0x2bf58a,'/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'));_0x2bf58a=0x0;return _0x472e58;}exports[_0xb985('0x94')]=function(_0x4cead2,_0x50d8f6,_0xb3e4e6){var _0x4bd062;return db['sequelize'][_0xb985('0x95')](function(_0x125a17){return db['FaxAccount'][_0xb985('0x5d')](_0x4cead2[_0xb985('0x5e')],{'transaction':_0x125a17})[_0xb985('0x37')](function(_0x2bd221){_0x4bd062=_0x2bd221[_0xb985('0x39')]({'plain':!![]});return db['VoiceExtension'][_0xb985('0x7d')](createExtensionsReciveFax(_0x4bd062),{'transaction':_0x125a17});});})['then'](function(){return _0x4bd062;})['then'](respondWithResult(_0x50d8f6,null))['catch'](handleError(_0x50d8f6,null));};exports['updateAccountApplications']=function(_0x3110f0,_0x51c7b8,_0x2ccba3){var _0x457a0e;return db[_0xb985('0x7b')][_0xb985('0x95')](function(_0x144690){return db[_0xb985('0x43')][_0xb985('0x36')](_0x3110f0[_0xb985('0x5e')],{'where':{'id':_0x3110f0[_0xb985('0x5e')]['id']},'transaction':_0x144690})[_0xb985('0x37')](function(_0x23bcf0){return db[_0xb985('0x96')]['destroy']({'where':{'FaxAccountId':_0x3110f0[_0xb985('0x5e')]['id']},'transaction':_0x144690})[_0xb985('0x37')](function(_0x1ca73f){return db['VoiceExtension']['bulkCreate'](createExtensionsReciveFax(_[_0xb985('0x73')](_0x3110f0[_0xb985('0x5e')],[_0xb985('0x97'),_0xb985('0x98'),_0xb985('0x99'),_0xb985('0x9a'),'TrunkId',_0xb985('0x9b')])),{'transaction':_0x144690});});});})[_0xb985('0x37')](function(){return db['FaxAccount']['findById'](_0x3110f0['body']['id']);})[_0xb985('0x37')](respondWithResult(_0x51c7b8,null))[_0xb985('0x2a')](handleError(_0x51c7b8,null));};exports[_0xb985('0x9c')]=function(_0x4e6233,_0x544c19,_0x34967f){var _0x2909b3={'raw':!![],'where':{}};var _0x48c87a={};var _0x3428d2={'count':0x0,'rows':[]};return db[_0xb985('0x43')]['findOne']({'where':{'id':_0x4e6233[_0xb985('0x5a')]['id']}})[_0xb985('0x37')](handleEntityNotFound(_0x544c19,null))[_0xb985('0x37')](function(_0xce084c){if(_0xce084c){_0x48c87a[_0xb985('0x46')]=_['keys'](db[_0xb985('0x9d')][_0xb985('0x5b')]);_0x48c87a[_0xb985('0x47')]=_['keys'](_0x4e6233[_0xb985('0x47')]);_0x48c87a[_0xb985('0x49')]=_['intersection'](_0x48c87a['model'],_0x48c87a[_0xb985('0x47')]);_0x2909b3[_0xb985('0x4b')]=_[_0xb985('0x4a')](_0x48c87a['model'],qs[_0xb985('0x4c')](_0x4e6233[_0xb985('0x47')][_0xb985('0x4c')]));_0x2909b3[_0xb985('0x4b')]=_0x2909b3['attributes'][_0xb985('0x4d')]?_0x2909b3[_0xb985('0x4b')]:_0x48c87a['model'];if(!_0x4e6233[_0xb985('0x47')][_0xb985('0x6a')]('nolimit')){_0x2909b3[_0xb985('0x2f')]=qs[_0xb985('0x2f')](_0x4e6233[_0xb985('0x47')][_0xb985('0x2f')]);_0x2909b3[_0xb985('0x31')]=qs[_0xb985('0x31')](_0x4e6233['query'][_0xb985('0x31')]);}_0x2909b3[_0xb985('0x4f')]=qs[_0xb985('0x50')](_0x4e6233[_0xb985('0x47')][_0xb985('0x50')]);_0x2909b3[_0xb985('0x51')]=qs[_0xb985('0x49')](_[_0xb985('0x6b')](_0x4e6233[_0xb985('0x47')],_0x48c87a[_0xb985('0x49')]));_0x2909b3[_0xb985('0x51')][_0xb985('0x66')]=_0xce084c['id'];if(_0x4e6233[_0xb985('0x47')]['filter']){_0x2909b3[_0xb985('0x51')]=_[_0xb985('0x53')](_0x2909b3[_0xb985('0x51')],{'$or':_['map'](_0x2909b3[_0xb985('0x4b')],function(_0x46affe){var _0x35c048={};_0x35c048[_0x46affe]={'$like':'%'+_0x4e6233['query'][_0xb985('0x52')]+'%'};return _0x35c048;})});}if(_0x4e6233[_0xb985('0x47')][_0xb985('0x9e')]){var _0x223125=_0x4e6233[_0xb985('0x47')][_0xb985('0x9e')]['split'](',');var _0x5b156a={};_0x5b156a[_0x223125[0x0]]={'$gte':moment(_0x223125[0x1])[_0xb985('0x9f')](_0xb985('0xa0'))};_0x2909b3['where']=_[_0xb985('0x53')](_0x2909b3[_0xb985('0x51')],_0x5b156a);}_0x2909b3=_['merge']({},_0x2909b3,_0x4e6233['options']);return db[_0xb985('0x9d')][_0xb985('0x30')]({'where':_0x2909b3[_0xb985('0x51')]})[_0xb985('0x37')](function(_0xa16022){_0x3428d2[_0xb985('0x30')]=_0xa16022;if(_0x4e6233[_0xb985('0x47')]['includeAll']){_0x2909b3['include']=[{'all':!![]}];}return db[_0xb985('0x9d')][_0xb985('0x57')](_0x2909b3);})[_0xb985('0x37')](function(_0xa7027f){_0x3428d2[_0xb985('0x58')]=_0xa7027f;return _0x3428d2;});}})['then'](respondWithFilteredResult(_0x544c19,_0x2909b3))[_0xb985('0x2a')](handleError(_0x544c19,null));};exports['send']=function(_0xe4fc9d,_0x5e7772,_0x3834bb){var _0x4ccc0c,_0x53727d={},_0xc6d862;if(_0xe4fc9d['body']['to']){_0xc6d862=_0xe4fc9d[_0xb985('0x5e')]['to'][0x0];}return db[_0xb985('0x43')]['find']({'where':{'id':_0xe4fc9d[_0xb985('0x5a')]['id']},'include':[{'model':db[_0xb985('0xa1')],'as':_0xb985('0xa2'),'include':[{'model':db[_0xb985('0xa3')],'as':_0xb985('0xa4'),'where':{'fax':_0xc6d862},'limit':0x1,'order':[[_0xb985('0x9a'),'DESC']]}]}]})['then'](handleEntityNotFound(_0x5e7772,null))[_0xb985('0x37')](function(_0x1f447a){_0x4ccc0c=_0x1f447a;if(_0xe4fc9d[_0xb985('0x5e')][_0xb985('0xa5')]&&_0xe4fc9d['body'][_0xb985('0xa5')][_0xb985('0x4d')]){for(var _0x5f34bf=0x0;_0x5f34bf<_0xe4fc9d['body']['attachments'][_0xb985('0x4d')];_0x5f34bf+=0x1){_0xe4fc9d[_0xb985('0x5e')]['attachments'][_0x5f34bf]={'filename':_0xe4fc9d[_0xb985('0x5e')]['attachments'][_0x5f34bf][_0xb985('0x3d')],'id':_0xe4fc9d['body'][_0xb985('0xa5')][_0x5f34bf]['id'],'path':path[_0xb985('0xa6')](config[_0xb985('0xa7')],_0xb985('0xa8'),_0xe4fc9d[_0xb985('0x5e')][_0xb985('0xa5')][_0x5f34bf][_0xb985('0xa9')])};}}return respondWithRpcPromise('CheckAfterSend',_0xb985('0xaa'),{'FaxAccountId':_[_0xb985('0xab')](_0xe4fc9d['params']['id'])?undefined:_0xe4fc9d[_0xb985('0x5a')]['id'],'path':_[_0xb985('0xab')](_0xe4fc9d[_0xb985('0x5e')][_0xb985('0xa5')][0x0][_0xb985('0x6')])?undefined:_0xe4fc9d[_0xb985('0x5e')][_0xb985('0xa5')][0x0][_0xb985('0x6')],'fax':_[_0xb985('0xab')](_0xe4fc9d[_0xb985('0x5e')]['to'][0x0])?undefined:_0xe4fc9d['body']['to'][0x0]},client9002);})[_0xb985('0x37')](function(){if(_0x4ccc0c){if(_['isNil'](_0xe4fc9d['body'][_0xb985('0xac')])){_0xe4fc9d[_0xb985('0x5e')][_0xb985('0xac')]=util['format']('\x22%s\x22\x20<%s>',_0x4ccc0c[_0xb985('0x3d')],_0x4ccc0c[_0xb985('0xad')]);}if(_0x4ccc0c[_0xb985('0xa2')]){if(_0x4ccc0c[_0xb985('0xa2')]['Contacts'][_0xb985('0x4d')]){return _0x4ccc0c[_0xb985('0xa2')][_0xb985('0xa4')][0x0];}else{return db[_0xb985('0xa3')][_0xb985('0x5d')](_['defaults'](_0xe4fc9d[_0xb985('0x5e')],{'firstName':_0xe4fc9d[_0xb985('0x5e')]['to'][0x0],'phone':_0xe4fc9d[_0xb985('0x5e')]['to'][0x0],'fax':_0xe4fc9d['body']['to'][0x0],'ListId':_0x4ccc0c['ListId']}));}}else{throw new Error(_0xb985('0xae'));}}else{throw new Error(_0xb985('0xaf'));}})[_0xb985('0x37')](function(_0x18c285){if(_0x18c285){return db[_0xb985('0x72')][_0xb985('0x5c')]({'where':{'ContactId':_0x18c285['id'],'closed':![],'FaxAccountId':_0x4ccc0c['id']}})['then'](function(_0x76a564){if(_0x76a564){return[_0x76a564,![]];}return db[_0xb985('0x72')][_0xb985('0x5d')]({'UserId':_0xe4fc9d[_0xb985('0xb0')]['id'],'ContactId':_0x18c285['id'],'FaxAccountId':_0x4ccc0c['id'],'fax':_0xe4fc9d[_0xb985('0x5e')]['to'][0x0],'firstMsgDirection':_0xb985('0xb1'),'Messages':[_[_0xb985('0x53')](_0xe4fc9d[_0xb985('0x5e')],{'read':![],'body':_0xe4fc9d['body'][_0xb985('0xa5')][0x0][_0xb985('0xb2')],'FaxAccountId':_0x4ccc0c['id'],'UserId':_0xe4fc9d[_0xb985('0xb0')]['id'],'ContactId':_0x18c285['id'],'AttachmentId':_0xe4fc9d[_0xb985('0x5e')][_0xb985('0xa5')][0x0]['id']})]},{'include':[{'model':db[_0xb985('0x9d')],'as':_0xb985('0xb3')}]})['then'](function(_0x2d7be6){return[_0x2d7be6,!![]];});});}else{throw new Error(_0xb985('0xb4'));}})[_0xb985('0xb5')](function(_0x2f58af,_0x30ff0b){if(_0x30ff0b){return _0x2f58af;}return db['FaxMessage'][_0xb985('0x5d')]({'direction':_0xb985('0xb1'),'read':![],'body':_0xe4fc9d[_0xb985('0x5e')]['attachments'][0x0]['filename'],'FaxAccountId':_0x4ccc0c['id'],'FaxInteractionId':_0x2f58af['id'],'UserId':_0xe4fc9d[_0xb985('0xb0')]['id'],'ContactId':_0x2f58af[_0xb985('0xb6')],'AttachmentId':_0xe4fc9d['body'][_0xb985('0xa5')][0x0]['id']})[_0xb985('0x37')](function(_0x5a7fbf){_0x2f58af['dataValues'][_0xb985('0xb3')]=[];_0x2f58af[_0xb985('0xb7')][_0xb985('0xb3')][_0xb985('0x89')](_0x5a7fbf[_0xb985('0xb7')]);return _0x2f58af;});})[_0xb985('0x37')](function(_0x2bff1d){respondWithRpcPromise(_0xb985('0xb8'),_0xb985('0xb8'),{'FaxAccountId':_['isNil'](_0xe4fc9d[_0xb985('0x5a')]['id'])?undefined:_0xe4fc9d[_0xb985('0x5a')]['id'],'path':_['isNil'](_0xe4fc9d['body'][_0xb985('0xa5')][0x0]['path'])?undefined:_0xe4fc9d['body'][_0xb985('0xa5')][0x0][_0xb985('0x6')],'fax':_[_0xb985('0xab')](_0xe4fc9d[_0xb985('0x5e')]['to'][0x0])?undefined:_0xe4fc9d['body']['to'][0x0],'AttachmentId':_0xe4fc9d[_0xb985('0x5e')][_0xb985('0xa5')][0x0]['id']},client9002)['then'](function(_0x7e7a1b){logger[_0xb985('0x21')](_0xb985('0xb9'),_0x7e7a1b);})[_0xb985('0x2a')](function(_0x3ac9e6){logger['info']('SendFaxRpc,\x20%s',_0x3ac9e6);});return _0x2bff1d;})['then'](respondWithResult(_0x5e7772,null))[_0xb985('0x2a')](handleError(_0x5e7772,null));};exports['addAgents']=function(_0x1f51f6,_0x19c40b,_0x21c51e){return db['FaxAccount'][_0xb985('0x5c')]({'where':{'id':_0x1f51f6[_0xb985('0x5a')]['id']}})[_0xb985('0x37')](handleEntityNotFound(_0x19c40b,null))[_0xb985('0x37')](function(_0x303989){if(_0x303989){return _0x303989[_0xb985('0xba')](_0x1f51f6[_0xb985('0x5e')][_0xb985('0x6d')],_[_0xb985('0x73')](_0x1f51f6[_0xb985('0x5e')],[_0xb985('0x6d'),'id'])||{})[_0xb985('0xb5')](function(_0x456535){for(var _0x290136=0x0;_0x290136<_0x1f51f6[_0xb985('0x5e')][_0xb985('0x6d')][_0xb985('0x4d')];_0x290136+=0x1){socket[_0xb985('0xbb')](_0xb985('0xbc'),{'UserId':_0x1f51f6[_0xb985('0x5e')]['ids'][_0x290136],'FaxAccountId':_0x1f51f6[_0xb985('0x5a')]['id']});}return _0x456535;});}})[_0xb985('0x37')](respondWithResult(_0x19c40b,null))['catch'](handleError(_0x19c40b,null));};exports[_0xb985('0xbd')]=function(_0x397f2f,_0x4714e0,_0x558ace){return db['FaxAccount'][_0xb985('0x5c')]({'where':{'id':_0x397f2f['params']['id']}})[_0xb985('0x37')](handleEntityNotFound(_0x4714e0,null))[_0xb985('0x37')](function(_0x10de4f){if(_0x10de4f){return _0x10de4f[_0xb985('0xbd')](_0x397f2f[_0xb985('0x47')][_0xb985('0x6d')])[_0xb985('0x37')](function(){if(_[_0xb985('0xbe')](_0x397f2f['query']['ids'])){for(var _0x1d8357=0x0;_0x1d8357<_0x397f2f[_0xb985('0x47')][_0xb985('0x6d')]['length'];_0x1d8357+=0x1){socket['emit'](_0xb985('0xbf'),{'UserId':Number(_0x397f2f[_0xb985('0x47')][_0xb985('0x6d')][_0x1d8357]),'FaxAccountId':Number(_0x397f2f[_0xb985('0x5a')]['id'])});}}else{socket[_0xb985('0xbb')](_0xb985('0xbf'),{'UserId':Number(_0x397f2f[_0xb985('0x47')][_0xb985('0x6d')]),'FaxAccountId':Number(_0x397f2f[_0xb985('0x5a')]['id'])});}});}})[_0xb985('0x37')](respondWithStatusCode(_0x4714e0,null))[_0xb985('0x2a')](handleError(_0x4714e0,null));};exports[_0xb985('0xc0')]=function(_0x1f70a1,_0xee77bb,_0x403274){var _0x233237={};var _0x5c56a7={};var _0x391096;var _0x50f030;return db['FaxAccount'][_0xb985('0x69')]({'where':{'id':_0x1f70a1[_0xb985('0x5a')]['id']}})[_0xb985('0x37')](handleEntityNotFound(_0xee77bb,null))[_0xb985('0x37')](function(_0x3ea7b6){if(_0x3ea7b6){_0x391096=_0x3ea7b6;_0x5c56a7[_0xb985('0x46')]=_['keys'](db[_0xb985('0x76')][_0xb985('0x5b')]);_0x5c56a7[_0xb985('0x47')]=_['keys'](_0x1f70a1[_0xb985('0x47')]);_0x5c56a7[_0xb985('0x49')]=_[_0xb985('0x4a')](_0x5c56a7['model'],_0x5c56a7[_0xb985('0x47')]);_0x233237[_0xb985('0x4b')]=_[_0xb985('0x4a')](_0x5c56a7[_0xb985('0x46')],qs['fields'](_0x1f70a1['query'][_0xb985('0x4c')]));_0x233237['attributes']=_0x233237[_0xb985('0x4b')][_0xb985('0x4d')]?_0x233237[_0xb985('0x4b')]:_0x5c56a7[_0xb985('0x46')];_0x233237[_0xb985('0x4f')]=qs['sort'](_0x1f70a1[_0xb985('0x47')][_0xb985('0x50')]);_0x233237[_0xb985('0x51')]=qs[_0xb985('0x49')](_[_0xb985('0x6b')](_0x1f70a1['query'],_0x5c56a7[_0xb985('0x49')]));if(_0x1f70a1[_0xb985('0x47')]['filter']){_0x233237[_0xb985('0x51')]=_[_0xb985('0x53')](_0x233237[_0xb985('0x51')],{'$or':_[_0xb985('0x42')](_0x233237['attributes'],function(_0x105023){var _0x5d2418={};_0x5d2418[_0x105023]={'$like':'%'+_0x1f70a1[_0xb985('0x47')][_0xb985('0x52')]+'%'};return _0x5d2418;})});}_0x233237=_[_0xb985('0x53')]({},_0x233237,_0x1f70a1['options']);return _0x391096[_0xb985('0xc0')](_0x233237);}})[_0xb985('0x37')](function(_0x1dc278){if(_0x1dc278){_0x50f030=_0x1dc278[_0xb985('0x4d')];if(!_0x1f70a1[_0xb985('0x47')][_0xb985('0x6a')](_0xb985('0x4e'))){_0x233237[_0xb985('0x2f')]=qs[_0xb985('0x2f')](_0x1f70a1['query'][_0xb985('0x2f')]);_0x233237['offset']=qs[_0xb985('0x31')](_0x1f70a1['query'][_0xb985('0x31')]);}return _0x391096['getAgents'](_0x233237);}})[_0xb985('0x37')](function(_0x592b34){if(_0x592b34){return _0x592b34?{'count':_0x50f030,'rows':_0x592b34}:null;}})['then'](respondWithResult(_0xee77bb,null))[_0xb985('0x2a')](handleError(_0xee77bb,null));};
\ No newline at end of file
+var _0x9c5e=['body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','FaxAccountId','Disposition','hasOwnProperty','nolimit','rows','removeDispositions','ids','addAnswer','CannedAnswer','findOne','removeAnswers','addInteraction','FaxInteraction','omit','getInteractions','CmContact','Contact','User','fullname','internal','Tag','color','tag','addApplications','sequelize','transaction','bulkCreate','FaxApplication','findAndCountAll','priority','getApplications','context','from-voip-provider','exten','localstationid','app','system','Fax\x20Extension','appdata','Answer','push','Set','gateway','faxdetect','headerinfo','maxrate','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','addAccountApplications','VoiceExtension','updateAccountApplications','update','tech','key','createdAt','updatedAt','TrunkId','ListId','findById','FaxMessage','$gte','split','YYYY-MM-DD\x20HH:mm:ss','List','Contacts','DESC','attachments','join','root','server/files/attachments','basename','CheckAfterSend','isNil','from','format','List\x20not\x20found','Send\x20Fax\x20failed','out','filename','Messages','Contact\x20not\x20found','spread','ContactId','dataValues','SendFax','SendFaxRpc,\x20%s','addAgents','emit','userFaxAccount:save','removeAgents','isArray','userFaxAccount:remove','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','squel','crypto','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','defaults','redis','./faxAccount.socket','register','jayson/promise','client','http','request','then','info','FaxAccount,\x20%s,\x20%s','request\x20sent','debug','error','code','message','result','catch','sendStatus','status','json','offset','limit','count','Content-Range','apply','reject','save','destroy','get','FaxAccounts','UserProfileResource','end','stack','name','send','index','Pause','mandatoryDispositionPause','map','FaxAccount','rawAttributes','fieldName','model','query','keys','filters','intersection','attributes','fields','length','order','sort','where','pick','filter','merge','type','VIRTUAL','options','include','findAll','params','includeAll','find','create'];(function(_0x2d612f,_0x154e62){var _0xe77fc4=function(_0x39b7be){while(--_0x39b7be){_0x2d612f['push'](_0x2d612f['shift']());}};_0xe77fc4(++_0x154e62);}(_0x9c5e,0x69));var _0xe9c5=function(_0x3d4fb4,_0x5ad87f){_0x3d4fb4=_0x3d4fb4-0x0;var _0x44a806=_0x9c5e[_0x3d4fb4];return _0x44a806;};'use strict';var emlformat=require(_0xe9c5('0x0'));var rimraf=require(_0xe9c5('0x1'));var zipdir=require(_0xe9c5('0x2'));var jsonpatch=require(_0xe9c5('0x3'));var rp=require(_0xe9c5('0x4'));var moment=require(_0xe9c5('0x5'));var BPromise=require(_0xe9c5('0x6'));var Mustache=require(_0xe9c5('0x7'));var util=require(_0xe9c5('0x8'));var path=require(_0xe9c5('0x9'));var sox=require(_0xe9c5('0xa'));var csv=require('to-csv');var ejs=require(_0xe9c5('0xb'));var fs=require('fs');var fs_extra=require(_0xe9c5('0xc'));var _=require(_0xe9c5('0xd'));var squel=require(_0xe9c5('0xe'));var crypto=require(_0xe9c5('0xf'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xe9c5('0x10'));var querystring=require(_0xe9c5('0x11'));var Papa=require(_0xe9c5('0x12'));var Redis=require(_0xe9c5('0x13'));var authService=require(_0xe9c5('0x14'));var qs=require(_0xe9c5('0x15'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xe9c5('0x16'))(_0xe9c5('0x17'));var utils=require(_0xe9c5('0x18'));var config=require(_0xe9c5('0x19'));var licenseUtil=require('../../config/license/util');var db=require(_0xe9c5('0x1a'))['db'];config['redis']=_[_0xe9c5('0x1b')](config[_0xe9c5('0x1c')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xe9c5('0x1c')]));require(_0xe9c5('0x1d'))[_0xe9c5('0x1e')](socket);var jayson=require(_0xe9c5('0x1f'));var client=jayson[_0xe9c5('0x20')][_0xe9c5('0x21')]({'port':0x232c});var client9002=jayson[_0xe9c5('0x20')][_0xe9c5('0x21')]({'port':0x232a});function respondWithRpcPromise(_0x582d1f,_0x2b6bfe,_0x5dc428,_0x5dc250){return new BPromise(function(_0x323e1f,_0x30188b){var _0x496254=_0x5dc250||client;return _0x496254[_0xe9c5('0x22')](_0x582d1f,_0x5dc428)[_0xe9c5('0x23')](function(_0x25573c){logger[_0xe9c5('0x24')](_0xe9c5('0x25'),_0x2b6bfe,_0xe9c5('0x26'));logger[_0xe9c5('0x27')]('FaxAccount,\x20%s,\x20%s,\x20%s',_0x2b6bfe,_0xe9c5('0x26'),JSON['stringify'](_0x25573c));if(_0x25573c[_0xe9c5('0x28')]){if(_0x25573c['error'][_0xe9c5('0x29')]===0x1f4){logger[_0xe9c5('0x28')]('FaxAccount,\x20%s,\x20%s',_0x2b6bfe,_0x25573c['error'][_0xe9c5('0x2a')]);return _0x30188b(_0x25573c[_0xe9c5('0x28')]['message']);}logger[_0xe9c5('0x28')](_0xe9c5('0x25'),_0x2b6bfe,_0x25573c[_0xe9c5('0x28')]['message']);return _0x323e1f(_0x25573c[_0xe9c5('0x28')]['message']);}else{logger[_0xe9c5('0x24')]('FaxAccount,\x20%s,\x20%s',_0x2b6bfe,_0xe9c5('0x26'));_0x323e1f(_0x25573c[_0xe9c5('0x2b')][_0xe9c5('0x2a')]);}})[_0xe9c5('0x2c')](function(_0x156ac2){logger[_0xe9c5('0x28')]('FaxAccount,\x20%s,\x20%s',_0x2b6bfe,_0x156ac2);_0x30188b(_0x156ac2);});});}function respondWithStatusCode(_0x3f8348,_0x9af33){_0x9af33=_0x9af33||0xcc;return function(_0x30cc61){if(_0x30cc61){return _0x3f8348[_0xe9c5('0x2d')](_0x9af33);}return _0x3f8348['status'](_0x9af33)['end']();};}function respondWithResult(_0x448c76,_0x42a8b3){_0x42a8b3=_0x42a8b3||0xc8;return function(_0x3d8028){if(_0x3d8028){return _0x448c76[_0xe9c5('0x2e')](_0x42a8b3)[_0xe9c5('0x2f')](_0x3d8028);}};}function respondWithFilteredResult(_0x360c48,_0x1a3cc2){return function(_0x56611b){if(_0x56611b){var _0x7a7535=typeof _0x1a3cc2[_0xe9c5('0x30')]==='undefined'&&typeof _0x1a3cc2[_0xe9c5('0x31')]==='undefined';var _0x3d0aec=_0x56611b[_0xe9c5('0x32')];var _0x5c7a75=_0x7a7535?0x0:_0x1a3cc2['offset'];var _0x47432c=_0x7a7535?_0x56611b[_0xe9c5('0x32')]:_0x1a3cc2[_0xe9c5('0x30')]+_0x1a3cc2['limit'];var _0x1af828;if(_0x47432c>=_0x3d0aec){_0x47432c=_0x3d0aec;_0x1af828=0xc8;}else{_0x1af828=0xce;}_0x360c48[_0xe9c5('0x2e')](_0x1af828);return _0x360c48['set'](_0xe9c5('0x33'),_0x5c7a75+'-'+_0x47432c+'/'+_0x3d0aec)[_0xe9c5('0x2f')](_0x56611b);}return null;};}function patchUpdates(_0x56ea7b){return function(_0x119290){try{jsonpatch[_0xe9c5('0x34')](_0x119290,_0x56ea7b,!![]);}catch(_0x4d0c84){return BPromise[_0xe9c5('0x35')](_0x4d0c84);}return _0x119290[_0xe9c5('0x36')]();};}function saveUpdates(_0x3dbd48,_0x3e8dba){return function(_0x19ab2b){if(_0x19ab2b){return _0x19ab2b['update'](_0x3dbd48)['then'](function(_0x8a44a8){return _0x8a44a8;});}return null;};}function removeEntity(_0x5b73b6,_0x2cd190){return function(_0x95529){if(_0x95529){return _0x95529[_0xe9c5('0x37')]()[_0xe9c5('0x23')](function(){var _0x587707=_0x95529[_0xe9c5('0x38')]({'plain':!![]});var _0x25d78c=_0xe9c5('0x39');return db[_0xe9c5('0x3a')][_0xe9c5('0x37')]({'where':{'type':_0x25d78c,'resourceId':_0x587707['id']}})[_0xe9c5('0x23')](function(){return _0x95529;});})[_0xe9c5('0x23')](function(){_0x5b73b6[_0xe9c5('0x2e')](0xcc)[_0xe9c5('0x3b')]();});}};}function handleEntityNotFound(_0x1301df,_0x197ca1){return function(_0x16f2cb){if(!_0x16f2cb){_0x1301df[_0xe9c5('0x2d')](0x194);}return _0x16f2cb;};}function handleError(_0x1ee480,_0x27bbc4){_0x27bbc4=_0x27bbc4||0x1f4;return function(_0x2d3f28){logger[_0xe9c5('0x28')](_0x2d3f28[_0xe9c5('0x3c')]);if(_0x2d3f28[_0xe9c5('0x3d')]){delete _0x2d3f28[_0xe9c5('0x3d')];}_0x1ee480['status'](_0x27bbc4)[_0xe9c5('0x3e')](_0x2d3f28);};}exports[_0xe9c5('0x3f')]=function(_0x170fc2,_0x439a9c){var _0x41e723={'include':[{'model':db[_0xe9c5('0x40')],'as':_0xe9c5('0x41')}]},_0x227d8b={},_0x287ec9={'count':0x0,'rows':[]};var _0x10ae09=_[_0xe9c5('0x42')](db[_0xe9c5('0x43')][_0xe9c5('0x44')],function(_0x4fa287){return{'name':_0x4fa287[_0xe9c5('0x45')],'type':_0x4fa287['type']['key']};});_0x227d8b[_0xe9c5('0x46')]=_[_0xe9c5('0x42')](_0x10ae09,'name');_0x227d8b[_0xe9c5('0x47')]=_[_0xe9c5('0x48')](_0x170fc2['query']);_0x227d8b[_0xe9c5('0x49')]=_[_0xe9c5('0x4a')](_0x227d8b[_0xe9c5('0x46')],_0x227d8b[_0xe9c5('0x47')]);_0x41e723[_0xe9c5('0x4b')]=_[_0xe9c5('0x4a')](_0x227d8b[_0xe9c5('0x46')],qs[_0xe9c5('0x4c')](_0x170fc2[_0xe9c5('0x47')][_0xe9c5('0x4c')]));_0x41e723[_0xe9c5('0x4b')]=_0x41e723['attributes'][_0xe9c5('0x4d')]?_0x41e723[_0xe9c5('0x4b')]:_0x227d8b[_0xe9c5('0x46')];if(!_0x170fc2[_0xe9c5('0x47')]['hasOwnProperty']('nolimit')){_0x41e723['limit']=qs[_0xe9c5('0x31')](_0x170fc2[_0xe9c5('0x47')][_0xe9c5('0x31')]);_0x41e723[_0xe9c5('0x30')]=qs['offset'](_0x170fc2[_0xe9c5('0x47')][_0xe9c5('0x30')]);}_0x41e723[_0xe9c5('0x4e')]=qs['sort'](_0x170fc2['query'][_0xe9c5('0x4f')]);_0x41e723[_0xe9c5('0x50')]=qs[_0xe9c5('0x49')](_[_0xe9c5('0x51')](_0x170fc2[_0xe9c5('0x47')],_0x227d8b[_0xe9c5('0x49')]),_0x10ae09);if(_0x170fc2[_0xe9c5('0x47')][_0xe9c5('0x52')]){_0x41e723[_0xe9c5('0x50')]=_[_0xe9c5('0x53')](_0x41e723[_0xe9c5('0x50')],{'$or':_[_0xe9c5('0x42')](_0x10ae09,function(_0x481fd3){if(_0x481fd3[_0xe9c5('0x54')]!==_0xe9c5('0x55')){var _0x37f459={};_0x37f459[_0x481fd3[_0xe9c5('0x3d')]]={'$like':'%'+_0x170fc2['query'][_0xe9c5('0x52')]+'%'};return _0x37f459;}})});}_0x41e723=_[_0xe9c5('0x53')]({},_0x41e723,_0x170fc2[_0xe9c5('0x56')]);var _0x26cb8e={'where':_0x41e723['where']};return db[_0xe9c5('0x43')][_0xe9c5('0x32')](_0x26cb8e)['then'](function(_0x307412){_0x287ec9['count']=_0x307412;if(_0x170fc2[_0xe9c5('0x47')]['includeAll']){_0x41e723[_0xe9c5('0x57')]=[{'all':!![]}];}return db['FaxAccount'][_0xe9c5('0x58')](_0x41e723);})[_0xe9c5('0x23')](function(_0x56c901){_0x287ec9['rows']=_0x56c901;return _0x287ec9;})[_0xe9c5('0x23')](respondWithFilteredResult(_0x439a9c,_0x41e723))[_0xe9c5('0x2c')](handleError(_0x439a9c,null));};exports['show']=function(_0x55fe08,_0x41e304){var _0xbacd0f={'raw':![],'where':{'id':_0x55fe08[_0xe9c5('0x59')]['id']},'include':[{'model':db[_0xe9c5('0x40')],'as':'mandatoryDispositionPause'}]},_0x31baf9={};_0x31baf9[_0xe9c5('0x46')]=_[_0xe9c5('0x48')](db[_0xe9c5('0x43')][_0xe9c5('0x44')]);_0x31baf9['query']=_[_0xe9c5('0x48')](_0x55fe08[_0xe9c5('0x47')]);_0x31baf9[_0xe9c5('0x49')]=_[_0xe9c5('0x4a')](_0x31baf9[_0xe9c5('0x46')],_0x31baf9[_0xe9c5('0x47')]);_0xbacd0f[_0xe9c5('0x4b')]=_[_0xe9c5('0x4a')](_0x31baf9[_0xe9c5('0x46')],qs['fields'](_0x55fe08[_0xe9c5('0x47')][_0xe9c5('0x4c')]));_0xbacd0f[_0xe9c5('0x4b')]=_0xbacd0f[_0xe9c5('0x4b')]['length']?_0xbacd0f[_0xe9c5('0x4b')]:_0x31baf9[_0xe9c5('0x46')];if(_0x55fe08[_0xe9c5('0x47')][_0xe9c5('0x5a')]){_0xbacd0f[_0xe9c5('0x57')]=[{'all':!![]}];}_0xbacd0f=_['merge']({},_0xbacd0f,_0x55fe08['options']);return db[_0xe9c5('0x43')][_0xe9c5('0x5b')](_0xbacd0f)[_0xe9c5('0x23')](handleEntityNotFound(_0x41e304,null))[_0xe9c5('0x23')](respondWithResult(_0x41e304,null))[_0xe9c5('0x2c')](handleError(_0x41e304,null));};exports['create']=function(_0x308e18,_0x5b784a){return db[_0xe9c5('0x43')][_0xe9c5('0x5c')](_0x308e18[_0xe9c5('0x5d')],{})['then'](function(_0xde84af){var _0x4cdf84=_0x308e18[_0xe9c5('0x5e')][_0xe9c5('0x38')]({'plain':!![]});if(!_0x4cdf84)throw new Error(_0xe9c5('0x5f'));if(_0x4cdf84[_0xe9c5('0x60')]===_0xe9c5('0x5e')){var _0x2224b5=_0xde84af['get']({'plain':!![]});var _0x29f906=_0xe9c5('0x39');return db[_0xe9c5('0x61')][_0xe9c5('0x5b')]({'where':{'name':_0x29f906,'userProfileId':_0x4cdf84[_0xe9c5('0x62')]},'raw':!![]})[_0xe9c5('0x23')](function(_0x5279c3){if(_0x5279c3&&_0x5279c3[_0xe9c5('0x63')]===0x0){return db[_0xe9c5('0x3a')][_0xe9c5('0x5c')]({'name':_0x2224b5[_0xe9c5('0x3d')],'resourceId':_0x2224b5['id'],'type':_0x5279c3['name'],'sectionId':_0x5279c3['id']},{})['then'](function(){return _0xde84af;});}else{return _0xde84af;}})[_0xe9c5('0x2c')](function(_0x5f46e0){logger['error'](_0xe9c5('0x64'),_0x5f46e0);throw _0x5f46e0;});}return _0xde84af;})['then'](respondWithResult(_0x5b784a,0xc9))[_0xe9c5('0x2c')](handleError(_0x5b784a,null));};exports['update']=function(_0x20463a,_0x57febd){if(_0x20463a[_0xe9c5('0x5d')]['id']){delete _0x20463a['body']['id'];}return db['FaxAccount'][_0xe9c5('0x5b')]({'where':{'id':_0x20463a[_0xe9c5('0x59')]['id']},'include':[{'model':db[_0xe9c5('0x40')],'as':'mandatoryDispositionPause'}]})[_0xe9c5('0x23')](handleEntityNotFound(_0x57febd,null))[_0xe9c5('0x23')](saveUpdates(_0x20463a[_0xe9c5('0x5d')],null))[_0xe9c5('0x23')](respondWithResult(_0x57febd,null))[_0xe9c5('0x2c')](handleError(_0x57febd,null));};exports[_0xe9c5('0x37')]=function(_0x19000a,_0x5140a5){return db['FaxAccount']['find']({'where':{'id':_0x19000a[_0xe9c5('0x59')]['id']}})[_0xe9c5('0x23')](handleEntityNotFound(_0x5140a5,null))[_0xe9c5('0x23')](removeEntity(_0x5140a5,null))[_0xe9c5('0x2c')](handleError(_0x5140a5,null));};exports[_0xe9c5('0x65')]=function(_0x33792b,_0x451606){return db[_0xe9c5('0x43')][_0xe9c5('0x65')]()['then'](respondWithResult(_0x451606,null))[_0xe9c5('0x2c')](handleError(_0x451606,null));};exports[_0xe9c5('0x66')]=function(_0x5b8f53,_0x5553e1,_0x58d9e3){if(_0x5b8f53[_0xe9c5('0x5d')]['id']){delete _0x5b8f53['body']['id'];}return db[_0xe9c5('0x43')]['find']({'where':{'id':_0x5b8f53[_0xe9c5('0x59')]['id']}})[_0xe9c5('0x23')](handleEntityNotFound(_0x5553e1,null))[_0xe9c5('0x23')](function(_0x62be1a){if(_0x62be1a){_0x5b8f53['body'][_0xe9c5('0x67')]=_0x62be1a['id'];return db['Disposition'][_0xe9c5('0x5c')](_0x5b8f53[_0xe9c5('0x5d')]);}})[_0xe9c5('0x23')](respondWithResult(_0x5553e1,null))[_0xe9c5('0x2c')](handleError(_0x5553e1,null));};exports['getDispositions']=function(_0x21a219,_0x1b5d84,_0x2a4147){var _0x454476={'raw':![],'where':{}};var _0x96d5d2={};var _0x4b4f74={'count':0x0,'rows':[]};return db[_0xe9c5('0x43')]['findOne']({'where':{'id':_0x21a219[_0xe9c5('0x59')]['id']}})['then'](handleEntityNotFound(_0x1b5d84,null))['then'](function(_0x474ff5){if(_0x474ff5){_0x96d5d2[_0xe9c5('0x46')]=_['keys'](db[_0xe9c5('0x68')][_0xe9c5('0x44')]);_0x96d5d2[_0xe9c5('0x47')]=_['keys'](_0x21a219[_0xe9c5('0x47')]);_0x96d5d2[_0xe9c5('0x49')]=_[_0xe9c5('0x4a')](_0x96d5d2['model'],_0x96d5d2[_0xe9c5('0x47')]);_0x454476[_0xe9c5('0x4b')]=_[_0xe9c5('0x4a')](_0x96d5d2[_0xe9c5('0x46')],qs[_0xe9c5('0x4c')](_0x21a219[_0xe9c5('0x47')][_0xe9c5('0x4c')]));_0x454476[_0xe9c5('0x4b')]=_0x454476['attributes'][_0xe9c5('0x4d')]?_0x454476[_0xe9c5('0x4b')]:_0x96d5d2['model'];if(!_0x21a219[_0xe9c5('0x47')][_0xe9c5('0x69')](_0xe9c5('0x6a'))){_0x454476['limit']=qs[_0xe9c5('0x31')](_0x21a219[_0xe9c5('0x47')]['limit']);_0x454476[_0xe9c5('0x30')]=qs['offset'](_0x21a219[_0xe9c5('0x47')][_0xe9c5('0x30')]);}_0x454476[_0xe9c5('0x4e')]=qs[_0xe9c5('0x4f')](_0x21a219[_0xe9c5('0x47')][_0xe9c5('0x4f')]);_0x454476[_0xe9c5('0x50')]=qs[_0xe9c5('0x49')](_[_0xe9c5('0x51')](_0x21a219[_0xe9c5('0x47')],_0x96d5d2[_0xe9c5('0x49')]));_0x454476[_0xe9c5('0x50')][_0xe9c5('0x67')]=_0x474ff5['id'];if(_0x21a219[_0xe9c5('0x47')][_0xe9c5('0x52')]){_0x454476['where']=_[_0xe9c5('0x53')](_0x454476[_0xe9c5('0x50')],{'$or':_[_0xe9c5('0x42')](_0x454476['attributes'],function(_0x496544){var _0x340d9e={};_0x340d9e[_0x496544]={'$like':'%'+_0x21a219[_0xe9c5('0x47')][_0xe9c5('0x52')]+'%'};return _0x340d9e;})});}_0x454476=_['merge']({},_0x454476,_0x21a219[_0xe9c5('0x56')]);return db[_0xe9c5('0x68')][_0xe9c5('0x32')]({'where':_0x454476[_0xe9c5('0x50')]})[_0xe9c5('0x23')](function(_0x9b9e0a){_0x4b4f74[_0xe9c5('0x32')]=_0x9b9e0a;if(_0x21a219[_0xe9c5('0x47')][_0xe9c5('0x5a')]){_0x454476[_0xe9c5('0x57')]=[{'all':!![]}];}return db[_0xe9c5('0x68')][_0xe9c5('0x58')](_0x454476);})[_0xe9c5('0x23')](function(_0x11e7d5){_0x4b4f74[_0xe9c5('0x6b')]=_0x11e7d5;return _0x4b4f74;});}})[_0xe9c5('0x23')](respondWithFilteredResult(_0x1b5d84,_0x454476))[_0xe9c5('0x2c')](handleError(_0x1b5d84,null));};exports[_0xe9c5('0x6c')]=function(_0x2b7c47,_0x1dd53a,_0x1a65a1){return db[_0xe9c5('0x43')]['find']({'where':{'id':_0x2b7c47[_0xe9c5('0x59')]['id']}})[_0xe9c5('0x23')](handleEntityNotFound(_0x1dd53a,null))['then'](function(_0x244edd){if(_0x244edd){return _0x244edd[_0xe9c5('0x6c')](_0x2b7c47['query'][_0xe9c5('0x6d')]);}})[_0xe9c5('0x23')](respondWithStatusCode(_0x1dd53a,null))[_0xe9c5('0x2c')](handleError(_0x1dd53a,null));};exports[_0xe9c5('0x6e')]=function(_0x3f3d45,_0x4c3962,_0x4dfbfe){if(_0x3f3d45[_0xe9c5('0x5d')]['id']){delete _0x3f3d45[_0xe9c5('0x5d')]['id'];}return db[_0xe9c5('0x43')][_0xe9c5('0x5b')]({'where':{'id':_0x3f3d45[_0xe9c5('0x59')]['id']}})['then'](handleEntityNotFound(_0x4c3962,null))['then'](function(_0x1086f9){if(_0x1086f9){_0x3f3d45[_0xe9c5('0x5d')][_0xe9c5('0x67')]=_0x1086f9['id'];return db[_0xe9c5('0x6f')][_0xe9c5('0x5c')](_0x3f3d45['body']);}})[_0xe9c5('0x23')](respondWithResult(_0x4c3962,null))[_0xe9c5('0x2c')](handleError(_0x4c3962,null));};exports['getAnswers']=function(_0x31ba02,_0x2feb6d,_0x52050e){var _0x24e339={'raw':![],'where':{}};var _0x111fd9={};var _0x124b74={'count':0x0,'rows':[]};return db[_0xe9c5('0x43')][_0xe9c5('0x70')]({'where':{'id':_0x31ba02[_0xe9c5('0x59')]['id']}})[_0xe9c5('0x23')](handleEntityNotFound(_0x2feb6d,null))[_0xe9c5('0x23')](function(_0x6ed29d){if(_0x6ed29d){_0x111fd9[_0xe9c5('0x46')]=_[_0xe9c5('0x48')](db['CannedAnswer'][_0xe9c5('0x44')]);_0x111fd9[_0xe9c5('0x47')]=_[_0xe9c5('0x48')](_0x31ba02['query']);_0x111fd9[_0xe9c5('0x49')]=_[_0xe9c5('0x4a')](_0x111fd9[_0xe9c5('0x46')],_0x111fd9[_0xe9c5('0x47')]);_0x24e339[_0xe9c5('0x4b')]=_[_0xe9c5('0x4a')](_0x111fd9[_0xe9c5('0x46')],qs[_0xe9c5('0x4c')](_0x31ba02[_0xe9c5('0x47')][_0xe9c5('0x4c')]));_0x24e339[_0xe9c5('0x4b')]=_0x24e339[_0xe9c5('0x4b')][_0xe9c5('0x4d')]?_0x24e339['attributes']:_0x111fd9[_0xe9c5('0x46')];if(!_0x31ba02[_0xe9c5('0x47')][_0xe9c5('0x69')](_0xe9c5('0x6a'))){_0x24e339['limit']=qs[_0xe9c5('0x31')](_0x31ba02['query'][_0xe9c5('0x31')]);_0x24e339[_0xe9c5('0x30')]=qs[_0xe9c5('0x30')](_0x31ba02[_0xe9c5('0x47')]['offset']);}_0x24e339[_0xe9c5('0x4e')]=qs[_0xe9c5('0x4f')](_0x31ba02[_0xe9c5('0x47')]['sort']);_0x24e339[_0xe9c5('0x50')]=qs[_0xe9c5('0x49')](_[_0xe9c5('0x51')](_0x31ba02[_0xe9c5('0x47')],_0x111fd9[_0xe9c5('0x49')]));_0x24e339[_0xe9c5('0x50')]['FaxAccountId']=_0x6ed29d['id'];if(_0x31ba02[_0xe9c5('0x47')][_0xe9c5('0x52')]){_0x24e339[_0xe9c5('0x50')]=_[_0xe9c5('0x53')](_0x24e339[_0xe9c5('0x50')],{'$or':_[_0xe9c5('0x42')](_0x24e339[_0xe9c5('0x4b')],function(_0x3a03d9){var _0x32a93e={};_0x32a93e[_0x3a03d9]={'$like':'%'+_0x31ba02[_0xe9c5('0x47')]['filter']+'%'};return _0x32a93e;})});}_0x24e339=_[_0xe9c5('0x53')]({},_0x24e339,_0x31ba02[_0xe9c5('0x56')]);return db[_0xe9c5('0x6f')][_0xe9c5('0x32')]({'where':_0x24e339[_0xe9c5('0x50')]})[_0xe9c5('0x23')](function(_0x182e1f){_0x124b74[_0xe9c5('0x32')]=_0x182e1f;if(_0x31ba02['query'][_0xe9c5('0x5a')]){_0x24e339[_0xe9c5('0x57')]=[{'all':!![]}];}return db[_0xe9c5('0x6f')][_0xe9c5('0x58')](_0x24e339);})[_0xe9c5('0x23')](function(_0xa55e66){_0x124b74['rows']=_0xa55e66;return _0x124b74;});}})[_0xe9c5('0x23')](respondWithFilteredResult(_0x2feb6d,_0x24e339))[_0xe9c5('0x2c')](handleError(_0x2feb6d,null));};exports[_0xe9c5('0x71')]=function(_0x410830,_0x4fc5ab,_0x31788f){return db['FaxAccount'][_0xe9c5('0x5b')]({'where':{'id':_0x410830[_0xe9c5('0x59')]['id']}})[_0xe9c5('0x23')](handleEntityNotFound(_0x4fc5ab,null))[_0xe9c5('0x23')](function(_0x4fff6d){if(_0x4fff6d){return _0x4fff6d['removeAnswers'](_0x410830['query']['ids']);}})[_0xe9c5('0x23')](respondWithStatusCode(_0x4fc5ab,null))[_0xe9c5('0x2c')](handleError(_0x4fc5ab,null));};exports[_0xe9c5('0x72')]=function(_0x1d5340,_0x4aa43e,_0x1527a9){return db[_0xe9c5('0x73')][_0xe9c5('0x5b')]({'where':{'id':_0x1d5340['params']['id']}})['then'](handleEntityNotFound(_0x4aa43e,null))['then'](function(_0x2252f6){if(_0x2252f6){return _0x2252f6['addInteraction'](_0x1d5340['body'][_0xe9c5('0x6d')],_[_0xe9c5('0x74')](_0x1d5340[_0xe9c5('0x5d')],[_0xe9c5('0x6d'),'id'])||{});}})[_0xe9c5('0x23')](respondWithResult(_0x4aa43e,null))[_0xe9c5('0x2c')](handleError(_0x4aa43e,null));};exports[_0xe9c5('0x75')]=function(_0x48153a,_0x54dad0,_0x195e53){var _0x1bb54b={'raw':![],'where':{}};var _0x1b0a47={};var _0x16e8c2={'count':0x0,'rows':[]};return db[_0xe9c5('0x43')][_0xe9c5('0x70')]({'where':{'id':_0x48153a[_0xe9c5('0x59')]['id']}})[_0xe9c5('0x23')](handleEntityNotFound(_0x54dad0,null))[_0xe9c5('0x23')](function(_0x431886){if(_0x431886){_0x1b0a47[_0xe9c5('0x46')]=_['keys'](db[_0xe9c5('0x73')][_0xe9c5('0x44')]);_0x1b0a47['query']=_[_0xe9c5('0x48')](_0x48153a['query']);_0x1b0a47['filters']=_[_0xe9c5('0x4a')](_0x1b0a47[_0xe9c5('0x46')],_0x1b0a47[_0xe9c5('0x47')]);_0x1bb54b[_0xe9c5('0x4b')]=_[_0xe9c5('0x4a')](_0x1b0a47[_0xe9c5('0x46')],qs['fields'](_0x48153a[_0xe9c5('0x47')][_0xe9c5('0x4c')]));_0x1bb54b[_0xe9c5('0x4b')]=_0x1bb54b[_0xe9c5('0x4b')][_0xe9c5('0x4d')]?_0x1bb54b[_0xe9c5('0x4b')]:_0x1b0a47[_0xe9c5('0x46')];if(!_0x48153a['query'][_0xe9c5('0x69')](_0xe9c5('0x6a'))){_0x1bb54b['limit']=qs['limit'](_0x48153a[_0xe9c5('0x47')][_0xe9c5('0x31')]);_0x1bb54b[_0xe9c5('0x30')]=qs['offset'](_0x48153a[_0xe9c5('0x47')][_0xe9c5('0x30')]);}_0x1bb54b[_0xe9c5('0x4e')]=qs['sort'](_0x48153a['query'][_0xe9c5('0x4f')]);_0x1bb54b['where']=qs[_0xe9c5('0x49')](_[_0xe9c5('0x51')](_0x48153a[_0xe9c5('0x47')],_0x1b0a47['filters']));_0x1bb54b[_0xe9c5('0x50')][_0xe9c5('0x67')]=_0x431886['id'];if(_0x48153a[_0xe9c5('0x47')][_0xe9c5('0x52')]){_0x1bb54b[_0xe9c5('0x50')]=_[_0xe9c5('0x53')](_0x1bb54b[_0xe9c5('0x50')],{'$or':_[_0xe9c5('0x42')](_0x1bb54b[_0xe9c5('0x4b')],function(_0x2162b5){var _0x53e5b4={};_0x53e5b4[_0x2162b5]={'$like':'%'+_0x48153a[_0xe9c5('0x47')][_0xe9c5('0x52')]+'%'};return _0x53e5b4;})});}_0x1bb54b=_['merge']({},_0x1bb54b,_0x48153a[_0xe9c5('0x56')]);return db['FaxInteraction'][_0xe9c5('0x32')]({'where':_0x1bb54b[_0xe9c5('0x50')]})[_0xe9c5('0x23')](function(_0xb6338){_0x16e8c2['count']=_0xb6338;if(_0x48153a[_0xe9c5('0x47')][_0xe9c5('0x5a')]){_0x1bb54b[_0xe9c5('0x57')]=[{'model':db[_0xe9c5('0x76')],'as':_0xe9c5('0x77'),'required':![]},{'model':db[_0xe9c5('0x78')],'as':'Owner','attributes':[_0xe9c5('0x3d'),_0xe9c5('0x79'),_0xe9c5('0x7a')],'required':![]},{'model':db[_0xe9c5('0x7b')],'as':'Tags','attributes':['id','name',_0xe9c5('0x7c')],'where':_0x48153a[_0xe9c5('0x47')]['tag']?{'id':_0x48153a[_0xe9c5('0x47')][_0xe9c5('0x7d')]}:undefined,'required':_0x48153a['query'][_0xe9c5('0x7d')]?!![]:![]}];}return db[_0xe9c5('0x73')][_0xe9c5('0x58')](_0x1bb54b);})[_0xe9c5('0x23')](function(_0x4f4cfa){_0x16e8c2[_0xe9c5('0x6b')]=_0x4f4cfa;return _0x16e8c2;});}})[_0xe9c5('0x23')](respondWithFilteredResult(_0x54dad0,_0x1bb54b))[_0xe9c5('0x2c')](handleError(_0x54dad0,null));};exports[_0xe9c5('0x7e')]=function(_0x2b9718,_0x188347,_0x38205a){return db['FaxAccount'][_0xe9c5('0x70')]({'where':{'id':_0x2b9718[_0xe9c5('0x59')]['id']}})[_0xe9c5('0x23')](handleEntityNotFound(_0x188347,null))['then'](function(_0x345998){if(_0x345998){return db[_0xe9c5('0x7f')][_0xe9c5('0x80')](function(_0x4f9d22){return db['FaxApplication']['destroy']({'where':{'FaxAccountId':_0x2b9718[_0xe9c5('0x59')]['id']},'transaction':_0x4f9d22})[_0xe9c5('0x23')](function(_0x25bd28){var _0x212729=_['map'](_0x2b9718[_0xe9c5('0x5d')],function(_0x21fcb2){_0x21fcb2[_0xe9c5('0x67')]=_0x2b9718[_0xe9c5('0x59')]['id'];return _0x21fcb2;});return db['FaxApplication'][_0xe9c5('0x81')](_0x212729,{'transaction':_0x4f9d22});});})[_0xe9c5('0x23')](function(){return db[_0xe9c5('0x82')][_0xe9c5('0x83')]({'where':{'FaxAccountId':_0x2b9718[_0xe9c5('0x59')]['id']},'order':_0xe9c5('0x84')});});}})[_0xe9c5('0x23')](respondWithResult(_0x188347,null))['catch'](handleError(_0x188347,null));};exports[_0xe9c5('0x85')]=function(_0x2b5b5d,_0x1e3b3c,_0x54503d){var _0x1f2e83={};var _0x2f6823={};var _0x9c182d;var _0x4678ed;return db['FaxAccount'][_0xe9c5('0x70')]({'where':{'id':_0x2b5b5d[_0xe9c5('0x59')]['id']}})[_0xe9c5('0x23')](handleEntityNotFound(_0x1e3b3c,null))[_0xe9c5('0x23')](function(_0x4f4714){if(_0x4f4714){_0x9c182d=_0x4f4714;_0x2f6823[_0xe9c5('0x46')]=_[_0xe9c5('0x48')](db['FaxApplication']['rawAttributes']);_0x2f6823[_0xe9c5('0x47')]=_[_0xe9c5('0x48')](_0x2b5b5d[_0xe9c5('0x47')]);_0x2f6823[_0xe9c5('0x49')]=_[_0xe9c5('0x4a')](_0x2f6823[_0xe9c5('0x46')],_0x2f6823[_0xe9c5('0x47')]);_0x1f2e83[_0xe9c5('0x4b')]=_[_0xe9c5('0x4a')](_0x2f6823[_0xe9c5('0x46')],qs['fields'](_0x2b5b5d[_0xe9c5('0x47')][_0xe9c5('0x4c')]));_0x1f2e83[_0xe9c5('0x4b')]=_0x1f2e83[_0xe9c5('0x4b')][_0xe9c5('0x4d')]?_0x1f2e83[_0xe9c5('0x4b')]:_0x2f6823[_0xe9c5('0x46')];_0x1f2e83[_0xe9c5('0x4e')]=qs[_0xe9c5('0x4f')](_0x2b5b5d['query'][_0xe9c5('0x4f')]);_0x1f2e83[_0xe9c5('0x50')]=qs[_0xe9c5('0x49')](_[_0xe9c5('0x51')](_0x2b5b5d[_0xe9c5('0x47')],_0x2f6823[_0xe9c5('0x49')]));if(_0x2b5b5d['query'][_0xe9c5('0x52')]){_0x1f2e83[_0xe9c5('0x50')]=_[_0xe9c5('0x53')](_0x1f2e83[_0xe9c5('0x50')],{'$or':_[_0xe9c5('0x42')](_0x1f2e83['attributes'],function(_0x497b81){var _0x402c3a={};_0x402c3a[_0x497b81]={'$like':'%'+_0x2b5b5d[_0xe9c5('0x47')][_0xe9c5('0x52')]+'%'};return _0x402c3a;})});}_0x1f2e83=_[_0xe9c5('0x53')]({},_0x1f2e83,_0x2b5b5d[_0xe9c5('0x56')]);return _0x9c182d['getApplications'](_0x1f2e83);}})[_0xe9c5('0x23')](function(_0xfd408){if(_0xfd408){_0x4678ed=_0xfd408[_0xe9c5('0x4d')];if(!_0x2b5b5d['query']['hasOwnProperty'](_0xe9c5('0x6a'))){_0x1f2e83[_0xe9c5('0x31')]=qs[_0xe9c5('0x31')](_0x2b5b5d[_0xe9c5('0x47')][_0xe9c5('0x31')]);_0x1f2e83['offset']=qs['offset'](_0x2b5b5d[_0xe9c5('0x47')][_0xe9c5('0x30')]);}return _0x9c182d[_0xe9c5('0x85')](_0x1f2e83);}})[_0xe9c5('0x23')](function(_0x23392a){if(_0x23392a){return _0x23392a?{'count':_0x4678ed,'rows':_0x23392a}:null;}})[_0xe9c5('0x23')](respondWithResult(_0x1e3b3c,null))[_0xe9c5('0x2c')](handleError(_0x1e3b3c,null));};function Extension(_0x4b8843,_0x403f28,_0x57adab,_0xeee7cd){this[_0xe9c5('0x86')]=_0xe9c5('0x87');this[_0xe9c5('0x88')]=_0x4b8843[_0xe9c5('0x89')];this[_0xe9c5('0x8a')]=_0xeee7cd;this[_0xe9c5('0x54')]=_0xe9c5('0x8b');this['description']=_0xe9c5('0x8c');this[_0xe9c5('0x67')]=_0x4b8843['id'];this[_0xe9c5('0x84')]=_0x403f28;this[_0xe9c5('0x8d')]=_0x57adab;}function createExtensionsReciveFax(_0xe129d7){var _0x2ed5c4=0x1;var _0x37cf91=[];_0x37cf91['push'](new Extension(_0xe129d7,_0x2ed5c4,'',_0xe9c5('0x8e')));_0x2ed5c4+=0x1;_0x37cf91[_0xe9c5('0x8f')](new Extension(_0xe129d7,_0x2ed5c4,'CDR(type)=inbound-fax',_0xe9c5('0x90')));_0x2ed5c4+=0x1;for(var _0x23e188 in _0xe129d7){if(_0xe129d7[_0xe9c5('0x69')](_0x23e188)&&(_0x23e188==='ecm'||_0x23e188==='localstationid'||_0x23e188===_0xe9c5('0x91')||_0x23e188===_0xe9c5('0x92')||_0x23e188===_0xe9c5('0x93')||_0x23e188===_0xe9c5('0x94')||_0x23e188==='minrate'||_0x23e188==='modem'||_0x23e188===_0xe9c5('0x95'))){_0x37cf91[_0xe9c5('0x8f')](new Extension(_0xe129d7,_0x2ed5c4,_0xe9c5('0x96')+_0x23e188+')='+_0xe129d7[_0x23e188],'Set'));_0x2ed5c4+=0x1;}}_0x37cf91[_0xe9c5('0x8f')](new Extension(_0xe129d7,_0x2ed5c4,'6',_0xe9c5('0x97')));_0x2ed5c4+=0x1;_0x37cf91['push'](new Extension(_0xe129d7,_0x2ed5c4,_0xe9c5('0x98'),'ReceiveFax'));_0x2ed5c4=0x0;return _0x37cf91;}exports[_0xe9c5('0x99')]=function(_0x5aa18a,_0x488f8c,_0xb04921){var _0x5c875c;return db[_0xe9c5('0x7f')][_0xe9c5('0x80')](function(_0x432ad3){return db[_0xe9c5('0x43')][_0xe9c5('0x5c')](_0x5aa18a[_0xe9c5('0x5d')],{'transaction':_0x432ad3})[_0xe9c5('0x23')](function(_0x567ba3){_0x5c875c=_0x567ba3[_0xe9c5('0x38')]({'plain':!![]});return db[_0xe9c5('0x9a')]['bulkCreate'](createExtensionsReciveFax(_0x5c875c),{'transaction':_0x432ad3});});})[_0xe9c5('0x23')](function(){return _0x5c875c;})['then'](respondWithResult(_0x488f8c,null))[_0xe9c5('0x2c')](handleError(_0x488f8c,null));};exports[_0xe9c5('0x9b')]=function(_0xc89d1f,_0xc48637,_0x2a5b5e){var _0x4f166a;return db[_0xe9c5('0x7f')]['transaction'](function(_0xcb222d){return db[_0xe9c5('0x43')][_0xe9c5('0x9c')](_0xc89d1f['body'],{'where':{'id':_0xc89d1f[_0xe9c5('0x5d')]['id']},'transaction':_0xcb222d})[_0xe9c5('0x23')](function(_0x517b55){return db[_0xe9c5('0x9a')][_0xe9c5('0x37')]({'where':{'FaxAccountId':_0xc89d1f[_0xe9c5('0x5d')]['id']},'transaction':_0xcb222d})[_0xe9c5('0x23')](function(_0x185c8b){return db[_0xe9c5('0x9a')][_0xe9c5('0x81')](createExtensionsReciveFax(_[_0xe9c5('0x74')](_0xc89d1f[_0xe9c5('0x5d')],[_0xe9c5('0x9d'),_0xe9c5('0x9e'),_0xe9c5('0x9f'),_0xe9c5('0xa0'),_0xe9c5('0xa1'),_0xe9c5('0xa2')])),{'transaction':_0xcb222d});});});})[_0xe9c5('0x23')](function(){return db[_0xe9c5('0x43')][_0xe9c5('0xa3')](_0xc89d1f['body']['id']);})[_0xe9c5('0x23')](respondWithResult(_0xc48637,null))['catch'](handleError(_0xc48637,null));};exports['getMessages']=function(_0x25603d,_0x3694fe,_0x119921){var _0x20f68f={'raw':!![],'where':{}};var _0x159d59={};var _0x291336={'count':0x0,'rows':[]};return db['FaxAccount'][_0xe9c5('0x70')]({'where':{'id':_0x25603d[_0xe9c5('0x59')]['id']}})[_0xe9c5('0x23')](handleEntityNotFound(_0x3694fe,null))[_0xe9c5('0x23')](function(_0xf06205){if(_0xf06205){_0x159d59[_0xe9c5('0x46')]=_[_0xe9c5('0x48')](db[_0xe9c5('0xa4')][_0xe9c5('0x44')]);_0x159d59[_0xe9c5('0x47')]=_['keys'](_0x25603d[_0xe9c5('0x47')]);_0x159d59[_0xe9c5('0x49')]=_[_0xe9c5('0x4a')](_0x159d59[_0xe9c5('0x46')],_0x159d59[_0xe9c5('0x47')]);_0x20f68f[_0xe9c5('0x4b')]=_[_0xe9c5('0x4a')](_0x159d59['model'],qs[_0xe9c5('0x4c')](_0x25603d['query'][_0xe9c5('0x4c')]));_0x20f68f['attributes']=_0x20f68f['attributes'][_0xe9c5('0x4d')]?_0x20f68f[_0xe9c5('0x4b')]:_0x159d59[_0xe9c5('0x46')];if(!_0x25603d[_0xe9c5('0x47')][_0xe9c5('0x69')](_0xe9c5('0x6a'))){_0x20f68f[_0xe9c5('0x31')]=qs[_0xe9c5('0x31')](_0x25603d[_0xe9c5('0x47')][_0xe9c5('0x31')]);_0x20f68f[_0xe9c5('0x30')]=qs[_0xe9c5('0x30')](_0x25603d[_0xe9c5('0x47')][_0xe9c5('0x30')]);}_0x20f68f[_0xe9c5('0x4e')]=qs[_0xe9c5('0x4f')](_0x25603d[_0xe9c5('0x47')][_0xe9c5('0x4f')]);_0x20f68f[_0xe9c5('0x50')]=qs[_0xe9c5('0x49')](_[_0xe9c5('0x51')](_0x25603d[_0xe9c5('0x47')],_0x159d59[_0xe9c5('0x49')]));_0x20f68f[_0xe9c5('0x50')][_0xe9c5('0x67')]=_0xf06205['id'];if(_0x25603d[_0xe9c5('0x47')][_0xe9c5('0x52')]){_0x20f68f[_0xe9c5('0x50')]=_['merge'](_0x20f68f['where'],{'$or':_[_0xe9c5('0x42')](_0x20f68f[_0xe9c5('0x4b')],function(_0x55be57){var _0x290ed7={};_0x290ed7[_0x55be57]={'$like':'%'+_0x25603d[_0xe9c5('0x47')]['filter']+'%'};return _0x290ed7;})});}if(_0x25603d[_0xe9c5('0x47')][_0xe9c5('0xa5')]){var _0x479c56=_0x25603d['query'][_0xe9c5('0xa5')][_0xe9c5('0xa6')](',');var _0x47ca50={};_0x47ca50[_0x479c56[0x0]]={'$gte':moment(_0x479c56[0x1])['format'](_0xe9c5('0xa7'))};_0x20f68f['where']=_['merge'](_0x20f68f[_0xe9c5('0x50')],_0x47ca50);}_0x20f68f=_['merge']({},_0x20f68f,_0x25603d['options']);return db['FaxMessage'][_0xe9c5('0x32')]({'where':_0x20f68f[_0xe9c5('0x50')]})['then'](function(_0xcf8120){_0x291336[_0xe9c5('0x32')]=_0xcf8120;if(_0x25603d[_0xe9c5('0x47')]['includeAll']){_0x20f68f[_0xe9c5('0x57')]=[{'all':!![]}];}return db[_0xe9c5('0xa4')][_0xe9c5('0x58')](_0x20f68f);})[_0xe9c5('0x23')](function(_0x29228a){_0x291336[_0xe9c5('0x6b')]=_0x29228a;return _0x291336;});}})[_0xe9c5('0x23')](respondWithFilteredResult(_0x3694fe,_0x20f68f))['catch'](handleError(_0x3694fe,null));};exports[_0xe9c5('0x3e')]=function(_0x4fd052,_0x308c66,_0x2b5550){var _0x379115,_0x477242={},_0x130b86;if(_0x4fd052[_0xe9c5('0x5d')]['to']){_0x130b86=_0x4fd052['body']['to'][0x0];}return db[_0xe9c5('0x43')][_0xe9c5('0x5b')]({'where':{'id':_0x4fd052[_0xe9c5('0x59')]['id']},'include':[{'model':db['CmList'],'as':_0xe9c5('0xa8'),'include':[{'model':db['CmContact'],'as':_0xe9c5('0xa9'),'where':{'fax':_0x130b86},'limit':0x1,'order':[[_0xe9c5('0xa0'),_0xe9c5('0xaa')]]}]}]})['then'](handleEntityNotFound(_0x308c66,null))[_0xe9c5('0x23')](function(_0x53c48f){_0x379115=_0x53c48f;if(_0x4fd052[_0xe9c5('0x5d')]['attachments']&&_0x4fd052[_0xe9c5('0x5d')][_0xe9c5('0xab')][_0xe9c5('0x4d')]){for(var _0xb5ae86=0x0;_0xb5ae86<_0x4fd052[_0xe9c5('0x5d')][_0xe9c5('0xab')][_0xe9c5('0x4d')];_0xb5ae86+=0x1){_0x4fd052[_0xe9c5('0x5d')][_0xe9c5('0xab')][_0xb5ae86]={'filename':_0x4fd052[_0xe9c5('0x5d')][_0xe9c5('0xab')][_0xb5ae86][_0xe9c5('0x3d')],'id':_0x4fd052[_0xe9c5('0x5d')][_0xe9c5('0xab')][_0xb5ae86]['id'],'path':path[_0xe9c5('0xac')](config[_0xe9c5('0xad')],_0xe9c5('0xae'),_0x4fd052[_0xe9c5('0x5d')][_0xe9c5('0xab')][_0xb5ae86][_0xe9c5('0xaf')])};}}return respondWithRpcPromise('CheckAfterSend',_0xe9c5('0xb0'),{'FaxAccountId':_[_0xe9c5('0xb1')](_0x4fd052[_0xe9c5('0x59')]['id'])?undefined:_0x4fd052[_0xe9c5('0x59')]['id'],'path':_[_0xe9c5('0xb1')](_0x4fd052['body'][_0xe9c5('0xab')][0x0][_0xe9c5('0x9')])?undefined:_0x4fd052['body']['attachments'][0x0][_0xe9c5('0x9')],'fax':_[_0xe9c5('0xb1')](_0x4fd052['body']['to'][0x0])?undefined:_0x4fd052['body']['to'][0x0]},client9002);})[_0xe9c5('0x23')](function(){if(_0x379115){if(_[_0xe9c5('0xb1')](_0x4fd052['body'][_0xe9c5('0xb2')])){_0x4fd052[_0xe9c5('0x5d')][_0xe9c5('0xb2')]=util[_0xe9c5('0xb3')]('\x22%s\x22\x20<%s>',_0x379115[_0xe9c5('0x3d')],_0x379115['fax']);}if(_0x379115[_0xe9c5('0xa8')]){if(_0x379115[_0xe9c5('0xa8')]['Contacts'][_0xe9c5('0x4d')]){return _0x379115['List'][_0xe9c5('0xa9')][0x0];}else{return db['CmContact']['create'](_[_0xe9c5('0x1b')](_0x4fd052[_0xe9c5('0x5d')],{'firstName':_0x4fd052[_0xe9c5('0x5d')]['to'][0x0],'phone':_0x4fd052[_0xe9c5('0x5d')]['to'][0x0],'fax':_0x4fd052[_0xe9c5('0x5d')]['to'][0x0],'ListId':_0x379115['ListId']}));}}else{throw new Error(_0xe9c5('0xb4'));}}else{throw new Error(_0xe9c5('0xb5'));}})[_0xe9c5('0x23')](function(_0x3e780a){if(_0x3e780a){return db[_0xe9c5('0x73')][_0xe9c5('0x5b')]({'where':{'ContactId':_0x3e780a['id'],'closed':![],'FaxAccountId':_0x379115['id']}})['then'](function(_0x3a615a){if(_0x3a615a){return[_0x3a615a,![]];}return db[_0xe9c5('0x73')][_0xe9c5('0x5c')]({'UserId':_0x4fd052['user']['id'],'ContactId':_0x3e780a['id'],'FaxAccountId':_0x379115['id'],'fax':_0x4fd052[_0xe9c5('0x5d')]['to'][0x0],'firstMsgDirection':_0xe9c5('0xb6'),'Messages':[_[_0xe9c5('0x53')](_0x4fd052[_0xe9c5('0x5d')],{'read':![],'body':_0x4fd052[_0xe9c5('0x5d')][_0xe9c5('0xab')][0x0][_0xe9c5('0xb7')],'FaxAccountId':_0x379115['id'],'UserId':_0x4fd052[_0xe9c5('0x5e')]['id'],'ContactId':_0x3e780a['id'],'AttachmentId':_0x4fd052[_0xe9c5('0x5d')][_0xe9c5('0xab')][0x0]['id']})]},{'include':[{'model':db['FaxMessage'],'as':_0xe9c5('0xb8')}]})[_0xe9c5('0x23')](function(_0x4ef44b){return[_0x4ef44b,!![]];});});}else{throw new Error(_0xe9c5('0xb9'));}})[_0xe9c5('0xba')](function(_0x7cac64,_0x46ad9b){if(_0x46ad9b){return _0x7cac64;}return db['FaxMessage'][_0xe9c5('0x5c')]({'direction':'out','read':![],'body':_0x4fd052[_0xe9c5('0x5d')][_0xe9c5('0xab')][0x0][_0xe9c5('0xb7')],'FaxAccountId':_0x379115['id'],'FaxInteractionId':_0x7cac64['id'],'UserId':_0x4fd052[_0xe9c5('0x5e')]['id'],'ContactId':_0x7cac64[_0xe9c5('0xbb')],'AttachmentId':_0x4fd052[_0xe9c5('0x5d')][_0xe9c5('0xab')][0x0]['id']})[_0xe9c5('0x23')](function(_0x545740){_0x7cac64['dataValues']['Messages']=[];_0x7cac64[_0xe9c5('0xbc')]['Messages'][_0xe9c5('0x8f')](_0x545740[_0xe9c5('0xbc')]);return _0x7cac64;});})[_0xe9c5('0x23')](function(_0x481837){respondWithRpcPromise(_0xe9c5('0xbd'),_0xe9c5('0xbd'),{'FaxAccountId':_[_0xe9c5('0xb1')](_0x4fd052[_0xe9c5('0x59')]['id'])?undefined:_0x4fd052[_0xe9c5('0x59')]['id'],'path':_[_0xe9c5('0xb1')](_0x4fd052[_0xe9c5('0x5d')][_0xe9c5('0xab')][0x0]['path'])?undefined:_0x4fd052[_0xe9c5('0x5d')][_0xe9c5('0xab')][0x0]['path'],'fax':_[_0xe9c5('0xb1')](_0x4fd052[_0xe9c5('0x5d')]['to'][0x0])?undefined:_0x4fd052[_0xe9c5('0x5d')]['to'][0x0],'AttachmentId':_0x4fd052[_0xe9c5('0x5d')][_0xe9c5('0xab')][0x0]['id']},client9002)[_0xe9c5('0x23')](function(_0x3a094c){logger[_0xe9c5('0x24')](_0xe9c5('0xbe'),_0x3a094c);})[_0xe9c5('0x2c')](function(_0x337938){logger[_0xe9c5('0x24')](_0xe9c5('0xbe'),_0x337938);});return _0x481837;})[_0xe9c5('0x23')](respondWithResult(_0x308c66,null))[_0xe9c5('0x2c')](handleError(_0x308c66,null));};exports[_0xe9c5('0xbf')]=function(_0x5beff6,_0xe9b6f9,_0x3f4134){return db[_0xe9c5('0x43')]['find']({'where':{'id':_0x5beff6[_0xe9c5('0x59')]['id']}})[_0xe9c5('0x23')](handleEntityNotFound(_0xe9b6f9,null))[_0xe9c5('0x23')](function(_0x112afc){if(_0x112afc){return _0x112afc[_0xe9c5('0xbf')](_0x5beff6[_0xe9c5('0x5d')][_0xe9c5('0x6d')],_[_0xe9c5('0x74')](_0x5beff6[_0xe9c5('0x5d')],[_0xe9c5('0x6d'),'id'])||{})[_0xe9c5('0xba')](function(_0x46a7f4){for(var _0x21a709=0x0;_0x21a709<_0x5beff6[_0xe9c5('0x5d')][_0xe9c5('0x6d')][_0xe9c5('0x4d')];_0x21a709+=0x1){socket[_0xe9c5('0xc0')](_0xe9c5('0xc1'),{'UserId':Number(_0x5beff6[_0xe9c5('0x5d')]['ids'][_0x21a709]),'FaxAccountId':Number(_0x5beff6['params']['id'])});}return _0x46a7f4;});}})[_0xe9c5('0x23')](respondWithResult(_0xe9b6f9,null))[_0xe9c5('0x2c')](handleError(_0xe9b6f9,null));};exports[_0xe9c5('0xc2')]=function(_0x446c98,_0x5d1a45,_0x4a1448){return db[_0xe9c5('0x43')]['find']({'where':{'id':_0x446c98['params']['id']}})[_0xe9c5('0x23')](handleEntityNotFound(_0x5d1a45,null))['then'](function(_0x2f8106){if(_0x2f8106){return _0x2f8106[_0xe9c5('0xc2')](_0x446c98['query'][_0xe9c5('0x6d')])[_0xe9c5('0x23')](function(){if(_[_0xe9c5('0xc3')](_0x446c98[_0xe9c5('0x47')]['ids'])){for(var _0x381ad4=0x0;_0x381ad4<_0x446c98[_0xe9c5('0x47')][_0xe9c5('0x6d')][_0xe9c5('0x4d')];_0x381ad4+=0x1){socket[_0xe9c5('0xc0')](_0xe9c5('0xc4'),{'UserId':Number(_0x446c98[_0xe9c5('0x47')][_0xe9c5('0x6d')][_0x381ad4]),'FaxAccountId':Number(_0x446c98[_0xe9c5('0x59')]['id'])});}}else{socket[_0xe9c5('0xc0')](_0xe9c5('0xc4'),{'UserId':Number(_0x446c98[_0xe9c5('0x47')]['ids']),'FaxAccountId':Number(_0x446c98[_0xe9c5('0x59')]['id'])});}});}})['then'](respondWithStatusCode(_0x5d1a45,null))[_0xe9c5('0x2c')](handleError(_0x5d1a45,null));};exports['getAgents']=function(_0x538b40,_0x5450e2,_0x5ec70b){var _0x2a66a7={};var _0x15cba9={};var _0x4aa820;var _0x381efc;return db['FaxAccount']['findOne']({'where':{'id':_0x538b40[_0xe9c5('0x59')]['id']}})[_0xe9c5('0x23')](handleEntityNotFound(_0x5450e2,null))[_0xe9c5('0x23')](function(_0x4d56cf){if(_0x4d56cf){_0x4aa820=_0x4d56cf;_0x15cba9[_0xe9c5('0x46')]=_[_0xe9c5('0x48')](db[_0xe9c5('0x78')][_0xe9c5('0x44')]);_0x15cba9[_0xe9c5('0x47')]=_[_0xe9c5('0x48')](_0x538b40[_0xe9c5('0x47')]);_0x15cba9[_0xe9c5('0x49')]=_[_0xe9c5('0x4a')](_0x15cba9[_0xe9c5('0x46')],_0x15cba9[_0xe9c5('0x47')]);_0x2a66a7[_0xe9c5('0x4b')]=_['intersection'](_0x15cba9['model'],qs['fields'](_0x538b40['query'][_0xe9c5('0x4c')]));_0x2a66a7[_0xe9c5('0x4b')]=_0x2a66a7[_0xe9c5('0x4b')]['length']?_0x2a66a7[_0xe9c5('0x4b')]:_0x15cba9['model'];_0x2a66a7[_0xe9c5('0x4e')]=qs[_0xe9c5('0x4f')](_0x538b40['query'][_0xe9c5('0x4f')]);_0x2a66a7[_0xe9c5('0x50')]=qs[_0xe9c5('0x49')](_[_0xe9c5('0x51')](_0x538b40[_0xe9c5('0x47')],_0x15cba9[_0xe9c5('0x49')]));if(_0x538b40['query']['filter']){_0x2a66a7[_0xe9c5('0x50')]=_[_0xe9c5('0x53')](_0x2a66a7[_0xe9c5('0x50')],{'$or':_['map'](_0x2a66a7[_0xe9c5('0x4b')],function(_0x1d18c5){var _0x11115b={};_0x11115b[_0x1d18c5]={'$like':'%'+_0x538b40[_0xe9c5('0x47')][_0xe9c5('0x52')]+'%'};return _0x11115b;})});}_0x2a66a7=_[_0xe9c5('0x53')]({},_0x2a66a7,_0x538b40[_0xe9c5('0x56')]);return _0x4aa820[_0xe9c5('0xc5')](_0x2a66a7);}})[_0xe9c5('0x23')](function(_0x212a9a){if(_0x212a9a){_0x381efc=_0x212a9a[_0xe9c5('0x4d')];if(!_0x538b40['query'][_0xe9c5('0x69')](_0xe9c5('0x6a'))){_0x2a66a7[_0xe9c5('0x31')]=qs['limit'](_0x538b40[_0xe9c5('0x47')][_0xe9c5('0x31')]);_0x2a66a7[_0xe9c5('0x30')]=qs[_0xe9c5('0x30')](_0x538b40[_0xe9c5('0x47')]['offset']);}return _0x4aa820[_0xe9c5('0xc5')](_0x2a66a7);}})[_0xe9c5('0x23')](function(_0x1ba895){if(_0x1ba895){return _0x1ba895?{'count':_0x381efc,'rows':_0x1ba895}:null;}})[_0xe9c5('0x23')](respondWithResult(_0x5450e2,null))[_0xe9c5('0x2c')](handleError(_0x5450e2,null));};
\ No newline at end of file