Built motion from commit (unavailable).|2.4.18
[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 _0x21f8=['papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','redis','localhost','./faxAccount.socket','register','jayson/promise','http','test','Sequelize','ValidationError','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','request','info','FaxAccount,\x20%s,\x20%s','request\x20sent','FaxAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','reject','update','then','UserProfileResource','destroy','end','stack','name','send','mandatoryDispositionPause','map','FaxAccount','rawAttributes','fieldName','model','query','keys','intersection','fields','attributes','length','nolimit','sort','where','filters','pick','filter','merge','type','VIRTUAL','options','include','rows','show','find','create','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','params','Pause','describe','addDisposition','FaxAccountId','findOne','hasOwnProperty','Disposition','includeAll','findAll','removeDispositions','CannedAnswer','order','removeAnswers','addInteraction','FaxInteraction','ids','omit','getInteractions','CmContact','Contact','User','Owner','internal','Tag','Tags','color','tag','sequelize','transaction','FaxApplication','bulkCreate','priority','getApplications','from-voip-provider','exten','localstationid','app','system','description','Fax\x20Extension','push','CDR(type)=inbound-fax','Set','gateway','faxdetect','headerinfo','maxrate','modem','t38timeout','FAXOPT(','Wait','/var/opt/motion2/server/files/attachments/fax-${CALLERID(num)}-${CUT(UNIQUEID,.,1)}-${CUT(UNIQUEID,.,2)}-${STRFTIME(,,%C%y%m%d%H%M%S)}-rx.tif,d','ReceiveFax','addAccountApplications','VoiceExtension','tech','key','createdAt','updatedAt','TrunkId','ListId','findById','FaxMessage','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','Contacts','DESC','attachments','join','root','server/files/attachments','basename','CheckAfterSend','isNil','from','\x22%s\x22\x20<%s>','fax','List','defaults','Send\x20Fax\x20failed','filename','Messages','spread','out','ContactId','dataValues','SendFax','SendFaxRpc,\x20%s','addAgents','emit','userFaxAccount:save','removeAgents','isArray','userFaxAccount:remove','getAgents','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js'];(function(_0x7e201,_0x3efc32){var _0x1c988e=function(_0x3bb303){while(--_0x3bb303){_0x7e201['push'](_0x7e201['shift']());}};_0x1c988e(++_0x3efc32);}(_0x21f8,0x179));var _0x821f=function(_0x39609a,_0x28a563){_0x39609a=_0x39609a-0x0;var _0xecd92=_0x21f8[_0x39609a];return _0xecd92;};'use strict';var pdf=require(_0x821f('0x0'));var emlformat=require(_0x821f('0x1'));var rimraf=require(_0x821f('0x2'));var zipdir=require(_0x821f('0x3'));var jsonpatch=require(_0x821f('0x4'));var rp=require(_0x821f('0x5'));var moment=require(_0x821f('0x6'));var BPromise=require(_0x821f('0x7'));var Mustache=require('mustache');var util=require(_0x821f('0x8'));var path=require(_0x821f('0x9'));var sox=require(_0x821f('0xa'));var csv=require(_0x821f('0xb'));var ejs=require(_0x821f('0xc'));var fs=require('fs');var _=require(_0x821f('0xd'));var squel=require(_0x821f('0xe'));var crypto=require('crypto');var jsforce=require(_0x821f('0xf'));var deskjs=require(_0x821f('0x10'));var toCsv=require(_0x821f('0xb'));var querystring=require('querystring');var Papa=require(_0x821f('0x11'));var Redis=require(_0x821f('0x12'));var authService=require(_0x821f('0x13'));var qs=require(_0x821f('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x821f('0x15'));var logger=require(_0x821f('0x16'))(_0x821f('0x17'));var utils=require(_0x821f('0x18'));var config=require(_0x821f('0x19'));var db=require(_0x821f('0x1a'))['db'];config[_0x821f('0x1b')]=_['defaults'](config[_0x821f('0x1b')],{'host':_0x821f('0x1c'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x821f('0x1b')]));require(_0x821f('0x1d'))[_0x821f('0x1e')](socket);var jayson=require(_0x821f('0x1f'));var client=jayson['client'][_0x821f('0x20')]({'port':0x232c});var client9002=jayson['client']['http']({'port':0x232a});function checkPasswordPattern(_0x856139,_0x1e4cc9,_0x41f554){if(_0x41f554){var _0x1be0b9=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x1be0b9[_0x821f('0x21')](_0x1e4cc9)){return _0x856139;}else{throw new db[(_0x821f('0x22'))][(_0x821f('0x23'))](_0x821f('0x24'));}}else{return _0x856139;}}function respondWithRpcPromise(_0x32ebf9,_0xaa4709,_0x316b95,_0x15cf4f){return new BPromise(function(_0x4ba7f6,_0xb5474b){var _0x34e804=_0x15cf4f||client;return _0x34e804[_0x821f('0x25')](_0x32ebf9,_0x316b95)['then'](function(_0x224764){logger[_0x821f('0x26')](_0x821f('0x27'),_0xaa4709,_0x821f('0x28'));logger['debug'](_0x821f('0x29'),_0xaa4709,'request\x20sent',JSON[_0x821f('0x2a')](_0x224764));if(_0x224764[_0x821f('0x2b')]){if(_0x224764['error'][_0x821f('0x2c')]===0x1f4){logger[_0x821f('0x2b')]('FaxAccount,\x20%s,\x20%s',_0xaa4709,_0x224764[_0x821f('0x2b')][_0x821f('0x2d')]);return _0xb5474b(_0x224764[_0x821f('0x2b')]['message']);}logger[_0x821f('0x2b')]('FaxAccount,\x20%s,\x20%s',_0xaa4709,_0x224764[_0x821f('0x2b')][_0x821f('0x2d')]);return _0x4ba7f6(_0x224764[_0x821f('0x2b')][_0x821f('0x2d')]);}else{logger['info'](_0x821f('0x27'),_0xaa4709,'request\x20sent');_0x4ba7f6(_0x224764[_0x821f('0x2e')][_0x821f('0x2d')]);}})[_0x821f('0x2f')](function(_0x4054fa){logger[_0x821f('0x2b')](_0x821f('0x27'),_0xaa4709,_0x4054fa);_0xb5474b(_0x4054fa);});});}function respondWithStatusCode(_0x414042,_0x36066d){_0x36066d=_0x36066d||0xcc;return function(_0xc6493e){if(_0xc6493e){return _0x414042[_0x821f('0x30')](_0x36066d);}return _0x414042[_0x821f('0x31')](_0x36066d)['end']();};}function respondWithResult(_0xe3dac4,_0x28ad2f){_0x28ad2f=_0x28ad2f||0xc8;return function(_0x1bb9cd){if(_0x1bb9cd){return _0xe3dac4[_0x821f('0x31')](_0x28ad2f)[_0x821f('0x32')](_0x1bb9cd);}};}function respondWithFilteredResult(_0x3e3468,_0x3b3a75){return function(_0x1e721b){if(_0x1e721b){var _0x1c9d33=_0x1e721b[_0x821f('0x33')],_0x2be7a4=_0x3b3a75[_0x821f('0x34')],_0x22db7e=_0x3b3a75['offset']+_0x3b3a75[_0x821f('0x35')],_0x2223bc;if(_0x22db7e>=_0x1c9d33){_0x22db7e=_0x1c9d33;_0x2223bc=0xc8;}else{_0x2223bc=0xce;}_0x3e3468['status'](_0x2223bc);return _0x3e3468[_0x821f('0x36')](_0x821f('0x37'),_0x2be7a4+'-'+_0x22db7e+'/'+_0x1c9d33)[_0x821f('0x32')](_0x1e721b);}return null;};}function patchUpdates(_0x13487e){return function(_0x2659fe){try{jsonpatch[_0x821f('0x38')](_0x2659fe,_0x13487e,!![]);}catch(_0x4a9b9f){return BPromise[_0x821f('0x39')](_0x4a9b9f);}return _0x2659fe['save']();};}function saveUpdates(_0x1c1d28,_0x15a204){return function(_0x310965){if(_0x310965){return _0x310965[_0x821f('0x3a')](_0x1c1d28)[_0x821f('0x3b')](function(_0xa0cd75){return _0xa0cd75;});}return null;};}function removeEntity(_0x1ab7e9,_0x4dcd6){return function(_0x25ee42){if(_0x25ee42){return _0x25ee42['destroy']()[_0x821f('0x3b')](function(){var _0x503f02=_0x25ee42['get']({'plain':!![]});var _0x1e9ab5='FaxAccounts';return db[_0x821f('0x3c')][_0x821f('0x3d')]({'where':{'type':_0x1e9ab5,'resourceId':_0x503f02['id']}})['then'](function(){return _0x25ee42;});})[_0x821f('0x3b')](function(){_0x1ab7e9[_0x821f('0x31')](0xcc)[_0x821f('0x3e')]();});}};}function handleEntityNotFound(_0x53c795,_0xa48b0){return function(_0x58cd37){if(!_0x58cd37){_0x53c795[_0x821f('0x30')](0x194);}return _0x58cd37;};}function handleError(_0x25a3c2,_0x497a81){_0x497a81=_0x497a81||0x1f4;return function(_0x49d2b4){logger[_0x821f('0x2b')](_0x49d2b4[_0x821f('0x3f')]);if(_0x49d2b4[_0x821f('0x40')]){delete _0x49d2b4[_0x821f('0x40')];}_0x25a3c2['status'](_0x497a81)[_0x821f('0x41')](_0x49d2b4);};}exports['index']=function(_0x25bffb,_0x58897d){var _0x4654b4={'include':[{'model':db['Pause'],'as':_0x821f('0x42')}]},_0x39af99={},_0x2bc1c5={'count':0x0,'rows':[]};var _0x46c2c4=_[_0x821f('0x43')](db[_0x821f('0x44')][_0x821f('0x45')],function(_0x59185e){return{'name':_0x59185e[_0x821f('0x46')],'type':_0x59185e['type']['key']};});_0x39af99[_0x821f('0x47')]=_[_0x821f('0x43')](_0x46c2c4,'name');_0x39af99[_0x821f('0x48')]=_[_0x821f('0x49')](_0x25bffb[_0x821f('0x48')]);_0x39af99['filters']=_[_0x821f('0x4a')](_0x39af99[_0x821f('0x47')],_0x39af99[_0x821f('0x48')]);_0x4654b4['attributes']=_[_0x821f('0x4a')](_0x39af99['model'],qs[_0x821f('0x4b')](_0x25bffb['query'][_0x821f('0x4b')]));_0x4654b4[_0x821f('0x4c')]=_0x4654b4[_0x821f('0x4c')][_0x821f('0x4d')]?_0x4654b4[_0x821f('0x4c')]:_0x39af99['model'];if(!_0x25bffb[_0x821f('0x48')]['hasOwnProperty'](_0x821f('0x4e'))){_0x4654b4[_0x821f('0x35')]=qs['limit'](_0x25bffb[_0x821f('0x48')][_0x821f('0x35')]);_0x4654b4[_0x821f('0x34')]=qs['offset'](_0x25bffb[_0x821f('0x48')]['offset']);}_0x4654b4['order']=qs[_0x821f('0x4f')](_0x25bffb[_0x821f('0x48')][_0x821f('0x4f')]);_0x4654b4[_0x821f('0x50')]=qs[_0x821f('0x51')](_[_0x821f('0x52')](_0x25bffb[_0x821f('0x48')],_0x39af99[_0x821f('0x51')]));if(_0x25bffb[_0x821f('0x48')][_0x821f('0x53')]){_0x4654b4[_0x821f('0x50')]=_[_0x821f('0x54')](_0x4654b4[_0x821f('0x50')],{'$or':_[_0x821f('0x43')](_0x46c2c4,function(_0x36f45a){if(_0x36f45a[_0x821f('0x55')]!==_0x821f('0x56')){var _0x382f8e={};_0x382f8e[_0x36f45a[_0x821f('0x40')]]={'$like':'%'+_0x25bffb['query']['filter']+'%'};return _0x382f8e;}})});}_0x4654b4=_[_0x821f('0x54')]({},_0x4654b4,_0x25bffb[_0x821f('0x57')]);var _0x4d795b={'where':_0x4654b4[_0x821f('0x50')]};return db[_0x821f('0x44')][_0x821f('0x33')](_0x4d795b)[_0x821f('0x3b')](function(_0x4db63c){_0x2bc1c5[_0x821f('0x33')]=_0x4db63c;if(_0x25bffb[_0x821f('0x48')]['includeAll']){_0x4654b4[_0x821f('0x58')]=[{'all':!![]}];}return db['FaxAccount']['findAll'](_0x4654b4);})[_0x821f('0x3b')](function(_0x44d903){_0x2bc1c5[_0x821f('0x59')]=_0x44d903;return _0x2bc1c5;})[_0x821f('0x3b')](respondWithFilteredResult(_0x58897d,_0x4654b4))[_0x821f('0x2f')](handleError(_0x58897d,null));};exports[_0x821f('0x5a')]=function(_0x257086,_0x5842e7){var _0x2f40b0={'raw':![],'where':{'id':_0x257086['params']['id']},'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]},_0x39b669={};_0x39b669['model']=_[_0x821f('0x49')](db[_0x821f('0x44')][_0x821f('0x45')]);_0x39b669[_0x821f('0x48')]=_[_0x821f('0x49')](_0x257086[_0x821f('0x48')]);_0x39b669['filters']=_[_0x821f('0x4a')](_0x39b669[_0x821f('0x47')],_0x39b669[_0x821f('0x48')]);_0x2f40b0['attributes']=_[_0x821f('0x4a')](_0x39b669[_0x821f('0x47')],qs['fields'](_0x257086[_0x821f('0x48')]['fields']));_0x2f40b0[_0x821f('0x4c')]=_0x2f40b0[_0x821f('0x4c')][_0x821f('0x4d')]?_0x2f40b0[_0x821f('0x4c')]:_0x39b669[_0x821f('0x47')];if(_0x257086[_0x821f('0x48')]['includeAll']){_0x2f40b0[_0x821f('0x58')]=[{'all':!![]}];}_0x2f40b0=_[_0x821f('0x54')]({},_0x2f40b0,_0x257086['options']);return db[_0x821f('0x44')][_0x821f('0x5b')](_0x2f40b0)[_0x821f('0x3b')](handleEntityNotFound(_0x5842e7,null))['then'](respondWithResult(_0x5842e7,null))[_0x821f('0x2f')](handleError(_0x5842e7,null));};exports[_0x821f('0x5c')]=function(_0x322fcd,_0x4d4316){return db[_0x821f('0x44')][_0x821f('0x5c')](_0x322fcd['body'],{})[_0x821f('0x3b')](function(_0x5152be){var _0xed9d4e=_0x322fcd[_0x821f('0x5d')][_0x821f('0x5e')]({'plain':!![]});if(!_0xed9d4e)throw new Error(_0x821f('0x5f'));if(_0xed9d4e['role']==='user'){var _0x531709=_0x5152be[_0x821f('0x5e')]({'plain':!![]});var _0x2295d0='FaxAccounts';return db['UserProfileSection'][_0x821f('0x5b')]({'where':{'name':_0x2295d0,'userProfileId':_0xed9d4e['userProfileId']},'raw':!![]})[_0x821f('0x3b')](function(_0x17963f){if(_0x17963f&&_0x17963f[_0x821f('0x60')]===0x0){return db[_0x821f('0x3c')][_0x821f('0x5c')]({'name':_0x531709[_0x821f('0x40')],'resourceId':_0x531709['id'],'type':_0x17963f[_0x821f('0x40')],'sectionId':_0x17963f['id']},{})[_0x821f('0x3b')](function(){return _0x5152be;});}else{return _0x5152be;}})['catch'](function(_0x144e0d){logger[_0x821f('0x2b')](_0x821f('0x61'),_0x144e0d);throw _0x144e0d;});}return _0x5152be;})[_0x821f('0x3b')](respondWithResult(_0x4d4316,0xc9))[_0x821f('0x2f')](handleError(_0x4d4316,null));};exports[_0x821f('0x3a')]=function(_0x4831ae,_0x121898){if(_0x4831ae['body']['id']){delete _0x4831ae[_0x821f('0x62')]['id'];}return db[_0x821f('0x44')][_0x821f('0x5b')]({'where':{'id':_0x4831ae[_0x821f('0x63')]['id']},'include':[{'model':db[_0x821f('0x64')],'as':_0x821f('0x42')}]})[_0x821f('0x3b')](handleEntityNotFound(_0x121898,null))[_0x821f('0x3b')](saveUpdates(_0x4831ae[_0x821f('0x62')],null))[_0x821f('0x3b')](respondWithResult(_0x121898,null))['catch'](handleError(_0x121898,null));};exports['destroy']=function(_0x21eaeb,_0x46bedc){return db['FaxAccount']['find']({'where':{'id':_0x21eaeb['params']['id']}})[_0x821f('0x3b')](handleEntityNotFound(_0x46bedc,null))[_0x821f('0x3b')](removeEntity(_0x46bedc,null))[_0x821f('0x2f')](handleError(_0x46bedc,null));};exports[_0x821f('0x65')]=function(_0x1a3083,_0x56b367){return db[_0x821f('0x44')][_0x821f('0x65')]()[_0x821f('0x3b')](respondWithResult(_0x56b367,null))['catch'](handleError(_0x56b367,null));};exports[_0x821f('0x66')]=function(_0x2336c2,_0x54cf3e,_0x3c9d64){if(_0x2336c2['body']['id']){delete _0x2336c2[_0x821f('0x62')]['id'];}return db[_0x821f('0x44')]['find']({'where':{'id':_0x2336c2['params']['id']}})[_0x821f('0x3b')](handleEntityNotFound(_0x54cf3e,null))[_0x821f('0x3b')](function(_0x2a7675){if(_0x2a7675){_0x2336c2[_0x821f('0x62')][_0x821f('0x67')]=_0x2a7675['id'];return db['Disposition']['create'](_0x2336c2[_0x821f('0x62')]);}})[_0x821f('0x3b')](respondWithResult(_0x54cf3e,null))[_0x821f('0x2f')](handleError(_0x54cf3e,null));};exports['getDispositions']=function(_0x113cab,_0x379687,_0x1abeff){var _0x5e7ae7={'raw':![],'where':{}};var _0x3fcd04={};var _0x170d64={'count':0x0,'rows':[]};return db[_0x821f('0x44')][_0x821f('0x68')]({'where':{'id':_0x113cab[_0x821f('0x63')]['id']}})[_0x821f('0x3b')](handleEntityNotFound(_0x379687,null))[_0x821f('0x3b')](function(_0x531206){if(_0x531206){_0x3fcd04[_0x821f('0x47')]=_[_0x821f('0x49')](db['Disposition'][_0x821f('0x45')]);_0x3fcd04[_0x821f('0x48')]=_[_0x821f('0x49')](_0x113cab[_0x821f('0x48')]);_0x3fcd04[_0x821f('0x51')]=_[_0x821f('0x4a')](_0x3fcd04[_0x821f('0x47')],_0x3fcd04[_0x821f('0x48')]);_0x5e7ae7[_0x821f('0x4c')]=_[_0x821f('0x4a')](_0x3fcd04[_0x821f('0x47')],qs[_0x821f('0x4b')](_0x113cab[_0x821f('0x48')][_0x821f('0x4b')]));_0x5e7ae7['attributes']=_0x5e7ae7[_0x821f('0x4c')][_0x821f('0x4d')]?_0x5e7ae7['attributes']:_0x3fcd04[_0x821f('0x47')];if(!_0x113cab['query'][_0x821f('0x69')](_0x821f('0x4e'))){_0x5e7ae7[_0x821f('0x35')]=qs['limit'](_0x113cab[_0x821f('0x48')]['limit']);_0x5e7ae7[_0x821f('0x34')]=qs[_0x821f('0x34')](_0x113cab[_0x821f('0x48')][_0x821f('0x34')]);}_0x5e7ae7['order']=qs[_0x821f('0x4f')](_0x113cab[_0x821f('0x48')][_0x821f('0x4f')]);_0x5e7ae7[_0x821f('0x50')]=qs['filters'](_[_0x821f('0x52')](_0x113cab['query'],_0x3fcd04['filters']));_0x5e7ae7[_0x821f('0x50')][_0x821f('0x67')]=_0x531206['id'];if(_0x113cab[_0x821f('0x48')]['filter']){_0x5e7ae7[_0x821f('0x50')]=_[_0x821f('0x54')](_0x5e7ae7[_0x821f('0x50')],{'$or':_['map'](_0x5e7ae7[_0x821f('0x4c')],function(_0x44304d){var _0x4e0fb3={};_0x4e0fb3[_0x44304d]={'$like':'%'+_0x113cab[_0x821f('0x48')]['filter']+'%'};return _0x4e0fb3;})});}_0x5e7ae7=_[_0x821f('0x54')]({},_0x5e7ae7,_0x113cab[_0x821f('0x57')]);return db[_0x821f('0x6a')][_0x821f('0x33')]({'where':_0x5e7ae7[_0x821f('0x50')]})[_0x821f('0x3b')](function(_0x172741){_0x170d64[_0x821f('0x33')]=_0x172741;if(_0x113cab[_0x821f('0x48')][_0x821f('0x6b')]){_0x5e7ae7[_0x821f('0x58')]=[{'all':!![]}];}return db[_0x821f('0x6a')][_0x821f('0x6c')](_0x5e7ae7);})['then'](function(_0x3bf75e){_0x170d64[_0x821f('0x59')]=_0x3bf75e;return _0x170d64;});}})[_0x821f('0x3b')](respondWithFilteredResult(_0x379687,_0x5e7ae7))['catch'](handleError(_0x379687,null));};exports[_0x821f('0x6d')]=function(_0x4f4e97,_0x22157,_0x48d366){return db[_0x821f('0x44')][_0x821f('0x5b')]({'where':{'id':_0x4f4e97['params']['id']}})[_0x821f('0x3b')](handleEntityNotFound(_0x22157,null))['then'](function(_0x172b97){if(_0x172b97){return _0x172b97[_0x821f('0x6d')](_0x4f4e97[_0x821f('0x48')]['ids']);}})[_0x821f('0x3b')](respondWithStatusCode(_0x22157,null))['catch'](handleError(_0x22157,null));};exports['addAnswer']=function(_0x5d6258,_0x4be830,_0x53230e){if(_0x5d6258[_0x821f('0x62')]['id']){delete _0x5d6258[_0x821f('0x62')]['id'];}return db['FaxAccount'][_0x821f('0x5b')]({'where':{'id':_0x5d6258[_0x821f('0x63')]['id']}})['then'](handleEntityNotFound(_0x4be830,null))[_0x821f('0x3b')](function(_0x1ffec2){if(_0x1ffec2){_0x5d6258[_0x821f('0x62')]['FaxAccountId']=_0x1ffec2['id'];return db[_0x821f('0x6e')][_0x821f('0x5c')](_0x5d6258[_0x821f('0x62')]);}})[_0x821f('0x3b')](respondWithResult(_0x4be830,null))['catch'](handleError(_0x4be830,null));};exports['getAnswers']=function(_0xed8409,_0x153107,_0x18c181){var _0x2390ed={'raw':![],'where':{}};var _0x2d631a={};var _0x128b39={'count':0x0,'rows':[]};return db[_0x821f('0x44')][_0x821f('0x68')]({'where':{'id':_0xed8409['params']['id']}})[_0x821f('0x3b')](handleEntityNotFound(_0x153107,null))[_0x821f('0x3b')](function(_0x1a7c21){if(_0x1a7c21){_0x2d631a[_0x821f('0x47')]=_[_0x821f('0x49')](db[_0x821f('0x6e')]['rawAttributes']);_0x2d631a['query']=_[_0x821f('0x49')](_0xed8409[_0x821f('0x48')]);_0x2d631a[_0x821f('0x51')]=_[_0x821f('0x4a')](_0x2d631a[_0x821f('0x47')],_0x2d631a[_0x821f('0x48')]);_0x2390ed[_0x821f('0x4c')]=_['intersection'](_0x2d631a[_0x821f('0x47')],qs[_0x821f('0x4b')](_0xed8409[_0x821f('0x48')][_0x821f('0x4b')]));_0x2390ed[_0x821f('0x4c')]=_0x2390ed[_0x821f('0x4c')][_0x821f('0x4d')]?_0x2390ed[_0x821f('0x4c')]:_0x2d631a[_0x821f('0x47')];if(!_0xed8409[_0x821f('0x48')][_0x821f('0x69')](_0x821f('0x4e'))){_0x2390ed[_0x821f('0x35')]=qs[_0x821f('0x35')](_0xed8409[_0x821f('0x48')][_0x821f('0x35')]);_0x2390ed[_0x821f('0x34')]=qs[_0x821f('0x34')](_0xed8409[_0x821f('0x48')][_0x821f('0x34')]);}_0x2390ed[_0x821f('0x6f')]=qs[_0x821f('0x4f')](_0xed8409[_0x821f('0x48')][_0x821f('0x4f')]);_0x2390ed[_0x821f('0x50')]=qs[_0x821f('0x51')](_[_0x821f('0x52')](_0xed8409[_0x821f('0x48')],_0x2d631a[_0x821f('0x51')]));_0x2390ed[_0x821f('0x50')][_0x821f('0x67')]=_0x1a7c21['id'];if(_0xed8409[_0x821f('0x48')][_0x821f('0x53')]){_0x2390ed[_0x821f('0x50')]=_[_0x821f('0x54')](_0x2390ed[_0x821f('0x50')],{'$or':_[_0x821f('0x43')](_0x2390ed['attributes'],function(_0x397ae9){var _0x6f95d2={};_0x6f95d2[_0x397ae9]={'$like':'%'+_0xed8409[_0x821f('0x48')][_0x821f('0x53')]+'%'};return _0x6f95d2;})});}_0x2390ed=_[_0x821f('0x54')]({},_0x2390ed,_0xed8409[_0x821f('0x57')]);return db['CannedAnswer'][_0x821f('0x33')]({'where':_0x2390ed[_0x821f('0x50')]})[_0x821f('0x3b')](function(_0x3d724a){_0x128b39[_0x821f('0x33')]=_0x3d724a;if(_0xed8409[_0x821f('0x48')][_0x821f('0x6b')]){_0x2390ed[_0x821f('0x58')]=[{'all':!![]}];}return db[_0x821f('0x6e')][_0x821f('0x6c')](_0x2390ed);})['then'](function(_0x4721ee){_0x128b39[_0x821f('0x59')]=_0x4721ee;return _0x128b39;});}})[_0x821f('0x3b')](respondWithFilteredResult(_0x153107,_0x2390ed))[_0x821f('0x2f')](handleError(_0x153107,null));};exports[_0x821f('0x70')]=function(_0x30db90,_0x49a7bc,_0x4baa71){return db[_0x821f('0x44')][_0x821f('0x5b')]({'where':{'id':_0x30db90['params']['id']}})[_0x821f('0x3b')](handleEntityNotFound(_0x49a7bc,null))[_0x821f('0x3b')](function(_0x39b02e){if(_0x39b02e){return _0x39b02e[_0x821f('0x70')](_0x30db90[_0x821f('0x48')]['ids']);}})[_0x821f('0x3b')](respondWithStatusCode(_0x49a7bc,null))[_0x821f('0x2f')](handleError(_0x49a7bc,null));};exports[_0x821f('0x71')]=function(_0x1cdd71,_0x46c9b3,_0x36f6e1){return db[_0x821f('0x72')]['find']({'where':{'id':_0x1cdd71[_0x821f('0x63')]['id']}})['then'](handleEntityNotFound(_0x46c9b3,null))[_0x821f('0x3b')](function(_0x12267f){if(_0x12267f){return _0x12267f[_0x821f('0x71')](_0x1cdd71['body'][_0x821f('0x73')],_[_0x821f('0x74')](_0x1cdd71['body'],[_0x821f('0x73'),'id'])||{});}})['then'](respondWithResult(_0x46c9b3,null))[_0x821f('0x2f')](handleError(_0x46c9b3,null));};exports[_0x821f('0x75')]=function(_0x2700f3,_0x4f1471,_0x253b61){var _0x20c3d5={'raw':![],'where':{}};var _0x1430e3={};var _0xa98c1f={'count':0x0,'rows':[]};return db[_0x821f('0x44')]['findOne']({'where':{'id':_0x2700f3[_0x821f('0x63')]['id']}})[_0x821f('0x3b')](handleEntityNotFound(_0x4f1471,null))[_0x821f('0x3b')](function(_0x121f25){if(_0x121f25){_0x1430e3[_0x821f('0x47')]=_[_0x821f('0x49')](db[_0x821f('0x72')][_0x821f('0x45')]);_0x1430e3[_0x821f('0x48')]=_[_0x821f('0x49')](_0x2700f3[_0x821f('0x48')]);_0x1430e3[_0x821f('0x51')]=_['intersection'](_0x1430e3['model'],_0x1430e3[_0x821f('0x48')]);_0x20c3d5[_0x821f('0x4c')]=_['intersection'](_0x1430e3[_0x821f('0x47')],qs[_0x821f('0x4b')](_0x2700f3[_0x821f('0x48')][_0x821f('0x4b')]));_0x20c3d5[_0x821f('0x4c')]=_0x20c3d5[_0x821f('0x4c')][_0x821f('0x4d')]?_0x20c3d5[_0x821f('0x4c')]:_0x1430e3[_0x821f('0x47')];if(!_0x2700f3['query'][_0x821f('0x69')](_0x821f('0x4e'))){_0x20c3d5[_0x821f('0x35')]=qs['limit'](_0x2700f3[_0x821f('0x48')]['limit']);_0x20c3d5[_0x821f('0x34')]=qs[_0x821f('0x34')](_0x2700f3[_0x821f('0x48')][_0x821f('0x34')]);}_0x20c3d5['order']=qs[_0x821f('0x4f')](_0x2700f3[_0x821f('0x48')]['sort']);_0x20c3d5[_0x821f('0x50')]=qs[_0x821f('0x51')](_['pick'](_0x2700f3[_0x821f('0x48')],_0x1430e3[_0x821f('0x51')]));_0x20c3d5[_0x821f('0x50')][_0x821f('0x67')]=_0x121f25['id'];if(_0x2700f3[_0x821f('0x48')][_0x821f('0x53')]){_0x20c3d5[_0x821f('0x50')]=_[_0x821f('0x54')](_0x20c3d5[_0x821f('0x50')],{'$or':_[_0x821f('0x43')](_0x20c3d5[_0x821f('0x4c')],function(_0x11a9c2){var _0x1207ee={};_0x1207ee[_0x11a9c2]={'$like':'%'+_0x2700f3[_0x821f('0x48')][_0x821f('0x53')]+'%'};return _0x1207ee;})});}_0x20c3d5=_['merge']({},_0x20c3d5,_0x2700f3[_0x821f('0x57')]);return db[_0x821f('0x72')][_0x821f('0x33')]({'where':_0x20c3d5[_0x821f('0x50')]})[_0x821f('0x3b')](function(_0x37a981){_0xa98c1f[_0x821f('0x33')]=_0x37a981;if(_0x2700f3[_0x821f('0x48')][_0x821f('0x6b')]){_0x20c3d5[_0x821f('0x58')]=[{'model':db[_0x821f('0x76')],'as':_0x821f('0x77'),'required':![]},{'model':db[_0x821f('0x78')],'as':_0x821f('0x79'),'attributes':[_0x821f('0x40'),'fullname',_0x821f('0x7a')],'required':![]},{'model':db[_0x821f('0x7b')],'as':_0x821f('0x7c'),'attributes':['id','name',_0x821f('0x7d')],'where':_0x2700f3['query']['tag']?{'id':_0x2700f3[_0x821f('0x48')]['tag']}:undefined,'required':_0x2700f3[_0x821f('0x48')][_0x821f('0x7e')]?!![]:![]}];}return db[_0x821f('0x72')][_0x821f('0x6c')](_0x20c3d5);})[_0x821f('0x3b')](function(_0x4b451c){_0xa98c1f['rows']=_0x4b451c;return _0xa98c1f;});}})['then'](respondWithFilteredResult(_0x4f1471,_0x20c3d5))[_0x821f('0x2f')](handleError(_0x4f1471,null));};exports['addApplications']=function(_0x5473ab,_0x1a678d,_0x4ec546){return db[_0x821f('0x44')]['findOne']({'where':{'id':_0x5473ab[_0x821f('0x63')]['id']}})['then'](handleEntityNotFound(_0x1a678d,null))['then'](function(_0x2192a4){if(_0x2192a4){return db[_0x821f('0x7f')][_0x821f('0x80')](function(_0x4850df){return db['FaxApplication'][_0x821f('0x3d')]({'where':{'FaxAccountId':_0x5473ab[_0x821f('0x63')]['id']},'transaction':_0x4850df})[_0x821f('0x3b')](function(_0x181a3d){var _0x4adec4=_[_0x821f('0x43')](_0x5473ab[_0x821f('0x62')],function(_0x4d64cb){_0x4d64cb[_0x821f('0x67')]=_0x5473ab[_0x821f('0x63')]['id'];return _0x4d64cb;});return db[_0x821f('0x81')][_0x821f('0x82')](_0x4adec4,{'transaction':_0x4850df});});})[_0x821f('0x3b')](function(){return db[_0x821f('0x81')]['findAndCountAll']({'where':{'FaxAccountId':_0x5473ab['params']['id']},'order':_0x821f('0x83')});});}})[_0x821f('0x3b')](respondWithResult(_0x1a678d,null))[_0x821f('0x2f')](handleError(_0x1a678d,null));};exports[_0x821f('0x84')]=function(_0x228d16,_0x1c0b5e,_0x53c93b){var _0x53b8e4={};var _0x5f3193={};var _0x5f5d87;var _0x3db91b;return db[_0x821f('0x44')][_0x821f('0x68')]({'where':{'id':_0x228d16[_0x821f('0x63')]['id']}})['then'](handleEntityNotFound(_0x1c0b5e,null))['then'](function(_0x21bba9){if(_0x21bba9){_0x5f5d87=_0x21bba9;_0x5f3193['model']=_[_0x821f('0x49')](db['FaxApplication']['rawAttributes']);_0x5f3193['query']=_[_0x821f('0x49')](_0x228d16[_0x821f('0x48')]);_0x5f3193['filters']=_[_0x821f('0x4a')](_0x5f3193[_0x821f('0x47')],_0x5f3193[_0x821f('0x48')]);_0x53b8e4['attributes']=_[_0x821f('0x4a')](_0x5f3193[_0x821f('0x47')],qs[_0x821f('0x4b')](_0x228d16['query'][_0x821f('0x4b')]));_0x53b8e4[_0x821f('0x4c')]=_0x53b8e4[_0x821f('0x4c')][_0x821f('0x4d')]?_0x53b8e4[_0x821f('0x4c')]:_0x5f3193[_0x821f('0x47')];_0x53b8e4[_0x821f('0x6f')]=qs['sort'](_0x228d16[_0x821f('0x48')]['sort']);_0x53b8e4['where']=qs['filters'](_[_0x821f('0x52')](_0x228d16[_0x821f('0x48')],_0x5f3193['filters']));if(_0x228d16[_0x821f('0x48')][_0x821f('0x53')]){_0x53b8e4['where']=_[_0x821f('0x54')](_0x53b8e4['where'],{'$or':_['map'](_0x53b8e4['attributes'],function(_0x2c7623){var _0x3f486d={};_0x3f486d[_0x2c7623]={'$like':'%'+_0x228d16[_0x821f('0x48')][_0x821f('0x53')]+'%'};return _0x3f486d;})});}_0x53b8e4=_[_0x821f('0x54')]({},_0x53b8e4,_0x228d16[_0x821f('0x57')]);return _0x5f5d87[_0x821f('0x84')](_0x53b8e4);}})[_0x821f('0x3b')](function(_0x4b75cd){if(_0x4b75cd){_0x3db91b=_0x4b75cd[_0x821f('0x4d')];if(!_0x228d16[_0x821f('0x48')][_0x821f('0x69')](_0x821f('0x4e'))){_0x53b8e4[_0x821f('0x35')]=qs[_0x821f('0x35')](_0x228d16[_0x821f('0x48')][_0x821f('0x35')]);_0x53b8e4['offset']=qs['offset'](_0x228d16[_0x821f('0x48')]['offset']);}return _0x5f5d87['getApplications'](_0x53b8e4);}})[_0x821f('0x3b')](function(_0x28bb14){if(_0x28bb14){return _0x28bb14?{'count':_0x3db91b,'rows':_0x28bb14}:null;}})[_0x821f('0x3b')](respondWithResult(_0x1c0b5e,null))[_0x821f('0x2f')](handleError(_0x1c0b5e,null));};function Extension(_0x1bccb5,_0x4a7231,_0x4d04a9,_0x3f65da){this['context']=_0x821f('0x85');this[_0x821f('0x86')]=_0x1bccb5[_0x821f('0x87')];this[_0x821f('0x88')]=_0x3f65da;this[_0x821f('0x55')]=_0x821f('0x89');this[_0x821f('0x8a')]=_0x821f('0x8b');this[_0x821f('0x67')]=_0x1bccb5['id'];this[_0x821f('0x83')]=_0x4a7231;this['appdata']=_0x4d04a9;}function createExtensionsReciveFax(_0x40cb52){var _0x2f9162=0x1;var _0xd09177=[];_0xd09177[_0x821f('0x8c')](new Extension(_0x40cb52,_0x2f9162,'','Answer'));_0x2f9162+=0x1;_0xd09177[_0x821f('0x8c')](new Extension(_0x40cb52,_0x2f9162,_0x821f('0x8d'),_0x821f('0x8e')));_0x2f9162+=0x1;for(var _0x580ae2 in _0x40cb52){if(_0x40cb52[_0x821f('0x69')](_0x580ae2)&&(_0x580ae2==='ecm'||_0x580ae2===_0x821f('0x87')||_0x580ae2===_0x821f('0x8f')||_0x580ae2===_0x821f('0x90')||_0x580ae2===_0x821f('0x91')||_0x580ae2===_0x821f('0x92')||_0x580ae2==='minrate'||_0x580ae2===_0x821f('0x93')||_0x580ae2===_0x821f('0x94'))){_0xd09177['push'](new Extension(_0x40cb52,_0x2f9162,_0x821f('0x95')+_0x580ae2+')='+_0x40cb52[_0x580ae2],_0x821f('0x8e')));_0x2f9162+=0x1;}}_0xd09177[_0x821f('0x8c')](new Extension(_0x40cb52,_0x2f9162,'6',_0x821f('0x96')));_0x2f9162+=0x1;_0xd09177[_0x821f('0x8c')](new Extension(_0x40cb52,_0x2f9162,_0x821f('0x97'),_0x821f('0x98')));_0x2f9162=0x0;return _0xd09177;}exports[_0x821f('0x99')]=function(_0x28bf52,_0x4dbef5,_0x3a0f98){var _0x365047;return db[_0x821f('0x7f')][_0x821f('0x80')](function(_0x33847d){return db[_0x821f('0x44')][_0x821f('0x5c')](_0x28bf52[_0x821f('0x62')],{'transaction':_0x33847d})[_0x821f('0x3b')](function(_0x566cf8){_0x365047=_0x566cf8[_0x821f('0x5e')]({'plain':!![]});return db['VoiceExtension']['bulkCreate'](createExtensionsReciveFax(_0x365047),{'transaction':_0x33847d});});})['then'](function(){return _0x365047;})[_0x821f('0x3b')](respondWithResult(_0x4dbef5,null))['catch'](handleError(_0x4dbef5,null));};exports['updateAccountApplications']=function(_0x423256,_0x3df701,_0x49434f){var _0x46bcc0;return db[_0x821f('0x7f')]['transaction'](function(_0x3f7260){return db[_0x821f('0x44')]['update'](_0x423256[_0x821f('0x62')],{'where':{'id':_0x423256[_0x821f('0x62')]['id']},'transaction':_0x3f7260})[_0x821f('0x3b')](function(_0x1f2a88){return db[_0x821f('0x9a')]['destroy']({'where':{'FaxAccountId':_0x423256[_0x821f('0x62')]['id']},'transaction':_0x3f7260})[_0x821f('0x3b')](function(_0x5bfb75){return db[_0x821f('0x9a')][_0x821f('0x82')](createExtensionsReciveFax(_[_0x821f('0x74')](_0x423256[_0x821f('0x62')],[_0x821f('0x9b'),_0x821f('0x9c'),_0x821f('0x9d'),_0x821f('0x9e'),_0x821f('0x9f'),_0x821f('0xa0')])),{'transaction':_0x3f7260});});});})[_0x821f('0x3b')](function(){return db[_0x821f('0x44')][_0x821f('0xa1')](_0x423256[_0x821f('0x62')]['id']);})[_0x821f('0x3b')](respondWithResult(_0x3df701,null))[_0x821f('0x2f')](handleError(_0x3df701,null));};exports['getMessages']=function(_0x2dbe41,_0x3f6a7b,_0x45fcef){var _0x4ec5bb={'raw':!![],'where':{}};var _0x22355f={};var _0x23d186={'count':0x0,'rows':[]};return db[_0x821f('0x44')][_0x821f('0x68')]({'where':{'id':_0x2dbe41[_0x821f('0x63')]['id']}})[_0x821f('0x3b')](handleEntityNotFound(_0x3f6a7b,null))[_0x821f('0x3b')](function(_0xa22627){if(_0xa22627){_0x22355f['model']=_[_0x821f('0x49')](db[_0x821f('0xa2')]['rawAttributes']);_0x22355f['query']=_[_0x821f('0x49')](_0x2dbe41[_0x821f('0x48')]);_0x22355f[_0x821f('0x51')]=_[_0x821f('0x4a')](_0x22355f[_0x821f('0x47')],_0x22355f['query']);_0x4ec5bb['attributes']=_[_0x821f('0x4a')](_0x22355f['model'],qs['fields'](_0x2dbe41['query']['fields']));_0x4ec5bb['attributes']=_0x4ec5bb[_0x821f('0x4c')][_0x821f('0x4d')]?_0x4ec5bb[_0x821f('0x4c')]:_0x22355f[_0x821f('0x47')];if(!_0x2dbe41[_0x821f('0x48')][_0x821f('0x69')]('nolimit')){_0x4ec5bb[_0x821f('0x35')]=qs['limit'](_0x2dbe41[_0x821f('0x48')][_0x821f('0x35')]);_0x4ec5bb[_0x821f('0x34')]=qs[_0x821f('0x34')](_0x2dbe41[_0x821f('0x48')][_0x821f('0x34')]);}_0x4ec5bb[_0x821f('0x6f')]=qs[_0x821f('0x4f')](_0x2dbe41['query']['sort']);_0x4ec5bb['where']=qs[_0x821f('0x51')](_[_0x821f('0x52')](_0x2dbe41[_0x821f('0x48')],_0x22355f['filters']));_0x4ec5bb[_0x821f('0x50')][_0x821f('0x67')]=_0xa22627['id'];if(_0x2dbe41['query'][_0x821f('0x53')]){_0x4ec5bb[_0x821f('0x50')]=_[_0x821f('0x54')](_0x4ec5bb[_0x821f('0x50')],{'$or':_[_0x821f('0x43')](_0x4ec5bb[_0x821f('0x4c')],function(_0x3c9980){var _0x249183={};_0x249183[_0x3c9980]={'$like':'%'+_0x2dbe41[_0x821f('0x48')]['filter']+'%'};return _0x249183;})});}if(_0x2dbe41[_0x821f('0x48')][_0x821f('0xa3')]){var _0x544a61=_0x2dbe41[_0x821f('0x48')][_0x821f('0xa3')][_0x821f('0xa4')](',');var _0x4c5cf4={};_0x4c5cf4[_0x544a61[0x0]]={'$gte':moment(_0x544a61[0x1])[_0x821f('0xa5')](_0x821f('0xa6'))};_0x4ec5bb[_0x821f('0x50')]=_[_0x821f('0x54')](_0x4ec5bb['where'],_0x4c5cf4);}_0x4ec5bb=_[_0x821f('0x54')]({},_0x4ec5bb,_0x2dbe41['options']);return db[_0x821f('0xa2')]['count']({'where':_0x4ec5bb[_0x821f('0x50')]})[_0x821f('0x3b')](function(_0x4289a9){_0x23d186[_0x821f('0x33')]=_0x4289a9;if(_0x2dbe41[_0x821f('0x48')][_0x821f('0x6b')]){_0x4ec5bb['include']=[{'all':!![]}];}return db[_0x821f('0xa2')][_0x821f('0x6c')](_0x4ec5bb);})['then'](function(_0x26416a){_0x23d186[_0x821f('0x59')]=_0x26416a;return _0x23d186;});}})[_0x821f('0x3b')](respondWithFilteredResult(_0x3f6a7b,_0x4ec5bb))[_0x821f('0x2f')](handleError(_0x3f6a7b,null));};exports['send']=function(_0x3a187c,_0x2c1788,_0x59a8b9){var _0x40b60e,_0x35de5d={},_0x1257d7;if(_0x3a187c[_0x821f('0x62')]['to']){_0x1257d7=_0x3a187c[_0x821f('0x62')]['to'][0x0];}return db[_0x821f('0x44')][_0x821f('0x5b')]({'where':{'id':_0x3a187c[_0x821f('0x63')]['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0x821f('0x76')],'as':_0x821f('0xa7'),'where':{'fax':_0x1257d7},'limit':0x1,'order':[[_0x821f('0x9e'),_0x821f('0xa8')]]}]}]})[_0x821f('0x3b')](handleEntityNotFound(_0x2c1788,null))[_0x821f('0x3b')](function(_0x59fa0f){_0x40b60e=_0x59fa0f;if(_0x3a187c[_0x821f('0x62')][_0x821f('0xa9')]&&_0x3a187c[_0x821f('0x62')][_0x821f('0xa9')]['length']){for(var _0x36ebba=0x0;_0x36ebba<_0x3a187c[_0x821f('0x62')]['attachments'][_0x821f('0x4d')];_0x36ebba+=0x1){_0x3a187c[_0x821f('0x62')][_0x821f('0xa9')][_0x36ebba]={'filename':_0x3a187c[_0x821f('0x62')]['attachments'][_0x36ebba][_0x821f('0x40')],'id':_0x3a187c[_0x821f('0x62')][_0x821f('0xa9')][_0x36ebba]['id'],'path':path[_0x821f('0xaa')](config[_0x821f('0xab')],_0x821f('0xac'),_0x3a187c[_0x821f('0x62')][_0x821f('0xa9')][_0x36ebba][_0x821f('0xad')])};}}return respondWithRpcPromise(_0x821f('0xae'),_0x821f('0xae'),{'FaxAccountId':_[_0x821f('0xaf')](_0x3a187c[_0x821f('0x63')]['id'])?undefined:_0x3a187c['params']['id'],'path':_[_0x821f('0xaf')](_0x3a187c[_0x821f('0x62')][_0x821f('0xa9')][0x0][_0x821f('0x9')])?undefined:_0x3a187c[_0x821f('0x62')][_0x821f('0xa9')][0x0]['path'],'fax':_[_0x821f('0xaf')](_0x3a187c[_0x821f('0x62')]['to'][0x0])?undefined:_0x3a187c[_0x821f('0x62')]['to'][0x0]},client9002);})[_0x821f('0x3b')](function(){if(_0x40b60e){if(_[_0x821f('0xaf')](_0x3a187c[_0x821f('0x62')][_0x821f('0xb0')])){_0x3a187c[_0x821f('0x62')][_0x821f('0xb0')]=util[_0x821f('0xa5')](_0x821f('0xb1'),_0x40b60e['name'],_0x40b60e[_0x821f('0xb2')]);}if(_0x40b60e[_0x821f('0xb3')]){if(_0x40b60e[_0x821f('0xb3')][_0x821f('0xa7')][_0x821f('0x4d')]){return _0x40b60e[_0x821f('0xb3')][_0x821f('0xa7')][0x0];}else{return db[_0x821f('0x76')]['create'](_[_0x821f('0xb4')](_0x3a187c[_0x821f('0x62')],{'firstName':_0x3a187c['body']['to'][0x0],'phone':_0x3a187c[_0x821f('0x62')]['to'][0x0],'fax':_0x3a187c[_0x821f('0x62')]['to'][0x0],'ListId':_0x40b60e[_0x821f('0xa0')]}));}}else{throw new Error('List\x20not\x20found');}}else{throw new Error(_0x821f('0xb5'));}})['then'](function(_0x2ee7d1){if(_0x2ee7d1){return db[_0x821f('0x72')][_0x821f('0x5b')]({'where':{'ContactId':_0x2ee7d1['id'],'closed':![],'FaxAccountId':_0x40b60e['id']}})['then'](function(_0x5cd9be){if(_0x5cd9be){return[_0x5cd9be,![]];}return db['FaxInteraction'][_0x821f('0x5c')]({'UserId':_0x3a187c[_0x821f('0x5d')]['id'],'ContactId':_0x2ee7d1['id'],'FaxAccountId':_0x40b60e['id'],'fax':_0x3a187c[_0x821f('0x62')]['to'][0x0],'firstMsgDirection':'out','Messages':[_[_0x821f('0x54')](_0x3a187c[_0x821f('0x62')],{'read':![],'body':_0x3a187c['body']['attachments'][0x0][_0x821f('0xb6')],'FaxAccountId':_0x40b60e['id'],'UserId':_0x3a187c['user']['id'],'ContactId':_0x2ee7d1['id'],'AttachmentId':_0x3a187c[_0x821f('0x62')][_0x821f('0xa9')][0x0]['id']})]},{'include':[{'model':db['FaxMessage'],'as':_0x821f('0xb7')}]})[_0x821f('0x3b')](function(_0x415b42){return[_0x415b42,!![]];});});}else{throw new Error('Contact\x20not\x20found');}})[_0x821f('0xb8')](function(_0x118a57,_0x5e4b4a){if(_0x5e4b4a){return _0x118a57;}return db[_0x821f('0xa2')]['create']({'direction':_0x821f('0xb9'),'read':![],'body':_0x3a187c[_0x821f('0x62')]['attachments'][0x0][_0x821f('0xb6')],'FaxAccountId':_0x40b60e['id'],'FaxInteractionId':_0x118a57['id'],'UserId':_0x3a187c['user']['id'],'ContactId':_0x118a57[_0x821f('0xba')],'AttachmentId':_0x3a187c[_0x821f('0x62')][_0x821f('0xa9')][0x0]['id']})[_0x821f('0x3b')](function(_0x14de47){_0x118a57[_0x821f('0xbb')][_0x821f('0xb7')]=[];_0x118a57['dataValues'][_0x821f('0xb7')]['push'](_0x14de47[_0x821f('0xbb')]);return _0x118a57;});})['then'](function(_0x58ee97){respondWithRpcPromise('SendFax',_0x821f('0xbc'),{'FaxAccountId':_[_0x821f('0xaf')](_0x3a187c[_0x821f('0x63')]['id'])?undefined:_0x3a187c['params']['id'],'path':_[_0x821f('0xaf')](_0x3a187c[_0x821f('0x62')]['attachments'][0x0][_0x821f('0x9')])?undefined:_0x3a187c[_0x821f('0x62')][_0x821f('0xa9')][0x0][_0x821f('0x9')],'fax':_[_0x821f('0xaf')](_0x3a187c['body']['to'][0x0])?undefined:_0x3a187c['body']['to'][0x0],'AttachmentId':_0x3a187c[_0x821f('0x62')][_0x821f('0xa9')][0x0]['id']},client9002)[_0x821f('0x3b')](function(_0x3c3261){logger[_0x821f('0x26')](_0x821f('0xbd'),_0x3c3261);})[_0x821f('0x2f')](function(_0xce427c){logger[_0x821f('0x26')](_0x821f('0xbd'),_0xce427c);});return _0x58ee97;})[_0x821f('0x3b')](respondWithResult(_0x2c1788,null))[_0x821f('0x2f')](handleError(_0x2c1788,null));};exports['addAgents']=function(_0x5de6f2,_0x581b9e,_0x42d766){return db[_0x821f('0x44')]['find']({'where':{'id':_0x5de6f2[_0x821f('0x63')]['id']}})['then'](handleEntityNotFound(_0x581b9e,null))['then'](function(_0x3d231b){if(_0x3d231b){return _0x3d231b[_0x821f('0xbe')](_0x5de6f2['body'][_0x821f('0x73')],_[_0x821f('0x74')](_0x5de6f2[_0x821f('0x62')],[_0x821f('0x73'),'id'])||{})[_0x821f('0xb8')](function(_0x49ac2b){for(var _0x50d34b=0x0;_0x50d34b<_0x5de6f2[_0x821f('0x62')][_0x821f('0x73')][_0x821f('0x4d')];_0x50d34b+=0x1){socket[_0x821f('0xbf')](_0x821f('0xc0'),{'UserId':_0x5de6f2[_0x821f('0x62')][_0x821f('0x73')][_0x50d34b],'FaxAccountId':_0x5de6f2['params']['id']});}return _0x49ac2b;});}})[_0x821f('0x3b')](respondWithResult(_0x581b9e,null))[_0x821f('0x2f')](handleError(_0x581b9e,null));};exports[_0x821f('0xc1')]=function(_0x1220fb,_0x17ca2d,_0x3fd14c){return db['FaxAccount'][_0x821f('0x5b')]({'where':{'id':_0x1220fb[_0x821f('0x63')]['id']}})['then'](handleEntityNotFound(_0x17ca2d,null))['then'](function(_0x30c527){if(_0x30c527){return _0x30c527['removeAgents'](_0x1220fb[_0x821f('0x48')]['ids'])['then'](function(){if(_[_0x821f('0xc2')](_0x1220fb[_0x821f('0x48')]['ids'])){for(var _0x1a9846=0x0;_0x1a9846<_0x1220fb[_0x821f('0x48')][_0x821f('0x73')][_0x821f('0x4d')];_0x1a9846+=0x1){socket[_0x821f('0xbf')](_0x821f('0xc3'),{'UserId':Number(_0x1220fb[_0x821f('0x48')][_0x821f('0x73')][_0x1a9846]),'FaxAccountId':Number(_0x1220fb[_0x821f('0x63')]['id'])});}}else{socket[_0x821f('0xbf')]('userFaxAccount:remove',{'UserId':Number(_0x1220fb['query'][_0x821f('0x73')]),'FaxAccountId':Number(_0x1220fb[_0x821f('0x63')]['id'])});}});}})[_0x821f('0x3b')](respondWithStatusCode(_0x17ca2d,null))[_0x821f('0x2f')](handleError(_0x17ca2d,null));};exports[_0x821f('0xc4')]=function(_0x30669d,_0x22fad6,_0xbba589){var _0x6aac71={};var _0x43c0d5={};var _0x4b1602;var _0xdd5c19;return db['FaxAccount']['findOne']({'where':{'id':_0x30669d[_0x821f('0x63')]['id']}})[_0x821f('0x3b')](handleEntityNotFound(_0x22fad6,null))[_0x821f('0x3b')](function(_0x175c46){if(_0x175c46){_0x4b1602=_0x175c46;_0x43c0d5['model']=_[_0x821f('0x49')](db['User'][_0x821f('0x45')]);_0x43c0d5[_0x821f('0x48')]=_[_0x821f('0x49')](_0x30669d[_0x821f('0x48')]);_0x43c0d5[_0x821f('0x51')]=_[_0x821f('0x4a')](_0x43c0d5[_0x821f('0x47')],_0x43c0d5[_0x821f('0x48')]);_0x6aac71[_0x821f('0x4c')]=_[_0x821f('0x4a')](_0x43c0d5[_0x821f('0x47')],qs['fields'](_0x30669d[_0x821f('0x48')]['fields']));_0x6aac71[_0x821f('0x4c')]=_0x6aac71[_0x821f('0x4c')]['length']?_0x6aac71[_0x821f('0x4c')]:_0x43c0d5[_0x821f('0x47')];_0x6aac71[_0x821f('0x6f')]=qs['sort'](_0x30669d[_0x821f('0x48')][_0x821f('0x4f')]);_0x6aac71[_0x821f('0x50')]=qs[_0x821f('0x51')](_[_0x821f('0x52')](_0x30669d[_0x821f('0x48')],_0x43c0d5[_0x821f('0x51')]));if(_0x30669d[_0x821f('0x48')][_0x821f('0x53')]){_0x6aac71[_0x821f('0x50')]=_['merge'](_0x6aac71[_0x821f('0x50')],{'$or':_[_0x821f('0x43')](_0x6aac71[_0x821f('0x4c')],function(_0x2fae0f){var _0x2f3b47={};_0x2f3b47[_0x2fae0f]={'$like':'%'+_0x30669d[_0x821f('0x48')][_0x821f('0x53')]+'%'};return _0x2f3b47;})});}_0x6aac71=_[_0x821f('0x54')]({},_0x6aac71,_0x30669d[_0x821f('0x57')]);return _0x4b1602[_0x821f('0xc4')](_0x6aac71);}})[_0x821f('0x3b')](function(_0x470f72){if(_0x470f72){_0xdd5c19=_0x470f72[_0x821f('0x4d')];if(!_0x30669d[_0x821f('0x48')][_0x821f('0x69')](_0x821f('0x4e'))){_0x6aac71[_0x821f('0x35')]=qs[_0x821f('0x35')](_0x30669d[_0x821f('0x48')][_0x821f('0x35')]);_0x6aac71['offset']=qs[_0x821f('0x34')](_0x30669d[_0x821f('0x48')][_0x821f('0x34')]);}return _0x4b1602[_0x821f('0xc4')](_0x6aac71);}})[_0x821f('0x3b')](function(_0x41b42b){if(_0x41b42b){return _0x41b42b?{'count':_0xdd5c19,'rows':_0x41b42b}:null;}})['then'](respondWithResult(_0x22fad6,null))[_0x821f('0x2f')](handleError(_0x22fad6,null));};