Built motion from commit 44b1f254.|2.6.26
[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 _0x63f4=['intersection','fields','attributes','length','nolimit','order','sort','where','pick','filter','merge','options','FaxAccount','includeAll','include','findAll','rows','params','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','find','describe','addDisposition','FaxAccountId','Disposition','getDispositions','hasOwnProperty','removeDispositions','addAnswer','findOne','CannedAnswer','removeAnswers','addInteraction','FaxInteraction','ids','getInteractions','CmContact','User','Owner','internal','Tag','Tags','color','tag','addApplications','sequelize','Transaction','FaxApplication','bulkCreate','findAndCountAll','priority','finally','getApplications','exten','localstationid','system','description','Fax\x20Extension','appdata','push','CDR(type)=inbound-fax','Set','gateway','faxdetect','minrate','t38timeout','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','VoiceExtension','transaction','createdAt','updatedAt','TrunkId','ListId','findById','getMessages','FaxMessage','$gte','format','Contacts','attachments','join','root','CheckAfterSend','isNil','fax','List','Send\x20Fax\x20failed','out','Contact\x20not\x20found','spread','ContactId','dataValues','Messages','SendFax','SendFaxRpc,\x20%s','addAgents','omit','removeAgents','userFaxAccount:remove','getAgents','eml-format','rimraf','fast-json-patch','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','defaults','redis','localhost','socket.io-emitter','./faxAccount.socket','register','jayson/promise','client','http','request','then','info','FaxAccount,\x20%s,\x20%s','request\x20sent','debug','FaxAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','end','status','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','update','destroy','FaxAccounts','stack','name','send','Pause','mandatoryDispositionPause','map','rawAttributes','fieldName','type','key','model','keys','query','filters'];(function(_0x152fff,_0x29c6c2){var _0x590d92=function(_0x39cd34){while(--_0x39cd34){_0x152fff['push'](_0x152fff['shift']());}};_0x590d92(++_0x29c6c2);}(_0x63f4,0x126));var _0x463f=function(_0x2a334c,_0x37c111){_0x2a334c=_0x2a334c-0x0;var _0x5ad593=_0x63f4[_0x2a334c];return _0x5ad593;};'use strict';var emlformat=require(_0x463f('0x0'));var rimraf=require(_0x463f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x463f('0x2'));var rp=require('request-promise');var moment=require(_0x463f('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x463f('0x4'));var util=require(_0x463f('0x5'));var path=require(_0x463f('0x6'));var sox=require(_0x463f('0x7'));var csv=require(_0x463f('0x8'));var ejs=require(_0x463f('0x9'));var fs=require('fs');var fs_extra=require(_0x463f('0xa'));var _=require(_0x463f('0xb'));var squel=require('squel');var crypto=require(_0x463f('0xc'));var jsforce=require(_0x463f('0xd'));var deskjs=require(_0x463f('0xe'));var toCsv=require(_0x463f('0x8'));var querystring=require(_0x463f('0xf'));var Papa=require(_0x463f('0x10'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x463f('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x463f('0x12'));var logger=require(_0x463f('0x13'))('api');var utils=require(_0x463f('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0x463f('0x15'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x463f('0x16')](config[_0x463f('0x17')],{'host':_0x463f('0x18'),'port':0x18eb});var socket=require(_0x463f('0x19'))(new Redis(config[_0x463f('0x17')]));require(_0x463f('0x1a'))[_0x463f('0x1b')](socket);var jayson=require(_0x463f('0x1c'));var client=jayson[_0x463f('0x1d')][_0x463f('0x1e')]({'port':0x232c});var client9002=jayson[_0x463f('0x1d')][_0x463f('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x55d467,_0x3bd02e,_0x235240,_0x5d2645){return new BPromise(function(_0x28da10,_0x115b72){var _0x11924b=_0x5d2645||client;return _0x11924b[_0x463f('0x1f')](_0x55d467,_0x235240)[_0x463f('0x20')](function(_0x3ecc99){logger[_0x463f('0x21')](_0x463f('0x22'),_0x3bd02e,_0x463f('0x23'));logger[_0x463f('0x24')](_0x463f('0x25'),_0x3bd02e,'request\x20sent',JSON[_0x463f('0x26')](_0x3ecc99));if(_0x3ecc99[_0x463f('0x27')]){if(_0x3ecc99['error'][_0x463f('0x28')]===0x1f4){logger[_0x463f('0x27')](_0x463f('0x22'),_0x3bd02e,_0x3ecc99[_0x463f('0x27')]['message']);return _0x115b72(_0x3ecc99['error'][_0x463f('0x29')]);}logger[_0x463f('0x27')](_0x463f('0x22'),_0x3bd02e,_0x3ecc99['error'][_0x463f('0x29')]);return _0x28da10(_0x3ecc99['error']['message']);}else{logger[_0x463f('0x21')](_0x463f('0x22'),_0x3bd02e,_0x463f('0x23'));_0x28da10(_0x3ecc99[_0x463f('0x2a')][_0x463f('0x29')]);}})[_0x463f('0x2b')](function(_0x53ced7){logger['error']('FaxAccount,\x20%s,\x20%s',_0x3bd02e,_0x53ced7);_0x115b72(_0x53ced7);});});}function respondWithStatusCode(_0x3f3a26,_0x4ccd88){_0x4ccd88=_0x4ccd88||0xcc;return function(_0x20cb20){if(_0x20cb20){return _0x3f3a26[_0x463f('0x2c')](_0x4ccd88);}return _0x3f3a26['status'](_0x4ccd88)[_0x463f('0x2d')]();};}function respondWithResult(_0x5e3fd0,_0x4b9588){_0x4b9588=_0x4b9588||0xc8;return function(_0x30c1fa){if(_0x30c1fa){return _0x5e3fd0[_0x463f('0x2e')](_0x4b9588)[_0x463f('0x2f')](_0x30c1fa);}};}function respondWithFilteredResult(_0x9f70ac,_0x4c13cc){return function(_0x3cc970){if(_0x3cc970){var _0x301387=typeof _0x4c13cc[_0x463f('0x30')]===_0x463f('0x31')&&typeof _0x4c13cc['limit']===_0x463f('0x31');var _0x1940d4=_0x3cc970[_0x463f('0x32')];var _0x3dace0=_0x301387?0x0:_0x4c13cc[_0x463f('0x30')];var _0x37ab05=_0x301387?_0x3cc970[_0x463f('0x32')]:_0x4c13cc['offset']+_0x4c13cc[_0x463f('0x33')];var _0xf4b88f;if(_0x37ab05>=_0x1940d4){_0x37ab05=_0x1940d4;_0xf4b88f=0xc8;}else{_0xf4b88f=0xce;}_0x9f70ac['status'](_0xf4b88f);return _0x9f70ac[_0x463f('0x34')](_0x463f('0x35'),_0x3dace0+'-'+_0x37ab05+'/'+_0x1940d4)[_0x463f('0x2f')](_0x3cc970);}return null;};}function patchUpdates(_0x17d1a9){return function(_0x2c5277){try{jsonpatch[_0x463f('0x36')](_0x2c5277,_0x17d1a9,!![]);}catch(_0x42f8c2){return BPromise[_0x463f('0x37')](_0x42f8c2);}return _0x2c5277[_0x463f('0x38')]();};}function saveUpdates(_0x5848e7,_0xec6190){return function(_0x1253b3){if(_0x1253b3){return _0x1253b3[_0x463f('0x39')](_0x5848e7)[_0x463f('0x20')](function(_0x12f631){return _0x12f631;});}return null;};}function removeEntity(_0x291982,_0x461508){return function(_0x38363b){if(_0x38363b){return _0x38363b[_0x463f('0x3a')]()['then'](function(){var _0x1e919f=_0x38363b['get']({'plain':!![]});var _0x19dc14=_0x463f('0x3b');return db['UserProfileResource'][_0x463f('0x3a')]({'where':{'type':_0x19dc14,'resourceId':_0x1e919f['id']}})[_0x463f('0x20')](function(){return _0x38363b;});})[_0x463f('0x20')](function(){_0x291982[_0x463f('0x2e')](0xcc)[_0x463f('0x2d')]();});}};}function handleEntityNotFound(_0x31d8f4,_0x3da403){return function(_0x525c91){if(!_0x525c91){_0x31d8f4[_0x463f('0x2c')](0x194);}return _0x525c91;};}function handleError(_0x83115f,_0x5763ec){_0x5763ec=_0x5763ec||0x1f4;return function(_0x250104){logger['error'](_0x250104[_0x463f('0x3c')]);if(_0x250104[_0x463f('0x3d')]){delete _0x250104['name'];}_0x83115f['status'](_0x5763ec)[_0x463f('0x3e')](_0x250104);};}exports['index']=function(_0x4cdb5e,_0x51e3ea){var _0x2ea9d5={'include':[{'model':db[_0x463f('0x3f')],'as':_0x463f('0x40')}]},_0x3036ce={},_0x5b9c54={'count':0x0,'rows':[]};var _0x42052a=_[_0x463f('0x41')](db['FaxAccount'][_0x463f('0x42')],function(_0x4359e0){return{'name':_0x4359e0[_0x463f('0x43')],'type':_0x4359e0[_0x463f('0x44')][_0x463f('0x45')]};});_0x3036ce[_0x463f('0x46')]=_['map'](_0x42052a,'name');_0x3036ce['query']=_[_0x463f('0x47')](_0x4cdb5e[_0x463f('0x48')]);_0x3036ce[_0x463f('0x49')]=_[_0x463f('0x4a')](_0x3036ce['model'],_0x3036ce['query']);_0x2ea9d5['attributes']=_[_0x463f('0x4a')](_0x3036ce['model'],qs[_0x463f('0x4b')](_0x4cdb5e['query']['fields']));_0x2ea9d5[_0x463f('0x4c')]=_0x2ea9d5[_0x463f('0x4c')][_0x463f('0x4d')]?_0x2ea9d5['attributes']:_0x3036ce['model'];if(!_0x4cdb5e['query']['hasOwnProperty'](_0x463f('0x4e'))){_0x2ea9d5[_0x463f('0x33')]=qs[_0x463f('0x33')](_0x4cdb5e['query'][_0x463f('0x33')]);_0x2ea9d5[_0x463f('0x30')]=qs[_0x463f('0x30')](_0x4cdb5e['query']['offset']);}_0x2ea9d5[_0x463f('0x4f')]=qs[_0x463f('0x50')](_0x4cdb5e['query'][_0x463f('0x50')]);_0x2ea9d5[_0x463f('0x51')]=qs[_0x463f('0x49')](_[_0x463f('0x52')](_0x4cdb5e['query'],_0x3036ce['filters']),_0x42052a);if(_0x4cdb5e['query'][_0x463f('0x53')]){_0x2ea9d5[_0x463f('0x51')]=_[_0x463f('0x54')](_0x2ea9d5[_0x463f('0x51')],{'$or':_['map'](_0x42052a,function(_0x4700f0){if(_0x4700f0[_0x463f('0x44')]!=='VIRTUAL'){var _0x2b72d7={};_0x2b72d7[_0x4700f0[_0x463f('0x3d')]]={'$like':'%'+_0x4cdb5e[_0x463f('0x48')][_0x463f('0x53')]+'%'};return _0x2b72d7;}})});}_0x2ea9d5=_[_0x463f('0x54')]({},_0x2ea9d5,_0x4cdb5e[_0x463f('0x55')]);var _0x51e5bd={'where':_0x2ea9d5[_0x463f('0x51')]};return db[_0x463f('0x56')][_0x463f('0x32')](_0x51e5bd)[_0x463f('0x20')](function(_0x530562){_0x5b9c54[_0x463f('0x32')]=_0x530562;if(_0x4cdb5e[_0x463f('0x48')][_0x463f('0x57')]){_0x2ea9d5[_0x463f('0x58')]=[{'all':!![]}];}return db[_0x463f('0x56')][_0x463f('0x59')](_0x2ea9d5);})[_0x463f('0x20')](function(_0x3ed6f0){_0x5b9c54[_0x463f('0x5a')]=_0x3ed6f0;return _0x5b9c54;})[_0x463f('0x20')](respondWithFilteredResult(_0x51e3ea,_0x2ea9d5))[_0x463f('0x2b')](handleError(_0x51e3ea,null));};exports['show']=function(_0x3b741f,_0x5d9a49){var _0x108cb1={'raw':![],'where':{'id':_0x3b741f[_0x463f('0x5b')]['id']},'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]},_0x2c1799={};_0x2c1799[_0x463f('0x46')]=_[_0x463f('0x47')](db[_0x463f('0x56')][_0x463f('0x42')]);_0x2c1799['query']=_[_0x463f('0x47')](_0x3b741f[_0x463f('0x48')]);_0x2c1799['filters']=_[_0x463f('0x4a')](_0x2c1799[_0x463f('0x46')],_0x2c1799['query']);_0x108cb1[_0x463f('0x4c')]=_['intersection'](_0x2c1799[_0x463f('0x46')],qs[_0x463f('0x4b')](_0x3b741f[_0x463f('0x48')][_0x463f('0x4b')]));_0x108cb1['attributes']=_0x108cb1[_0x463f('0x4c')][_0x463f('0x4d')]?_0x108cb1['attributes']:_0x2c1799[_0x463f('0x46')];if(_0x3b741f['query'][_0x463f('0x57')]){_0x108cb1[_0x463f('0x58')]=[{'all':!![]}];}_0x108cb1=_[_0x463f('0x54')]({},_0x108cb1,_0x3b741f['options']);return db[_0x463f('0x56')]['find'](_0x108cb1)['then'](handleEntityNotFound(_0x5d9a49,null))[_0x463f('0x20')](respondWithResult(_0x5d9a49,null))[_0x463f('0x2b')](handleError(_0x5d9a49,null));};exports[_0x463f('0x5c')]=function(_0x572036,_0x2b483b){return db[_0x463f('0x56')][_0x463f('0x5c')](_0x572036[_0x463f('0x5d')],{})['then'](function(_0x26b699){var _0x536e9a=_0x572036[_0x463f('0x5e')][_0x463f('0x5f')]({'plain':!![]});if(!_0x536e9a)throw new Error(_0x463f('0x60'));if(_0x536e9a[_0x463f('0x61')]===_0x463f('0x5e')){var _0x556721=_0x26b699[_0x463f('0x5f')]({'plain':!![]});var _0x27e70b=_0x463f('0x3b');return db[_0x463f('0x62')]['find']({'where':{'name':_0x27e70b,'userProfileId':_0x536e9a[_0x463f('0x63')]},'raw':!![]})[_0x463f('0x20')](function(_0x404581){if(_0x404581&&_0x404581[_0x463f('0x64')]===0x0){return db[_0x463f('0x65')][_0x463f('0x5c')]({'name':_0x556721['name'],'resourceId':_0x556721['id'],'type':_0x404581[_0x463f('0x3d')],'sectionId':_0x404581['id']},{})[_0x463f('0x20')](function(){return _0x26b699;});}else{return _0x26b699;}})[_0x463f('0x2b')](function(_0x524bd0){logger[_0x463f('0x27')](_0x463f('0x66'),_0x524bd0);throw _0x524bd0;});}return _0x26b699;})['then'](respondWithResult(_0x2b483b,0xc9))['catch'](handleError(_0x2b483b,null));};exports[_0x463f('0x39')]=function(_0x8bf69e,_0x318ff7){if(_0x8bf69e[_0x463f('0x5d')]['id']){delete _0x8bf69e[_0x463f('0x5d')]['id'];}return db[_0x463f('0x56')][_0x463f('0x67')]({'where':{'id':_0x8bf69e[_0x463f('0x5b')]['id']},'include':[{'model':db[_0x463f('0x3f')],'as':_0x463f('0x40')}]})['then'](handleEntityNotFound(_0x318ff7,null))[_0x463f('0x20')](saveUpdates(_0x8bf69e['body'],null))['then'](respondWithResult(_0x318ff7,null))[_0x463f('0x2b')](handleError(_0x318ff7,null));};exports[_0x463f('0x3a')]=function(_0x55f599,_0x14d1f5){return db[_0x463f('0x56')][_0x463f('0x67')]({'where':{'id':_0x55f599['params']['id']}})['then'](handleEntityNotFound(_0x14d1f5,null))[_0x463f('0x20')](removeEntity(_0x14d1f5,null))[_0x463f('0x2b')](handleError(_0x14d1f5,null));};exports['describe']=function(_0x300252,_0x473472){return db[_0x463f('0x56')][_0x463f('0x68')]()[_0x463f('0x20')](respondWithResult(_0x473472,null))[_0x463f('0x2b')](handleError(_0x473472,null));};exports[_0x463f('0x69')]=function(_0x239519,_0x5352bf,_0x4bbb79){if(_0x239519[_0x463f('0x5d')]['id']){delete _0x239519[_0x463f('0x5d')]['id'];}return db[_0x463f('0x56')][_0x463f('0x67')]({'where':{'id':_0x239519[_0x463f('0x5b')]['id']}})[_0x463f('0x20')](handleEntityNotFound(_0x5352bf,null))[_0x463f('0x20')](function(_0x4bcad2){if(_0x4bcad2){_0x239519['body'][_0x463f('0x6a')]=_0x4bcad2['id'];return db[_0x463f('0x6b')][_0x463f('0x5c')](_0x239519[_0x463f('0x5d')]);}})[_0x463f('0x20')](respondWithResult(_0x5352bf,null))[_0x463f('0x2b')](handleError(_0x5352bf,null));};exports[_0x463f('0x6c')]=function(_0x271268,_0x11cdd9,_0x4c1017){var _0x191548={'raw':![],'where':{}};var _0x221b3c={};var _0x4249ac={'count':0x0,'rows':[]};return db[_0x463f('0x56')]['findOne']({'where':{'id':_0x271268[_0x463f('0x5b')]['id']}})['then'](handleEntityNotFound(_0x11cdd9,null))[_0x463f('0x20')](function(_0x17071e){if(_0x17071e){_0x221b3c[_0x463f('0x46')]=_[_0x463f('0x47')](db[_0x463f('0x6b')][_0x463f('0x42')]);_0x221b3c[_0x463f('0x48')]=_['keys'](_0x271268[_0x463f('0x48')]);_0x221b3c[_0x463f('0x49')]=_[_0x463f('0x4a')](_0x221b3c[_0x463f('0x46')],_0x221b3c[_0x463f('0x48')]);_0x191548[_0x463f('0x4c')]=_[_0x463f('0x4a')](_0x221b3c[_0x463f('0x46')],qs[_0x463f('0x4b')](_0x271268['query'][_0x463f('0x4b')]));_0x191548[_0x463f('0x4c')]=_0x191548['attributes'][_0x463f('0x4d')]?_0x191548['attributes']:_0x221b3c['model'];if(!_0x271268[_0x463f('0x48')][_0x463f('0x6d')](_0x463f('0x4e'))){_0x191548[_0x463f('0x33')]=qs['limit'](_0x271268['query']['limit']);_0x191548['offset']=qs[_0x463f('0x30')](_0x271268['query'][_0x463f('0x30')]);}_0x191548[_0x463f('0x4f')]=qs[_0x463f('0x50')](_0x271268[_0x463f('0x48')]['sort']);_0x191548[_0x463f('0x51')]=qs[_0x463f('0x49')](_[_0x463f('0x52')](_0x271268['query'],_0x221b3c['filters']));_0x191548[_0x463f('0x51')][_0x463f('0x6a')]=_0x17071e['id'];if(_0x271268['query'][_0x463f('0x53')]){_0x191548[_0x463f('0x51')]=_[_0x463f('0x54')](_0x191548[_0x463f('0x51')],{'$or':_['map'](_0x191548['attributes'],function(_0x4f19aa){var _0x59c567={};_0x59c567[_0x4f19aa]={'$like':'%'+_0x271268[_0x463f('0x48')][_0x463f('0x53')]+'%'};return _0x59c567;})});}_0x191548=_[_0x463f('0x54')]({},_0x191548,_0x271268[_0x463f('0x55')]);return db[_0x463f('0x6b')]['count']({'where':_0x191548['where']})['then'](function(_0x53c163){_0x4249ac[_0x463f('0x32')]=_0x53c163;if(_0x271268[_0x463f('0x48')][_0x463f('0x57')]){_0x191548[_0x463f('0x58')]=[{'all':!![]}];}return db[_0x463f('0x6b')][_0x463f('0x59')](_0x191548);})[_0x463f('0x20')](function(_0x53a8bc){_0x4249ac[_0x463f('0x5a')]=_0x53a8bc;return _0x4249ac;});}})['then'](respondWithFilteredResult(_0x11cdd9,_0x191548))[_0x463f('0x2b')](handleError(_0x11cdd9,null));};exports[_0x463f('0x6e')]=function(_0x2263c4,_0x4896eb,_0x55a24b){return db[_0x463f('0x56')]['find']({'where':{'id':_0x2263c4[_0x463f('0x5b')]['id']}})['then'](handleEntityNotFound(_0x4896eb,null))[_0x463f('0x20')](function(_0x2804c7){if(_0x2804c7){return _0x2804c7[_0x463f('0x6e')](_0x2263c4[_0x463f('0x48')]['ids']);}})[_0x463f('0x20')](respondWithStatusCode(_0x4896eb,null))[_0x463f('0x2b')](handleError(_0x4896eb,null));};exports[_0x463f('0x6f')]=function(_0x1efc76,_0x11d46d,_0xb8e7ef){if(_0x1efc76['body']['id']){delete _0x1efc76[_0x463f('0x5d')]['id'];}return db[_0x463f('0x56')]['find']({'where':{'id':_0x1efc76[_0x463f('0x5b')]['id']}})[_0x463f('0x20')](handleEntityNotFound(_0x11d46d,null))[_0x463f('0x20')](function(_0x60c68a){if(_0x60c68a){_0x1efc76[_0x463f('0x5d')][_0x463f('0x6a')]=_0x60c68a['id'];return db['CannedAnswer'][_0x463f('0x5c')](_0x1efc76[_0x463f('0x5d')]);}})[_0x463f('0x20')](respondWithResult(_0x11d46d,null))[_0x463f('0x2b')](handleError(_0x11d46d,null));};exports['getAnswers']=function(_0x59ce34,_0xff8420,_0x92547a){var _0x173bd1={'raw':![],'where':{}};var _0x11f522={};var _0x4f0884={'count':0x0,'rows':[]};return db[_0x463f('0x56')][_0x463f('0x70')]({'where':{'id':_0x59ce34[_0x463f('0x5b')]['id']}})[_0x463f('0x20')](handleEntityNotFound(_0xff8420,null))[_0x463f('0x20')](function(_0x476b27){if(_0x476b27){_0x11f522[_0x463f('0x46')]=_[_0x463f('0x47')](db[_0x463f('0x71')][_0x463f('0x42')]);_0x11f522['query']=_[_0x463f('0x47')](_0x59ce34[_0x463f('0x48')]);_0x11f522[_0x463f('0x49')]=_[_0x463f('0x4a')](_0x11f522['model'],_0x11f522['query']);_0x173bd1[_0x463f('0x4c')]=_[_0x463f('0x4a')](_0x11f522['model'],qs['fields'](_0x59ce34[_0x463f('0x48')][_0x463f('0x4b')]));_0x173bd1[_0x463f('0x4c')]=_0x173bd1[_0x463f('0x4c')][_0x463f('0x4d')]?_0x173bd1[_0x463f('0x4c')]:_0x11f522['model'];if(!_0x59ce34['query']['hasOwnProperty'](_0x463f('0x4e'))){_0x173bd1[_0x463f('0x33')]=qs[_0x463f('0x33')](_0x59ce34[_0x463f('0x48')][_0x463f('0x33')]);_0x173bd1[_0x463f('0x30')]=qs[_0x463f('0x30')](_0x59ce34[_0x463f('0x48')]['offset']);}_0x173bd1[_0x463f('0x4f')]=qs['sort'](_0x59ce34['query']['sort']);_0x173bd1[_0x463f('0x51')]=qs[_0x463f('0x49')](_[_0x463f('0x52')](_0x59ce34[_0x463f('0x48')],_0x11f522['filters']));_0x173bd1[_0x463f('0x51')][_0x463f('0x6a')]=_0x476b27['id'];if(_0x59ce34[_0x463f('0x48')][_0x463f('0x53')]){_0x173bd1[_0x463f('0x51')]=_[_0x463f('0x54')](_0x173bd1[_0x463f('0x51')],{'$or':_[_0x463f('0x41')](_0x173bd1[_0x463f('0x4c')],function(_0x658cff){var _0x249bbb={};_0x249bbb[_0x658cff]={'$like':'%'+_0x59ce34[_0x463f('0x48')]['filter']+'%'};return _0x249bbb;})});}_0x173bd1=_[_0x463f('0x54')]({},_0x173bd1,_0x59ce34['options']);return db[_0x463f('0x71')][_0x463f('0x32')]({'where':_0x173bd1[_0x463f('0x51')]})['then'](function(_0x280cd8){_0x4f0884[_0x463f('0x32')]=_0x280cd8;if(_0x59ce34[_0x463f('0x48')][_0x463f('0x57')]){_0x173bd1[_0x463f('0x58')]=[{'all':!![]}];}return db[_0x463f('0x71')][_0x463f('0x59')](_0x173bd1);})[_0x463f('0x20')](function(_0x54a02f){_0x4f0884[_0x463f('0x5a')]=_0x54a02f;return _0x4f0884;});}})[_0x463f('0x20')](respondWithFilteredResult(_0xff8420,_0x173bd1))[_0x463f('0x2b')](handleError(_0xff8420,null));};exports[_0x463f('0x72')]=function(_0x3b61a2,_0x51b6a4,_0x309582){return db[_0x463f('0x56')][_0x463f('0x67')]({'where':{'id':_0x3b61a2[_0x463f('0x5b')]['id']}})[_0x463f('0x20')](handleEntityNotFound(_0x51b6a4,null))[_0x463f('0x20')](function(_0x335837){if(_0x335837){return _0x335837[_0x463f('0x72')](_0x3b61a2['query']['ids']);}})[_0x463f('0x20')](respondWithStatusCode(_0x51b6a4,null))[_0x463f('0x2b')](handleError(_0x51b6a4,null));};exports[_0x463f('0x73')]=function(_0x244244,_0x2911b7,_0x5d7b3c){return db[_0x463f('0x74')][_0x463f('0x67')]({'where':{'id':_0x244244[_0x463f('0x5b')]['id']}})['then'](handleEntityNotFound(_0x2911b7,null))['then'](function(_0x4ff126){if(_0x4ff126){return _0x4ff126[_0x463f('0x73')](_0x244244['body']['ids'],_['omit'](_0x244244[_0x463f('0x5d')],[_0x463f('0x75'),'id'])||{});}})[_0x463f('0x20')](respondWithResult(_0x2911b7,null))[_0x463f('0x2b')](handleError(_0x2911b7,null));};exports[_0x463f('0x76')]=function(_0x59f589,_0x5114a6,_0x3379e3){var _0x2dc63e={'raw':![],'where':{}};var _0x208bfb={};var _0x2e1c93={'count':0x0,'rows':[]};return db[_0x463f('0x56')]['findOne']({'where':{'id':_0x59f589['params']['id']}})['then'](handleEntityNotFound(_0x5114a6,null))[_0x463f('0x20')](function(_0x2e858f){if(_0x2e858f){_0x208bfb['model']=_[_0x463f('0x47')](db['FaxInteraction'][_0x463f('0x42')]);_0x208bfb[_0x463f('0x48')]=_[_0x463f('0x47')](_0x59f589[_0x463f('0x48')]);_0x208bfb['filters']=_[_0x463f('0x4a')](_0x208bfb[_0x463f('0x46')],_0x208bfb[_0x463f('0x48')]);_0x2dc63e['attributes']=_['intersection'](_0x208bfb['model'],qs[_0x463f('0x4b')](_0x59f589[_0x463f('0x48')][_0x463f('0x4b')]));_0x2dc63e[_0x463f('0x4c')]=_0x2dc63e[_0x463f('0x4c')][_0x463f('0x4d')]?_0x2dc63e[_0x463f('0x4c')]:_0x208bfb[_0x463f('0x46')];if(!_0x59f589[_0x463f('0x48')]['hasOwnProperty']('nolimit')){_0x2dc63e[_0x463f('0x33')]=qs[_0x463f('0x33')](_0x59f589[_0x463f('0x48')][_0x463f('0x33')]);_0x2dc63e['offset']=qs[_0x463f('0x30')](_0x59f589[_0x463f('0x48')][_0x463f('0x30')]);}_0x2dc63e[_0x463f('0x4f')]=qs[_0x463f('0x50')](_0x59f589[_0x463f('0x48')][_0x463f('0x50')]);_0x2dc63e[_0x463f('0x51')]=qs[_0x463f('0x49')](_[_0x463f('0x52')](_0x59f589[_0x463f('0x48')],_0x208bfb[_0x463f('0x49')]));_0x2dc63e[_0x463f('0x51')][_0x463f('0x6a')]=_0x2e858f['id'];if(_0x59f589['query']['filter']){_0x2dc63e[_0x463f('0x51')]=_[_0x463f('0x54')](_0x2dc63e[_0x463f('0x51')],{'$or':_[_0x463f('0x41')](_0x2dc63e[_0x463f('0x4c')],function(_0x427245){var _0x489e66={};_0x489e66[_0x427245]={'$like':'%'+_0x59f589[_0x463f('0x48')][_0x463f('0x53')]+'%'};return _0x489e66;})});}_0x2dc63e=_['merge']({},_0x2dc63e,_0x59f589['options']);return db['FaxInteraction']['count']({'where':_0x2dc63e[_0x463f('0x51')]})[_0x463f('0x20')](function(_0x16aa83){_0x2e1c93[_0x463f('0x32')]=_0x16aa83;if(_0x59f589[_0x463f('0x48')][_0x463f('0x57')]){_0x2dc63e[_0x463f('0x58')]=[{'model':db[_0x463f('0x77')],'as':'Contact','required':![]},{'model':db[_0x463f('0x78')],'as':_0x463f('0x79'),'attributes':['name','fullname',_0x463f('0x7a')],'required':![]},{'model':db[_0x463f('0x7b')],'as':_0x463f('0x7c'),'attributes':['id',_0x463f('0x3d'),_0x463f('0x7d')],'where':_0x59f589[_0x463f('0x48')][_0x463f('0x7e')]?{'id':_0x59f589[_0x463f('0x48')][_0x463f('0x7e')]}:undefined,'required':_0x59f589[_0x463f('0x48')][_0x463f('0x7e')]?!![]:![]}];}return db['FaxInteraction'][_0x463f('0x59')](_0x2dc63e);})[_0x463f('0x20')](function(_0x517a80){_0x2e1c93[_0x463f('0x5a')]=_0x517a80;return _0x2e1c93;});}})[_0x463f('0x20')](respondWithFilteredResult(_0x5114a6,_0x2dc63e))[_0x463f('0x2b')](handleError(_0x5114a6,null));};exports[_0x463f('0x7f')]=function(_0x6c0d03,_0x42d58c){var _0x343353=_0x6c0d03['params']['id'];var _0xc9437d=_0x6c0d03[_0x463f('0x5d')];var _0x2f578b=0xc8;var _0xda3d72=null;return db['sequelize']['transaction']({'isolationLevel':db[_0x463f('0x80')][_0x463f('0x81')]['ISOLATION_LEVELS']['READ_COMMITTED']},function(_0x1834a6){return db[_0x463f('0x56')][_0x463f('0x70')]({'where':{'id':_0x343353},'transaction':_0x1834a6})[_0x463f('0x20')](function(_0x42e1a2){if(_0x42e1a2){return db[_0x463f('0x82')]['destroy']({'where':{'FaxAccountId':_0x343353},'transaction':_0x1834a6})['then'](function(){var _0x136698=_['map'](_0xc9437d,function(_0x374154){_0x374154['FaxAccountId']=_0x343353;return _0x374154;});return db[_0x463f('0x82')][_0x463f('0x83')](_0x136698,{'transaction':_0x1834a6});});}else{_0x2f578b=0x194;_0xda3d72=[];}});})[_0x463f('0x20')](function(){if(_0x2f578b!==0x194){return db[_0x463f('0x82')][_0x463f('0x84')]({'where':{'FaxAccountId':_0x343353},'order':_0x463f('0x85')})[_0x463f('0x20')](function(_0x199c3e){_0xda3d72=_0x199c3e;});}})[_0x463f('0x2b')](function(_0x1dd859){_0x2f578b=0x1f4;logger[_0x463f('0x27')](_0x1dd859['stack']);if(_0x1dd859['name']){delete _0x1dd859['name'];}_0xda3d72=_0x1dd859;})[_0x463f('0x86')](function(){if(_0xda3d72===null){_0x42d58c[_0x463f('0x2c')](_0x2f578b);}else{if(_0x2f578b===0x1f4){_0x42d58c[_0x463f('0x2e')](_0x2f578b)['send'](_0xda3d72);}else{_0x42d58c[_0x463f('0x2e')](_0x2f578b)[_0x463f('0x2f')](_0xda3d72);}}});};exports['getApplications']=function(_0x3e7ea5,_0x2a65e0,_0x2ecc99){var _0x35a1aa={};var _0x6c4a0f={};var _0x2cc41f;var _0x4cc86d;return db[_0x463f('0x56')]['findOne']({'where':{'id':_0x3e7ea5[_0x463f('0x5b')]['id']}})[_0x463f('0x20')](handleEntityNotFound(_0x2a65e0,null))[_0x463f('0x20')](function(_0x476c2a){if(_0x476c2a){_0x2cc41f=_0x476c2a;_0x6c4a0f[_0x463f('0x46')]=_[_0x463f('0x47')](db[_0x463f('0x82')][_0x463f('0x42')]);_0x6c4a0f[_0x463f('0x48')]=_[_0x463f('0x47')](_0x3e7ea5[_0x463f('0x48')]);_0x6c4a0f[_0x463f('0x49')]=_[_0x463f('0x4a')](_0x6c4a0f[_0x463f('0x46')],_0x6c4a0f['query']);_0x35a1aa[_0x463f('0x4c')]=_[_0x463f('0x4a')](_0x6c4a0f[_0x463f('0x46')],qs[_0x463f('0x4b')](_0x3e7ea5['query'][_0x463f('0x4b')]));_0x35a1aa[_0x463f('0x4c')]=_0x35a1aa[_0x463f('0x4c')][_0x463f('0x4d')]?_0x35a1aa[_0x463f('0x4c')]:_0x6c4a0f[_0x463f('0x46')];_0x35a1aa[_0x463f('0x4f')]=qs['sort'](_0x3e7ea5[_0x463f('0x48')][_0x463f('0x50')]);_0x35a1aa[_0x463f('0x51')]=qs[_0x463f('0x49')](_['pick'](_0x3e7ea5[_0x463f('0x48')],_0x6c4a0f['filters']));if(_0x3e7ea5['query']['filter']){_0x35a1aa['where']=_[_0x463f('0x54')](_0x35a1aa[_0x463f('0x51')],{'$or':_[_0x463f('0x41')](_0x35a1aa[_0x463f('0x4c')],function(_0x58132d){var _0x2d3d03={};_0x2d3d03[_0x58132d]={'$like':'%'+_0x3e7ea5[_0x463f('0x48')][_0x463f('0x53')]+'%'};return _0x2d3d03;})});}_0x35a1aa=_[_0x463f('0x54')]({},_0x35a1aa,_0x3e7ea5[_0x463f('0x55')]);return _0x2cc41f[_0x463f('0x87')](_0x35a1aa);}})[_0x463f('0x20')](function(_0x4fb3e6){if(_0x4fb3e6){_0x4cc86d=_0x4fb3e6[_0x463f('0x4d')];if(!_0x3e7ea5['query'][_0x463f('0x6d')]('nolimit')){_0x35a1aa[_0x463f('0x33')]=qs['limit'](_0x3e7ea5[_0x463f('0x48')][_0x463f('0x33')]);_0x35a1aa['offset']=qs[_0x463f('0x30')](_0x3e7ea5['query']['offset']);}return _0x2cc41f[_0x463f('0x87')](_0x35a1aa);}})['then'](function(_0x57e7c3){if(_0x57e7c3){return _0x57e7c3?{'count':_0x4cc86d,'rows':_0x57e7c3}:null;}})[_0x463f('0x20')](respondWithResult(_0x2a65e0,null))['catch'](handleError(_0x2a65e0,null));};function Extension(_0x43d5e7,_0x2f18ba,_0x2203f4,_0x5d9af9){this['context']='from-voip-provider';this[_0x463f('0x88')]=_0x43d5e7[_0x463f('0x89')];this['app']=_0x5d9af9;this[_0x463f('0x44')]=_0x463f('0x8a');this[_0x463f('0x8b')]=_0x463f('0x8c');this['FaxAccountId']=_0x43d5e7['id'];this[_0x463f('0x85')]=_0x2f18ba;this[_0x463f('0x8d')]=_0x2203f4;}function createExtensionsReciveFax(_0x39a87d){var _0x1a052c=0x1;var _0x5c8fdb=[];_0x5c8fdb[_0x463f('0x8e')](new Extension(_0x39a87d,_0x1a052c,'','Answer'));_0x1a052c+=0x1;_0x5c8fdb[_0x463f('0x8e')](new Extension(_0x39a87d,_0x1a052c,_0x463f('0x8f'),_0x463f('0x90')));_0x1a052c+=0x1;for(var _0x3a4a9a in _0x39a87d){if(_0x39a87d['hasOwnProperty'](_0x3a4a9a)&&(_0x3a4a9a==='ecm'||_0x3a4a9a===_0x463f('0x89')||_0x3a4a9a===_0x463f('0x91')||_0x3a4a9a===_0x463f('0x92')||_0x3a4a9a==='headerinfo'||_0x3a4a9a==='maxrate'||_0x3a4a9a===_0x463f('0x93')||_0x3a4a9a==='modem'||_0x3a4a9a===_0x463f('0x94'))){_0x5c8fdb[_0x463f('0x8e')](new Extension(_0x39a87d,_0x1a052c,'FAXOPT('+_0x3a4a9a+')='+_0x39a87d[_0x3a4a9a],'Set'));_0x1a052c+=0x1;}}_0x5c8fdb[_0x463f('0x8e')](new Extension(_0x39a87d,_0x1a052c,'6',_0x463f('0x95')));_0x1a052c+=0x1;_0x5c8fdb[_0x463f('0x8e')](new Extension(_0x39a87d,_0x1a052c,_0x463f('0x96'),'ReceiveFax'));_0x1a052c=0x0;return _0x5c8fdb;}exports['addAccountApplications']=function(_0x43edea,_0x4464ee,_0x24f8de){var _0x216340;return db['sequelize']['transaction'](function(_0x399c7e){return db[_0x463f('0x56')][_0x463f('0x5c')](_0x43edea['body'],{'transaction':_0x399c7e})[_0x463f('0x20')](function(_0x393060){_0x216340=_0x393060[_0x463f('0x5f')]({'plain':!![]});return db[_0x463f('0x97')]['bulkCreate'](createExtensionsReciveFax(_0x216340),{'transaction':_0x399c7e});});})['then'](function(){return _0x216340;})[_0x463f('0x20')](respondWithResult(_0x4464ee,null))[_0x463f('0x2b')](handleError(_0x4464ee,null));};exports['updateAccountApplications']=function(_0x27ae2e,_0x5cff7b,_0x4e1c28){var _0x524826;return db['sequelize'][_0x463f('0x98')](function(_0x41924b){return db[_0x463f('0x56')][_0x463f('0x39')](_0x27ae2e[_0x463f('0x5d')],{'where':{'id':_0x27ae2e[_0x463f('0x5d')]['id']},'transaction':_0x41924b})['then'](function(_0x46d1bd){return db[_0x463f('0x97')][_0x463f('0x3a')]({'where':{'FaxAccountId':_0x27ae2e[_0x463f('0x5d')]['id']},'transaction':_0x41924b})[_0x463f('0x20')](function(_0x138306){return db[_0x463f('0x97')][_0x463f('0x83')](createExtensionsReciveFax(_['omit'](_0x27ae2e[_0x463f('0x5d')],['tech','key',_0x463f('0x99'),_0x463f('0x9a'),_0x463f('0x9b'),_0x463f('0x9c')])),{'transaction':_0x41924b});});});})[_0x463f('0x20')](function(){return db[_0x463f('0x56')][_0x463f('0x9d')](_0x27ae2e[_0x463f('0x5d')]['id']);})[_0x463f('0x20')](respondWithResult(_0x5cff7b,null))[_0x463f('0x2b')](handleError(_0x5cff7b,null));};exports[_0x463f('0x9e')]=function(_0x2d84b0,_0x2e9f66,_0x4c3707){var _0x54dc5d={'raw':!![],'where':{}};var _0x4d6b5f={};var _0x360db2={'count':0x0,'rows':[]};return db[_0x463f('0x56')]['findOne']({'where':{'id':_0x2d84b0[_0x463f('0x5b')]['id']}})[_0x463f('0x20')](handleEntityNotFound(_0x2e9f66,null))['then'](function(_0x45467b){if(_0x45467b){_0x4d6b5f['model']=_[_0x463f('0x47')](db[_0x463f('0x9f')][_0x463f('0x42')]);_0x4d6b5f[_0x463f('0x48')]=_['keys'](_0x2d84b0['query']);_0x4d6b5f[_0x463f('0x49')]=_[_0x463f('0x4a')](_0x4d6b5f['model'],_0x4d6b5f[_0x463f('0x48')]);_0x54dc5d[_0x463f('0x4c')]=_['intersection'](_0x4d6b5f[_0x463f('0x46')],qs[_0x463f('0x4b')](_0x2d84b0['query'][_0x463f('0x4b')]));_0x54dc5d[_0x463f('0x4c')]=_0x54dc5d[_0x463f('0x4c')][_0x463f('0x4d')]?_0x54dc5d[_0x463f('0x4c')]:_0x4d6b5f[_0x463f('0x46')];if(!_0x2d84b0[_0x463f('0x48')][_0x463f('0x6d')]('nolimit')){_0x54dc5d[_0x463f('0x33')]=qs[_0x463f('0x33')](_0x2d84b0['query'][_0x463f('0x33')]);_0x54dc5d[_0x463f('0x30')]=qs[_0x463f('0x30')](_0x2d84b0[_0x463f('0x48')]['offset']);}_0x54dc5d[_0x463f('0x4f')]=qs[_0x463f('0x50')](_0x2d84b0[_0x463f('0x48')]['sort']);_0x54dc5d[_0x463f('0x51')]=qs[_0x463f('0x49')](_[_0x463f('0x52')](_0x2d84b0[_0x463f('0x48')],_0x4d6b5f[_0x463f('0x49')]));_0x54dc5d[_0x463f('0x51')]['FaxAccountId']=_0x45467b['id'];if(_0x2d84b0['query'][_0x463f('0x53')]){_0x54dc5d['where']=_['merge'](_0x54dc5d[_0x463f('0x51')],{'$or':_[_0x463f('0x41')](_0x54dc5d[_0x463f('0x4c')],function(_0x36f6cf){var _0x525e98={};_0x525e98[_0x36f6cf]={'$like':'%'+_0x2d84b0[_0x463f('0x48')]['filter']+'%'};return _0x525e98;})});}if(_0x2d84b0[_0x463f('0x48')][_0x463f('0xa0')]){var _0x56c656=_0x2d84b0[_0x463f('0x48')][_0x463f('0xa0')]['split'](',');var _0x571805={};_0x571805[_0x56c656[0x0]]={'$gte':moment(_0x56c656[0x1])[_0x463f('0xa1')]('YYYY-MM-DD\x20HH:mm:ss')};_0x54dc5d[_0x463f('0x51')]=_['merge'](_0x54dc5d[_0x463f('0x51')],_0x571805);}_0x54dc5d=_[_0x463f('0x54')]({},_0x54dc5d,_0x2d84b0[_0x463f('0x55')]);return db[_0x463f('0x9f')]['count']({'where':_0x54dc5d[_0x463f('0x51')]})[_0x463f('0x20')](function(_0x51b1c4){_0x360db2[_0x463f('0x32')]=_0x51b1c4;if(_0x2d84b0['query']['includeAll']){_0x54dc5d[_0x463f('0x58')]=[{'all':!![]}];}return db[_0x463f('0x9f')][_0x463f('0x59')](_0x54dc5d);})[_0x463f('0x20')](function(_0x26311b){_0x360db2[_0x463f('0x5a')]=_0x26311b;return _0x360db2;});}})[_0x463f('0x20')](respondWithFilteredResult(_0x2e9f66,_0x54dc5d))['catch'](handleError(_0x2e9f66,null));};exports[_0x463f('0x3e')]=function(_0x284fe9,_0x39ec18,_0x104e6c){var _0x3a5174,_0x514a4e={},_0x18274b;if(_0x284fe9[_0x463f('0x5d')]['to']){_0x18274b=_0x284fe9[_0x463f('0x5d')]['to'][0x0];}return db[_0x463f('0x56')]['find']({'where':{'id':_0x284fe9[_0x463f('0x5b')]['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0x463f('0x77')],'as':_0x463f('0xa2'),'where':{'fax':_0x18274b},'limit':0x1,'order':[[_0x463f('0x9a'),'DESC']]}]}]})['then'](handleEntityNotFound(_0x39ec18,null))[_0x463f('0x20')](function(_0x16a1e3){_0x3a5174=_0x16a1e3;if(_0x284fe9[_0x463f('0x5d')][_0x463f('0xa3')]&&_0x284fe9[_0x463f('0x5d')]['attachments'][_0x463f('0x4d')]){for(var _0x3d1134=0x0;_0x3d1134<_0x284fe9[_0x463f('0x5d')]['attachments'][_0x463f('0x4d')];_0x3d1134+=0x1){_0x284fe9[_0x463f('0x5d')][_0x463f('0xa3')][_0x3d1134]={'filename':_0x284fe9[_0x463f('0x5d')][_0x463f('0xa3')][_0x3d1134][_0x463f('0x3d')],'id':_0x284fe9[_0x463f('0x5d')][_0x463f('0xa3')][_0x3d1134]['id'],'path':path[_0x463f('0xa4')](config[_0x463f('0xa5')],'server/files/attachments',_0x284fe9[_0x463f('0x5d')][_0x463f('0xa3')][_0x3d1134]['basename'])};}}return respondWithRpcPromise(_0x463f('0xa6'),_0x463f('0xa6'),{'FaxAccountId':_[_0x463f('0xa7')](_0x284fe9[_0x463f('0x5b')]['id'])?undefined:_0x284fe9[_0x463f('0x5b')]['id'],'path':_[_0x463f('0xa7')](_0x284fe9['body']['attachments'][0x0]['path'])?undefined:_0x284fe9[_0x463f('0x5d')][_0x463f('0xa3')][0x0][_0x463f('0x6')],'fax':_[_0x463f('0xa7')](_0x284fe9['body']['to'][0x0])?undefined:_0x284fe9[_0x463f('0x5d')]['to'][0x0]},client9002);})[_0x463f('0x20')](function(){if(_0x3a5174){if(_['isNil'](_0x284fe9[_0x463f('0x5d')]['from'])){_0x284fe9[_0x463f('0x5d')]['from']=util['format']('\x22%s\x22\x20<%s>',_0x3a5174[_0x463f('0x3d')],_0x3a5174[_0x463f('0xa8')]);}if(_0x3a5174[_0x463f('0xa9')]){if(_0x3a5174['List'][_0x463f('0xa2')][_0x463f('0x4d')]){return _0x3a5174[_0x463f('0xa9')][_0x463f('0xa2')][0x0];}else{return db[_0x463f('0x77')][_0x463f('0x5c')](_[_0x463f('0x16')](_0x284fe9[_0x463f('0x5d')],{'firstName':_0x284fe9['body']['to'][0x0],'phone':_0x284fe9[_0x463f('0x5d')]['to'][0x0],'fax':_0x284fe9[_0x463f('0x5d')]['to'][0x0],'ListId':_0x3a5174[_0x463f('0x9c')]}));}}else{throw new Error('List\x20not\x20found');}}else{throw new Error(_0x463f('0xaa'));}})[_0x463f('0x20')](function(_0x14686e){if(_0x14686e){return db['FaxInteraction'][_0x463f('0x67')]({'where':{'ContactId':_0x14686e['id'],'closed':![],'FaxAccountId':_0x3a5174['id']}})[_0x463f('0x20')](function(_0x3526c9){if(_0x3526c9){return[_0x3526c9,![]];}return db[_0x463f('0x74')]['create']({'UserId':_0x284fe9[_0x463f('0x5e')]['id'],'ContactId':_0x14686e['id'],'FaxAccountId':_0x3a5174['id'],'fax':_0x284fe9[_0x463f('0x5d')]['to'][0x0],'firstMsgDirection':_0x463f('0xab'),'Messages':[_['merge'](_0x284fe9[_0x463f('0x5d')],{'read':![],'body':_0x284fe9[_0x463f('0x5d')][_0x463f('0xa3')][0x0]['filename'],'FaxAccountId':_0x3a5174['id'],'UserId':_0x284fe9[_0x463f('0x5e')]['id'],'ContactId':_0x14686e['id'],'AttachmentId':_0x284fe9['body'][_0x463f('0xa3')][0x0]['id']})]},{'include':[{'model':db[_0x463f('0x9f')],'as':'Messages'}]})[_0x463f('0x20')](function(_0x8081c9){return[_0x8081c9,!![]];});});}else{throw new Error(_0x463f('0xac'));}})[_0x463f('0xad')](function(_0x1cdb4b,_0x49ef16){if(_0x49ef16){return _0x1cdb4b;}return db['FaxMessage'][_0x463f('0x5c')]({'direction':'out','read':![],'body':_0x284fe9[_0x463f('0x5d')][_0x463f('0xa3')][0x0]['filename'],'FaxAccountId':_0x3a5174['id'],'FaxInteractionId':_0x1cdb4b['id'],'UserId':_0x284fe9[_0x463f('0x5e')]['id'],'ContactId':_0x1cdb4b[_0x463f('0xae')],'AttachmentId':_0x284fe9['body'][_0x463f('0xa3')][0x0]['id']})['then'](function(_0x54ddd6){_0x1cdb4b[_0x463f('0xaf')]['Messages']=[];_0x1cdb4b[_0x463f('0xaf')][_0x463f('0xb0')]['push'](_0x54ddd6['dataValues']);return _0x1cdb4b;});})[_0x463f('0x20')](function(_0x4c6b9b){respondWithRpcPromise(_0x463f('0xb1'),_0x463f('0xb1'),{'FaxAccountId':_[_0x463f('0xa7')](_0x284fe9[_0x463f('0x5b')]['id'])?undefined:_0x284fe9[_0x463f('0x5b')]['id'],'path':_['isNil'](_0x284fe9[_0x463f('0x5d')]['attachments'][0x0][_0x463f('0x6')])?undefined:_0x284fe9['body'][_0x463f('0xa3')][0x0][_0x463f('0x6')],'fax':_[_0x463f('0xa7')](_0x284fe9[_0x463f('0x5d')]['to'][0x0])?undefined:_0x284fe9[_0x463f('0x5d')]['to'][0x0],'AttachmentId':_0x284fe9[_0x463f('0x5d')][_0x463f('0xa3')][0x0]['id']},client9002)[_0x463f('0x20')](function(_0x99f116){logger[_0x463f('0x21')](_0x463f('0xb2'),_0x99f116);})[_0x463f('0x2b')](function(_0x5ad31d){logger[_0x463f('0x21')]('SendFaxRpc,\x20%s',_0x5ad31d);});return _0x4c6b9b;})[_0x463f('0x20')](respondWithResult(_0x39ec18,null))[_0x463f('0x2b')](handleError(_0x39ec18,null));};exports[_0x463f('0xb3')]=function(_0x129d6c,_0x527969,_0x5e6578){return db[_0x463f('0x56')][_0x463f('0x67')]({'where':{'id':_0x129d6c['params']['id']}})[_0x463f('0x20')](handleEntityNotFound(_0x527969,null))[_0x463f('0x20')](function(_0x2852e9){if(_0x2852e9){return _0x2852e9['addAgents'](_0x129d6c[_0x463f('0x5d')][_0x463f('0x75')],_[_0x463f('0xb4')](_0x129d6c[_0x463f('0x5d')],[_0x463f('0x75'),'id'])||{})['spread'](function(_0x37a055){for(var _0x136f0a=0x0;_0x136f0a<_0x129d6c[_0x463f('0x5d')]['ids']['length'];_0x136f0a+=0x1){socket['emit']('userFaxAccount:save',{'UserId':Number(_0x129d6c['body'][_0x463f('0x75')][_0x136f0a]),'FaxAccountId':Number(_0x129d6c[_0x463f('0x5b')]['id'])});}return _0x37a055;});}})['then'](respondWithResult(_0x527969,null))[_0x463f('0x2b')](handleError(_0x527969,null));};exports[_0x463f('0xb5')]=function(_0x450335,_0x4131a9,_0x7d99e9){return db[_0x463f('0x56')][_0x463f('0x67')]({'where':{'id':_0x450335['params']['id']}})[_0x463f('0x20')](handleEntityNotFound(_0x4131a9,null))[_0x463f('0x20')](function(_0x484fff){if(_0x484fff){return _0x484fff[_0x463f('0xb5')](_0x450335['query'][_0x463f('0x75')])[_0x463f('0x20')](function(){if(_['isArray'](_0x450335[_0x463f('0x48')][_0x463f('0x75')])){for(var _0x2b3bdf=0x0;_0x2b3bdf<_0x450335[_0x463f('0x48')][_0x463f('0x75')][_0x463f('0x4d')];_0x2b3bdf+=0x1){socket['emit'](_0x463f('0xb6'),{'UserId':Number(_0x450335[_0x463f('0x48')][_0x463f('0x75')][_0x2b3bdf]),'FaxAccountId':Number(_0x450335[_0x463f('0x5b')]['id'])});}}else{socket['emit'](_0x463f('0xb6'),{'UserId':Number(_0x450335['query'][_0x463f('0x75')]),'FaxAccountId':Number(_0x450335[_0x463f('0x5b')]['id'])});}});}})[_0x463f('0x20')](respondWithStatusCode(_0x4131a9,null))[_0x463f('0x2b')](handleError(_0x4131a9,null));};exports['getAgents']=function(_0x1b7049,_0x369b1f,_0x2d1f5e){var _0x77c5b3={};var _0x125e30={};var _0x36c931;var _0x3a1c2b;return db[_0x463f('0x56')][_0x463f('0x70')]({'where':{'id':_0x1b7049[_0x463f('0x5b')]['id']}})[_0x463f('0x20')](handleEntityNotFound(_0x369b1f,null))['then'](function(_0x109a04){if(_0x109a04){_0x36c931=_0x109a04;_0x125e30[_0x463f('0x46')]=_[_0x463f('0x47')](db[_0x463f('0x78')][_0x463f('0x42')]);_0x125e30['query']=_[_0x463f('0x47')](_0x1b7049[_0x463f('0x48')]);_0x125e30[_0x463f('0x49')]=_[_0x463f('0x4a')](_0x125e30[_0x463f('0x46')],_0x125e30['query']);_0x77c5b3[_0x463f('0x4c')]=_[_0x463f('0x4a')](_0x125e30['model'],qs[_0x463f('0x4b')](_0x1b7049[_0x463f('0x48')][_0x463f('0x4b')]));_0x77c5b3[_0x463f('0x4c')]=_0x77c5b3[_0x463f('0x4c')][_0x463f('0x4d')]?_0x77c5b3[_0x463f('0x4c')]:_0x125e30[_0x463f('0x46')];_0x77c5b3[_0x463f('0x4f')]=qs[_0x463f('0x50')](_0x1b7049[_0x463f('0x48')][_0x463f('0x50')]);_0x77c5b3[_0x463f('0x51')]=qs[_0x463f('0x49')](_['pick'](_0x1b7049[_0x463f('0x48')],_0x125e30[_0x463f('0x49')]));if(_0x1b7049[_0x463f('0x48')][_0x463f('0x53')]){_0x77c5b3['where']=_[_0x463f('0x54')](_0x77c5b3[_0x463f('0x51')],{'$or':_[_0x463f('0x41')](_0x77c5b3[_0x463f('0x4c')],function(_0x566c74){var _0x58b89d={};_0x58b89d[_0x566c74]={'$like':'%'+_0x1b7049['query'][_0x463f('0x53')]+'%'};return _0x58b89d;})});}_0x77c5b3=_[_0x463f('0x54')]({},_0x77c5b3,_0x1b7049['options']);return _0x36c931[_0x463f('0xb7')](_0x77c5b3);}})[_0x463f('0x20')](function(_0x1b7a05){if(_0x1b7a05){_0x3a1c2b=_0x1b7a05[_0x463f('0x4d')];if(!_0x1b7049[_0x463f('0x48')][_0x463f('0x6d')](_0x463f('0x4e'))){_0x77c5b3[_0x463f('0x33')]=qs[_0x463f('0x33')](_0x1b7049[_0x463f('0x48')][_0x463f('0x33')]);_0x77c5b3[_0x463f('0x30')]=qs['offset'](_0x1b7049[_0x463f('0x48')][_0x463f('0x30')]);}return _0x36c931[_0x463f('0xb7')](_0x77c5b3);}})['then'](function(_0xe03028){if(_0xe03028){return _0xe03028?{'count':_0x3a1c2b,'rows':_0xe03028}:null;}})[_0x463f('0x20')](respondWithResult(_0x369b1f,null))[_0x463f('0x2b')](handleError(_0x369b1f,null));};