6a6605dd30774f3454d656efc58ba8170c628c76
[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 _0xf95f=['../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./faxAccount.socket','jayson/promise','client','http','then','request\x20sent','debug','FaxAccount,\x20%s,\x20%s,\x20%s','stringify','error','FaxAccount,\x20%s,\x20%s','message','result','catch','status','end','json','undefined','count','offset','limit','set','reject','save','update','destroy','get','FaxAccounts','UserProfileResource','stack','name','send','index','Pause','mandatoryDispositionPause','map','FaxAccount','rawAttributes','fieldName','type','key','model','keys','query','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','filters','pick','merge','filter','includeAll','rows','show','params','length','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','find','autoAssociation','describe','addDisposition','FaxAccountId','Disposition','getDispositions','findOne','options','include','findAll','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','omit','getInteractions','FaxInteraction','CmContact','Contact','User','Owner','fullname','internal','Tags','color','tag','transaction','sequelize','ISOLATION_LEVELS','FaxApplication','bulkCreate','findAndCountAll','finally','sendStatus','getApplications','context','from-voip-provider','exten','localstationid','system','description','priority','appdata','Answer','push','CDR(type)=inbound-fax','ecm','gateway','headerinfo','maxrate','modem','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','ListId','findById','getMessages','FaxMessage','$gte','split','format','CmList','Contacts','DESC','attachments','join','server/files/attachments','basename','CheckAfterSend','isNil','from','\x22%s\x22\x20<%s>','fax','List','List\x20not\x20found','Send\x20Fax\x20failed','out','filename','Contact\x20not\x20found','spread','ContactId','Messages','dataValues','SendFax','info','SendFaxRpc,\x20%s','addAgents','emit','userFaxAccount:save','removeAgents','isArray','userFaxAccount:remove','getAgents','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware'];(function(_0x53ccf2,_0x13cb67){var _0x5a2964=function(_0x3b0514){while(--_0x3b0514){_0x53ccf2['push'](_0x53ccf2['shift']());}};_0x5a2964(++_0x13cb67);}(_0xf95f,0x16f));var _0xff95=function(_0x49536b,_0x2abe5d){_0x49536b=_0x49536b-0x0;var _0x30de59=_0xf95f[_0x49536b];return _0x30de59;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xff95('0x0'));var zipdir=require(_0xff95('0x1'));var jsonpatch=require(_0xff95('0x2'));var rp=require(_0xff95('0x3'));var moment=require('moment');var BPromise=require(_0xff95('0x4'));var Mustache=require(_0xff95('0x5'));var util=require(_0xff95('0x6'));var path=require(_0xff95('0x7'));var sox=require(_0xff95('0x8'));var csv=require('to-csv');var ejs=require(_0xff95('0x9'));var fs=require('fs');var fs_extra=require(_0xff95('0xa'));var _=require(_0xff95('0xb'));var squel=require('squel');var crypto=require(_0xff95('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xff95('0xd'));var toCsv=require('to-csv');var querystring=require(_0xff95('0xe'));var Papa=require(_0xff95('0xf'));var Redis=require(_0xff95('0x10'));var authService=require(_0xff95('0x11'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xff95('0x12'));var logger=require(_0xff95('0x13'))(_0xff95('0x14'));var utils=require('../../config/utils');var config=require(_0xff95('0x15'));var licenseUtil=require(_0xff95('0x16'));var db=require(_0xff95('0x17'))['db'];config[_0xff95('0x18')]=_[_0xff95('0x19')](config[_0xff95('0x18')],{'host':_0xff95('0x1a'),'port':0x18eb});var socket=require(_0xff95('0x1b'))(new Redis(config['redis']));require(_0xff95('0x1c'))['register'](socket);var jayson=require(_0xff95('0x1d'));var client=jayson[_0xff95('0x1e')][_0xff95('0x1f')]({'port':0x232c});var client9002=jayson['client'][_0xff95('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x172062,_0x24a1c0,_0x15ed0f,_0x2c0dfd){return new BPromise(function(_0x240cae,_0x49d490){var _0x5aeba0=_0x2c0dfd||client;return _0x5aeba0['request'](_0x172062,_0x15ed0f)[_0xff95('0x20')](function(_0x523ab2){logger['info']('FaxAccount,\x20%s,\x20%s',_0x24a1c0,_0xff95('0x21'));logger[_0xff95('0x22')](_0xff95('0x23'),_0x24a1c0,_0xff95('0x21'),JSON[_0xff95('0x24')](_0x523ab2));if(_0x523ab2[_0xff95('0x25')]){if(_0x523ab2[_0xff95('0x25')]['code']===0x1f4){logger['error'](_0xff95('0x26'),_0x24a1c0,_0x523ab2['error'][_0xff95('0x27')]);return _0x49d490(_0x523ab2[_0xff95('0x25')][_0xff95('0x27')]);}logger[_0xff95('0x25')]('FaxAccount,\x20%s,\x20%s',_0x24a1c0,_0x523ab2[_0xff95('0x25')][_0xff95('0x27')]);return _0x240cae(_0x523ab2['error'][_0xff95('0x27')]);}else{logger['info']('FaxAccount,\x20%s,\x20%s',_0x24a1c0,_0xff95('0x21'));_0x240cae(_0x523ab2[_0xff95('0x28')]['message']);}})[_0xff95('0x29')](function(_0x24e308){logger['error'](_0xff95('0x26'),_0x24a1c0,_0x24e308);_0x49d490(_0x24e308);});});}function respondWithStatusCode(_0x1d70af,_0x5010c8){_0x5010c8=_0x5010c8||0xcc;return function(_0x2f99fc){if(_0x2f99fc){return _0x1d70af['sendStatus'](_0x5010c8);}return _0x1d70af[_0xff95('0x2a')](_0x5010c8)[_0xff95('0x2b')]();};}function respondWithResult(_0x21749c,_0x2c70c6){_0x2c70c6=_0x2c70c6||0xc8;return function(_0x2ba66a){if(_0x2ba66a){return _0x21749c[_0xff95('0x2a')](_0x2c70c6)[_0xff95('0x2c')](_0x2ba66a);}};}function respondWithFilteredResult(_0x3b4c06,_0x1613d6){return function(_0x28938f){if(_0x28938f){var _0x54e059=typeof _0x1613d6['offset']===_0xff95('0x2d')&&typeof _0x1613d6['limit']===_0xff95('0x2d');var _0x4302ab=_0x28938f[_0xff95('0x2e')];var _0x31aaa6=_0x54e059?0x0:_0x1613d6[_0xff95('0x2f')];var _0x627b6d=_0x54e059?_0x28938f['count']:_0x1613d6['offset']+_0x1613d6[_0xff95('0x30')];var _0x12493f;if(_0x627b6d>=_0x4302ab){_0x627b6d=_0x4302ab;_0x12493f=0xc8;}else{_0x12493f=0xce;}_0x3b4c06[_0xff95('0x2a')](_0x12493f);return _0x3b4c06[_0xff95('0x31')]('Content-Range',_0x31aaa6+'-'+_0x627b6d+'/'+_0x4302ab)[_0xff95('0x2c')](_0x28938f);}return null;};}function patchUpdates(_0x2a7bdd){return function(_0x1b82b4){try{jsonpatch['apply'](_0x1b82b4,_0x2a7bdd,!![]);}catch(_0x575098){return BPromise[_0xff95('0x32')](_0x575098);}return _0x1b82b4[_0xff95('0x33')]();};}function saveUpdates(_0x45527c,_0x58d1d8){return function(_0x1b3a44){if(_0x1b3a44){return _0x1b3a44[_0xff95('0x34')](_0x45527c)[_0xff95('0x20')](function(_0x141895){return _0x141895;});}return null;};}function removeEntity(_0x46a9ed,_0x171f9d){return function(_0xaa7a54){if(_0xaa7a54){return _0xaa7a54[_0xff95('0x35')]()[_0xff95('0x20')](function(){var _0x4ab000=_0xaa7a54[_0xff95('0x36')]({'plain':!![]});var _0x306cd5=_0xff95('0x37');return db[_0xff95('0x38')][_0xff95('0x35')]({'where':{'type':_0x306cd5,'resourceId':_0x4ab000['id']}})[_0xff95('0x20')](function(){return _0xaa7a54;});})[_0xff95('0x20')](function(){_0x46a9ed['status'](0xcc)[_0xff95('0x2b')]();});}};}function handleEntityNotFound(_0x2e0b26,_0x42a82c){return function(_0x4a3a23){if(!_0x4a3a23){_0x2e0b26['sendStatus'](0x194);}return _0x4a3a23;};}function handleError(_0x3c65b8,_0x4dce23){_0x4dce23=_0x4dce23||0x1f4;return function(_0x13ab41){logger[_0xff95('0x25')](_0x13ab41[_0xff95('0x39')]);if(_0x13ab41[_0xff95('0x3a')]){delete _0x13ab41[_0xff95('0x3a')];}_0x3c65b8[_0xff95('0x2a')](_0x4dce23)[_0xff95('0x3b')](_0x13ab41);};}exports[_0xff95('0x3c')]=function(_0x8c75f4,_0x37122c){var _0x56faae={'include':[{'model':db[_0xff95('0x3d')],'as':_0xff95('0x3e')}]},_0x5618a1={},_0x1e5fc4={'count':0x0,'rows':[]};var _0x43f443=_[_0xff95('0x3f')](db[_0xff95('0x40')][_0xff95('0x41')],function(_0x315dde){return{'name':_0x315dde[_0xff95('0x42')],'type':_0x315dde[_0xff95('0x43')][_0xff95('0x44')]};});_0x5618a1[_0xff95('0x45')]=_[_0xff95('0x3f')](_0x43f443,_0xff95('0x3a'));_0x5618a1['query']=_[_0xff95('0x46')](_0x8c75f4[_0xff95('0x47')]);_0x5618a1['filters']=_[_0xff95('0x48')](_0x5618a1[_0xff95('0x45')],_0x5618a1[_0xff95('0x47')]);_0x56faae[_0xff95('0x49')]=_['intersection'](_0x5618a1[_0xff95('0x45')],qs[_0xff95('0x4a')](_0x8c75f4[_0xff95('0x47')][_0xff95('0x4a')]));_0x56faae[_0xff95('0x49')]=_0x56faae['attributes']['length']?_0x56faae[_0xff95('0x49')]:_0x5618a1[_0xff95('0x45')];if(!_0x8c75f4[_0xff95('0x47')][_0xff95('0x4b')](_0xff95('0x4c'))){_0x56faae['limit']=qs[_0xff95('0x30')](_0x8c75f4[_0xff95('0x47')][_0xff95('0x30')]);_0x56faae['offset']=qs[_0xff95('0x2f')](_0x8c75f4[_0xff95('0x47')][_0xff95('0x2f')]);}_0x56faae[_0xff95('0x4d')]=qs[_0xff95('0x4e')](_0x8c75f4[_0xff95('0x47')][_0xff95('0x4e')]);_0x56faae[_0xff95('0x4f')]=qs[_0xff95('0x50')](_[_0xff95('0x51')](_0x8c75f4[_0xff95('0x47')],_0x5618a1[_0xff95('0x50')]),_0x43f443);if(_0x8c75f4[_0xff95('0x47')]['filter']){_0x56faae['where']=_[_0xff95('0x52')](_0x56faae[_0xff95('0x4f')],{'$or':_[_0xff95('0x3f')](_0x43f443,function(_0x45e091){if(_0x45e091['type']!=='VIRTUAL'){var _0x3f0a36={};_0x3f0a36[_0x45e091[_0xff95('0x3a')]]={'$like':'%'+_0x8c75f4[_0xff95('0x47')][_0xff95('0x53')]+'%'};return _0x3f0a36;}})});}_0x56faae=_[_0xff95('0x52')]({},_0x56faae,_0x8c75f4['options']);var _0x2601da={'where':_0x56faae['where']};return db[_0xff95('0x40')][_0xff95('0x2e')](_0x2601da)['then'](function(_0x1d7c87){_0x1e5fc4[_0xff95('0x2e')]=_0x1d7c87;if(_0x8c75f4[_0xff95('0x47')][_0xff95('0x54')]){_0x56faae['include']=[{'all':!![]}];}return db['FaxAccount']['findAll'](_0x56faae);})['then'](function(_0x543c18){_0x1e5fc4[_0xff95('0x55')]=_0x543c18;return _0x1e5fc4;})['then'](respondWithFilteredResult(_0x37122c,_0x56faae))['catch'](handleError(_0x37122c,null));};exports[_0xff95('0x56')]=function(_0x5dabd0,_0x34286d){var _0x18c365={'raw':![],'where':{'id':_0x5dabd0[_0xff95('0x57')]['id']},'include':[{'model':db[_0xff95('0x3d')],'as':_0xff95('0x3e')}]},_0xc31cc0={};_0xc31cc0[_0xff95('0x45')]=_['keys'](db[_0xff95('0x40')]['rawAttributes']);_0xc31cc0['query']=_[_0xff95('0x46')](_0x5dabd0[_0xff95('0x47')]);_0xc31cc0[_0xff95('0x50')]=_[_0xff95('0x48')](_0xc31cc0['model'],_0xc31cc0[_0xff95('0x47')]);_0x18c365[_0xff95('0x49')]=_[_0xff95('0x48')](_0xc31cc0[_0xff95('0x45')],qs['fields'](_0x5dabd0['query'][_0xff95('0x4a')]));_0x18c365[_0xff95('0x49')]=_0x18c365['attributes'][_0xff95('0x58')]?_0x18c365[_0xff95('0x49')]:_0xc31cc0['model'];if(_0x5dabd0[_0xff95('0x47')][_0xff95('0x54')]){_0x18c365['include']=[{'all':!![]}];}_0x18c365=_[_0xff95('0x52')]({},_0x18c365,_0x5dabd0['options']);return db[_0xff95('0x40')]['find'](_0x18c365)['then'](handleEntityNotFound(_0x34286d,null))['then'](respondWithResult(_0x34286d,null))['catch'](handleError(_0x34286d,null));};exports[_0xff95('0x59')]=function(_0x1a00e0,_0x123d90){return db[_0xff95('0x40')][_0xff95('0x59')](_0x1a00e0[_0xff95('0x5a')],{})[_0xff95('0x20')](function(_0x1709e8){var _0x250cfa=_0x1a00e0[_0xff95('0x5b')][_0xff95('0x36')]({'plain':!![]});if(!_0x250cfa)throw new Error(_0xff95('0x5c'));if(_0x250cfa['role']===_0xff95('0x5b')){var _0x3f03d7=_0x1709e8[_0xff95('0x36')]({'plain':!![]});var _0xf74dcd='FaxAccounts';return db[_0xff95('0x5d')][_0xff95('0x5e')]({'where':{'name':_0xf74dcd,'userProfileId':_0x250cfa['userProfileId']},'raw':!![]})[_0xff95('0x20')](function(_0x47fa24){if(_0x47fa24&&_0x47fa24[_0xff95('0x5f')]===0x0){return db[_0xff95('0x38')][_0xff95('0x59')]({'name':_0x3f03d7[_0xff95('0x3a')],'resourceId':_0x3f03d7['id'],'type':_0x47fa24['name'],'sectionId':_0x47fa24['id']},{})[_0xff95('0x20')](function(){return _0x1709e8;});}else{return _0x1709e8;}})[_0xff95('0x29')](function(_0x2e29e3){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x2e29e3);throw _0x2e29e3;});}return _0x1709e8;})[_0xff95('0x20')](respondWithResult(_0x123d90,0xc9))['catch'](handleError(_0x123d90,null));};exports[_0xff95('0x34')]=function(_0xd5d027,_0x5e8d74){if(_0xd5d027[_0xff95('0x5a')]['id']){delete _0xd5d027['body']['id'];}return db['FaxAccount'][_0xff95('0x5e')]({'where':{'id':_0xd5d027['params']['id']},'include':[{'model':db[_0xff95('0x3d')],'as':_0xff95('0x3e')}]})[_0xff95('0x20')](handleEntityNotFound(_0x5e8d74,null))[_0xff95('0x20')](saveUpdates(_0xd5d027['body'],null))['then'](respondWithResult(_0x5e8d74,null))[_0xff95('0x29')](handleError(_0x5e8d74,null));};exports[_0xff95('0x35')]=function(_0x1e72f6,_0x504408){return db[_0xff95('0x40')][_0xff95('0x5e')]({'where':{'id':_0x1e72f6[_0xff95('0x57')]['id']}})[_0xff95('0x20')](handleEntityNotFound(_0x504408,null))[_0xff95('0x20')](removeEntity(_0x504408,null))[_0xff95('0x29')](handleError(_0x504408,null));};exports[_0xff95('0x60')]=function(_0x2de52b,_0x40cf5f){return db['FaxAccount'][_0xff95('0x60')]()['then'](respondWithResult(_0x40cf5f,null))[_0xff95('0x29')](handleError(_0x40cf5f,null));};exports[_0xff95('0x61')]=function(_0x3cd996,_0x18131b,_0x1ede1a){if(_0x3cd996[_0xff95('0x5a')]['id']){delete _0x3cd996[_0xff95('0x5a')]['id'];}return db[_0xff95('0x40')][_0xff95('0x5e')]({'where':{'id':_0x3cd996[_0xff95('0x57')]['id']}})[_0xff95('0x20')](handleEntityNotFound(_0x18131b,null))['then'](function(_0x9c419b){if(_0x9c419b){_0x3cd996[_0xff95('0x5a')][_0xff95('0x62')]=_0x9c419b['id'];return db[_0xff95('0x63')][_0xff95('0x59')](_0x3cd996[_0xff95('0x5a')]);}})[_0xff95('0x20')](respondWithResult(_0x18131b,null))[_0xff95('0x29')](handleError(_0x18131b,null));};exports[_0xff95('0x64')]=function(_0x4b7d5f,_0x517334,_0xd068df){var _0x4f4f00={'raw':![],'where':{}};var _0x505f40={};var _0x74fcf6={'count':0x0,'rows':[]};return db[_0xff95('0x40')][_0xff95('0x65')]({'where':{'id':_0x4b7d5f['params']['id']}})[_0xff95('0x20')](handleEntityNotFound(_0x517334,null))[_0xff95('0x20')](function(_0x3e449f){if(_0x3e449f){_0x505f40[_0xff95('0x45')]=_[_0xff95('0x46')](db[_0xff95('0x63')][_0xff95('0x41')]);_0x505f40['query']=_[_0xff95('0x46')](_0x4b7d5f['query']);_0x505f40[_0xff95('0x50')]=_[_0xff95('0x48')](_0x505f40[_0xff95('0x45')],_0x505f40['query']);_0x4f4f00[_0xff95('0x49')]=_['intersection'](_0x505f40[_0xff95('0x45')],qs['fields'](_0x4b7d5f[_0xff95('0x47')][_0xff95('0x4a')]));_0x4f4f00[_0xff95('0x49')]=_0x4f4f00['attributes'][_0xff95('0x58')]?_0x4f4f00[_0xff95('0x49')]:_0x505f40[_0xff95('0x45')];if(!_0x4b7d5f[_0xff95('0x47')]['hasOwnProperty'](_0xff95('0x4c'))){_0x4f4f00[_0xff95('0x30')]=qs[_0xff95('0x30')](_0x4b7d5f[_0xff95('0x47')][_0xff95('0x30')]);_0x4f4f00[_0xff95('0x2f')]=qs[_0xff95('0x2f')](_0x4b7d5f[_0xff95('0x47')][_0xff95('0x2f')]);}_0x4f4f00[_0xff95('0x4d')]=qs['sort'](_0x4b7d5f[_0xff95('0x47')][_0xff95('0x4e')]);_0x4f4f00[_0xff95('0x4f')]=qs[_0xff95('0x50')](_['pick'](_0x4b7d5f[_0xff95('0x47')],_0x505f40[_0xff95('0x50')]));_0x4f4f00[_0xff95('0x4f')][_0xff95('0x62')]=_0x3e449f['id'];if(_0x4b7d5f[_0xff95('0x47')][_0xff95('0x53')]){_0x4f4f00[_0xff95('0x4f')]=_['merge'](_0x4f4f00[_0xff95('0x4f')],{'$or':_['map'](_0x4f4f00[_0xff95('0x49')],function(_0x528ee1){var _0x1d88b7={};_0x1d88b7[_0x528ee1]={'$like':'%'+_0x4b7d5f[_0xff95('0x47')][_0xff95('0x53')]+'%'};return _0x1d88b7;})});}_0x4f4f00=_['merge']({},_0x4f4f00,_0x4b7d5f[_0xff95('0x66')]);return db[_0xff95('0x63')][_0xff95('0x2e')]({'where':_0x4f4f00[_0xff95('0x4f')]})[_0xff95('0x20')](function(_0xc1204d){_0x74fcf6[_0xff95('0x2e')]=_0xc1204d;if(_0x4b7d5f['query'][_0xff95('0x54')]){_0x4f4f00[_0xff95('0x67')]=[{'all':!![]}];}return db['Disposition'][_0xff95('0x68')](_0x4f4f00);})[_0xff95('0x20')](function(_0x4fa67e){_0x74fcf6[_0xff95('0x55')]=_0x4fa67e;return _0x74fcf6;});}})[_0xff95('0x20')](respondWithFilteredResult(_0x517334,_0x4f4f00))['catch'](handleError(_0x517334,null));};exports[_0xff95('0x69')]=function(_0x6815f1,_0x4e6e4b,_0x286acf){return db[_0xff95('0x40')][_0xff95('0x5e')]({'where':{'id':_0x6815f1[_0xff95('0x57')]['id']}})['then'](handleEntityNotFound(_0x4e6e4b,null))[_0xff95('0x20')](function(_0x479d26){if(_0x479d26){return _0x479d26[_0xff95('0x69')](_0x6815f1[_0xff95('0x47')][_0xff95('0x6a')]);}})[_0xff95('0x20')](respondWithStatusCode(_0x4e6e4b,null))[_0xff95('0x29')](handleError(_0x4e6e4b,null));};exports[_0xff95('0x6b')]=function(_0x7b69d7,_0x1d2d78,_0x280508){if(_0x7b69d7[_0xff95('0x5a')]['id']){delete _0x7b69d7[_0xff95('0x5a')]['id'];}return db[_0xff95('0x40')][_0xff95('0x5e')]({'where':{'id':_0x7b69d7[_0xff95('0x57')]['id']}})['then'](handleEntityNotFound(_0x1d2d78,null))[_0xff95('0x20')](function(_0x15cf83){if(_0x15cf83){_0x7b69d7[_0xff95('0x5a')][_0xff95('0x62')]=_0x15cf83['id'];return db[_0xff95('0x6c')][_0xff95('0x59')](_0x7b69d7['body']);}})[_0xff95('0x20')](respondWithResult(_0x1d2d78,null))[_0xff95('0x29')](handleError(_0x1d2d78,null));};exports[_0xff95('0x6d')]=function(_0x3aa31d,_0x4461a2,_0x46946b){var _0x1a2080={'raw':![],'where':{}};var _0x2730e3={};var _0x19e8d2={'count':0x0,'rows':[]};return db[_0xff95('0x40')][_0xff95('0x65')]({'where':{'id':_0x3aa31d[_0xff95('0x57')]['id']}})[_0xff95('0x20')](handleEntityNotFound(_0x4461a2,null))[_0xff95('0x20')](function(_0x16e596){if(_0x16e596){_0x2730e3['model']=_['keys'](db['CannedAnswer'][_0xff95('0x41')]);_0x2730e3['query']=_['keys'](_0x3aa31d[_0xff95('0x47')]);_0x2730e3['filters']=_[_0xff95('0x48')](_0x2730e3[_0xff95('0x45')],_0x2730e3['query']);_0x1a2080[_0xff95('0x49')]=_[_0xff95('0x48')](_0x2730e3[_0xff95('0x45')],qs[_0xff95('0x4a')](_0x3aa31d['query']['fields']));_0x1a2080[_0xff95('0x49')]=_0x1a2080['attributes'][_0xff95('0x58')]?_0x1a2080[_0xff95('0x49')]:_0x2730e3[_0xff95('0x45')];if(!_0x3aa31d[_0xff95('0x47')][_0xff95('0x4b')](_0xff95('0x4c'))){_0x1a2080[_0xff95('0x30')]=qs[_0xff95('0x30')](_0x3aa31d[_0xff95('0x47')][_0xff95('0x30')]);_0x1a2080[_0xff95('0x2f')]=qs[_0xff95('0x2f')](_0x3aa31d[_0xff95('0x47')][_0xff95('0x2f')]);}_0x1a2080[_0xff95('0x4d')]=qs['sort'](_0x3aa31d[_0xff95('0x47')][_0xff95('0x4e')]);_0x1a2080['where']=qs['filters'](_['pick'](_0x3aa31d['query'],_0x2730e3[_0xff95('0x50')]));_0x1a2080[_0xff95('0x4f')][_0xff95('0x62')]=_0x16e596['id'];if(_0x3aa31d[_0xff95('0x47')][_0xff95('0x53')]){_0x1a2080[_0xff95('0x4f')]=_[_0xff95('0x52')](_0x1a2080['where'],{'$or':_[_0xff95('0x3f')](_0x1a2080[_0xff95('0x49')],function(_0x287c31){var _0x3b5d93={};_0x3b5d93[_0x287c31]={'$like':'%'+_0x3aa31d[_0xff95('0x47')][_0xff95('0x53')]+'%'};return _0x3b5d93;})});}_0x1a2080=_[_0xff95('0x52')]({},_0x1a2080,_0x3aa31d[_0xff95('0x66')]);return db[_0xff95('0x6c')]['count']({'where':_0x1a2080[_0xff95('0x4f')]})[_0xff95('0x20')](function(_0x472e5a){_0x19e8d2[_0xff95('0x2e')]=_0x472e5a;if(_0x3aa31d[_0xff95('0x47')][_0xff95('0x54')]){_0x1a2080[_0xff95('0x67')]=[{'all':!![]}];}return db[_0xff95('0x6c')][_0xff95('0x68')](_0x1a2080);})[_0xff95('0x20')](function(_0x2c6804){_0x19e8d2['rows']=_0x2c6804;return _0x19e8d2;});}})[_0xff95('0x20')](respondWithFilteredResult(_0x4461a2,_0x1a2080))[_0xff95('0x29')](handleError(_0x4461a2,null));};exports['removeAnswers']=function(_0x5f012a,_0x1d5de5,_0xbd48dd){return db['FaxAccount']['find']({'where':{'id':_0x5f012a[_0xff95('0x57')]['id']}})['then'](handleEntityNotFound(_0x1d5de5,null))[_0xff95('0x20')](function(_0xd69789){if(_0xd69789){return _0xd69789[_0xff95('0x6e')](_0x5f012a['query'][_0xff95('0x6a')]);}})[_0xff95('0x20')](respondWithStatusCode(_0x1d5de5,null))[_0xff95('0x29')](handleError(_0x1d5de5,null));};exports['addInteraction']=function(_0x11f2b2,_0x554178,_0x1e46e4){return db['FaxInteraction'][_0xff95('0x5e')]({'where':{'id':_0x11f2b2['params']['id']}})[_0xff95('0x20')](handleEntityNotFound(_0x554178,null))[_0xff95('0x20')](function(_0x1cf806){if(_0x1cf806){return _0x1cf806['addInteraction'](_0x11f2b2[_0xff95('0x5a')][_0xff95('0x6a')],_[_0xff95('0x6f')](_0x11f2b2[_0xff95('0x5a')],['ids','id'])||{});}})['then'](respondWithResult(_0x554178,null))[_0xff95('0x29')](handleError(_0x554178,null));};exports[_0xff95('0x70')]=function(_0x16f436,_0x54ada7,_0x2ed68c){var _0x351050={'raw':![],'where':{}};var _0x76b843={};var _0x13f62d={'count':0x0,'rows':[]};return db[_0xff95('0x40')][_0xff95('0x65')]({'where':{'id':_0x16f436[_0xff95('0x57')]['id']}})[_0xff95('0x20')](handleEntityNotFound(_0x54ada7,null))[_0xff95('0x20')](function(_0x215e42){if(_0x215e42){_0x76b843[_0xff95('0x45')]=_[_0xff95('0x46')](db[_0xff95('0x71')][_0xff95('0x41')]);_0x76b843[_0xff95('0x47')]=_[_0xff95('0x46')](_0x16f436['query']);_0x76b843[_0xff95('0x50')]=_[_0xff95('0x48')](_0x76b843[_0xff95('0x45')],_0x76b843[_0xff95('0x47')]);_0x351050[_0xff95('0x49')]=_[_0xff95('0x48')](_0x76b843[_0xff95('0x45')],qs[_0xff95('0x4a')](_0x16f436[_0xff95('0x47')]['fields']));_0x351050['attributes']=_0x351050[_0xff95('0x49')]['length']?_0x351050[_0xff95('0x49')]:_0x76b843[_0xff95('0x45')];if(!_0x16f436[_0xff95('0x47')][_0xff95('0x4b')](_0xff95('0x4c'))){_0x351050['limit']=qs[_0xff95('0x30')](_0x16f436[_0xff95('0x47')][_0xff95('0x30')]);_0x351050['offset']=qs[_0xff95('0x2f')](_0x16f436[_0xff95('0x47')]['offset']);}_0x351050[_0xff95('0x4d')]=qs['sort'](_0x16f436[_0xff95('0x47')]['sort']);_0x351050[_0xff95('0x4f')]=qs[_0xff95('0x50')](_[_0xff95('0x51')](_0x16f436[_0xff95('0x47')],_0x76b843['filters']));_0x351050['where'][_0xff95('0x62')]=_0x215e42['id'];if(_0x16f436['query'][_0xff95('0x53')]){_0x351050['where']=_[_0xff95('0x52')](_0x351050[_0xff95('0x4f')],{'$or':_[_0xff95('0x3f')](_0x351050[_0xff95('0x49')],function(_0x52d0b6){var _0x4053ad={};_0x4053ad[_0x52d0b6]={'$like':'%'+_0x16f436[_0xff95('0x47')][_0xff95('0x53')]+'%'};return _0x4053ad;})});}_0x351050=_['merge']({},_0x351050,_0x16f436[_0xff95('0x66')]);return db['FaxInteraction'][_0xff95('0x2e')]({'where':_0x351050['where']})[_0xff95('0x20')](function(_0x13b768){_0x13f62d[_0xff95('0x2e')]=_0x13b768;if(_0x16f436['query'][_0xff95('0x54')]){_0x351050['include']=[{'model':db[_0xff95('0x72')],'as':_0xff95('0x73'),'required':![]},{'model':db[_0xff95('0x74')],'as':_0xff95('0x75'),'attributes':[_0xff95('0x3a'),_0xff95('0x76'),_0xff95('0x77')],'required':![]},{'model':db['Tag'],'as':_0xff95('0x78'),'attributes':['id',_0xff95('0x3a'),_0xff95('0x79')],'where':_0x16f436['query'][_0xff95('0x7a')]?{'id':_0x16f436['query'][_0xff95('0x7a')]}:undefined,'required':_0x16f436[_0xff95('0x47')][_0xff95('0x7a')]?!![]:![]}];}return db[_0xff95('0x71')]['findAll'](_0x351050);})[_0xff95('0x20')](function(_0x55d285){_0x13f62d[_0xff95('0x55')]=_0x55d285;return _0x13f62d;});}})[_0xff95('0x20')](respondWithFilteredResult(_0x54ada7,_0x351050))[_0xff95('0x29')](handleError(_0x54ada7,null));};exports['addApplications']=function(_0x165376,_0x49048d){var _0x5ebf35=_0x165376[_0xff95('0x57')]['id'];var _0x16c528=_0x165376['body'];var _0x3bb6df=0xc8;var _0x1dd05d=null;return db['sequelize'][_0xff95('0x7b')]({'isolationLevel':db[_0xff95('0x7c')]['Transaction'][_0xff95('0x7d')]['READ_COMMITTED']},function(_0xbc6e68){return db[_0xff95('0x40')][_0xff95('0x65')]({'where':{'id':_0x5ebf35},'transaction':_0xbc6e68})[_0xff95('0x20')](function(_0x1196fb){if(_0x1196fb){return db[_0xff95('0x7e')]['destroy']({'where':{'FaxAccountId':_0x5ebf35},'transaction':_0xbc6e68})[_0xff95('0x20')](function(){var _0x26e142=_[_0xff95('0x3f')](_0x16c528,function(_0x228fed){_0x228fed[_0xff95('0x62')]=_0x5ebf35;return _0x228fed;});return db[_0xff95('0x7e')][_0xff95('0x7f')](_0x26e142,{'transaction':_0xbc6e68});});}else{_0x3bb6df=0x194;_0x1dd05d=[];}});})['then'](function(){if(_0x3bb6df!==0x194){return db['FaxApplication'][_0xff95('0x80')]({'where':{'FaxAccountId':_0x5ebf35},'order':'priority'})['then'](function(_0x3258d2){_0x1dd05d=_0x3258d2;});}})['catch'](function(_0x23ad7f){_0x3bb6df=0x1f4;logger[_0xff95('0x25')](_0x23ad7f[_0xff95('0x39')]);if(_0x23ad7f[_0xff95('0x3a')]){delete _0x23ad7f[_0xff95('0x3a')];}_0x1dd05d=_0x23ad7f;})[_0xff95('0x81')](function(){if(_0x1dd05d===null){_0x49048d[_0xff95('0x82')](_0x3bb6df);}else{if(_0x3bb6df===0x1f4){_0x49048d['status'](_0x3bb6df)['send'](_0x1dd05d);}else{_0x49048d[_0xff95('0x2a')](_0x3bb6df)[_0xff95('0x2c')](_0x1dd05d);}}});};exports[_0xff95('0x83')]=function(_0x5d0805,_0x5958db,_0x1e0c92){var _0x379276={};var _0x5dea3b={};var _0x2a7e78;var _0x91640d;return db[_0xff95('0x40')]['findOne']({'where':{'id':_0x5d0805[_0xff95('0x57')]['id']}})[_0xff95('0x20')](handleEntityNotFound(_0x5958db,null))[_0xff95('0x20')](function(_0x816ccb){if(_0x816ccb){_0x2a7e78=_0x816ccb;_0x5dea3b['model']=_['keys'](db[_0xff95('0x7e')][_0xff95('0x41')]);_0x5dea3b[_0xff95('0x47')]=_['keys'](_0x5d0805[_0xff95('0x47')]);_0x5dea3b[_0xff95('0x50')]=_[_0xff95('0x48')](_0x5dea3b[_0xff95('0x45')],_0x5dea3b['query']);_0x379276['attributes']=_[_0xff95('0x48')](_0x5dea3b[_0xff95('0x45')],qs[_0xff95('0x4a')](_0x5d0805[_0xff95('0x47')]['fields']));_0x379276[_0xff95('0x49')]=_0x379276[_0xff95('0x49')][_0xff95('0x58')]?_0x379276[_0xff95('0x49')]:_0x5dea3b[_0xff95('0x45')];_0x379276[_0xff95('0x4d')]=qs[_0xff95('0x4e')](_0x5d0805[_0xff95('0x47')][_0xff95('0x4e')]);_0x379276[_0xff95('0x4f')]=qs[_0xff95('0x50')](_[_0xff95('0x51')](_0x5d0805[_0xff95('0x47')],_0x5dea3b[_0xff95('0x50')]));if(_0x5d0805[_0xff95('0x47')][_0xff95('0x53')]){_0x379276[_0xff95('0x4f')]=_[_0xff95('0x52')](_0x379276[_0xff95('0x4f')],{'$or':_['map'](_0x379276[_0xff95('0x49')],function(_0x2a4a84){var _0x3b75bf={};_0x3b75bf[_0x2a4a84]={'$like':'%'+_0x5d0805[_0xff95('0x47')][_0xff95('0x53')]+'%'};return _0x3b75bf;})});}_0x379276=_[_0xff95('0x52')]({},_0x379276,_0x5d0805[_0xff95('0x66')]);return _0x2a7e78['getApplications'](_0x379276);}})[_0xff95('0x20')](function(_0x85123a){if(_0x85123a){_0x91640d=_0x85123a[_0xff95('0x58')];if(!_0x5d0805[_0xff95('0x47')][_0xff95('0x4b')](_0xff95('0x4c'))){_0x379276[_0xff95('0x30')]=qs[_0xff95('0x30')](_0x5d0805[_0xff95('0x47')]['limit']);_0x379276[_0xff95('0x2f')]=qs[_0xff95('0x2f')](_0x5d0805[_0xff95('0x47')]['offset']);}return _0x2a7e78['getApplications'](_0x379276);}})[_0xff95('0x20')](function(_0x5db45e){if(_0x5db45e){return _0x5db45e?{'count':_0x91640d,'rows':_0x5db45e}:null;}})[_0xff95('0x20')](respondWithResult(_0x5958db,null))[_0xff95('0x29')](handleError(_0x5958db,null));};function Extension(_0x5ee563,_0x378c02,_0x3e2f5c,_0x3c6d3a){this[_0xff95('0x84')]=_0xff95('0x85');this[_0xff95('0x86')]=_0x5ee563[_0xff95('0x87')];this['app']=_0x3c6d3a;this[_0xff95('0x43')]=_0xff95('0x88');this[_0xff95('0x89')]='Fax\x20Extension';this[_0xff95('0x62')]=_0x5ee563['id'];this[_0xff95('0x8a')]=_0x378c02;this[_0xff95('0x8b')]=_0x3e2f5c;}function createExtensionsReciveFax(_0x5dca3f){var _0x2fcb7a=0x1;var _0x462105=[];_0x462105['push'](new Extension(_0x5dca3f,_0x2fcb7a,'',_0xff95('0x8c')));_0x2fcb7a+=0x1;_0x462105[_0xff95('0x8d')](new Extension(_0x5dca3f,_0x2fcb7a,_0xff95('0x8e'),'Set'));_0x2fcb7a+=0x1;for(var _0x4667b6 in _0x5dca3f){if(_0x5dca3f['hasOwnProperty'](_0x4667b6)&&(_0x4667b6===_0xff95('0x8f')||_0x4667b6===_0xff95('0x87')||_0x4667b6===_0xff95('0x90')||_0x4667b6==='faxdetect'||_0x4667b6===_0xff95('0x91')||_0x4667b6===_0xff95('0x92')||_0x4667b6==='minrate'||_0x4667b6===_0xff95('0x93')||_0x4667b6==='t38timeout')){_0x462105[_0xff95('0x8d')](new Extension(_0x5dca3f,_0x2fcb7a,'FAXOPT('+_0x4667b6+')='+_0x5dca3f[_0x4667b6],'Set'));_0x2fcb7a+=0x1;}}_0x462105[_0xff95('0x8d')](new Extension(_0x5dca3f,_0x2fcb7a,'6',_0xff95('0x94')));_0x2fcb7a+=0x1;_0x462105['push'](new Extension(_0x5dca3f,_0x2fcb7a,_0xff95('0x95'),_0xff95('0x96')));_0x2fcb7a=0x0;return _0x462105;}exports[_0xff95('0x97')]=function(_0x3b25d2,_0x26b1ac,_0x51b413){var _0xab3042;return db[_0xff95('0x7c')][_0xff95('0x7b')](function(_0x1e0e0e){return db[_0xff95('0x40')]['create'](_0x3b25d2[_0xff95('0x5a')],{'transaction':_0x1e0e0e})[_0xff95('0x20')](function(_0x4680b2){_0xab3042=_0x4680b2['get']({'plain':!![]});return db[_0xff95('0x98')][_0xff95('0x7f')](createExtensionsReciveFax(_0xab3042),{'transaction':_0x1e0e0e});});})[_0xff95('0x20')](function(){return _0xab3042;})[_0xff95('0x20')](respondWithResult(_0x26b1ac,null))[_0xff95('0x29')](handleError(_0x26b1ac,null));};exports[_0xff95('0x99')]=function(_0x55e3b0,_0x4c7d7c,_0x2bc368){var _0x2d3c94;return db[_0xff95('0x7c')]['transaction'](function(_0x152539){return db[_0xff95('0x40')]['update'](_0x55e3b0[_0xff95('0x5a')],{'where':{'id':_0x55e3b0[_0xff95('0x5a')]['id']},'transaction':_0x152539})[_0xff95('0x20')](function(_0x278812){return db['VoiceExtension'][_0xff95('0x35')]({'where':{'FaxAccountId':_0x55e3b0[_0xff95('0x5a')]['id']},'transaction':_0x152539})['then'](function(_0x561e24){return db[_0xff95('0x98')][_0xff95('0x7f')](createExtensionsReciveFax(_[_0xff95('0x6f')](_0x55e3b0[_0xff95('0x5a')],['tech',_0xff95('0x44'),'createdAt','updatedAt','TrunkId',_0xff95('0x9a')])),{'transaction':_0x152539});});});})['then'](function(){return db['FaxAccount'][_0xff95('0x9b')](_0x55e3b0[_0xff95('0x5a')]['id']);})[_0xff95('0x20')](respondWithResult(_0x4c7d7c,null))['catch'](handleError(_0x4c7d7c,null));};exports[_0xff95('0x9c')]=function(_0x4f99b1,_0x3aff8e,_0x5b1a9){var _0x437f39={'raw':!![],'where':{}};var _0x182ab6={};var _0x4f1606={'count':0x0,'rows':[]};return db[_0xff95('0x40')][_0xff95('0x65')]({'where':{'id':_0x4f99b1['params']['id']}})[_0xff95('0x20')](handleEntityNotFound(_0x3aff8e,null))[_0xff95('0x20')](function(_0x50e721){if(_0x50e721){_0x182ab6['model']=_['keys'](db[_0xff95('0x9d')]['rawAttributes']);_0x182ab6['query']=_['keys'](_0x4f99b1['query']);_0x182ab6[_0xff95('0x50')]=_[_0xff95('0x48')](_0x182ab6[_0xff95('0x45')],_0x182ab6[_0xff95('0x47')]);_0x437f39[_0xff95('0x49')]=_['intersection'](_0x182ab6[_0xff95('0x45')],qs[_0xff95('0x4a')](_0x4f99b1[_0xff95('0x47')][_0xff95('0x4a')]));_0x437f39['attributes']=_0x437f39[_0xff95('0x49')]['length']?_0x437f39['attributes']:_0x182ab6[_0xff95('0x45')];if(!_0x4f99b1[_0xff95('0x47')]['hasOwnProperty'](_0xff95('0x4c'))){_0x437f39[_0xff95('0x30')]=qs[_0xff95('0x30')](_0x4f99b1[_0xff95('0x47')]['limit']);_0x437f39['offset']=qs['offset'](_0x4f99b1['query']['offset']);}_0x437f39['order']=qs[_0xff95('0x4e')](_0x4f99b1['query'][_0xff95('0x4e')]);_0x437f39[_0xff95('0x4f')]=qs['filters'](_[_0xff95('0x51')](_0x4f99b1[_0xff95('0x47')],_0x182ab6[_0xff95('0x50')]));_0x437f39[_0xff95('0x4f')]['FaxAccountId']=_0x50e721['id'];if(_0x4f99b1[_0xff95('0x47')]['filter']){_0x437f39[_0xff95('0x4f')]=_[_0xff95('0x52')](_0x437f39[_0xff95('0x4f')],{'$or':_[_0xff95('0x3f')](_0x437f39[_0xff95('0x49')],function(_0x3c417d){var _0x3930cf={};_0x3930cf[_0x3c417d]={'$like':'%'+_0x4f99b1[_0xff95('0x47')][_0xff95('0x53')]+'%'};return _0x3930cf;})});}if(_0x4f99b1[_0xff95('0x47')][_0xff95('0x9e')]){var _0x32332a=_0x4f99b1[_0xff95('0x47')][_0xff95('0x9e')][_0xff95('0x9f')](',');var _0x3ee6ed={};_0x3ee6ed[_0x32332a[0x0]]={'$gte':moment(_0x32332a[0x1])[_0xff95('0xa0')]('YYYY-MM-DD\x20HH:mm:ss')};_0x437f39[_0xff95('0x4f')]=_[_0xff95('0x52')](_0x437f39[_0xff95('0x4f')],_0x3ee6ed);}_0x437f39=_[_0xff95('0x52')]({},_0x437f39,_0x4f99b1[_0xff95('0x66')]);return db['FaxMessage'][_0xff95('0x2e')]({'where':_0x437f39[_0xff95('0x4f')]})[_0xff95('0x20')](function(_0x1ee34c){_0x4f1606[_0xff95('0x2e')]=_0x1ee34c;if(_0x4f99b1[_0xff95('0x47')][_0xff95('0x54')]){_0x437f39[_0xff95('0x67')]=[{'all':!![]}];}return db[_0xff95('0x9d')]['findAll'](_0x437f39);})[_0xff95('0x20')](function(_0x5f57a7){_0x4f1606[_0xff95('0x55')]=_0x5f57a7;return _0x4f1606;});}})[_0xff95('0x20')](respondWithFilteredResult(_0x3aff8e,_0x437f39))[_0xff95('0x29')](handleError(_0x3aff8e,null));};exports[_0xff95('0x3b')]=function(_0x5b9100,_0x20ef22,_0x381787){var _0x551b38,_0x109c6a={},_0x5b5bd9;if(_0x5b9100[_0xff95('0x5a')]['to']){_0x5b5bd9=_0x5b9100[_0xff95('0x5a')]['to'][0x0];}return db[_0xff95('0x40')][_0xff95('0x5e')]({'where':{'id':_0x5b9100[_0xff95('0x57')]['id']},'include':[{'model':db[_0xff95('0xa1')],'as':'List','include':[{'model':db[_0xff95('0x72')],'as':_0xff95('0xa2'),'where':{'fax':_0x5b5bd9},'limit':0x1,'order':[['updatedAt',_0xff95('0xa3')]]}]}]})[_0xff95('0x20')](handleEntityNotFound(_0x20ef22,null))[_0xff95('0x20')](function(_0x33eca0){_0x551b38=_0x33eca0;if(_0x5b9100[_0xff95('0x5a')][_0xff95('0xa4')]&&_0x5b9100[_0xff95('0x5a')]['attachments'][_0xff95('0x58')]){for(var _0x3fda44=0x0;_0x3fda44<_0x5b9100[_0xff95('0x5a')][_0xff95('0xa4')][_0xff95('0x58')];_0x3fda44+=0x1){_0x5b9100[_0xff95('0x5a')]['attachments'][_0x3fda44]={'filename':_0x5b9100[_0xff95('0x5a')][_0xff95('0xa4')][_0x3fda44][_0xff95('0x3a')],'id':_0x5b9100[_0xff95('0x5a')][_0xff95('0xa4')][_0x3fda44]['id'],'path':path[_0xff95('0xa5')](config['root'],_0xff95('0xa6'),_0x5b9100['body']['attachments'][_0x3fda44][_0xff95('0xa7')])};}}return respondWithRpcPromise('CheckAfterSend',_0xff95('0xa8'),{'FaxAccountId':_[_0xff95('0xa9')](_0x5b9100[_0xff95('0x57')]['id'])?undefined:_0x5b9100[_0xff95('0x57')]['id'],'path':_['isNil'](_0x5b9100[_0xff95('0x5a')]['attachments'][0x0][_0xff95('0x7')])?undefined:_0x5b9100['body'][_0xff95('0xa4')][0x0][_0xff95('0x7')],'fax':_[_0xff95('0xa9')](_0x5b9100[_0xff95('0x5a')]['to'][0x0])?undefined:_0x5b9100[_0xff95('0x5a')]['to'][0x0]},client9002);})[_0xff95('0x20')](function(){if(_0x551b38){if(_[_0xff95('0xa9')](_0x5b9100[_0xff95('0x5a')]['from'])){_0x5b9100[_0xff95('0x5a')][_0xff95('0xaa')]=util[_0xff95('0xa0')](_0xff95('0xab'),_0x551b38[_0xff95('0x3a')],_0x551b38[_0xff95('0xac')]);}if(_0x551b38[_0xff95('0xad')]){if(_0x551b38[_0xff95('0xad')][_0xff95('0xa2')][_0xff95('0x58')]){return _0x551b38[_0xff95('0xad')][_0xff95('0xa2')][0x0];}else{return db[_0xff95('0x72')][_0xff95('0x59')](_['defaults'](_0x5b9100[_0xff95('0x5a')],{'firstName':_0x5b9100['body']['to'][0x0],'phone':_0x5b9100['body']['to'][0x0],'fax':_0x5b9100[_0xff95('0x5a')]['to'][0x0],'ListId':_0x551b38['ListId']}));}}else{throw new Error(_0xff95('0xae'));}}else{throw new Error(_0xff95('0xaf'));}})[_0xff95('0x20')](function(_0x30899e){if(_0x30899e){return db['FaxInteraction'][_0xff95('0x5e')]({'where':{'ContactId':_0x30899e['id'],'closed':![],'FaxAccountId':_0x551b38['id']}})['then'](function(_0x30cb1a){if(_0x30cb1a){return[_0x30cb1a,![]];}return db[_0xff95('0x71')][_0xff95('0x59')]({'UserId':_0x5b9100[_0xff95('0x5b')]['id'],'ContactId':_0x30899e['id'],'FaxAccountId':_0x551b38['id'],'fax':_0x5b9100[_0xff95('0x5a')]['to'][0x0],'firstMsgDirection':_0xff95('0xb0'),'Messages':[_[_0xff95('0x52')](_0x5b9100[_0xff95('0x5a')],{'read':![],'body':_0x5b9100[_0xff95('0x5a')][_0xff95('0xa4')][0x0][_0xff95('0xb1')],'FaxAccountId':_0x551b38['id'],'UserId':_0x5b9100[_0xff95('0x5b')]['id'],'ContactId':_0x30899e['id'],'AttachmentId':_0x5b9100[_0xff95('0x5a')][_0xff95('0xa4')][0x0]['id']})]},{'include':[{'model':db[_0xff95('0x9d')],'as':'Messages'}]})[_0xff95('0x20')](function(_0x2ae9b2){return[_0x2ae9b2,!![]];});});}else{throw new Error(_0xff95('0xb2'));}})[_0xff95('0xb3')](function(_0x47bee9,_0x41f08b){if(_0x41f08b){return _0x47bee9;}return db[_0xff95('0x9d')][_0xff95('0x59')]({'direction':_0xff95('0xb0'),'read':![],'body':_0x5b9100[_0xff95('0x5a')]['attachments'][0x0][_0xff95('0xb1')],'FaxAccountId':_0x551b38['id'],'FaxInteractionId':_0x47bee9['id'],'UserId':_0x5b9100[_0xff95('0x5b')]['id'],'ContactId':_0x47bee9[_0xff95('0xb4')],'AttachmentId':_0x5b9100['body'][_0xff95('0xa4')][0x0]['id']})[_0xff95('0x20')](function(_0x3f19e9){_0x47bee9['dataValues'][_0xff95('0xb5')]=[];_0x47bee9[_0xff95('0xb6')][_0xff95('0xb5')][_0xff95('0x8d')](_0x3f19e9[_0xff95('0xb6')]);return _0x47bee9;});})[_0xff95('0x20')](function(_0x3f9abf){respondWithRpcPromise(_0xff95('0xb7'),_0xff95('0xb7'),{'FaxAccountId':_[_0xff95('0xa9')](_0x5b9100['params']['id'])?undefined:_0x5b9100[_0xff95('0x57')]['id'],'path':_[_0xff95('0xa9')](_0x5b9100[_0xff95('0x5a')]['attachments'][0x0][_0xff95('0x7')])?undefined:_0x5b9100[_0xff95('0x5a')][_0xff95('0xa4')][0x0][_0xff95('0x7')],'fax':_[_0xff95('0xa9')](_0x5b9100[_0xff95('0x5a')]['to'][0x0])?undefined:_0x5b9100[_0xff95('0x5a')]['to'][0x0],'AttachmentId':_0x5b9100[_0xff95('0x5a')]['attachments'][0x0]['id']},client9002)['then'](function(_0x3c528d){logger[_0xff95('0xb8')]('SendFaxRpc,\x20%s',_0x3c528d);})[_0xff95('0x29')](function(_0xa4692b){logger[_0xff95('0xb8')](_0xff95('0xb9'),_0xa4692b);});return _0x3f9abf;})[_0xff95('0x20')](respondWithResult(_0x20ef22,null))[_0xff95('0x29')](handleError(_0x20ef22,null));};exports[_0xff95('0xba')]=function(_0x645f94,_0x1d201f,_0x42e38a){return db[_0xff95('0x40')][_0xff95('0x5e')]({'where':{'id':_0x645f94['params']['id']}})[_0xff95('0x20')](handleEntityNotFound(_0x1d201f,null))[_0xff95('0x20')](function(_0x2ce50b){if(_0x2ce50b){return _0x2ce50b[_0xff95('0xba')](_0x645f94[_0xff95('0x5a')][_0xff95('0x6a')],_[_0xff95('0x6f')](_0x645f94[_0xff95('0x5a')],[_0xff95('0x6a'),'id'])||{})[_0xff95('0xb3')](function(_0x5bcd05){for(var _0x3ba6d1=0x0;_0x3ba6d1<_0x645f94[_0xff95('0x5a')][_0xff95('0x6a')][_0xff95('0x58')];_0x3ba6d1+=0x1){socket[_0xff95('0xbb')](_0xff95('0xbc'),{'UserId':Number(_0x645f94['body'][_0xff95('0x6a')][_0x3ba6d1]),'FaxAccountId':Number(_0x645f94[_0xff95('0x57')]['id'])});}return _0x5bcd05;});}})['then'](respondWithResult(_0x1d201f,null))[_0xff95('0x29')](handleError(_0x1d201f,null));};exports['removeAgents']=function(_0x2c1e18,_0x1e5c97,_0x3e5852){return db[_0xff95('0x40')][_0xff95('0x5e')]({'where':{'id':_0x2c1e18['params']['id']}})[_0xff95('0x20')](handleEntityNotFound(_0x1e5c97,null))['then'](function(_0x441db4){if(_0x441db4){return _0x441db4[_0xff95('0xbd')](_0x2c1e18[_0xff95('0x47')][_0xff95('0x6a')])[_0xff95('0x20')](function(){if(_[_0xff95('0xbe')](_0x2c1e18[_0xff95('0x47')][_0xff95('0x6a')])){for(var _0x3a4923=0x0;_0x3a4923<_0x2c1e18['query'][_0xff95('0x6a')][_0xff95('0x58')];_0x3a4923+=0x1){socket[_0xff95('0xbb')](_0xff95('0xbf'),{'UserId':Number(_0x2c1e18[_0xff95('0x47')][_0xff95('0x6a')][_0x3a4923]),'FaxAccountId':Number(_0x2c1e18[_0xff95('0x57')]['id'])});}}else{socket['emit'](_0xff95('0xbf'),{'UserId':Number(_0x2c1e18[_0xff95('0x47')][_0xff95('0x6a')]),'FaxAccountId':Number(_0x2c1e18['params']['id'])});}});}})[_0xff95('0x20')](respondWithStatusCode(_0x1e5c97,null))[_0xff95('0x29')](handleError(_0x1e5c97,null));};exports[_0xff95('0xc0')]=function(_0x4ea067,_0x3f5621,_0x452b39){var _0x443718={};var _0x211b4e={};var _0x37959a;var _0x1178f1;return db['FaxAccount']['findOne']({'where':{'id':_0x4ea067[_0xff95('0x57')]['id']}})['then'](handleEntityNotFound(_0x3f5621,null))[_0xff95('0x20')](function(_0x27e445){if(_0x27e445){_0x37959a=_0x27e445;_0x211b4e[_0xff95('0x45')]=_['keys'](db[_0xff95('0x74')][_0xff95('0x41')]);_0x211b4e[_0xff95('0x47')]=_[_0xff95('0x46')](_0x4ea067[_0xff95('0x47')]);_0x211b4e[_0xff95('0x50')]=_[_0xff95('0x48')](_0x211b4e[_0xff95('0x45')],_0x211b4e[_0xff95('0x47')]);_0x443718[_0xff95('0x49')]=_['intersection'](_0x211b4e[_0xff95('0x45')],qs['fields'](_0x4ea067[_0xff95('0x47')][_0xff95('0x4a')]));_0x443718[_0xff95('0x49')]=_0x443718[_0xff95('0x49')][_0xff95('0x58')]?_0x443718['attributes']:_0x211b4e[_0xff95('0x45')];_0x443718['order']=qs[_0xff95('0x4e')](_0x4ea067['query'][_0xff95('0x4e')]);_0x443718[_0xff95('0x4f')]=qs[_0xff95('0x50')](_[_0xff95('0x51')](_0x4ea067[_0xff95('0x47')],_0x211b4e['filters']));if(_0x4ea067[_0xff95('0x47')][_0xff95('0x53')]){_0x443718[_0xff95('0x4f')]=_[_0xff95('0x52')](_0x443718[_0xff95('0x4f')],{'$or':_[_0xff95('0x3f')](_0x443718[_0xff95('0x49')],function(_0xf4a34){var _0x4d16e1={};_0x4d16e1[_0xf4a34]={'$like':'%'+_0x4ea067[_0xff95('0x47')][_0xff95('0x53')]+'%'};return _0x4d16e1;})});}_0x443718=_['merge']({},_0x443718,_0x4ea067[_0xff95('0x66')]);return _0x37959a['getAgents'](_0x443718);}})['then'](function(_0x1b7c72){if(_0x1b7c72){_0x1178f1=_0x1b7c72[_0xff95('0x58')];if(!_0x4ea067[_0xff95('0x47')][_0xff95('0x4b')](_0xff95('0x4c'))){_0x443718[_0xff95('0x30')]=qs[_0xff95('0x30')](_0x4ea067['query'][_0xff95('0x30')]);_0x443718[_0xff95('0x2f')]=qs[_0xff95('0x2f')](_0x4ea067[_0xff95('0x47')][_0xff95('0x2f')]);}return _0x37959a['getAgents'](_0x443718);}})[_0xff95('0x20')](function(_0x345d90){if(_0x345d90){return _0x345d90?{'count':_0x1178f1,'rows':_0x345d90}:null;}})[_0xff95('0x20')](respondWithResult(_0x3f5621,null))[_0xff95('0x29')](handleError(_0x3f5621,null));};