3694052438d6734baa409d06f7119648d528be86
[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 _0xf204=['debug','FaxAccount,\x20%s,\x20%s,\x20%s','request\x20sent','error','message','result','catch','sendStatus','status','end','offset','undefined','limit','count','Content-Range','apply','reject','save','update','destroy','get','FaxAccounts','UserProfileResource','stack','name','Pause','mandatoryDispositionPause','map','FaxAccount','type','key','model','query','keys','filters','attributes','intersection','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','include','findAll','rows','show','params','rawAttributes','find','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','FaxAccountId','Disposition','create','getDispositions','findOne','length','options','includeAll','removeDispositions','addAnswer','CannedAnswer','getAnswers','removeAnswers','ids','addInteraction','FaxInteraction','omit','getInteractions','CmContact','Contact','User','Owner','fullname','Tag','color','tag','addApplications','transaction','sequelize','READ_COMMITTED','FaxApplication','bulkCreate','findAndCountAll','priority','finally','send','json','getApplications','context','from-voip-provider','exten','localstationid','app','system','description','Fax\x20Extension','appdata','push','CDR(type)=inbound-fax','ecm','gateway','headerinfo','maxrate','minrate','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','addAccountApplications','VoiceExtension','updateAccountApplications','tech','createdAt','TrunkId','ListId','findById','getMessages','FaxMessage','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','List','updatedAt','attachments','join','server/files/attachments','basename','CheckAfterSend','isNil','path','from','fax','Contacts','List\x20not\x20found','Send\x20Fax\x20failed','out','filename','spread','Messages','dataValues','SendFax','SendFaxRpc,\x20%s','addAgents','emit','userFaxAccount:save','removeAgents','isArray','userFaxAccount:remove','getAgents','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','sox','ejs','fs-extra','squel','crypto','jsforce','to-csv','querystring','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','./faxAccount.socket','jayson/promise','client','http','request','then','info','FaxAccount,\x20%s,\x20%s'];(function(_0x334841,_0x2bbc4c){var _0x5beb4b=function(_0x4bea72){while(--_0x4bea72){_0x334841['push'](_0x334841['shift']());}};_0x5beb4b(++_0x2bbc4c);}(_0xf204,0x167));var _0x4f20=function(_0x2e12b8,_0xdb92fe){_0x2e12b8=_0x2e12b8-0x0;var _0x2f1213=_0xf204[_0x2e12b8];return _0x2f1213;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x4f20('0x0'));var zipdir=require(_0x4f20('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x4f20('0x2'));var moment=require(_0x4f20('0x3'));var BPromise=require(_0x4f20('0x4'));var Mustache=require(_0x4f20('0x5'));var util=require(_0x4f20('0x6'));var path=require('path');var sox=require(_0x4f20('0x7'));var csv=require('to-csv');var ejs=require(_0x4f20('0x8'));var fs=require('fs');var fs_extra=require(_0x4f20('0x9'));var _=require('lodash');var squel=require(_0x4f20('0xa'));var crypto=require(_0x4f20('0xb'));var jsforce=require(_0x4f20('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x4f20('0xd'));var querystring=require(_0x4f20('0xe'));var Papa=require('papaparse');var Redis=require(_0x4f20('0xf'));var authService=require('../../components/auth/service');var qs=require(_0x4f20('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x4f20('0x11'))(_0x4f20('0x12'));var utils=require('../../config/utils');var config=require(_0x4f20('0x13'));var licenseUtil=require(_0x4f20('0x14'));var db=require(_0x4f20('0x15'))['db'];config[_0x4f20('0x16')]=_[_0x4f20('0x17')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x4f20('0x18'))(new Redis(config[_0x4f20('0x16')]));require(_0x4f20('0x19'))['register'](socket);var jayson=require(_0x4f20('0x1a'));var client=jayson[_0x4f20('0x1b')][_0x4f20('0x1c')]({'port':0x232c});var client9002=jayson[_0x4f20('0x1b')][_0x4f20('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x10f131,_0xc584d1,_0x5f0352,_0x26745e){return new BPromise(function(_0x25b799,_0x93f5a5){var _0x284839=_0x26745e||client;return _0x284839[_0x4f20('0x1d')](_0x10f131,_0x5f0352)[_0x4f20('0x1e')](function(_0x5bc149){logger[_0x4f20('0x1f')](_0x4f20('0x20'),_0xc584d1,'request\x20sent');logger[_0x4f20('0x21')](_0x4f20('0x22'),_0xc584d1,_0x4f20('0x23'),JSON['stringify'](_0x5bc149));if(_0x5bc149[_0x4f20('0x24')]){if(_0x5bc149['error']['code']===0x1f4){logger['error'](_0x4f20('0x20'),_0xc584d1,_0x5bc149['error']['message']);return _0x93f5a5(_0x5bc149[_0x4f20('0x24')][_0x4f20('0x25')]);}logger['error'](_0x4f20('0x20'),_0xc584d1,_0x5bc149[_0x4f20('0x24')][_0x4f20('0x25')]);return _0x25b799(_0x5bc149[_0x4f20('0x24')][_0x4f20('0x25')]);}else{logger[_0x4f20('0x1f')](_0x4f20('0x20'),_0xc584d1,'request\x20sent');_0x25b799(_0x5bc149[_0x4f20('0x26')][_0x4f20('0x25')]);}})[_0x4f20('0x27')](function(_0x7aa932){logger[_0x4f20('0x24')]('FaxAccount,\x20%s,\x20%s',_0xc584d1,_0x7aa932);_0x93f5a5(_0x7aa932);});});}function respondWithStatusCode(_0x528ae0,_0x3ced62){_0x3ced62=_0x3ced62||0xcc;return function(_0x54a4d7){if(_0x54a4d7){return _0x528ae0[_0x4f20('0x28')](_0x3ced62);}return _0x528ae0[_0x4f20('0x29')](_0x3ced62)[_0x4f20('0x2a')]();};}function respondWithResult(_0x153028,_0x3f7ed1){_0x3f7ed1=_0x3f7ed1||0xc8;return function(_0x3996c4){if(_0x3996c4){return _0x153028[_0x4f20('0x29')](_0x3f7ed1)['json'](_0x3996c4);}};}function respondWithFilteredResult(_0x245cac,_0x2adcfa){return function(_0x3d07b1){if(_0x3d07b1){var _0x2fcc6b=typeof _0x2adcfa[_0x4f20('0x2b')]===_0x4f20('0x2c')&&typeof _0x2adcfa[_0x4f20('0x2d')]===_0x4f20('0x2c');var _0x34ca6d=_0x3d07b1[_0x4f20('0x2e')];var _0x124bd6=_0x2fcc6b?0x0:_0x2adcfa[_0x4f20('0x2b')];var _0x4a7137=_0x2fcc6b?_0x3d07b1['count']:_0x2adcfa[_0x4f20('0x2b')]+_0x2adcfa[_0x4f20('0x2d')];var _0x1a7f4f;if(_0x4a7137>=_0x34ca6d){_0x4a7137=_0x34ca6d;_0x1a7f4f=0xc8;}else{_0x1a7f4f=0xce;}_0x245cac[_0x4f20('0x29')](_0x1a7f4f);return _0x245cac['set'](_0x4f20('0x2f'),_0x124bd6+'-'+_0x4a7137+'/'+_0x34ca6d)['json'](_0x3d07b1);}return null;};}function patchUpdates(_0x2a84dc){return function(_0xaec4a3){try{jsonpatch[_0x4f20('0x30')](_0xaec4a3,_0x2a84dc,!![]);}catch(_0x339446){return BPromise[_0x4f20('0x31')](_0x339446);}return _0xaec4a3[_0x4f20('0x32')]();};}function saveUpdates(_0x493525,_0x53ae8f){return function(_0x5803cf){if(_0x5803cf){return _0x5803cf[_0x4f20('0x33')](_0x493525)[_0x4f20('0x1e')](function(_0xaa889c){return _0xaa889c;});}return null;};}function removeEntity(_0x209e3d,_0xe08da7){return function(_0x53ee67){if(_0x53ee67){return _0x53ee67[_0x4f20('0x34')]()['then'](function(){var _0x26ed27=_0x53ee67[_0x4f20('0x35')]({'plain':!![]});var _0x5208ed=_0x4f20('0x36');return db[_0x4f20('0x37')][_0x4f20('0x34')]({'where':{'type':_0x5208ed,'resourceId':_0x26ed27['id']}})['then'](function(){return _0x53ee67;});})[_0x4f20('0x1e')](function(){_0x209e3d[_0x4f20('0x29')](0xcc)[_0x4f20('0x2a')]();});}};}function handleEntityNotFound(_0x4042b5,_0x1a21cd){return function(_0x1effcf){if(!_0x1effcf){_0x4042b5[_0x4f20('0x28')](0x194);}return _0x1effcf;};}function handleError(_0x3e5c55,_0x3d1860){_0x3d1860=_0x3d1860||0x1f4;return function(_0x205014){logger[_0x4f20('0x24')](_0x205014[_0x4f20('0x38')]);if(_0x205014[_0x4f20('0x39')]){delete _0x205014[_0x4f20('0x39')];}_0x3e5c55[_0x4f20('0x29')](_0x3d1860)['send'](_0x205014);};}exports['index']=function(_0x281689,_0x52c01f){var _0x3ab3bc={'include':[{'model':db[_0x4f20('0x3a')],'as':_0x4f20('0x3b')}]},_0x3a1ff2={},_0xb7b0e={'count':0x0,'rows':[]};var _0x369767=_[_0x4f20('0x3c')](db[_0x4f20('0x3d')]['rawAttributes'],function(_0x274fd4){return{'name':_0x274fd4['fieldName'],'type':_0x274fd4[_0x4f20('0x3e')][_0x4f20('0x3f')]};});_0x3a1ff2[_0x4f20('0x40')]=_[_0x4f20('0x3c')](_0x369767,_0x4f20('0x39'));_0x3a1ff2[_0x4f20('0x41')]=_[_0x4f20('0x42')](_0x281689[_0x4f20('0x41')]);_0x3a1ff2[_0x4f20('0x43')]=_['intersection'](_0x3a1ff2[_0x4f20('0x40')],_0x3a1ff2[_0x4f20('0x41')]);_0x3ab3bc[_0x4f20('0x44')]=_[_0x4f20('0x45')](_0x3a1ff2[_0x4f20('0x40')],qs['fields'](_0x281689['query'][_0x4f20('0x46')]));_0x3ab3bc['attributes']=_0x3ab3bc['attributes']['length']?_0x3ab3bc[_0x4f20('0x44')]:_0x3a1ff2[_0x4f20('0x40')];if(!_0x281689[_0x4f20('0x41')][_0x4f20('0x47')](_0x4f20('0x48'))){_0x3ab3bc['limit']=qs[_0x4f20('0x2d')](_0x281689[_0x4f20('0x41')][_0x4f20('0x2d')]);_0x3ab3bc['offset']=qs['offset'](_0x281689[_0x4f20('0x41')]['offset']);}_0x3ab3bc[_0x4f20('0x49')]=qs[_0x4f20('0x4a')](_0x281689[_0x4f20('0x41')]['sort']);_0x3ab3bc[_0x4f20('0x4b')]=qs[_0x4f20('0x43')](_[_0x4f20('0x4c')](_0x281689[_0x4f20('0x41')],_0x3a1ff2['filters']),_0x369767);if(_0x281689[_0x4f20('0x41')][_0x4f20('0x4d')]){_0x3ab3bc['where']=_[_0x4f20('0x4e')](_0x3ab3bc[_0x4f20('0x4b')],{'$or':_[_0x4f20('0x3c')](_0x369767,function(_0x1ac4bf){if(_0x1ac4bf[_0x4f20('0x3e')]!==_0x4f20('0x4f')){var _0x350687={};_0x350687[_0x1ac4bf[_0x4f20('0x39')]]={'$like':'%'+_0x281689['query'][_0x4f20('0x4d')]+'%'};return _0x350687;}})});}_0x3ab3bc=_['merge']({},_0x3ab3bc,_0x281689['options']);var _0x2b3555={'where':_0x3ab3bc[_0x4f20('0x4b')]};return db['FaxAccount']['count'](_0x2b3555)[_0x4f20('0x1e')](function(_0x5ca11e){_0xb7b0e['count']=_0x5ca11e;if(_0x281689['query']['includeAll']){_0x3ab3bc[_0x4f20('0x50')]=[{'all':!![]}];}return db['FaxAccount'][_0x4f20('0x51')](_0x3ab3bc);})[_0x4f20('0x1e')](function(_0x3a45e1){_0xb7b0e[_0x4f20('0x52')]=_0x3a45e1;return _0xb7b0e;})[_0x4f20('0x1e')](respondWithFilteredResult(_0x52c01f,_0x3ab3bc))[_0x4f20('0x27')](handleError(_0x52c01f,null));};exports[_0x4f20('0x53')]=function(_0x4911f0,_0xce99df){var _0x1b5b22={'raw':![],'where':{'id':_0x4911f0[_0x4f20('0x54')]['id']},'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]},_0x4c6011={};_0x4c6011[_0x4f20('0x40')]=_[_0x4f20('0x42')](db[_0x4f20('0x3d')][_0x4f20('0x55')]);_0x4c6011[_0x4f20('0x41')]=_['keys'](_0x4911f0['query']);_0x4c6011[_0x4f20('0x43')]=_[_0x4f20('0x45')](_0x4c6011[_0x4f20('0x40')],_0x4c6011[_0x4f20('0x41')]);_0x1b5b22[_0x4f20('0x44')]=_['intersection'](_0x4c6011[_0x4f20('0x40')],qs[_0x4f20('0x46')](_0x4911f0['query'][_0x4f20('0x46')]));_0x1b5b22[_0x4f20('0x44')]=_0x1b5b22['attributes']['length']?_0x1b5b22[_0x4f20('0x44')]:_0x4c6011[_0x4f20('0x40')];if(_0x4911f0[_0x4f20('0x41')]['includeAll']){_0x1b5b22[_0x4f20('0x50')]=[{'all':!![]}];}_0x1b5b22=_['merge']({},_0x1b5b22,_0x4911f0['options']);return db['FaxAccount'][_0x4f20('0x56')](_0x1b5b22)[_0x4f20('0x1e')](handleEntityNotFound(_0xce99df,null))[_0x4f20('0x1e')](respondWithResult(_0xce99df,null))[_0x4f20('0x27')](handleError(_0xce99df,null));};exports['create']=function(_0x4a2460,_0x3d7dc8){return db[_0x4f20('0x3d')]['create'](_0x4a2460['body'],{})[_0x4f20('0x1e')](function(_0x405d8c){var _0x1712d6=_0x4a2460[_0x4f20('0x57')][_0x4f20('0x35')]({'plain':!![]});if(!_0x1712d6)throw new Error(_0x4f20('0x58'));if(_0x1712d6[_0x4f20('0x59')]===_0x4f20('0x57')){var _0x58f90b=_0x405d8c[_0x4f20('0x35')]({'plain':!![]});var _0x39dcb0='FaxAccounts';return db[_0x4f20('0x5a')]['find']({'where':{'name':_0x39dcb0,'userProfileId':_0x1712d6[_0x4f20('0x5b')]},'raw':!![]})[_0x4f20('0x1e')](function(_0x44794f){if(_0x44794f&&_0x44794f[_0x4f20('0x5c')]===0x0){return db['UserProfileResource']['create']({'name':_0x58f90b['name'],'resourceId':_0x58f90b['id'],'type':_0x44794f[_0x4f20('0x39')],'sectionId':_0x44794f['id']},{})['then'](function(){return _0x405d8c;});}else{return _0x405d8c;}})[_0x4f20('0x27')](function(_0x41df92){logger[_0x4f20('0x24')](_0x4f20('0x5d'),_0x41df92);throw _0x41df92;});}return _0x405d8c;})[_0x4f20('0x1e')](respondWithResult(_0x3d7dc8,0xc9))[_0x4f20('0x27')](handleError(_0x3d7dc8,null));};exports['update']=function(_0x395d2c,_0x14e0bc){if(_0x395d2c[_0x4f20('0x5e')]['id']){delete _0x395d2c['body']['id'];}return db[_0x4f20('0x3d')]['find']({'where':{'id':_0x395d2c[_0x4f20('0x54')]['id']},'include':[{'model':db[_0x4f20('0x3a')],'as':_0x4f20('0x3b')}]})[_0x4f20('0x1e')](handleEntityNotFound(_0x14e0bc,null))[_0x4f20('0x1e')](saveUpdates(_0x395d2c[_0x4f20('0x5e')],null))[_0x4f20('0x1e')](respondWithResult(_0x14e0bc,null))[_0x4f20('0x27')](handleError(_0x14e0bc,null));};exports[_0x4f20('0x34')]=function(_0x9aa453,_0xcc954e){return db[_0x4f20('0x3d')][_0x4f20('0x56')]({'where':{'id':_0x9aa453[_0x4f20('0x54')]['id']}})[_0x4f20('0x1e')](handleEntityNotFound(_0xcc954e,null))[_0x4f20('0x1e')](removeEntity(_0xcc954e,null))['catch'](handleError(_0xcc954e,null));};exports['describe']=function(_0x42c73e,_0x383040){return db[_0x4f20('0x3d')]['describe']()[_0x4f20('0x1e')](respondWithResult(_0x383040,null))['catch'](handleError(_0x383040,null));};exports['addDisposition']=function(_0x91b6ac,_0x14fecd,_0x12b396){if(_0x91b6ac[_0x4f20('0x5e')]['id']){delete _0x91b6ac['body']['id'];}return db[_0x4f20('0x3d')][_0x4f20('0x56')]({'where':{'id':_0x91b6ac[_0x4f20('0x54')]['id']}})[_0x4f20('0x1e')](handleEntityNotFound(_0x14fecd,null))[_0x4f20('0x1e')](function(_0xe14e96){if(_0xe14e96){_0x91b6ac[_0x4f20('0x5e')][_0x4f20('0x5f')]=_0xe14e96['id'];return db[_0x4f20('0x60')][_0x4f20('0x61')](_0x91b6ac['body']);}})[_0x4f20('0x1e')](respondWithResult(_0x14fecd,null))['catch'](handleError(_0x14fecd,null));};exports[_0x4f20('0x62')]=function(_0x4df427,_0x4480f4,_0x10738c){var _0x101949={'raw':![],'where':{}};var _0x3e0f64={};var _0x31cae6={'count':0x0,'rows':[]};return db[_0x4f20('0x3d')][_0x4f20('0x63')]({'where':{'id':_0x4df427[_0x4f20('0x54')]['id']}})[_0x4f20('0x1e')](handleEntityNotFound(_0x4480f4,null))[_0x4f20('0x1e')](function(_0x431e81){if(_0x431e81){_0x3e0f64[_0x4f20('0x40')]=_[_0x4f20('0x42')](db['Disposition']['rawAttributes']);_0x3e0f64[_0x4f20('0x41')]=_[_0x4f20('0x42')](_0x4df427[_0x4f20('0x41')]);_0x3e0f64[_0x4f20('0x43')]=_[_0x4f20('0x45')](_0x3e0f64['model'],_0x3e0f64['query']);_0x101949[_0x4f20('0x44')]=_[_0x4f20('0x45')](_0x3e0f64[_0x4f20('0x40')],qs[_0x4f20('0x46')](_0x4df427['query'][_0x4f20('0x46')]));_0x101949['attributes']=_0x101949[_0x4f20('0x44')][_0x4f20('0x64')]?_0x101949[_0x4f20('0x44')]:_0x3e0f64[_0x4f20('0x40')];if(!_0x4df427[_0x4f20('0x41')][_0x4f20('0x47')](_0x4f20('0x48'))){_0x101949[_0x4f20('0x2d')]=qs['limit'](_0x4df427[_0x4f20('0x41')][_0x4f20('0x2d')]);_0x101949[_0x4f20('0x2b')]=qs[_0x4f20('0x2b')](_0x4df427[_0x4f20('0x41')]['offset']);}_0x101949[_0x4f20('0x49')]=qs['sort'](_0x4df427[_0x4f20('0x41')]['sort']);_0x101949['where']=qs[_0x4f20('0x43')](_[_0x4f20('0x4c')](_0x4df427[_0x4f20('0x41')],_0x3e0f64[_0x4f20('0x43')]));_0x101949['where'][_0x4f20('0x5f')]=_0x431e81['id'];if(_0x4df427[_0x4f20('0x41')]['filter']){_0x101949['where']=_[_0x4f20('0x4e')](_0x101949['where'],{'$or':_['map'](_0x101949['attributes'],function(_0x7dc56d){var _0x41bf82={};_0x41bf82[_0x7dc56d]={'$like':'%'+_0x4df427[_0x4f20('0x41')][_0x4f20('0x4d')]+'%'};return _0x41bf82;})});}_0x101949=_[_0x4f20('0x4e')]({},_0x101949,_0x4df427[_0x4f20('0x65')]);return db['Disposition'][_0x4f20('0x2e')]({'where':_0x101949[_0x4f20('0x4b')]})[_0x4f20('0x1e')](function(_0x56ee8e){_0x31cae6[_0x4f20('0x2e')]=_0x56ee8e;if(_0x4df427[_0x4f20('0x41')][_0x4f20('0x66')]){_0x101949['include']=[{'all':!![]}];}return db['Disposition'][_0x4f20('0x51')](_0x101949);})[_0x4f20('0x1e')](function(_0x2fb5d2){_0x31cae6[_0x4f20('0x52')]=_0x2fb5d2;return _0x31cae6;});}})[_0x4f20('0x1e')](respondWithFilteredResult(_0x4480f4,_0x101949))[_0x4f20('0x27')](handleError(_0x4480f4,null));};exports[_0x4f20('0x67')]=function(_0x34a8c7,_0x3a9259,_0x3c9756){return db['FaxAccount'][_0x4f20('0x56')]({'where':{'id':_0x34a8c7[_0x4f20('0x54')]['id']}})[_0x4f20('0x1e')](handleEntityNotFound(_0x3a9259,null))[_0x4f20('0x1e')](function(_0x5cc2ef){if(_0x5cc2ef){return _0x5cc2ef[_0x4f20('0x67')](_0x34a8c7[_0x4f20('0x41')]['ids']);}})['then'](respondWithStatusCode(_0x3a9259,null))[_0x4f20('0x27')](handleError(_0x3a9259,null));};exports[_0x4f20('0x68')]=function(_0x34bdef,_0x71aefe,_0x1a71c8){if(_0x34bdef['body']['id']){delete _0x34bdef[_0x4f20('0x5e')]['id'];}return db[_0x4f20('0x3d')][_0x4f20('0x56')]({'where':{'id':_0x34bdef[_0x4f20('0x54')]['id']}})['then'](handleEntityNotFound(_0x71aefe,null))[_0x4f20('0x1e')](function(_0x1c158a){if(_0x1c158a){_0x34bdef[_0x4f20('0x5e')]['FaxAccountId']=_0x1c158a['id'];return db[_0x4f20('0x69')][_0x4f20('0x61')](_0x34bdef[_0x4f20('0x5e')]);}})['then'](respondWithResult(_0x71aefe,null))['catch'](handleError(_0x71aefe,null));};exports[_0x4f20('0x6a')]=function(_0x175d3d,_0x6dea82,_0x3ae57e){var _0x2b7bae={'raw':![],'where':{}};var _0xcd87fc={};var _0xea2ea7={'count':0x0,'rows':[]};return db[_0x4f20('0x3d')][_0x4f20('0x63')]({'where':{'id':_0x175d3d['params']['id']}})[_0x4f20('0x1e')](handleEntityNotFound(_0x6dea82,null))[_0x4f20('0x1e')](function(_0x519f79){if(_0x519f79){_0xcd87fc[_0x4f20('0x40')]=_[_0x4f20('0x42')](db[_0x4f20('0x69')]['rawAttributes']);_0xcd87fc[_0x4f20('0x41')]=_[_0x4f20('0x42')](_0x175d3d[_0x4f20('0x41')]);_0xcd87fc[_0x4f20('0x43')]=_[_0x4f20('0x45')](_0xcd87fc['model'],_0xcd87fc[_0x4f20('0x41')]);_0x2b7bae[_0x4f20('0x44')]=_[_0x4f20('0x45')](_0xcd87fc[_0x4f20('0x40')],qs[_0x4f20('0x46')](_0x175d3d['query'][_0x4f20('0x46')]));_0x2b7bae['attributes']=_0x2b7bae[_0x4f20('0x44')][_0x4f20('0x64')]?_0x2b7bae[_0x4f20('0x44')]:_0xcd87fc[_0x4f20('0x40')];if(!_0x175d3d[_0x4f20('0x41')][_0x4f20('0x47')]('nolimit')){_0x2b7bae[_0x4f20('0x2d')]=qs[_0x4f20('0x2d')](_0x175d3d[_0x4f20('0x41')]['limit']);_0x2b7bae[_0x4f20('0x2b')]=qs[_0x4f20('0x2b')](_0x175d3d['query'][_0x4f20('0x2b')]);}_0x2b7bae['order']=qs[_0x4f20('0x4a')](_0x175d3d[_0x4f20('0x41')]['sort']);_0x2b7bae[_0x4f20('0x4b')]=qs[_0x4f20('0x43')](_[_0x4f20('0x4c')](_0x175d3d['query'],_0xcd87fc[_0x4f20('0x43')]));_0x2b7bae[_0x4f20('0x4b')][_0x4f20('0x5f')]=_0x519f79['id'];if(_0x175d3d['query'][_0x4f20('0x4d')]){_0x2b7bae['where']=_['merge'](_0x2b7bae[_0x4f20('0x4b')],{'$or':_['map'](_0x2b7bae[_0x4f20('0x44')],function(_0x7b473a){var _0x35fc27={};_0x35fc27[_0x7b473a]={'$like':'%'+_0x175d3d[_0x4f20('0x41')][_0x4f20('0x4d')]+'%'};return _0x35fc27;})});}_0x2b7bae=_[_0x4f20('0x4e')]({},_0x2b7bae,_0x175d3d[_0x4f20('0x65')]);return db[_0x4f20('0x69')][_0x4f20('0x2e')]({'where':_0x2b7bae[_0x4f20('0x4b')]})[_0x4f20('0x1e')](function(_0x516a8f){_0xea2ea7[_0x4f20('0x2e')]=_0x516a8f;if(_0x175d3d[_0x4f20('0x41')][_0x4f20('0x66')]){_0x2b7bae[_0x4f20('0x50')]=[{'all':!![]}];}return db[_0x4f20('0x69')][_0x4f20('0x51')](_0x2b7bae);})[_0x4f20('0x1e')](function(_0x1b3f38){_0xea2ea7[_0x4f20('0x52')]=_0x1b3f38;return _0xea2ea7;});}})[_0x4f20('0x1e')](respondWithFilteredResult(_0x6dea82,_0x2b7bae))[_0x4f20('0x27')](handleError(_0x6dea82,null));};exports[_0x4f20('0x6b')]=function(_0x5ca77b,_0x12f865,_0x19f37c){return db[_0x4f20('0x3d')]['find']({'where':{'id':_0x5ca77b[_0x4f20('0x54')]['id']}})[_0x4f20('0x1e')](handleEntityNotFound(_0x12f865,null))['then'](function(_0x4089ca){if(_0x4089ca){return _0x4089ca['removeAnswers'](_0x5ca77b[_0x4f20('0x41')][_0x4f20('0x6c')]);}})[_0x4f20('0x1e')](respondWithStatusCode(_0x12f865,null))[_0x4f20('0x27')](handleError(_0x12f865,null));};exports[_0x4f20('0x6d')]=function(_0x5ec17d,_0x57d74f,_0x9dabb0){return db[_0x4f20('0x6e')][_0x4f20('0x56')]({'where':{'id':_0x5ec17d[_0x4f20('0x54')]['id']}})[_0x4f20('0x1e')](handleEntityNotFound(_0x57d74f,null))[_0x4f20('0x1e')](function(_0xb6e92c){if(_0xb6e92c){return _0xb6e92c[_0x4f20('0x6d')](_0x5ec17d['body'][_0x4f20('0x6c')],_[_0x4f20('0x6f')](_0x5ec17d[_0x4f20('0x5e')],[_0x4f20('0x6c'),'id'])||{});}})[_0x4f20('0x1e')](respondWithResult(_0x57d74f,null))[_0x4f20('0x27')](handleError(_0x57d74f,null));};exports[_0x4f20('0x70')]=function(_0x550e3f,_0x49e76c,_0x4a8e9a){var _0x5b5822={'raw':![],'where':{}};var _0x518d77={};var _0x416af1={'count':0x0,'rows':[]};return db[_0x4f20('0x3d')][_0x4f20('0x63')]({'where':{'id':_0x550e3f['params']['id']}})[_0x4f20('0x1e')](handleEntityNotFound(_0x49e76c,null))[_0x4f20('0x1e')](function(_0x4e1677){if(_0x4e1677){_0x518d77[_0x4f20('0x40')]=_['keys'](db[_0x4f20('0x6e')][_0x4f20('0x55')]);_0x518d77[_0x4f20('0x41')]=_[_0x4f20('0x42')](_0x550e3f[_0x4f20('0x41')]);_0x518d77[_0x4f20('0x43')]=_[_0x4f20('0x45')](_0x518d77[_0x4f20('0x40')],_0x518d77[_0x4f20('0x41')]);_0x5b5822[_0x4f20('0x44')]=_[_0x4f20('0x45')](_0x518d77[_0x4f20('0x40')],qs[_0x4f20('0x46')](_0x550e3f['query'][_0x4f20('0x46')]));_0x5b5822[_0x4f20('0x44')]=_0x5b5822['attributes'][_0x4f20('0x64')]?_0x5b5822[_0x4f20('0x44')]:_0x518d77[_0x4f20('0x40')];if(!_0x550e3f[_0x4f20('0x41')][_0x4f20('0x47')](_0x4f20('0x48'))){_0x5b5822[_0x4f20('0x2d')]=qs[_0x4f20('0x2d')](_0x550e3f['query'][_0x4f20('0x2d')]);_0x5b5822[_0x4f20('0x2b')]=qs[_0x4f20('0x2b')](_0x550e3f[_0x4f20('0x41')][_0x4f20('0x2b')]);}_0x5b5822[_0x4f20('0x49')]=qs[_0x4f20('0x4a')](_0x550e3f[_0x4f20('0x41')][_0x4f20('0x4a')]);_0x5b5822[_0x4f20('0x4b')]=qs['filters'](_[_0x4f20('0x4c')](_0x550e3f[_0x4f20('0x41')],_0x518d77[_0x4f20('0x43')]));_0x5b5822['where']['FaxAccountId']=_0x4e1677['id'];if(_0x550e3f[_0x4f20('0x41')][_0x4f20('0x4d')]){_0x5b5822['where']=_[_0x4f20('0x4e')](_0x5b5822[_0x4f20('0x4b')],{'$or':_[_0x4f20('0x3c')](_0x5b5822[_0x4f20('0x44')],function(_0x15eb05){var _0x2454e9={};_0x2454e9[_0x15eb05]={'$like':'%'+_0x550e3f[_0x4f20('0x41')][_0x4f20('0x4d')]+'%'};return _0x2454e9;})});}_0x5b5822=_[_0x4f20('0x4e')]({},_0x5b5822,_0x550e3f[_0x4f20('0x65')]);return db[_0x4f20('0x6e')][_0x4f20('0x2e')]({'where':_0x5b5822[_0x4f20('0x4b')]})[_0x4f20('0x1e')](function(_0x39c395){_0x416af1[_0x4f20('0x2e')]=_0x39c395;if(_0x550e3f[_0x4f20('0x41')][_0x4f20('0x66')]){_0x5b5822[_0x4f20('0x50')]=[{'model':db[_0x4f20('0x71')],'as':_0x4f20('0x72'),'required':![]},{'model':db[_0x4f20('0x73')],'as':_0x4f20('0x74'),'attributes':[_0x4f20('0x39'),_0x4f20('0x75'),'internal'],'required':![]},{'model':db[_0x4f20('0x76')],'as':'Tags','attributes':['id',_0x4f20('0x39'),_0x4f20('0x77')],'where':_0x550e3f[_0x4f20('0x41')][_0x4f20('0x78')]?{'id':_0x550e3f[_0x4f20('0x41')][_0x4f20('0x78')]}:undefined,'required':_0x550e3f[_0x4f20('0x41')][_0x4f20('0x78')]?!![]:![]}];}return db[_0x4f20('0x6e')][_0x4f20('0x51')](_0x5b5822);})[_0x4f20('0x1e')](function(_0x540fdb){_0x416af1['rows']=_0x540fdb;return _0x416af1;});}})['then'](respondWithFilteredResult(_0x49e76c,_0x5b5822))['catch'](handleError(_0x49e76c,null));};exports[_0x4f20('0x79')]=function(_0x1e39f7,_0x141e79){var _0x1c8ce6=_0x1e39f7[_0x4f20('0x54')]['id'];var _0x105fca=_0x1e39f7[_0x4f20('0x5e')];var _0xb30c6d=0xc8;var _0x83682f=null;return db['sequelize'][_0x4f20('0x7a')]({'isolationLevel':db[_0x4f20('0x7b')]['Transaction']['ISOLATION_LEVELS'][_0x4f20('0x7c')]},function(_0x284e5e){return db[_0x4f20('0x3d')]['findOne']({'where':{'id':_0x1c8ce6},'transaction':_0x284e5e})[_0x4f20('0x1e')](function(_0x1502fc){if(_0x1502fc){return db[_0x4f20('0x7d')][_0x4f20('0x34')]({'where':{'FaxAccountId':_0x1c8ce6},'transaction':_0x284e5e})[_0x4f20('0x1e')](function(){var _0x58dac1=_['map'](_0x105fca,function(_0x533a36){_0x533a36[_0x4f20('0x5f')]=_0x1c8ce6;return _0x533a36;});return db[_0x4f20('0x7d')][_0x4f20('0x7e')](_0x58dac1,{'transaction':_0x284e5e});});}else{_0xb30c6d=0x194;_0x83682f=[];}});})[_0x4f20('0x1e')](function(){if(_0xb30c6d!==0x194){return db[_0x4f20('0x7d')][_0x4f20('0x7f')]({'where':{'FaxAccountId':_0x1c8ce6},'order':_0x4f20('0x80')})['then'](function(_0x358a61){_0x83682f=_0x358a61;});}})['catch'](function(_0x4a7773){_0xb30c6d=0x1f4;logger[_0x4f20('0x24')](_0x4a7773['stack']);if(_0x4a7773[_0x4f20('0x39')]){delete _0x4a7773[_0x4f20('0x39')];}_0x83682f=_0x4a7773;})[_0x4f20('0x81')](function(){if(_0x83682f===null){_0x141e79[_0x4f20('0x28')](_0xb30c6d);}else{if(_0xb30c6d===0x1f4){_0x141e79[_0x4f20('0x29')](_0xb30c6d)[_0x4f20('0x82')](_0x83682f);}else{_0x141e79['status'](_0xb30c6d)[_0x4f20('0x83')](_0x83682f);}}});};exports[_0x4f20('0x84')]=function(_0x30030a,_0x58b76a,_0x3e0eb3){var _0x353097={};var _0x4aee4f={};var _0x4f6d7b;var _0x107961;return db[_0x4f20('0x3d')][_0x4f20('0x63')]({'where':{'id':_0x30030a['params']['id']}})['then'](handleEntityNotFound(_0x58b76a,null))[_0x4f20('0x1e')](function(_0x5892aa){if(_0x5892aa){_0x4f6d7b=_0x5892aa;_0x4aee4f[_0x4f20('0x40')]=_['keys'](db[_0x4f20('0x7d')][_0x4f20('0x55')]);_0x4aee4f[_0x4f20('0x41')]=_[_0x4f20('0x42')](_0x30030a['query']);_0x4aee4f[_0x4f20('0x43')]=_['intersection'](_0x4aee4f[_0x4f20('0x40')],_0x4aee4f[_0x4f20('0x41')]);_0x353097['attributes']=_['intersection'](_0x4aee4f['model'],qs[_0x4f20('0x46')](_0x30030a[_0x4f20('0x41')]['fields']));_0x353097[_0x4f20('0x44')]=_0x353097[_0x4f20('0x44')][_0x4f20('0x64')]?_0x353097[_0x4f20('0x44')]:_0x4aee4f[_0x4f20('0x40')];_0x353097['order']=qs['sort'](_0x30030a[_0x4f20('0x41')][_0x4f20('0x4a')]);_0x353097[_0x4f20('0x4b')]=qs[_0x4f20('0x43')](_['pick'](_0x30030a[_0x4f20('0x41')],_0x4aee4f[_0x4f20('0x43')]));if(_0x30030a['query'][_0x4f20('0x4d')]){_0x353097[_0x4f20('0x4b')]=_['merge'](_0x353097[_0x4f20('0x4b')],{'$or':_[_0x4f20('0x3c')](_0x353097[_0x4f20('0x44')],function(_0x23a9b7){var _0x53f67e={};_0x53f67e[_0x23a9b7]={'$like':'%'+_0x30030a[_0x4f20('0x41')][_0x4f20('0x4d')]+'%'};return _0x53f67e;})});}_0x353097=_[_0x4f20('0x4e')]({},_0x353097,_0x30030a[_0x4f20('0x65')]);return _0x4f6d7b['getApplications'](_0x353097);}})['then'](function(_0x1c670d){if(_0x1c670d){_0x107961=_0x1c670d['length'];if(!_0x30030a[_0x4f20('0x41')][_0x4f20('0x47')](_0x4f20('0x48'))){_0x353097[_0x4f20('0x2d')]=qs['limit'](_0x30030a[_0x4f20('0x41')][_0x4f20('0x2d')]);_0x353097[_0x4f20('0x2b')]=qs[_0x4f20('0x2b')](_0x30030a[_0x4f20('0x41')][_0x4f20('0x2b')]);}return _0x4f6d7b[_0x4f20('0x84')](_0x353097);}})['then'](function(_0x3e5797){if(_0x3e5797){return _0x3e5797?{'count':_0x107961,'rows':_0x3e5797}:null;}})[_0x4f20('0x1e')](respondWithResult(_0x58b76a,null))[_0x4f20('0x27')](handleError(_0x58b76a,null));};function Extension(_0x588f84,_0x4e1a4d,_0x2f69ef,_0x178f6d){this[_0x4f20('0x85')]=_0x4f20('0x86');this[_0x4f20('0x87')]=_0x588f84[_0x4f20('0x88')];this[_0x4f20('0x89')]=_0x178f6d;this[_0x4f20('0x3e')]=_0x4f20('0x8a');this[_0x4f20('0x8b')]=_0x4f20('0x8c');this[_0x4f20('0x5f')]=_0x588f84['id'];this[_0x4f20('0x80')]=_0x4e1a4d;this[_0x4f20('0x8d')]=_0x2f69ef;}function createExtensionsReciveFax(_0x45c574){var _0x5ec4c9=0x1;var _0x1ea725=[];_0x1ea725[_0x4f20('0x8e')](new Extension(_0x45c574,_0x5ec4c9,'','Answer'));_0x5ec4c9+=0x1;_0x1ea725['push'](new Extension(_0x45c574,_0x5ec4c9,_0x4f20('0x8f'),'Set'));_0x5ec4c9+=0x1;for(var _0x10c8d5 in _0x45c574){if(_0x45c574['hasOwnProperty'](_0x10c8d5)&&(_0x10c8d5===_0x4f20('0x90')||_0x10c8d5===_0x4f20('0x88')||_0x10c8d5===_0x4f20('0x91')||_0x10c8d5==='faxdetect'||_0x10c8d5===_0x4f20('0x92')||_0x10c8d5===_0x4f20('0x93')||_0x10c8d5===_0x4f20('0x94')||_0x10c8d5==='modem'||_0x10c8d5===_0x4f20('0x95'))){_0x1ea725[_0x4f20('0x8e')](new Extension(_0x45c574,_0x5ec4c9,_0x4f20('0x96')+_0x10c8d5+')='+_0x45c574[_0x10c8d5],'Set'));_0x5ec4c9+=0x1;}}_0x1ea725[_0x4f20('0x8e')](new Extension(_0x45c574,_0x5ec4c9,'6',_0x4f20('0x97')));_0x5ec4c9+=0x1;_0x1ea725[_0x4f20('0x8e')](new Extension(_0x45c574,_0x5ec4c9,_0x4f20('0x98'),_0x4f20('0x99')));_0x5ec4c9=0x0;return _0x1ea725;}exports[_0x4f20('0x9a')]=function(_0x1a6ebf,_0x48d457,_0x2b15e5){var _0x11ca78;return db['sequelize'][_0x4f20('0x7a')](function(_0x43166e){return db[_0x4f20('0x3d')][_0x4f20('0x61')](_0x1a6ebf[_0x4f20('0x5e')],{'transaction':_0x43166e})[_0x4f20('0x1e')](function(_0x380eb8){_0x11ca78=_0x380eb8[_0x4f20('0x35')]({'plain':!![]});return db[_0x4f20('0x9b')][_0x4f20('0x7e')](createExtensionsReciveFax(_0x11ca78),{'transaction':_0x43166e});});})[_0x4f20('0x1e')](function(){return _0x11ca78;})[_0x4f20('0x1e')](respondWithResult(_0x48d457,null))[_0x4f20('0x27')](handleError(_0x48d457,null));};exports[_0x4f20('0x9c')]=function(_0x471ad5,_0x5bc76c,_0x2779db){var _0x26a9f3;return db[_0x4f20('0x7b')][_0x4f20('0x7a')](function(_0x136ed6){return db['FaxAccount']['update'](_0x471ad5[_0x4f20('0x5e')],{'where':{'id':_0x471ad5['body']['id']},'transaction':_0x136ed6})[_0x4f20('0x1e')](function(_0x3925f5){return db[_0x4f20('0x9b')]['destroy']({'where':{'FaxAccountId':_0x471ad5[_0x4f20('0x5e')]['id']},'transaction':_0x136ed6})[_0x4f20('0x1e')](function(_0x39aaf4){return db[_0x4f20('0x9b')][_0x4f20('0x7e')](createExtensionsReciveFax(_[_0x4f20('0x6f')](_0x471ad5[_0x4f20('0x5e')],[_0x4f20('0x9d'),_0x4f20('0x3f'),_0x4f20('0x9e'),'updatedAt',_0x4f20('0x9f'),_0x4f20('0xa0')])),{'transaction':_0x136ed6});});});})[_0x4f20('0x1e')](function(){return db[_0x4f20('0x3d')][_0x4f20('0xa1')](_0x471ad5['body']['id']);})[_0x4f20('0x1e')](respondWithResult(_0x5bc76c,null))[_0x4f20('0x27')](handleError(_0x5bc76c,null));};exports[_0x4f20('0xa2')]=function(_0x4046e3,_0x1ed6f8,_0x31440a){var _0x1ada15={'raw':!![],'where':{}};var _0x1bb100={};var _0x8f6cae={'count':0x0,'rows':[]};return db['FaxAccount'][_0x4f20('0x63')]({'where':{'id':_0x4046e3[_0x4f20('0x54')]['id']}})['then'](handleEntityNotFound(_0x1ed6f8,null))[_0x4f20('0x1e')](function(_0x539d1b){if(_0x539d1b){_0x1bb100[_0x4f20('0x40')]=_[_0x4f20('0x42')](db[_0x4f20('0xa3')]['rawAttributes']);_0x1bb100[_0x4f20('0x41')]=_['keys'](_0x4046e3[_0x4f20('0x41')]);_0x1bb100['filters']=_['intersection'](_0x1bb100[_0x4f20('0x40')],_0x1bb100[_0x4f20('0x41')]);_0x1ada15[_0x4f20('0x44')]=_[_0x4f20('0x45')](_0x1bb100[_0x4f20('0x40')],qs[_0x4f20('0x46')](_0x4046e3[_0x4f20('0x41')][_0x4f20('0x46')]));_0x1ada15[_0x4f20('0x44')]=_0x1ada15['attributes'][_0x4f20('0x64')]?_0x1ada15['attributes']:_0x1bb100[_0x4f20('0x40')];if(!_0x4046e3['query'][_0x4f20('0x47')]('nolimit')){_0x1ada15[_0x4f20('0x2d')]=qs[_0x4f20('0x2d')](_0x4046e3[_0x4f20('0x41')][_0x4f20('0x2d')]);_0x1ada15['offset']=qs['offset'](_0x4046e3[_0x4f20('0x41')][_0x4f20('0x2b')]);}_0x1ada15['order']=qs[_0x4f20('0x4a')](_0x4046e3[_0x4f20('0x41')][_0x4f20('0x4a')]);_0x1ada15['where']=qs['filters'](_[_0x4f20('0x4c')](_0x4046e3['query'],_0x1bb100['filters']));_0x1ada15['where'][_0x4f20('0x5f')]=_0x539d1b['id'];if(_0x4046e3[_0x4f20('0x41')][_0x4f20('0x4d')]){_0x1ada15[_0x4f20('0x4b')]=_[_0x4f20('0x4e')](_0x1ada15[_0x4f20('0x4b')],{'$or':_['map'](_0x1ada15[_0x4f20('0x44')],function(_0x4b009d){var _0x4d9ea7={};_0x4d9ea7[_0x4b009d]={'$like':'%'+_0x4046e3['query'][_0x4f20('0x4d')]+'%'};return _0x4d9ea7;})});}if(_0x4046e3[_0x4f20('0x41')]['$gte']){var _0x2de1b4=_0x4046e3[_0x4f20('0x41')][_0x4f20('0xa4')][_0x4f20('0xa5')](',');var _0x3203ce={};_0x3203ce[_0x2de1b4[0x0]]={'$gte':moment(_0x2de1b4[0x1])[_0x4f20('0xa6')](_0x4f20('0xa7'))};_0x1ada15['where']=_[_0x4f20('0x4e')](_0x1ada15[_0x4f20('0x4b')],_0x3203ce);}_0x1ada15=_['merge']({},_0x1ada15,_0x4046e3['options']);return db[_0x4f20('0xa3')]['count']({'where':_0x1ada15[_0x4f20('0x4b')]})[_0x4f20('0x1e')](function(_0x3e0df7){_0x8f6cae['count']=_0x3e0df7;if(_0x4046e3['query'][_0x4f20('0x66')]){_0x1ada15[_0x4f20('0x50')]=[{'all':!![]}];}return db[_0x4f20('0xa3')][_0x4f20('0x51')](_0x1ada15);})[_0x4f20('0x1e')](function(_0x4b3365){_0x8f6cae[_0x4f20('0x52')]=_0x4b3365;return _0x8f6cae;});}})['then'](respondWithFilteredResult(_0x1ed6f8,_0x1ada15))[_0x4f20('0x27')](handleError(_0x1ed6f8,null));};exports[_0x4f20('0x82')]=function(_0x349108,_0x534630,_0x1fe1e0){var _0x4f8bbd,_0x4e4820={},_0x58337c;if(_0x349108[_0x4f20('0x5e')]['to']){_0x58337c=_0x349108[_0x4f20('0x5e')]['to'][0x0];}return db['FaxAccount'][_0x4f20('0x56')]({'where':{'id':_0x349108[_0x4f20('0x54')]['id']},'include':[{'model':db['CmList'],'as':_0x4f20('0xa8'),'include':[{'model':db[_0x4f20('0x71')],'as':'Contacts','where':{'fax':_0x58337c},'limit':0x1,'order':[[_0x4f20('0xa9'),'DESC']]}]}]})[_0x4f20('0x1e')](handleEntityNotFound(_0x534630,null))['then'](function(_0x74e13b){_0x4f8bbd=_0x74e13b;if(_0x349108[_0x4f20('0x5e')]['attachments']&&_0x349108[_0x4f20('0x5e')][_0x4f20('0xaa')][_0x4f20('0x64')]){for(var _0x622ab2=0x0;_0x622ab2<_0x349108[_0x4f20('0x5e')][_0x4f20('0xaa')]['length'];_0x622ab2+=0x1){_0x349108[_0x4f20('0x5e')][_0x4f20('0xaa')][_0x622ab2]={'filename':_0x349108[_0x4f20('0x5e')][_0x4f20('0xaa')][_0x622ab2][_0x4f20('0x39')],'id':_0x349108[_0x4f20('0x5e')]['attachments'][_0x622ab2]['id'],'path':path[_0x4f20('0xab')](config['root'],_0x4f20('0xac'),_0x349108[_0x4f20('0x5e')][_0x4f20('0xaa')][_0x622ab2][_0x4f20('0xad')])};}}return respondWithRpcPromise(_0x4f20('0xae'),_0x4f20('0xae'),{'FaxAccountId':_[_0x4f20('0xaf')](_0x349108[_0x4f20('0x54')]['id'])?undefined:_0x349108['params']['id'],'path':_['isNil'](_0x349108['body']['attachments'][0x0][_0x4f20('0xb0')])?undefined:_0x349108[_0x4f20('0x5e')]['attachments'][0x0][_0x4f20('0xb0')],'fax':_[_0x4f20('0xaf')](_0x349108[_0x4f20('0x5e')]['to'][0x0])?undefined:_0x349108[_0x4f20('0x5e')]['to'][0x0]},client9002);})[_0x4f20('0x1e')](function(){if(_0x4f8bbd){if(_[_0x4f20('0xaf')](_0x349108['body']['from'])){_0x349108[_0x4f20('0x5e')][_0x4f20('0xb1')]=util[_0x4f20('0xa6')]('\x22%s\x22\x20<%s>',_0x4f8bbd['name'],_0x4f8bbd[_0x4f20('0xb2')]);}if(_0x4f8bbd[_0x4f20('0xa8')]){if(_0x4f8bbd[_0x4f20('0xa8')][_0x4f20('0xb3')][_0x4f20('0x64')]){return _0x4f8bbd[_0x4f20('0xa8')][_0x4f20('0xb3')][0x0];}else{return db[_0x4f20('0x71')][_0x4f20('0x61')](_['defaults'](_0x349108[_0x4f20('0x5e')],{'firstName':_0x349108['body']['to'][0x0],'phone':_0x349108['body']['to'][0x0],'fax':_0x349108['body']['to'][0x0],'ListId':_0x4f8bbd[_0x4f20('0xa0')]}));}}else{throw new Error(_0x4f20('0xb4'));}}else{throw new Error(_0x4f20('0xb5'));}})[_0x4f20('0x1e')](function(_0x5ee433){if(_0x5ee433){return db[_0x4f20('0x6e')][_0x4f20('0x56')]({'where':{'ContactId':_0x5ee433['id'],'closed':![],'FaxAccountId':_0x4f8bbd['id']}})['then'](function(_0xfdc424){if(_0xfdc424){return[_0xfdc424,![]];}return db['FaxInteraction'][_0x4f20('0x61')]({'UserId':_0x349108[_0x4f20('0x57')]['id'],'ContactId':_0x5ee433['id'],'FaxAccountId':_0x4f8bbd['id'],'fax':_0x349108[_0x4f20('0x5e')]['to'][0x0],'firstMsgDirection':_0x4f20('0xb6'),'Messages':[_[_0x4f20('0x4e')](_0x349108['body'],{'read':![],'body':_0x349108['body'][_0x4f20('0xaa')][0x0][_0x4f20('0xb7')],'FaxAccountId':_0x4f8bbd['id'],'UserId':_0x349108[_0x4f20('0x57')]['id'],'ContactId':_0x5ee433['id'],'AttachmentId':_0x349108[_0x4f20('0x5e')][_0x4f20('0xaa')][0x0]['id']})]},{'include':[{'model':db[_0x4f20('0xa3')],'as':'Messages'}]})[_0x4f20('0x1e')](function(_0x311651){return[_0x311651,!![]];});});}else{throw new Error('Contact\x20not\x20found');}})[_0x4f20('0xb8')](function(_0x2bc01c,_0x46c6a6){if(_0x46c6a6){return _0x2bc01c;}return db['FaxMessage']['create']({'direction':_0x4f20('0xb6'),'read':![],'body':_0x349108['body'][_0x4f20('0xaa')][0x0][_0x4f20('0xb7')],'FaxAccountId':_0x4f8bbd['id'],'FaxInteractionId':_0x2bc01c['id'],'UserId':_0x349108[_0x4f20('0x57')]['id'],'ContactId':_0x2bc01c['ContactId'],'AttachmentId':_0x349108[_0x4f20('0x5e')][_0x4f20('0xaa')][0x0]['id']})[_0x4f20('0x1e')](function(_0x3fd6f4){_0x2bc01c['dataValues'][_0x4f20('0xb9')]=[];_0x2bc01c['dataValues'][_0x4f20('0xb9')][_0x4f20('0x8e')](_0x3fd6f4[_0x4f20('0xba')]);return _0x2bc01c;});})[_0x4f20('0x1e')](function(_0x432aed){respondWithRpcPromise(_0x4f20('0xbb'),_0x4f20('0xbb'),{'FaxAccountId':_['isNil'](_0x349108[_0x4f20('0x54')]['id'])?undefined:_0x349108[_0x4f20('0x54')]['id'],'path':_[_0x4f20('0xaf')](_0x349108[_0x4f20('0x5e')][_0x4f20('0xaa')][0x0][_0x4f20('0xb0')])?undefined:_0x349108[_0x4f20('0x5e')][_0x4f20('0xaa')][0x0][_0x4f20('0xb0')],'fax':_['isNil'](_0x349108[_0x4f20('0x5e')]['to'][0x0])?undefined:_0x349108[_0x4f20('0x5e')]['to'][0x0],'AttachmentId':_0x349108[_0x4f20('0x5e')][_0x4f20('0xaa')][0x0]['id']},client9002)['then'](function(_0x31b529){logger[_0x4f20('0x1f')]('SendFaxRpc,\x20%s',_0x31b529);})[_0x4f20('0x27')](function(_0x5657dd){logger[_0x4f20('0x1f')](_0x4f20('0xbc'),_0x5657dd);});return _0x432aed;})['then'](respondWithResult(_0x534630,null))[_0x4f20('0x27')](handleError(_0x534630,null));};exports['addAgents']=function(_0x46da63,_0x3d6c4a,_0x5bf26e){return db['FaxAccount'][_0x4f20('0x56')]({'where':{'id':_0x46da63[_0x4f20('0x54')]['id']}})['then'](handleEntityNotFound(_0x3d6c4a,null))[_0x4f20('0x1e')](function(_0x4cdb34){if(_0x4cdb34){return _0x4cdb34[_0x4f20('0xbd')](_0x46da63[_0x4f20('0x5e')][_0x4f20('0x6c')],_[_0x4f20('0x6f')](_0x46da63[_0x4f20('0x5e')],[_0x4f20('0x6c'),'id'])||{})[_0x4f20('0xb8')](function(_0x1b1e9f){for(var _0x314e70=0x0;_0x314e70<_0x46da63[_0x4f20('0x5e')]['ids'][_0x4f20('0x64')];_0x314e70+=0x1){socket[_0x4f20('0xbe')](_0x4f20('0xbf'),{'UserId':Number(_0x46da63[_0x4f20('0x5e')]['ids'][_0x314e70]),'FaxAccountId':Number(_0x46da63[_0x4f20('0x54')]['id'])});}return _0x1b1e9f;});}})['then'](respondWithResult(_0x3d6c4a,null))[_0x4f20('0x27')](handleError(_0x3d6c4a,null));};exports[_0x4f20('0xc0')]=function(_0x1ca453,_0x2dfa97,_0x50ae84){return db[_0x4f20('0x3d')]['find']({'where':{'id':_0x1ca453['params']['id']}})[_0x4f20('0x1e')](handleEntityNotFound(_0x2dfa97,null))[_0x4f20('0x1e')](function(_0x27f284){if(_0x27f284){return _0x27f284[_0x4f20('0xc0')](_0x1ca453[_0x4f20('0x41')][_0x4f20('0x6c')])[_0x4f20('0x1e')](function(){if(_[_0x4f20('0xc1')](_0x1ca453[_0x4f20('0x41')]['ids'])){for(var _0x595cf9=0x0;_0x595cf9<_0x1ca453['query'][_0x4f20('0x6c')][_0x4f20('0x64')];_0x595cf9+=0x1){socket['emit'](_0x4f20('0xc2'),{'UserId':Number(_0x1ca453[_0x4f20('0x41')][_0x4f20('0x6c')][_0x595cf9]),'FaxAccountId':Number(_0x1ca453[_0x4f20('0x54')]['id'])});}}else{socket['emit'](_0x4f20('0xc2'),{'UserId':Number(_0x1ca453[_0x4f20('0x41')]['ids']),'FaxAccountId':Number(_0x1ca453[_0x4f20('0x54')]['id'])});}});}})[_0x4f20('0x1e')](respondWithStatusCode(_0x2dfa97,null))[_0x4f20('0x27')](handleError(_0x2dfa97,null));};exports['getAgents']=function(_0x51397c,_0x4e50ab,_0x1a506b){var _0x3509b7={};var _0x2fbf21={};var _0x2986f4;var _0x20554d;return db[_0x4f20('0x3d')][_0x4f20('0x63')]({'where':{'id':_0x51397c[_0x4f20('0x54')]['id']}})[_0x4f20('0x1e')](handleEntityNotFound(_0x4e50ab,null))[_0x4f20('0x1e')](function(_0x1865a9){if(_0x1865a9){_0x2986f4=_0x1865a9;_0x2fbf21[_0x4f20('0x40')]=_['keys'](db[_0x4f20('0x73')][_0x4f20('0x55')]);_0x2fbf21[_0x4f20('0x41')]=_['keys'](_0x51397c[_0x4f20('0x41')]);_0x2fbf21['filters']=_['intersection'](_0x2fbf21[_0x4f20('0x40')],_0x2fbf21['query']);_0x3509b7[_0x4f20('0x44')]=_['intersection'](_0x2fbf21[_0x4f20('0x40')],qs[_0x4f20('0x46')](_0x51397c[_0x4f20('0x41')]['fields']));_0x3509b7[_0x4f20('0x44')]=_0x3509b7[_0x4f20('0x44')][_0x4f20('0x64')]?_0x3509b7[_0x4f20('0x44')]:_0x2fbf21[_0x4f20('0x40')];_0x3509b7['order']=qs[_0x4f20('0x4a')](_0x51397c[_0x4f20('0x41')][_0x4f20('0x4a')]);_0x3509b7[_0x4f20('0x4b')]=qs[_0x4f20('0x43')](_[_0x4f20('0x4c')](_0x51397c[_0x4f20('0x41')],_0x2fbf21[_0x4f20('0x43')]));if(_0x51397c['query'][_0x4f20('0x4d')]){_0x3509b7['where']=_['merge'](_0x3509b7['where'],{'$or':_[_0x4f20('0x3c')](_0x3509b7[_0x4f20('0x44')],function(_0x73f32d){var _0x2486dc={};_0x2486dc[_0x73f32d]={'$like':'%'+_0x51397c[_0x4f20('0x41')][_0x4f20('0x4d')]+'%'};return _0x2486dc;})});}_0x3509b7=_['merge']({},_0x3509b7,_0x51397c[_0x4f20('0x65')]);return _0x2986f4[_0x4f20('0xc3')](_0x3509b7);}})['then'](function(_0x138ba1){if(_0x138ba1){_0x20554d=_0x138ba1[_0x4f20('0x64')];if(!_0x51397c[_0x4f20('0x41')]['hasOwnProperty']('nolimit')){_0x3509b7[_0x4f20('0x2d')]=qs[_0x4f20('0x2d')](_0x51397c[_0x4f20('0x41')][_0x4f20('0x2d')]);_0x3509b7[_0x4f20('0x2b')]=qs['offset'](_0x51397c['query'][_0x4f20('0x2b')]);}return _0x2986f4[_0x4f20('0xc3')](_0x3509b7);}})['then'](function(_0x38d8e2){if(_0x38d8e2){return _0x38d8e2?{'count':_0x20554d,'rows':_0x38d8e2}:null;}})[_0x4f20('0x1e')](respondWithResult(_0x4e50ab,null))[_0x4f20('0x27')](handleError(_0x4e50ab,null));};