5f42da0a3033c2467fc1af40b8366df5ed35afe1
[motion2.git] / server / api / faxAccount / faxAccount.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xe9d0=['length','options','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','addInteraction','FaxInteraction','omit','getInteractions','CmContact','User','fullname','internal','Tag','color','tag','addApplications','sequelize','transaction','FaxApplication','bulkCreate','findAndCountAll','priority','getApplications','context','from-voip-provider','exten','localstationid','app','system','Fax\x20Extension','appdata','push','CDR(type)=inbound-fax','ecm','gateway','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','tech','createdAt','updatedAt','TrunkId','findById','getMessages','FaxMessage','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','CmList','List','Contacts','DESC','attachments','join','server/files/attachments','CheckAfterSend','isNil','from','\x22%s\x22\x20<%s>','fax','ListId','out','Messages','Contact\x20not\x20found','spread','filename','ContactId','dataValues','SendFax','info','SendFaxRpc,\x20%s','addAgents','emit','userFaxAccount:save','removeAgents','isArray','userFaxAccount:remove','getAgents','html-pdf','eml-format','rimraf','zip-dir','request-promise','moment','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','defaults','redis','localhost','socket.io-emitter','./faxAccount.socket','register','jayson/promise','client','http','Sequelize','ValidationError','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','then','FaxAccount,\x20%s,\x20%s','request\x20sent','debug','FaxAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','sendStatus','status','end','count','offset','limit','set','json','apply','reject','save','update','FaxAccounts','destroy','name','send','index','Pause','FaxAccount','rawAttributes','type','key','model','map','keys','intersection','query','attributes','fields','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','VIRTUAL','includeAll','findAll','rows','show','params','include','find','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','mandatoryDispositionPause','describe','addDisposition','FaxAccountId','Disposition','getDispositions','findOne'];(function(_0x2866f6,_0x572c3a){var _0x5311f3=function(_0x40993d){while(--_0x40993d){_0x2866f6['push'](_0x2866f6['shift']());}};_0x5311f3(++_0x572c3a);}(_0xe9d0,0x124));var _0x0e9d=function(_0x5625d7,_0x203f58){_0x5625d7=_0x5625d7-0x0;var _0x1d6e86=_0xe9d0[_0x5625d7];return _0x1d6e86;};'use strict';var pdf=require(_0x0e9d('0x0'));var emlformat=require(_0x0e9d('0x1'));var rimraf=require(_0x0e9d('0x2'));var zipdir=require(_0x0e9d('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0x0e9d('0x4'));var moment=require(_0x0e9d('0x5'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x0e9d('0x6'));var path=require(_0x0e9d('0x7'));var sox=require(_0x0e9d('0x8'));var csv=require(_0x0e9d('0x9'));var ejs=require(_0x0e9d('0xa'));var fs=require('fs');var _=require(_0x0e9d('0xb'));var squel=require(_0x0e9d('0xc'));var crypto=require(_0x0e9d('0xd'));var jsforce=require(_0x0e9d('0xe'));var deskjs=require(_0x0e9d('0xf'));var toCsv=require(_0x0e9d('0x9'));var querystring=require(_0x0e9d('0x10'));var Papa=require(_0x0e9d('0x11'));var Redis=require(_0x0e9d('0x12'));var authService=require(_0x0e9d('0x13'));var qs=require(_0x0e9d('0x14'));var as=require(_0x0e9d('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x0e9d('0x16'))(_0x0e9d('0x17'));var utils=require(_0x0e9d('0x18'));var config=require(_0x0e9d('0x19'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x0e9d('0x1a')](config[_0x0e9d('0x1b')],{'host':_0x0e9d('0x1c'),'port':0x18eb});var socket=require(_0x0e9d('0x1d'))(new Redis(config[_0x0e9d('0x1b')]));require(_0x0e9d('0x1e'))[_0x0e9d('0x1f')](socket);var jayson=require(_0x0e9d('0x20'));var client=jayson[_0x0e9d('0x21')][_0x0e9d('0x22')]({'port':0x232c});var client9002=jayson[_0x0e9d('0x21')][_0x0e9d('0x22')]({'port':0x232a});function checkPasswordPattern(_0x41c13a,_0x2f9225,_0x35bdc2){if(_0x35bdc2){var _0x5d0757=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x5d0757['test'](_0x2f9225)){return _0x41c13a;}else{throw new db[(_0x0e9d('0x23'))][(_0x0e9d('0x24'))](_0x0e9d('0x25'));}}else{return _0x41c13a;}}function respondWithRpcPromise(_0x442e01,_0x4fdf22,_0x259a10,_0x333274){return new BPromise(function(_0x6a9c5a,_0x24429e){var _0x3e100c=_0x333274||client;return _0x3e100c['request'](_0x442e01,_0x259a10)[_0x0e9d('0x26')](function(_0x341ba0){logger['info'](_0x0e9d('0x27'),_0x4fdf22,_0x0e9d('0x28'));logger[_0x0e9d('0x29')](_0x0e9d('0x2a'),_0x4fdf22,'request\x20sent',JSON[_0x0e9d('0x2b')](_0x341ba0));if(_0x341ba0[_0x0e9d('0x2c')]){if(_0x341ba0[_0x0e9d('0x2c')][_0x0e9d('0x2d')]===0x1f4){logger[_0x0e9d('0x2c')](_0x0e9d('0x27'),_0x4fdf22,_0x341ba0['error'][_0x0e9d('0x2e')]);return _0x24429e(_0x341ba0['error'][_0x0e9d('0x2e')]);}logger[_0x0e9d('0x2c')](_0x0e9d('0x27'),_0x4fdf22,_0x341ba0[_0x0e9d('0x2c')][_0x0e9d('0x2e')]);return _0x6a9c5a(_0x341ba0[_0x0e9d('0x2c')][_0x0e9d('0x2e')]);}else{logger['info']('FaxAccount,\x20%s,\x20%s',_0x4fdf22,'request\x20sent');_0x6a9c5a(_0x341ba0['result']['message']);}})[_0x0e9d('0x2f')](function(_0x2e78fc){logger['error'](_0x0e9d('0x27'),_0x4fdf22,_0x2e78fc);_0x24429e(_0x2e78fc);});});}function respondWithStatusCode(_0xf0c35c,_0x10a3a2){_0x10a3a2=_0x10a3a2||0xcc;return function(_0x5ea206){if(_0x5ea206){return _0xf0c35c[_0x0e9d('0x30')](_0x10a3a2);}return _0xf0c35c[_0x0e9d('0x31')](_0x10a3a2)[_0x0e9d('0x32')]();};}function respondWithResult(_0x321ac5,_0x126d1b){_0x126d1b=_0x126d1b||0xc8;return function(_0x7f7c1a){if(_0x7f7c1a){return _0x321ac5[_0x0e9d('0x31')](_0x126d1b)['json'](_0x7f7c1a);}};}function respondWithFilteredResult(_0x15fd39,_0x24639e){return function(_0x22b339){if(_0x22b339){var _0x5b27e6=_0x22b339[_0x0e9d('0x33')],_0x3cf75b=_0x24639e[_0x0e9d('0x34')],_0x200378=_0x24639e[_0x0e9d('0x34')]+_0x24639e[_0x0e9d('0x35')],_0x2d5583;if(_0x200378>=_0x5b27e6){_0x200378=_0x5b27e6;_0x2d5583=0xc8;}else{_0x2d5583=0xce;}_0x15fd39[_0x0e9d('0x31')](_0x2d5583);return _0x15fd39[_0x0e9d('0x36')]('Content-Range',_0x3cf75b+'-'+_0x200378+'/'+_0x5b27e6)[_0x0e9d('0x37')](_0x22b339);}return null;};}function patchUpdates(_0x26a6af){return function(_0x24ce69){try{jsonpatch[_0x0e9d('0x38')](_0x24ce69,_0x26a6af,!![]);}catch(_0x2f06c6){return BPromise[_0x0e9d('0x39')](_0x2f06c6);}return _0x24ce69[_0x0e9d('0x3a')]();};}function saveUpdates(_0x49e7e9,_0xce641f){return function(_0x13a505){if(_0x13a505){return _0x13a505[_0x0e9d('0x3b')](_0x49e7e9)[_0x0e9d('0x26')](function(_0x34aa06){return _0x34aa06;});}return null;};}function removeEntity(_0x1fb637,_0x387402){return function(_0x52b111){if(_0x52b111){return _0x52b111['destroy']()[_0x0e9d('0x26')](function(){var _0x5df720=_0x52b111['get']({'plain':!![]});var _0x419f2e=_0x0e9d('0x3c');return db['UserProfileResource'][_0x0e9d('0x3d')]({'where':{'type':_0x419f2e,'resourceId':_0x5df720['id']}})['then'](function(){return _0x52b111;});})[_0x0e9d('0x26')](function(){_0x1fb637[_0x0e9d('0x31')](0xcc)[_0x0e9d('0x32')]();});}};}function handleEntityNotFound(_0x5b325d,_0x3fc918){return function(_0x1c09b2){if(!_0x1c09b2){_0x5b325d[_0x0e9d('0x30')](0x194);}return _0x1c09b2;};}function handleError(_0x3dcb44,_0x389f9c){_0x389f9c=_0x389f9c||0x1f4;return function(_0xd8cd02){logger[_0x0e9d('0x2c')](_0xd8cd02['stack']);if(_0xd8cd02[_0x0e9d('0x3e')]){delete _0xd8cd02[_0x0e9d('0x3e')];}_0x3dcb44['status'](_0x389f9c)[_0x0e9d('0x3f')](_0xd8cd02);};}exports[_0x0e9d('0x40')]=function(_0x50bbf8,_0x4a5b1f){var _0x507092={'include':[{'model':db[_0x0e9d('0x41')],'as':'mandatoryDispositionPause'}]},_0x70b998={},_0x35368a={'count':0x0,'rows':[]};var _0xfb024a=_['map'](db[_0x0e9d('0x42')][_0x0e9d('0x43')],function(_0x2b2e5f){return{'name':_0x2b2e5f['fieldName'],'type':_0x2b2e5f[_0x0e9d('0x44')][_0x0e9d('0x45')]};});_0x70b998[_0x0e9d('0x46')]=_[_0x0e9d('0x47')](_0xfb024a,_0x0e9d('0x3e'));_0x70b998['query']=_[_0x0e9d('0x48')](_0x50bbf8['query']);_0x70b998['filters']=_[_0x0e9d('0x49')](_0x70b998[_0x0e9d('0x46')],_0x70b998[_0x0e9d('0x4a')]);_0x507092[_0x0e9d('0x4b')]=_[_0x0e9d('0x49')](_0x70b998[_0x0e9d('0x46')],qs[_0x0e9d('0x4c')](_0x50bbf8[_0x0e9d('0x4a')]['fields']));_0x507092['attributes']=_0x507092[_0x0e9d('0x4b')]['length']?_0x507092['attributes']:_0x70b998[_0x0e9d('0x46')];if(!_0x50bbf8[_0x0e9d('0x4a')][_0x0e9d('0x4d')](_0x0e9d('0x4e'))){_0x507092[_0x0e9d('0x35')]=qs[_0x0e9d('0x35')](_0x50bbf8[_0x0e9d('0x4a')]['limit']);_0x507092[_0x0e9d('0x34')]=qs['offset'](_0x50bbf8[_0x0e9d('0x4a')][_0x0e9d('0x34')]);}_0x507092[_0x0e9d('0x4f')]=qs[_0x0e9d('0x50')](_0x50bbf8[_0x0e9d('0x4a')]['sort']);_0x507092[_0x0e9d('0x51')]=qs[_0x0e9d('0x52')](_[_0x0e9d('0x53')](_0x50bbf8[_0x0e9d('0x4a')],_0x70b998[_0x0e9d('0x52')]));if(_0x50bbf8[_0x0e9d('0x4a')][_0x0e9d('0x54')]){_0x507092[_0x0e9d('0x51')]=_[_0x0e9d('0x55')](_0x507092['where'],{'$or':_[_0x0e9d('0x47')](_0xfb024a,function(_0x57cdb9){if(_0x57cdb9[_0x0e9d('0x44')]!==_0x0e9d('0x56')){var _0x24386c={};_0x24386c[_0x57cdb9[_0x0e9d('0x3e')]]={'$like':'%'+_0x50bbf8[_0x0e9d('0x4a')]['filter']+'%'};return _0x24386c;}})});}_0x507092=_[_0x0e9d('0x55')]({},_0x507092,_0x50bbf8['options']);var _0x531e0f={'where':_0x507092['where']};return db[_0x0e9d('0x42')][_0x0e9d('0x33')](_0x531e0f)[_0x0e9d('0x26')](function(_0x20512f){_0x35368a[_0x0e9d('0x33')]=_0x20512f;if(_0x50bbf8[_0x0e9d('0x4a')][_0x0e9d('0x57')]){_0x507092['include']=[{'all':!![]}];}return db[_0x0e9d('0x42')][_0x0e9d('0x58')](_0x507092);})[_0x0e9d('0x26')](function(_0x3f9250){_0x35368a[_0x0e9d('0x59')]=_0x3f9250;return _0x35368a;})[_0x0e9d('0x26')](respondWithFilteredResult(_0x4a5b1f,_0x507092))['catch'](handleError(_0x4a5b1f,null));};exports[_0x0e9d('0x5a')]=function(_0x25bb44,_0x53b40d){var _0xe561b0={'raw':![],'where':{'id':_0x25bb44[_0x0e9d('0x5b')]['id']},'include':[{'model':db[_0x0e9d('0x41')],'as':'mandatoryDispositionPause'}]},_0x2c8ac4={};_0x2c8ac4['model']=_[_0x0e9d('0x48')](db[_0x0e9d('0x42')][_0x0e9d('0x43')]);_0x2c8ac4['query']=_['keys'](_0x25bb44[_0x0e9d('0x4a')]);_0x2c8ac4[_0x0e9d('0x52')]=_[_0x0e9d('0x49')](_0x2c8ac4[_0x0e9d('0x46')],_0x2c8ac4[_0x0e9d('0x4a')]);_0xe561b0[_0x0e9d('0x4b')]=_[_0x0e9d('0x49')](_0x2c8ac4['model'],qs[_0x0e9d('0x4c')](_0x25bb44[_0x0e9d('0x4a')][_0x0e9d('0x4c')]));_0xe561b0[_0x0e9d('0x4b')]=_0xe561b0[_0x0e9d('0x4b')]['length']?_0xe561b0[_0x0e9d('0x4b')]:_0x2c8ac4[_0x0e9d('0x46')];if(_0x25bb44[_0x0e9d('0x4a')][_0x0e9d('0x57')]){_0xe561b0[_0x0e9d('0x5c')]=[{'all':!![]}];}_0xe561b0=_[_0x0e9d('0x55')]({},_0xe561b0,_0x25bb44['options']);return db[_0x0e9d('0x42')][_0x0e9d('0x5d')](_0xe561b0)['then'](handleEntityNotFound(_0x53b40d,null))[_0x0e9d('0x26')](respondWithResult(_0x53b40d,null))['catch'](handleError(_0x53b40d,null));};exports[_0x0e9d('0x5e')]=function(_0xf4983d,_0x3522ea){return db[_0x0e9d('0x42')]['create'](_0xf4983d[_0x0e9d('0x5f')],{})['then'](function(_0x8fbb3e){var _0x289b92=_0xf4983d[_0x0e9d('0x60')][_0x0e9d('0x61')]({'plain':!![]});if(!_0x289b92)throw new Error(_0x0e9d('0x62'));if(_0x289b92[_0x0e9d('0x63')]===_0x0e9d('0x60')){var _0x30786b=_0x8fbb3e[_0x0e9d('0x61')]({'plain':!![]});var _0x4b159b=_0x0e9d('0x3c');return db[_0x0e9d('0x64')][_0x0e9d('0x5d')]({'where':{'name':_0x4b159b,'userProfileId':_0x289b92['userProfileId']},'raw':!![]})[_0x0e9d('0x26')](function(_0x2ded8d){if(_0x2ded8d&&_0x2ded8d['autoAssociation']===0x0){return db[_0x0e9d('0x65')]['create']({'name':_0x30786b['name'],'resourceId':_0x30786b['id'],'type':_0x2ded8d['name'],'sectionId':_0x2ded8d['id']},{})[_0x0e9d('0x26')](function(){return _0x8fbb3e;});}else{return _0x8fbb3e;}})['catch'](function(_0x17564d){logger['error'](_0x0e9d('0x66'),_0x17564d);throw _0x17564d;});}return _0x8fbb3e;})[_0x0e9d('0x26')](respondWithResult(_0x3522ea,0xc9))[_0x0e9d('0x2f')](handleError(_0x3522ea,null));};exports[_0x0e9d('0x3b')]=function(_0x2e22a3,_0x44077c){if(_0x2e22a3[_0x0e9d('0x5f')]['id']){delete _0x2e22a3['body']['id'];}return db['FaxAccount'][_0x0e9d('0x5d')]({'where':{'id':_0x2e22a3[_0x0e9d('0x5b')]['id']},'include':[{'model':db[_0x0e9d('0x41')],'as':_0x0e9d('0x67')}]})[_0x0e9d('0x26')](handleEntityNotFound(_0x44077c,null))[_0x0e9d('0x26')](saveUpdates(_0x2e22a3[_0x0e9d('0x5f')],null))[_0x0e9d('0x26')](respondWithResult(_0x44077c,null))[_0x0e9d('0x2f')](handleError(_0x44077c,null));};exports[_0x0e9d('0x3d')]=function(_0x140c74,_0x1ae49a){return db[_0x0e9d('0x42')]['find']({'where':{'id':_0x140c74[_0x0e9d('0x5b')]['id']}})[_0x0e9d('0x26')](handleEntityNotFound(_0x1ae49a,null))[_0x0e9d('0x26')](removeEntity(_0x1ae49a,null))[_0x0e9d('0x2f')](handleError(_0x1ae49a,null));};exports[_0x0e9d('0x68')]=function(_0x424187,_0x34b614){return db['FaxAccount']['describe']()[_0x0e9d('0x26')](respondWithResult(_0x34b614,null))[_0x0e9d('0x2f')](handleError(_0x34b614,null));};exports[_0x0e9d('0x69')]=function(_0x17339e,_0x136bdf,_0x28cf2e){if(_0x17339e[_0x0e9d('0x5f')]['id']){delete _0x17339e[_0x0e9d('0x5f')]['id'];}return db[_0x0e9d('0x42')][_0x0e9d('0x5d')]({'where':{'id':_0x17339e[_0x0e9d('0x5b')]['id']}})[_0x0e9d('0x26')](handleEntityNotFound(_0x136bdf,null))[_0x0e9d('0x26')](function(_0x253d62){if(_0x253d62){_0x17339e[_0x0e9d('0x5f')][_0x0e9d('0x6a')]=_0x253d62['id'];return db[_0x0e9d('0x6b')][_0x0e9d('0x5e')](_0x17339e[_0x0e9d('0x5f')]);}})[_0x0e9d('0x26')](respondWithResult(_0x136bdf,null))[_0x0e9d('0x2f')](handleError(_0x136bdf,null));};exports[_0x0e9d('0x6c')]=function(_0x504dc6,_0x60e542,_0x2ee96d){var _0x2eb0eb={'raw':![],'where':{}};var _0x145caa={};var _0x51681c={'count':0x0,'rows':[]};return db[_0x0e9d('0x42')][_0x0e9d('0x6d')]({'where':{'id':_0x504dc6[_0x0e9d('0x5b')]['id']}})[_0x0e9d('0x26')](handleEntityNotFound(_0x60e542,null))[_0x0e9d('0x26')](function(_0x5f1b18){if(_0x5f1b18){_0x145caa[_0x0e9d('0x46')]=_['keys'](db[_0x0e9d('0x6b')][_0x0e9d('0x43')]);_0x145caa[_0x0e9d('0x4a')]=_[_0x0e9d('0x48')](_0x504dc6[_0x0e9d('0x4a')]);_0x145caa['filters']=_[_0x0e9d('0x49')](_0x145caa['model'],_0x145caa['query']);_0x2eb0eb['attributes']=_['intersection'](_0x145caa[_0x0e9d('0x46')],qs['fields'](_0x504dc6['query'][_0x0e9d('0x4c')]));_0x2eb0eb[_0x0e9d('0x4b')]=_0x2eb0eb['attributes'][_0x0e9d('0x6e')]?_0x2eb0eb[_0x0e9d('0x4b')]:_0x145caa[_0x0e9d('0x46')];if(!_0x504dc6[_0x0e9d('0x4a')][_0x0e9d('0x4d')](_0x0e9d('0x4e'))){_0x2eb0eb[_0x0e9d('0x35')]=qs['limit'](_0x504dc6[_0x0e9d('0x4a')]['limit']);_0x2eb0eb[_0x0e9d('0x34')]=qs['offset'](_0x504dc6[_0x0e9d('0x4a')][_0x0e9d('0x34')]);}_0x2eb0eb[_0x0e9d('0x4f')]=qs[_0x0e9d('0x50')](_0x504dc6[_0x0e9d('0x4a')][_0x0e9d('0x50')]);_0x2eb0eb[_0x0e9d('0x51')]=qs['filters'](_['pick'](_0x504dc6[_0x0e9d('0x4a')],_0x145caa[_0x0e9d('0x52')]));_0x2eb0eb[_0x0e9d('0x51')][_0x0e9d('0x6a')]=_0x5f1b18['id'];if(_0x504dc6[_0x0e9d('0x4a')][_0x0e9d('0x54')]){_0x2eb0eb[_0x0e9d('0x51')]=_[_0x0e9d('0x55')](_0x2eb0eb[_0x0e9d('0x51')],{'$or':_[_0x0e9d('0x47')](_0x2eb0eb['attributes'],function(_0x4955bc){var _0x162e71={};_0x162e71[_0x4955bc]={'$like':'%'+_0x504dc6[_0x0e9d('0x4a')][_0x0e9d('0x54')]+'%'};return _0x162e71;})});}_0x2eb0eb=_['merge']({},_0x2eb0eb,_0x504dc6[_0x0e9d('0x6f')]);return db[_0x0e9d('0x6b')][_0x0e9d('0x33')]({'where':_0x2eb0eb['where']})[_0x0e9d('0x26')](function(_0x59acb4){_0x51681c[_0x0e9d('0x33')]=_0x59acb4;if(_0x504dc6[_0x0e9d('0x4a')][_0x0e9d('0x57')]){_0x2eb0eb['include']=[{'all':!![]}];}return db[_0x0e9d('0x6b')][_0x0e9d('0x58')](_0x2eb0eb);})[_0x0e9d('0x26')](function(_0x151831){_0x51681c[_0x0e9d('0x59')]=_0x151831;return _0x51681c;});}})[_0x0e9d('0x26')](respondWithFilteredResult(_0x60e542,_0x2eb0eb))[_0x0e9d('0x2f')](handleError(_0x60e542,null));};exports['removeDispositions']=function(_0x87ef4a,_0x417d01,_0x354320){return db['FaxAccount'][_0x0e9d('0x5d')]({'where':{'id':_0x87ef4a[_0x0e9d('0x5b')]['id']}})[_0x0e9d('0x26')](handleEntityNotFound(_0x417d01,null))[_0x0e9d('0x26')](function(_0x18dc31){if(_0x18dc31){return _0x18dc31[_0x0e9d('0x70')](_0x87ef4a[_0x0e9d('0x4a')][_0x0e9d('0x71')]);}})[_0x0e9d('0x26')](respondWithStatusCode(_0x417d01,null))[_0x0e9d('0x2f')](handleError(_0x417d01,null));};exports[_0x0e9d('0x72')]=function(_0x4433c4,_0x37cbf6,_0x510737){if(_0x4433c4[_0x0e9d('0x5f')]['id']){delete _0x4433c4[_0x0e9d('0x5f')]['id'];}return db[_0x0e9d('0x42')][_0x0e9d('0x5d')]({'where':{'id':_0x4433c4['params']['id']}})[_0x0e9d('0x26')](handleEntityNotFound(_0x37cbf6,null))['then'](function(_0x59578d){if(_0x59578d){_0x4433c4['body'][_0x0e9d('0x6a')]=_0x59578d['id'];return db[_0x0e9d('0x73')][_0x0e9d('0x5e')](_0x4433c4['body']);}})[_0x0e9d('0x26')](respondWithResult(_0x37cbf6,null))[_0x0e9d('0x2f')](handleError(_0x37cbf6,null));};exports[_0x0e9d('0x74')]=function(_0x479adb,_0x2e24e3,_0xb472b7){var _0xbd846d={'raw':![],'where':{}};var _0x180ef5={};var _0x362569={'count':0x0,'rows':[]};return db[_0x0e9d('0x42')][_0x0e9d('0x6d')]({'where':{'id':_0x479adb['params']['id']}})[_0x0e9d('0x26')](handleEntityNotFound(_0x2e24e3,null))[_0x0e9d('0x26')](function(_0x13a137){if(_0x13a137){_0x180ef5[_0x0e9d('0x46')]=_[_0x0e9d('0x48')](db[_0x0e9d('0x73')][_0x0e9d('0x43')]);_0x180ef5[_0x0e9d('0x4a')]=_[_0x0e9d('0x48')](_0x479adb[_0x0e9d('0x4a')]);_0x180ef5[_0x0e9d('0x52')]=_[_0x0e9d('0x49')](_0x180ef5[_0x0e9d('0x46')],_0x180ef5[_0x0e9d('0x4a')]);_0xbd846d['attributes']=_['intersection'](_0x180ef5[_0x0e9d('0x46')],qs[_0x0e9d('0x4c')](_0x479adb[_0x0e9d('0x4a')][_0x0e9d('0x4c')]));_0xbd846d['attributes']=_0xbd846d[_0x0e9d('0x4b')][_0x0e9d('0x6e')]?_0xbd846d[_0x0e9d('0x4b')]:_0x180ef5[_0x0e9d('0x46')];if(!_0x479adb[_0x0e9d('0x4a')][_0x0e9d('0x4d')]('nolimit')){_0xbd846d[_0x0e9d('0x35')]=qs[_0x0e9d('0x35')](_0x479adb[_0x0e9d('0x4a')][_0x0e9d('0x35')]);_0xbd846d[_0x0e9d('0x34')]=qs[_0x0e9d('0x34')](_0x479adb[_0x0e9d('0x4a')][_0x0e9d('0x34')]);}_0xbd846d[_0x0e9d('0x4f')]=qs[_0x0e9d('0x50')](_0x479adb[_0x0e9d('0x4a')][_0x0e9d('0x50')]);_0xbd846d[_0x0e9d('0x51')]=qs[_0x0e9d('0x52')](_[_0x0e9d('0x53')](_0x479adb[_0x0e9d('0x4a')],_0x180ef5[_0x0e9d('0x52')]));_0xbd846d['where'][_0x0e9d('0x6a')]=_0x13a137['id'];if(_0x479adb[_0x0e9d('0x4a')][_0x0e9d('0x54')]){_0xbd846d[_0x0e9d('0x51')]=_[_0x0e9d('0x55')](_0xbd846d[_0x0e9d('0x51')],{'$or':_['map'](_0xbd846d[_0x0e9d('0x4b')],function(_0x14f920){var _0x5df53b={};_0x5df53b[_0x14f920]={'$like':'%'+_0x479adb['query']['filter']+'%'};return _0x5df53b;})});}_0xbd846d=_[_0x0e9d('0x55')]({},_0xbd846d,_0x479adb[_0x0e9d('0x6f')]);return db['CannedAnswer'][_0x0e9d('0x33')]({'where':_0xbd846d[_0x0e9d('0x51')]})[_0x0e9d('0x26')](function(_0x46a277){_0x362569[_0x0e9d('0x33')]=_0x46a277;if(_0x479adb[_0x0e9d('0x4a')][_0x0e9d('0x57')]){_0xbd846d[_0x0e9d('0x5c')]=[{'all':!![]}];}return db[_0x0e9d('0x73')][_0x0e9d('0x58')](_0xbd846d);})[_0x0e9d('0x26')](function(_0x27081b){_0x362569[_0x0e9d('0x59')]=_0x27081b;return _0x362569;});}})[_0x0e9d('0x26')](respondWithFilteredResult(_0x2e24e3,_0xbd846d))[_0x0e9d('0x2f')](handleError(_0x2e24e3,null));};exports[_0x0e9d('0x75')]=function(_0x3c1a3d,_0x3dcc4c,_0x46b016){return db[_0x0e9d('0x42')][_0x0e9d('0x5d')]({'where':{'id':_0x3c1a3d['params']['id']}})[_0x0e9d('0x26')](handleEntityNotFound(_0x3dcc4c,null))[_0x0e9d('0x26')](function(_0x559049){if(_0x559049){return _0x559049[_0x0e9d('0x75')](_0x3c1a3d[_0x0e9d('0x4a')]['ids']);}})[_0x0e9d('0x26')](respondWithStatusCode(_0x3dcc4c,null))[_0x0e9d('0x2f')](handleError(_0x3dcc4c,null));};exports[_0x0e9d('0x76')]=function(_0x190dcd,_0x1c5b39,_0x14970e){return db[_0x0e9d('0x77')][_0x0e9d('0x5d')]({'where':{'id':_0x190dcd[_0x0e9d('0x5b')]['id']}})['then'](handleEntityNotFound(_0x1c5b39,null))[_0x0e9d('0x26')](function(_0x1302da){if(_0x1302da){return _0x1302da[_0x0e9d('0x76')](_0x190dcd[_0x0e9d('0x5f')][_0x0e9d('0x71')],_[_0x0e9d('0x78')](_0x190dcd[_0x0e9d('0x5f')],[_0x0e9d('0x71'),'id'])||{});}})[_0x0e9d('0x26')](respondWithResult(_0x1c5b39,null))[_0x0e9d('0x2f')](handleError(_0x1c5b39,null));};exports[_0x0e9d('0x79')]=function(_0x22e323,_0x14f7df,_0x214f0b){var _0x2a9c84={'raw':![],'where':{}};var _0x5dedc5={};var _0x33ccb7={'count':0x0,'rows':[]};return db[_0x0e9d('0x42')]['findOne']({'where':{'id':_0x22e323[_0x0e9d('0x5b')]['id']}})[_0x0e9d('0x26')](handleEntityNotFound(_0x14f7df,null))['then'](function(_0x5a552f){if(_0x5a552f){_0x5dedc5[_0x0e9d('0x46')]=_[_0x0e9d('0x48')](db['FaxInteraction'][_0x0e9d('0x43')]);_0x5dedc5[_0x0e9d('0x4a')]=_[_0x0e9d('0x48')](_0x22e323[_0x0e9d('0x4a')]);_0x5dedc5[_0x0e9d('0x52')]=_[_0x0e9d('0x49')](_0x5dedc5[_0x0e9d('0x46')],_0x5dedc5['query']);_0x2a9c84[_0x0e9d('0x4b')]=_[_0x0e9d('0x49')](_0x5dedc5[_0x0e9d('0x46')],qs[_0x0e9d('0x4c')](_0x22e323[_0x0e9d('0x4a')]['fields']));_0x2a9c84[_0x0e9d('0x4b')]=_0x2a9c84[_0x0e9d('0x4b')]['length']?_0x2a9c84[_0x0e9d('0x4b')]:_0x5dedc5[_0x0e9d('0x46')];if(!_0x22e323['query']['hasOwnProperty']('nolimit')){_0x2a9c84[_0x0e9d('0x35')]=qs[_0x0e9d('0x35')](_0x22e323[_0x0e9d('0x4a')][_0x0e9d('0x35')]);_0x2a9c84['offset']=qs['offset'](_0x22e323[_0x0e9d('0x4a')][_0x0e9d('0x34')]);}_0x2a9c84['order']=qs['sort'](_0x22e323[_0x0e9d('0x4a')][_0x0e9d('0x50')]);_0x2a9c84[_0x0e9d('0x51')]=qs['filters'](_[_0x0e9d('0x53')](_0x22e323[_0x0e9d('0x4a')],_0x5dedc5['filters']));_0x2a9c84[_0x0e9d('0x51')]['FaxAccountId']=_0x5a552f['id'];if(_0x22e323['query'][_0x0e9d('0x54')]){_0x2a9c84[_0x0e9d('0x51')]=_[_0x0e9d('0x55')](_0x2a9c84[_0x0e9d('0x51')],{'$or':_[_0x0e9d('0x47')](_0x2a9c84[_0x0e9d('0x4b')],function(_0x2a0932){var _0x98c8f1={};_0x98c8f1[_0x2a0932]={'$like':'%'+_0x22e323['query']['filter']+'%'};return _0x98c8f1;})});}_0x2a9c84=_[_0x0e9d('0x55')]({},_0x2a9c84,_0x22e323[_0x0e9d('0x6f')]);return db[_0x0e9d('0x77')]['count']({'where':_0x2a9c84[_0x0e9d('0x51')]})[_0x0e9d('0x26')](function(_0x27d055){_0x33ccb7['count']=_0x27d055;if(_0x22e323[_0x0e9d('0x4a')][_0x0e9d('0x57')]){_0x2a9c84[_0x0e9d('0x5c')]=[{'model':db[_0x0e9d('0x7a')],'as':'Contact','required':![]},{'model':db[_0x0e9d('0x7b')],'as':'Owner','attributes':[_0x0e9d('0x3e'),_0x0e9d('0x7c'),_0x0e9d('0x7d')],'required':![]},{'model':db[_0x0e9d('0x7e')],'as':'Tags','attributes':['id',_0x0e9d('0x3e'),_0x0e9d('0x7f')],'where':_0x22e323['query'][_0x0e9d('0x80')]?{'id':_0x22e323[_0x0e9d('0x4a')]['tag']}:undefined,'required':_0x22e323[_0x0e9d('0x4a')]['tag']?!![]:![]}];}return db[_0x0e9d('0x77')][_0x0e9d('0x58')](_0x2a9c84);})['then'](function(_0x5df011){_0x33ccb7['rows']=_0x5df011;return _0x33ccb7;});}})[_0x0e9d('0x26')](respondWithFilteredResult(_0x14f7df,_0x2a9c84))[_0x0e9d('0x2f')](handleError(_0x14f7df,null));};exports[_0x0e9d('0x81')]=function(_0x5443fd,_0x2df78c,_0x877c35){return db[_0x0e9d('0x42')][_0x0e9d('0x6d')]({'where':{'id':_0x5443fd[_0x0e9d('0x5b')]['id']}})[_0x0e9d('0x26')](handleEntityNotFound(_0x2df78c,null))[_0x0e9d('0x26')](function(_0x1df358){if(_0x1df358){return db[_0x0e9d('0x82')][_0x0e9d('0x83')](function(_0x2ec571){return db[_0x0e9d('0x84')][_0x0e9d('0x3d')]({'where':{'FaxAccountId':_0x5443fd[_0x0e9d('0x5b')]['id']},'transaction':_0x2ec571})[_0x0e9d('0x26')](function(_0x5640fb){var _0x32308a=_['map'](_0x5443fd[_0x0e9d('0x5f')],function(_0x179494){_0x179494[_0x0e9d('0x6a')]=_0x5443fd['params']['id'];return _0x179494;});return db[_0x0e9d('0x84')][_0x0e9d('0x85')](_0x32308a,{'transaction':_0x2ec571});});})[_0x0e9d('0x26')](function(){return db[_0x0e9d('0x84')][_0x0e9d('0x86')]({'where':{'FaxAccountId':_0x5443fd['params']['id']},'order':_0x0e9d('0x87')});});}})[_0x0e9d('0x26')](respondWithResult(_0x2df78c,null))['catch'](handleError(_0x2df78c,null));};exports[_0x0e9d('0x88')]=function(_0x4f8707,_0x54ee46,_0x5465a8){var _0x786686={};var _0x2f0c77={};var _0x253c7c;var _0x4ecd32;return db[_0x0e9d('0x42')][_0x0e9d('0x6d')]({'where':{'id':_0x4f8707[_0x0e9d('0x5b')]['id']}})[_0x0e9d('0x26')](handleEntityNotFound(_0x54ee46,null))[_0x0e9d('0x26')](function(_0x21a47d){if(_0x21a47d){_0x253c7c=_0x21a47d;_0x2f0c77['model']=_[_0x0e9d('0x48')](db['FaxApplication'][_0x0e9d('0x43')]);_0x2f0c77[_0x0e9d('0x4a')]=_[_0x0e9d('0x48')](_0x4f8707[_0x0e9d('0x4a')]);_0x2f0c77['filters']=_['intersection'](_0x2f0c77[_0x0e9d('0x46')],_0x2f0c77[_0x0e9d('0x4a')]);_0x786686['attributes']=_['intersection'](_0x2f0c77[_0x0e9d('0x46')],qs['fields'](_0x4f8707[_0x0e9d('0x4a')][_0x0e9d('0x4c')]));_0x786686[_0x0e9d('0x4b')]=_0x786686[_0x0e9d('0x4b')][_0x0e9d('0x6e')]?_0x786686[_0x0e9d('0x4b')]:_0x2f0c77[_0x0e9d('0x46')];_0x786686[_0x0e9d('0x4f')]=qs[_0x0e9d('0x50')](_0x4f8707['query']['sort']);_0x786686[_0x0e9d('0x51')]=qs[_0x0e9d('0x52')](_[_0x0e9d('0x53')](_0x4f8707[_0x0e9d('0x4a')],_0x2f0c77['filters']));if(_0x4f8707[_0x0e9d('0x4a')]['filter']){_0x786686[_0x0e9d('0x51')]=_[_0x0e9d('0x55')](_0x786686[_0x0e9d('0x51')],{'$or':_[_0x0e9d('0x47')](_0x786686[_0x0e9d('0x4b')],function(_0x16ee82){var _0x463d02={};_0x463d02[_0x16ee82]={'$like':'%'+_0x4f8707['query'][_0x0e9d('0x54')]+'%'};return _0x463d02;})});}_0x786686=_[_0x0e9d('0x55')]({},_0x786686,_0x4f8707[_0x0e9d('0x6f')]);return _0x253c7c[_0x0e9d('0x88')](_0x786686);}})['then'](function(_0x386c1f){if(_0x386c1f){_0x4ecd32=_0x386c1f[_0x0e9d('0x6e')];if(!_0x4f8707[_0x0e9d('0x4a')][_0x0e9d('0x4d')](_0x0e9d('0x4e'))){_0x786686['limit']=qs[_0x0e9d('0x35')](_0x4f8707['query'][_0x0e9d('0x35')]);_0x786686[_0x0e9d('0x34')]=qs[_0x0e9d('0x34')](_0x4f8707[_0x0e9d('0x4a')]['offset']);}return _0x253c7c[_0x0e9d('0x88')](_0x786686);}})[_0x0e9d('0x26')](function(_0x3b1bd2){if(_0x3b1bd2){return _0x3b1bd2?{'count':_0x4ecd32,'rows':_0x3b1bd2}:null;}})['then'](respondWithResult(_0x54ee46,null))[_0x0e9d('0x2f')](handleError(_0x54ee46,null));};function Extension(_0xcfdf94,_0x25503d,_0x5921d0,_0x18eb30){this[_0x0e9d('0x89')]=_0x0e9d('0x8a');this[_0x0e9d('0x8b')]=_0xcfdf94[_0x0e9d('0x8c')];this[_0x0e9d('0x8d')]=_0x18eb30;this['type']=_0x0e9d('0x8e');this['description']=_0x0e9d('0x8f');this[_0x0e9d('0x6a')]=_0xcfdf94['id'];this[_0x0e9d('0x87')]=_0x25503d;this[_0x0e9d('0x90')]=_0x5921d0;}function createExtensionsReciveFax(_0xe1755f){var _0x288e63=0x1;var _0x4890a0=[];_0x4890a0[_0x0e9d('0x91')](new Extension(_0xe1755f,_0x288e63,'','Answer'));_0x288e63+=0x1;_0x4890a0['push'](new Extension(_0xe1755f,_0x288e63,_0x0e9d('0x92'),'Set'));_0x288e63+=0x1;for(var _0x34ed90 in _0xe1755f){if(_0xe1755f['hasOwnProperty'](_0x34ed90)&&(_0x34ed90===_0x0e9d('0x93')||_0x34ed90===_0x0e9d('0x8c')||_0x34ed90===_0x0e9d('0x94')||_0x34ed90==='faxdetect'||_0x34ed90===_0x0e9d('0x95')||_0x34ed90===_0x0e9d('0x96')||_0x34ed90===_0x0e9d('0x97')||_0x34ed90===_0x0e9d('0x98')||_0x34ed90===_0x0e9d('0x99'))){_0x4890a0[_0x0e9d('0x91')](new Extension(_0xe1755f,_0x288e63,_0x0e9d('0x9a')+_0x34ed90+')='+_0xe1755f[_0x34ed90],'Set'));_0x288e63+=0x1;}}_0x4890a0[_0x0e9d('0x91')](new Extension(_0xe1755f,_0x288e63,'6',_0x0e9d('0x9b')));_0x288e63+=0x1;_0x4890a0[_0x0e9d('0x91')](new Extension(_0xe1755f,_0x288e63,_0x0e9d('0x9c'),_0x0e9d('0x9d')));_0x288e63=0x0;return _0x4890a0;}exports['addAccountApplications']=function(_0x45d93d,_0x511c99,_0x27d465){var _0x12c9a4;return db[_0x0e9d('0x82')]['transaction'](function(_0x156fa0){return db[_0x0e9d('0x42')]['create'](_0x45d93d['body'],{'transaction':_0x156fa0})[_0x0e9d('0x26')](function(_0x4a27c9){_0x12c9a4=_0x4a27c9['get']({'plain':!![]});return db[_0x0e9d('0x9e')]['bulkCreate'](createExtensionsReciveFax(_0x12c9a4),{'transaction':_0x156fa0});});})[_0x0e9d('0x26')](function(){return _0x12c9a4;})['then'](respondWithResult(_0x511c99,null))[_0x0e9d('0x2f')](handleError(_0x511c99,null));};exports[_0x0e9d('0x9f')]=function(_0x318533,_0x4fb228,_0x17ea58){var _0x2949fb;return db['sequelize'][_0x0e9d('0x83')](function(_0x3513e4){return db[_0x0e9d('0x42')]['update'](_0x318533[_0x0e9d('0x5f')],{'where':{'id':_0x318533[_0x0e9d('0x5f')]['id']},'transaction':_0x3513e4})['then'](function(_0x3ec80e){return db[_0x0e9d('0x9e')][_0x0e9d('0x3d')]({'where':{'FaxAccountId':_0x318533[_0x0e9d('0x5f')]['id']},'transaction':_0x3513e4})[_0x0e9d('0x26')](function(_0x123912){return db['VoiceExtension'][_0x0e9d('0x85')](createExtensionsReciveFax(_[_0x0e9d('0x78')](_0x318533[_0x0e9d('0x5f')],[_0x0e9d('0xa0'),_0x0e9d('0x45'),_0x0e9d('0xa1'),_0x0e9d('0xa2'),_0x0e9d('0xa3'),'ListId'])),{'transaction':_0x3513e4});});});})[_0x0e9d('0x26')](function(){return db[_0x0e9d('0x42')][_0x0e9d('0xa4')](_0x318533[_0x0e9d('0x5f')]['id']);})['then'](respondWithResult(_0x4fb228,null))['catch'](handleError(_0x4fb228,null));};exports[_0x0e9d('0xa5')]=function(_0x5e47a4,_0x313812,_0x7ba40e){var _0x49c6ff={'raw':!![],'where':{}};var _0x5df6c0={};var _0x524b00={'count':0x0,'rows':[]};return db[_0x0e9d('0x42')]['findOne']({'where':{'id':_0x5e47a4[_0x0e9d('0x5b')]['id']}})[_0x0e9d('0x26')](handleEntityNotFound(_0x313812,null))['then'](function(_0x593535){if(_0x593535){_0x5df6c0[_0x0e9d('0x46')]=_[_0x0e9d('0x48')](db[_0x0e9d('0xa6')][_0x0e9d('0x43')]);_0x5df6c0['query']=_['keys'](_0x5e47a4[_0x0e9d('0x4a')]);_0x5df6c0['filters']=_[_0x0e9d('0x49')](_0x5df6c0[_0x0e9d('0x46')],_0x5df6c0[_0x0e9d('0x4a')]);_0x49c6ff['attributes']=_[_0x0e9d('0x49')](_0x5df6c0['model'],qs['fields'](_0x5e47a4[_0x0e9d('0x4a')][_0x0e9d('0x4c')]));_0x49c6ff[_0x0e9d('0x4b')]=_0x49c6ff[_0x0e9d('0x4b')][_0x0e9d('0x6e')]?_0x49c6ff[_0x0e9d('0x4b')]:_0x5df6c0['model'];if(!_0x5e47a4['query']['hasOwnProperty']('nolimit')){_0x49c6ff[_0x0e9d('0x35')]=qs[_0x0e9d('0x35')](_0x5e47a4[_0x0e9d('0x4a')][_0x0e9d('0x35')]);_0x49c6ff['offset']=qs[_0x0e9d('0x34')](_0x5e47a4[_0x0e9d('0x4a')][_0x0e9d('0x34')]);}_0x49c6ff['order']=qs['sort'](_0x5e47a4['query'][_0x0e9d('0x50')]);_0x49c6ff['where']=qs['filters'](_[_0x0e9d('0x53')](_0x5e47a4[_0x0e9d('0x4a')],_0x5df6c0[_0x0e9d('0x52')]));_0x49c6ff[_0x0e9d('0x51')][_0x0e9d('0x6a')]=_0x593535['id'];if(_0x5e47a4['query'][_0x0e9d('0x54')]){_0x49c6ff[_0x0e9d('0x51')]=_[_0x0e9d('0x55')](_0x49c6ff[_0x0e9d('0x51')],{'$or':_[_0x0e9d('0x47')](_0x49c6ff[_0x0e9d('0x4b')],function(_0x35b2ce){var _0x768391={};_0x768391[_0x35b2ce]={'$like':'%'+_0x5e47a4['query'][_0x0e9d('0x54')]+'%'};return _0x768391;})});}if(_0x5e47a4[_0x0e9d('0x4a')][_0x0e9d('0xa7')]){var _0x26fba0=_0x5e47a4[_0x0e9d('0x4a')][_0x0e9d('0xa7')][_0x0e9d('0xa8')](',');var _0x555dbc={};_0x555dbc[_0x26fba0[0x0]]={'$gte':moment(_0x26fba0[0x1])[_0x0e9d('0xa9')](_0x0e9d('0xaa'))};_0x49c6ff[_0x0e9d('0x51')]=_[_0x0e9d('0x55')](_0x49c6ff[_0x0e9d('0x51')],_0x555dbc);}_0x49c6ff=_[_0x0e9d('0x55')]({},_0x49c6ff,_0x5e47a4[_0x0e9d('0x6f')]);return db[_0x0e9d('0xa6')][_0x0e9d('0x33')]({'where':_0x49c6ff[_0x0e9d('0x51')]})[_0x0e9d('0x26')](function(_0x541249){_0x524b00[_0x0e9d('0x33')]=_0x541249;if(_0x5e47a4['query'][_0x0e9d('0x57')]){_0x49c6ff[_0x0e9d('0x5c')]=[{'all':!![]}];}return db['FaxMessage'][_0x0e9d('0x58')](_0x49c6ff);})[_0x0e9d('0x26')](function(_0x44174d){_0x524b00[_0x0e9d('0x59')]=_0x44174d;return _0x524b00;});}})['then'](respondWithFilteredResult(_0x313812,_0x49c6ff))[_0x0e9d('0x2f')](handleError(_0x313812,null));};exports[_0x0e9d('0x3f')]=function(_0x1adddf,_0x229ad9,_0x571c91){var _0x32fffa,_0x2796ce={},_0x2f2211;if(_0x1adddf['body']['to']){_0x2f2211=_0x1adddf[_0x0e9d('0x5f')]['to'][0x0];}return db['FaxAccount'][_0x0e9d('0x5d')]({'where':{'id':_0x1adddf[_0x0e9d('0x5b')]['id']},'include':[{'model':db[_0x0e9d('0xab')],'as':_0x0e9d('0xac'),'include':[{'model':db[_0x0e9d('0x7a')],'as':_0x0e9d('0xad'),'where':{'fax':_0x2f2211},'limit':0x1,'order':[['updatedAt',_0x0e9d('0xae')]]}]}]})['then'](handleEntityNotFound(_0x229ad9,null))[_0x0e9d('0x26')](function(_0x1b032d){_0x32fffa=_0x1b032d;if(_0x1adddf[_0x0e9d('0x5f')]['attachments']&&_0x1adddf['body'][_0x0e9d('0xaf')][_0x0e9d('0x6e')]){for(var _0x1d0dc0=0x0;_0x1d0dc0<_0x1adddf[_0x0e9d('0x5f')]['attachments'][_0x0e9d('0x6e')];_0x1d0dc0+=0x1){_0x1adddf['body'][_0x0e9d('0xaf')][_0x1d0dc0]={'filename':_0x1adddf[_0x0e9d('0x5f')][_0x0e9d('0xaf')][_0x1d0dc0][_0x0e9d('0x3e')],'id':_0x1adddf[_0x0e9d('0x5f')][_0x0e9d('0xaf')][_0x1d0dc0]['id'],'path':path[_0x0e9d('0xb0')](config['root'],_0x0e9d('0xb1'),_0x1adddf[_0x0e9d('0x5f')][_0x0e9d('0xaf')][_0x1d0dc0]['basename'])};}}return respondWithRpcPromise(_0x0e9d('0xb2'),'CheckAfterSend',{'FaxAccountId':_['isNil'](_0x1adddf[_0x0e9d('0x5b')]['id'])?undefined:_0x1adddf[_0x0e9d('0x5b')]['id'],'path':_[_0x0e9d('0xb3')](_0x1adddf['body'][_0x0e9d('0xaf')][0x0][_0x0e9d('0x7')])?undefined:_0x1adddf[_0x0e9d('0x5f')][_0x0e9d('0xaf')][0x0][_0x0e9d('0x7')],'fax':_[_0x0e9d('0xb3')](_0x1adddf[_0x0e9d('0x5f')]['to'][0x0])?undefined:_0x1adddf['body']['to'][0x0]},client9002);})[_0x0e9d('0x26')](function(){if(_0x32fffa){if(_['isNil'](_0x1adddf[_0x0e9d('0x5f')]['from'])){_0x1adddf[_0x0e9d('0x5f')][_0x0e9d('0xb4')]=util[_0x0e9d('0xa9')](_0x0e9d('0xb5'),_0x32fffa[_0x0e9d('0x3e')],_0x32fffa[_0x0e9d('0xb6')]);}if(_0x32fffa['List']){if(_0x32fffa[_0x0e9d('0xac')][_0x0e9d('0xad')][_0x0e9d('0x6e')]){return _0x32fffa[_0x0e9d('0xac')][_0x0e9d('0xad')][0x0];}else{return db[_0x0e9d('0x7a')][_0x0e9d('0x5e')](_[_0x0e9d('0x1a')](_0x1adddf[_0x0e9d('0x5f')],{'firstName':_0x1adddf[_0x0e9d('0x5f')]['to'][0x0],'phone':_0x1adddf[_0x0e9d('0x5f')]['to'][0x0],'fax':_0x1adddf[_0x0e9d('0x5f')]['to'][0x0],'ListId':_0x32fffa[_0x0e9d('0xb7')]}));}}else{throw new Error('List\x20not\x20found');}}else{throw new Error('Send\x20Fax\x20failed');}})[_0x0e9d('0x26')](function(_0x1f1722){if(_0x1f1722){return db['FaxInteraction'][_0x0e9d('0x5d')]({'where':{'ContactId':_0x1f1722['id'],'closed':![],'FaxAccountId':_0x32fffa['id']}})[_0x0e9d('0x26')](function(_0x5e07e2){if(_0x5e07e2){return[_0x5e07e2,![]];}return db['FaxInteraction'][_0x0e9d('0x5e')]({'UserId':_0x1adddf[_0x0e9d('0x60')]['id'],'ContactId':_0x1f1722['id'],'FaxAccountId':_0x32fffa['id'],'fax':_0x1adddf[_0x0e9d('0x5f')]['to'][0x0],'firstMsgDirection':_0x0e9d('0xb8'),'Messages':[_[_0x0e9d('0x55')](_0x1adddf[_0x0e9d('0x5f')],{'read':![],'body':_0x1adddf['body'][_0x0e9d('0xaf')][0x0]['filename'],'FaxAccountId':_0x32fffa['id'],'UserId':_0x1adddf[_0x0e9d('0x60')]['id'],'ContactId':_0x1f1722['id'],'AttachmentId':_0x1adddf[_0x0e9d('0x5f')][_0x0e9d('0xaf')][0x0]['id']})]},{'include':[{'model':db[_0x0e9d('0xa6')],'as':_0x0e9d('0xb9')}]})[_0x0e9d('0x26')](function(_0x5c214e){return[_0x5c214e,!![]];});});}else{throw new Error(_0x0e9d('0xba'));}})[_0x0e9d('0xbb')](function(_0x5727e6,_0x1448de){if(_0x1448de){return _0x5727e6;}return db[_0x0e9d('0xa6')][_0x0e9d('0x5e')]({'direction':'out','read':![],'body':_0x1adddf[_0x0e9d('0x5f')][_0x0e9d('0xaf')][0x0][_0x0e9d('0xbc')],'FaxAccountId':_0x32fffa['id'],'FaxInteractionId':_0x5727e6['id'],'UserId':_0x1adddf['user']['id'],'ContactId':_0x5727e6[_0x0e9d('0xbd')],'AttachmentId':_0x1adddf[_0x0e9d('0x5f')][_0x0e9d('0xaf')][0x0]['id']})[_0x0e9d('0x26')](function(_0x12c6ea){_0x5727e6[_0x0e9d('0xbe')]['Messages']=[];_0x5727e6[_0x0e9d('0xbe')][_0x0e9d('0xb9')][_0x0e9d('0x91')](_0x12c6ea[_0x0e9d('0xbe')]);return _0x5727e6;});})[_0x0e9d('0x26')](function(_0x53103e){respondWithRpcPromise('SendFax',_0x0e9d('0xbf'),{'FaxAccountId':_[_0x0e9d('0xb3')](_0x1adddf[_0x0e9d('0x5b')]['id'])?undefined:_0x1adddf[_0x0e9d('0x5b')]['id'],'path':_['isNil'](_0x1adddf[_0x0e9d('0x5f')]['attachments'][0x0][_0x0e9d('0x7')])?undefined:_0x1adddf[_0x0e9d('0x5f')]['attachments'][0x0]['path'],'fax':_[_0x0e9d('0xb3')](_0x1adddf['body']['to'][0x0])?undefined:_0x1adddf[_0x0e9d('0x5f')]['to'][0x0],'AttachmentId':_0x1adddf[_0x0e9d('0x5f')]['attachments'][0x0]['id']},client9002)[_0x0e9d('0x26')](function(_0x37fc3c){logger[_0x0e9d('0xc0')](_0x0e9d('0xc1'),_0x37fc3c);})[_0x0e9d('0x2f')](function(_0x192ac2){logger[_0x0e9d('0xc0')](_0x0e9d('0xc1'),_0x192ac2);});return _0x53103e;})[_0x0e9d('0x26')](respondWithResult(_0x229ad9,null))[_0x0e9d('0x2f')](handleError(_0x229ad9,null));};exports[_0x0e9d('0xc2')]=function(_0x1bbfe6,_0x24a34e,_0x5657fb){return db['FaxAccount']['find']({'where':{'id':_0x1bbfe6[_0x0e9d('0x5b')]['id']}})[_0x0e9d('0x26')](handleEntityNotFound(_0x24a34e,null))[_0x0e9d('0x26')](function(_0xcfc88a){if(_0xcfc88a){return _0xcfc88a['addAgents'](_0x1bbfe6[_0x0e9d('0x5f')][_0x0e9d('0x71')],_[_0x0e9d('0x78')](_0x1bbfe6[_0x0e9d('0x5f')],['ids','id'])||{})['spread'](function(_0x36f1ed){for(var _0x1a9df2=0x0;_0x1a9df2<_0x1bbfe6['body'][_0x0e9d('0x71')]['length'];_0x1a9df2+=0x1){socket[_0x0e9d('0xc3')](_0x0e9d('0xc4'),{'UserId':_0x1bbfe6['body'][_0x0e9d('0x71')][_0x1a9df2],'FaxAccountId':_0x1bbfe6[_0x0e9d('0x5b')]['id']});}return _0x36f1ed;});}})['then'](respondWithResult(_0x24a34e,null))[_0x0e9d('0x2f')](handleError(_0x24a34e,null));};exports[_0x0e9d('0xc5')]=function(_0x392602,_0x567d0f,_0x30df2b){return db['FaxAccount'][_0x0e9d('0x5d')]({'where':{'id':_0x392602[_0x0e9d('0x5b')]['id']}})[_0x0e9d('0x26')](handleEntityNotFound(_0x567d0f,null))['then'](function(_0x13f2af){if(_0x13f2af){return _0x13f2af[_0x0e9d('0xc5')](_0x392602[_0x0e9d('0x4a')][_0x0e9d('0x71')])[_0x0e9d('0x26')](function(){if(_[_0x0e9d('0xc6')](_0x392602[_0x0e9d('0x4a')][_0x0e9d('0x71')])){for(var _0x1fb065=0x0;_0x1fb065<_0x392602[_0x0e9d('0x4a')]['ids'][_0x0e9d('0x6e')];_0x1fb065+=0x1){socket[_0x0e9d('0xc3')](_0x0e9d('0xc7'),{'UserId':Number(_0x392602[_0x0e9d('0x4a')][_0x0e9d('0x71')][_0x1fb065]),'FaxAccountId':Number(_0x392602[_0x0e9d('0x5b')]['id'])});}}else{socket[_0x0e9d('0xc3')](_0x0e9d('0xc7'),{'UserId':Number(_0x392602[_0x0e9d('0x4a')][_0x0e9d('0x71')]),'FaxAccountId':Number(_0x392602[_0x0e9d('0x5b')]['id'])});}});}})[_0x0e9d('0x26')](respondWithStatusCode(_0x567d0f,null))[_0x0e9d('0x2f')](handleError(_0x567d0f,null));};exports[_0x0e9d('0xc8')]=function(_0x124ed7,_0x3b8fda,_0x55f3f5){var _0x38b9c7={};var _0x527c65={};var _0x173c3f;var _0x551812;return db[_0x0e9d('0x42')][_0x0e9d('0x6d')]({'where':{'id':_0x124ed7[_0x0e9d('0x5b')]['id']}})[_0x0e9d('0x26')](handleEntityNotFound(_0x3b8fda,null))[_0x0e9d('0x26')](function(_0xb7b62d){if(_0xb7b62d){_0x173c3f=_0xb7b62d;_0x527c65['model']=_[_0x0e9d('0x48')](db[_0x0e9d('0x7b')][_0x0e9d('0x43')]);_0x527c65['query']=_[_0x0e9d('0x48')](_0x124ed7[_0x0e9d('0x4a')]);_0x527c65[_0x0e9d('0x52')]=_[_0x0e9d('0x49')](_0x527c65[_0x0e9d('0x46')],_0x527c65['query']);_0x38b9c7[_0x0e9d('0x4b')]=_[_0x0e9d('0x49')](_0x527c65[_0x0e9d('0x46')],qs[_0x0e9d('0x4c')](_0x124ed7[_0x0e9d('0x4a')][_0x0e9d('0x4c')]));_0x38b9c7[_0x0e9d('0x4b')]=_0x38b9c7['attributes'][_0x0e9d('0x6e')]?_0x38b9c7[_0x0e9d('0x4b')]:_0x527c65['model'];_0x38b9c7['order']=qs[_0x0e9d('0x50')](_0x124ed7[_0x0e9d('0x4a')][_0x0e9d('0x50')]);_0x38b9c7[_0x0e9d('0x51')]=qs[_0x0e9d('0x52')](_[_0x0e9d('0x53')](_0x124ed7[_0x0e9d('0x4a')],_0x527c65[_0x0e9d('0x52')]));if(_0x124ed7['query']['filter']){_0x38b9c7[_0x0e9d('0x51')]=_[_0x0e9d('0x55')](_0x38b9c7[_0x0e9d('0x51')],{'$or':_[_0x0e9d('0x47')](_0x38b9c7[_0x0e9d('0x4b')],function(_0x2305ec){var _0x7ad7b3={};_0x7ad7b3[_0x2305ec]={'$like':'%'+_0x124ed7[_0x0e9d('0x4a')][_0x0e9d('0x54')]+'%'};return _0x7ad7b3;})});}_0x38b9c7=_[_0x0e9d('0x55')]({},_0x38b9c7,_0x124ed7['options']);return _0x173c3f[_0x0e9d('0xc8')](_0x38b9c7);}})[_0x0e9d('0x26')](function(_0x1bbaa0){if(_0x1bbaa0){_0x551812=_0x1bbaa0['length'];if(!_0x124ed7[_0x0e9d('0x4a')][_0x0e9d('0x4d')](_0x0e9d('0x4e'))){_0x38b9c7[_0x0e9d('0x35')]=qs[_0x0e9d('0x35')](_0x124ed7['query']['limit']);_0x38b9c7[_0x0e9d('0x34')]=qs['offset'](_0x124ed7[_0x0e9d('0x4a')][_0x0e9d('0x34')]);}return _0x173c3f['getAgents'](_0x38b9c7);}})[_0x0e9d('0x26')](function(_0x4d8908){if(_0x4d8908){return _0x4d8908?{'count':_0x551812,'rows':_0x4d8908}:null;}})[_0x0e9d('0x26')](respondWithResult(_0x3b8fda,null))[_0x0e9d('0x2f')](handleError(_0x3b8fda,null));};