Built motion from commit 85328c08.|2.5.50
[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 _0x697f=['includeAll','include','findAll','show','params','options','find','create','body','user','FaxAccounts','UserProfileSection','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','FaxAccountId','Disposition','getDispositions','rows','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','findOne','hasOwnProperty','removeAnswers','addInteraction','FaxInteraction','omit','getInteractions','CmContact','Contact','User','internal','Tag','Tags','color','tag','addApplications','transaction','sequelize','Transaction','READ_COMMITTED','FaxApplication','bulkCreate','priority','finally','getApplications','context','from-voip-provider','exten','localstationid','app','system','description','Fax\x20Extension','push','Answer','Set','faxdetect','headerinfo','minrate','t38timeout','FAXOPT(','Wait','/var/opt/motion2/server/files/attachments/fax-${CALLERID(num)}-${CUT(UNIQUEID,.,1)}-${CUT(UNIQUEID,.,2)}-${STRFTIME(,,%C%y%m%d%H%M%S)}-rx.tif,d','ReceiveFax','updateAccountApplications','VoiceExtension','updatedAt','TrunkId','ListId','findById','$gte','format','YYYY-MM-DD\x20HH:mm:ss','FaxMessage','CmList','List','attachments','root','server/files/attachments','basename','CheckAfterSend','isNil','path','from','\x22%s\x22\x20<%s>','fax','Contacts','defaults','List\x20not\x20found','Send\x20Fax\x20failed','out','filename','Messages','Contact\x20not\x20found','spread','ContactId','dataValues','SendFax','addAgents','emit','userFaxAccount:save','removeAgents','isArray','getAgents','eml-format','zip-dir','request-promise','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../mysqldb','redis','localhost','./faxAccount.socket','register','jayson/promise','client','http','then','FaxAccount,\x20%s,\x20%s','request\x20sent','FaxAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','catch','sendStatus','status','end','json','offset','undefined','count','limit','set','Content-Range','apply','save','update','get','destroy','stack','name','send','Pause','mandatoryDispositionPause','map','FaxAccount','rawAttributes','fieldName','key','model','keys','filters','intersection','query','attributes','fields','length','nolimit','order','sort','pick','where','merge','type','VIRTUAL','filter'];(function(_0x1db843,_0x18be51){var _0x588c54=function(_0xc3134d){while(--_0xc3134d){_0x1db843['push'](_0x1db843['shift']());}};_0x588c54(++_0x18be51);}(_0x697f,0x6d));var _0xf697=function(_0x5e6cb8,_0x16cf56){_0x5e6cb8=_0x5e6cb8-0x0;var _0x3faeb3=_0x697f[_0x5e6cb8];return _0x3faeb3;};'use strict';var emlformat=require(_0xf697('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xf697('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf697('0x2'));var moment=require('moment');var BPromise=require(_0xf697('0x3'));var Mustache=require(_0xf697('0x4'));var util=require(_0xf697('0x5'));var path=require('path');var sox=require(_0xf697('0x6'));var csv=require(_0xf697('0x7'));var ejs=require(_0xf697('0x8'));var fs=require('fs');var fs_extra=require(_0xf697('0x9'));var _=require(_0xf697('0xa'));var squel=require('squel');var crypto=require(_0xf697('0xb'));var jsforce=require(_0xf697('0xc'));var deskjs=require(_0xf697('0xd'));var toCsv=require(_0xf697('0x7'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xf697('0xe'));var authService=require(_0xf697('0xf'));var qs=require(_0xf697('0x10'));var as=require(_0xf697('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xf697('0x12'));var utils=require(_0xf697('0x13'));var config=require(_0xf697('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0xf697('0x15'))['db'];config[_0xf697('0x16')]=_['defaults'](config[_0xf697('0x16')],{'host':_0xf697('0x17'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xf697('0x16')]));require(_0xf697('0x18'))[_0xf697('0x19')](socket);var jayson=require(_0xf697('0x1a'));var client=jayson[_0xf697('0x1b')][_0xf697('0x1c')]({'port':0x232c});var client9002=jayson['client'][_0xf697('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x5ae3c7,_0x3e5350,_0x2721f2,_0x241b84){return new BPromise(function(_0x330314,_0x2b8d8f){var _0x212548=_0x241b84||client;return _0x212548['request'](_0x5ae3c7,_0x2721f2)[_0xf697('0x1d')](function(_0x44dcee){logger['info'](_0xf697('0x1e'),_0x3e5350,_0xf697('0x1f'));logger['debug'](_0xf697('0x20'),_0x3e5350,_0xf697('0x1f'),JSON[_0xf697('0x21')](_0x44dcee));if(_0x44dcee[_0xf697('0x22')]){if(_0x44dcee[_0xf697('0x22')][_0xf697('0x23')]===0x1f4){logger[_0xf697('0x22')](_0xf697('0x1e'),_0x3e5350,_0x44dcee['error']['message']);return _0x2b8d8f(_0x44dcee['error'][_0xf697('0x24')]);}logger[_0xf697('0x22')]('FaxAccount,\x20%s,\x20%s',_0x3e5350,_0x44dcee[_0xf697('0x22')][_0xf697('0x24')]);return _0x330314(_0x44dcee[_0xf697('0x22')][_0xf697('0x24')]);}else{logger[_0xf697('0x25')](_0xf697('0x1e'),_0x3e5350,_0xf697('0x1f'));_0x330314(_0x44dcee[_0xf697('0x26')][_0xf697('0x24')]);}})[_0xf697('0x27')](function(_0x305028){logger[_0xf697('0x22')](_0xf697('0x1e'),_0x3e5350,_0x305028);_0x2b8d8f(_0x305028);});});}function respondWithStatusCode(_0x46cba5,_0x4939fd){_0x4939fd=_0x4939fd||0xcc;return function(_0x40a38c){if(_0x40a38c){return _0x46cba5[_0xf697('0x28')](_0x4939fd);}return _0x46cba5[_0xf697('0x29')](_0x4939fd)[_0xf697('0x2a')]();};}function respondWithResult(_0x5729a0,_0x4fe66d){_0x4fe66d=_0x4fe66d||0xc8;return function(_0x628d90){if(_0x628d90){return _0x5729a0[_0xf697('0x29')](_0x4fe66d)[_0xf697('0x2b')](_0x628d90);}};}function respondWithFilteredResult(_0x5ce691,_0xd82c41){return function(_0x47a906){if(_0x47a906){var _0x4020c7=typeof _0xd82c41[_0xf697('0x2c')]===_0xf697('0x2d')&&typeof _0xd82c41['limit']==='undefined';var _0x573e16=_0x47a906[_0xf697('0x2e')];var _0x7105db=_0x4020c7?0x0:_0xd82c41[_0xf697('0x2c')];var _0x2a1475=_0x4020c7?_0x47a906[_0xf697('0x2e')]:_0xd82c41[_0xf697('0x2c')]+_0xd82c41[_0xf697('0x2f')];var _0x5db651;if(_0x2a1475>=_0x573e16){_0x2a1475=_0x573e16;_0x5db651=0xc8;}else{_0x5db651=0xce;}_0x5ce691[_0xf697('0x29')](_0x5db651);return _0x5ce691[_0xf697('0x30')](_0xf697('0x31'),_0x7105db+'-'+_0x2a1475+'/'+_0x573e16)[_0xf697('0x2b')](_0x47a906);}return null;};}function patchUpdates(_0x248ff2){return function(_0x5c194f){try{jsonpatch[_0xf697('0x32')](_0x5c194f,_0x248ff2,!![]);}catch(_0x2abde6){return BPromise['reject'](_0x2abde6);}return _0x5c194f[_0xf697('0x33')]();};}function saveUpdates(_0xcd76e5,_0xf16886){return function(_0x213e0a){if(_0x213e0a){return _0x213e0a[_0xf697('0x34')](_0xcd76e5)[_0xf697('0x1d')](function(_0x40770b){return _0x40770b;});}return null;};}function removeEntity(_0x4a1869,_0x2d0183){return function(_0x1041e8){if(_0x1041e8){return _0x1041e8['destroy']()[_0xf697('0x1d')](function(){var _0x4595be=_0x1041e8[_0xf697('0x35')]({'plain':!![]});var _0x32cd62='FaxAccounts';return db['UserProfileResource'][_0xf697('0x36')]({'where':{'type':_0x32cd62,'resourceId':_0x4595be['id']}})[_0xf697('0x1d')](function(){return _0x1041e8;});})[_0xf697('0x1d')](function(){_0x4a1869[_0xf697('0x29')](0xcc)[_0xf697('0x2a')]();});}};}function handleEntityNotFound(_0x46b31c,_0x28f306){return function(_0x3118da){if(!_0x3118da){_0x46b31c[_0xf697('0x28')](0x194);}return _0x3118da;};}function handleError(_0x236d22,_0x328e55){_0x328e55=_0x328e55||0x1f4;return function(_0x2a0bf6){logger[_0xf697('0x22')](_0x2a0bf6[_0xf697('0x37')]);if(_0x2a0bf6['name']){delete _0x2a0bf6[_0xf697('0x38')];}_0x236d22[_0xf697('0x29')](_0x328e55)[_0xf697('0x39')](_0x2a0bf6);};}exports['index']=function(_0x4b5425,_0x3a15aa){var _0x5b94ae={'include':[{'model':db[_0xf697('0x3a')],'as':_0xf697('0x3b')}]},_0x31f435={},_0x176700={'count':0x0,'rows':[]};var _0x497a9a=_[_0xf697('0x3c')](db[_0xf697('0x3d')][_0xf697('0x3e')],function(_0x4bacd0){return{'name':_0x4bacd0[_0xf697('0x3f')],'type':_0x4bacd0['type'][_0xf697('0x40')]};});_0x31f435[_0xf697('0x41')]=_[_0xf697('0x3c')](_0x497a9a,_0xf697('0x38'));_0x31f435['query']=_[_0xf697('0x42')](_0x4b5425['query']);_0x31f435[_0xf697('0x43')]=_[_0xf697('0x44')](_0x31f435[_0xf697('0x41')],_0x31f435[_0xf697('0x45')]);_0x5b94ae[_0xf697('0x46')]=_[_0xf697('0x44')](_0x31f435['model'],qs[_0xf697('0x47')](_0x4b5425[_0xf697('0x45')][_0xf697('0x47')]));_0x5b94ae[_0xf697('0x46')]=_0x5b94ae[_0xf697('0x46')][_0xf697('0x48')]?_0x5b94ae['attributes']:_0x31f435['model'];if(!_0x4b5425[_0xf697('0x45')]['hasOwnProperty'](_0xf697('0x49'))){_0x5b94ae[_0xf697('0x2f')]=qs['limit'](_0x4b5425['query'][_0xf697('0x2f')]);_0x5b94ae[_0xf697('0x2c')]=qs[_0xf697('0x2c')](_0x4b5425[_0xf697('0x45')][_0xf697('0x2c')]);}_0x5b94ae[_0xf697('0x4a')]=qs[_0xf697('0x4b')](_0x4b5425[_0xf697('0x45')]['sort']);_0x5b94ae['where']=qs[_0xf697('0x43')](_[_0xf697('0x4c')](_0x4b5425[_0xf697('0x45')],_0x31f435['filters']),_0x497a9a);if(_0x4b5425['query']['filter']){_0x5b94ae[_0xf697('0x4d')]=_[_0xf697('0x4e')](_0x5b94ae[_0xf697('0x4d')],{'$or':_['map'](_0x497a9a,function(_0x15b2a5){if(_0x15b2a5[_0xf697('0x4f')]!==_0xf697('0x50')){var _0x410277={};_0x410277[_0x15b2a5[_0xf697('0x38')]]={'$like':'%'+_0x4b5425[_0xf697('0x45')][_0xf697('0x51')]+'%'};return _0x410277;}})});}_0x5b94ae=_[_0xf697('0x4e')]({},_0x5b94ae,_0x4b5425['options']);var _0x3d5f61={'where':_0x5b94ae[_0xf697('0x4d')]};return db['FaxAccount'][_0xf697('0x2e')](_0x3d5f61)[_0xf697('0x1d')](function(_0x36782d){_0x176700[_0xf697('0x2e')]=_0x36782d;if(_0x4b5425[_0xf697('0x45')][_0xf697('0x52')]){_0x5b94ae[_0xf697('0x53')]=[{'all':!![]}];}return db[_0xf697('0x3d')][_0xf697('0x54')](_0x5b94ae);})[_0xf697('0x1d')](function(_0x11c9dd){_0x176700['rows']=_0x11c9dd;return _0x176700;})['then'](respondWithFilteredResult(_0x3a15aa,_0x5b94ae))[_0xf697('0x27')](handleError(_0x3a15aa,null));};exports[_0xf697('0x55')]=function(_0x25baa4,_0xf00cff){var _0x1e8af8={'raw':![],'where':{'id':_0x25baa4[_0xf697('0x56')]['id']},'include':[{'model':db[_0xf697('0x3a')],'as':_0xf697('0x3b')}]},_0x42947b={};_0x42947b[_0xf697('0x41')]=_['keys'](db['FaxAccount'][_0xf697('0x3e')]);_0x42947b[_0xf697('0x45')]=_[_0xf697('0x42')](_0x25baa4['query']);_0x42947b[_0xf697('0x43')]=_[_0xf697('0x44')](_0x42947b[_0xf697('0x41')],_0x42947b[_0xf697('0x45')]);_0x1e8af8[_0xf697('0x46')]=_[_0xf697('0x44')](_0x42947b[_0xf697('0x41')],qs[_0xf697('0x47')](_0x25baa4[_0xf697('0x45')][_0xf697('0x47')]));_0x1e8af8[_0xf697('0x46')]=_0x1e8af8[_0xf697('0x46')][_0xf697('0x48')]?_0x1e8af8['attributes']:_0x42947b[_0xf697('0x41')];if(_0x25baa4[_0xf697('0x45')][_0xf697('0x52')]){_0x1e8af8['include']=[{'all':!![]}];}_0x1e8af8=_['merge']({},_0x1e8af8,_0x25baa4[_0xf697('0x57')]);return db[_0xf697('0x3d')][_0xf697('0x58')](_0x1e8af8)[_0xf697('0x1d')](handleEntityNotFound(_0xf00cff,null))[_0xf697('0x1d')](respondWithResult(_0xf00cff,null))['catch'](handleError(_0xf00cff,null));};exports['create']=function(_0x25c72c,_0x20c34e){return db[_0xf697('0x3d')][_0xf697('0x59')](_0x25c72c[_0xf697('0x5a')],{})[_0xf697('0x1d')](function(_0xc10317){var _0x2d6940=_0x25c72c[_0xf697('0x5b')][_0xf697('0x35')]({'plain':!![]});if(!_0x2d6940)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x2d6940['role']===_0xf697('0x5b')){var _0x88d847=_0xc10317['get']({'plain':!![]});var _0x538589=_0xf697('0x5c');return db[_0xf697('0x5d')]['find']({'where':{'name':_0x538589,'userProfileId':_0x2d6940['userProfileId']},'raw':!![]})['then'](function(_0x451901){if(_0x451901&&_0x451901[_0xf697('0x5e')]===0x0){return db[_0xf697('0x5f')][_0xf697('0x59')]({'name':_0x88d847[_0xf697('0x38')],'resourceId':_0x88d847['id'],'type':_0x451901['name'],'sectionId':_0x451901['id']},{})[_0xf697('0x1d')](function(){return _0xc10317;});}else{return _0xc10317;}})[_0xf697('0x27')](function(_0x14fa04){logger[_0xf697('0x22')](_0xf697('0x60'),_0x14fa04);throw _0x14fa04;});}return _0xc10317;})[_0xf697('0x1d')](respondWithResult(_0x20c34e,0xc9))[_0xf697('0x27')](handleError(_0x20c34e,null));};exports[_0xf697('0x34')]=function(_0x2ec1ed,_0x4d2215){if(_0x2ec1ed[_0xf697('0x5a')]['id']){delete _0x2ec1ed['body']['id'];}return db['FaxAccount'][_0xf697('0x58')]({'where':{'id':_0x2ec1ed[_0xf697('0x56')]['id']},'include':[{'model':db[_0xf697('0x3a')],'as':_0xf697('0x3b')}]})['then'](handleEntityNotFound(_0x4d2215,null))['then'](saveUpdates(_0x2ec1ed[_0xf697('0x5a')],null))['then'](respondWithResult(_0x4d2215,null))[_0xf697('0x27')](handleError(_0x4d2215,null));};exports['destroy']=function(_0x360de4,_0x1d45f8){return db[_0xf697('0x3d')]['find']({'where':{'id':_0x360de4[_0xf697('0x56')]['id']}})[_0xf697('0x1d')](handleEntityNotFound(_0x1d45f8,null))['then'](removeEntity(_0x1d45f8,null))[_0xf697('0x27')](handleError(_0x1d45f8,null));};exports[_0xf697('0x61')]=function(_0x5b6640,_0x7f781f){return db[_0xf697('0x3d')]['describe']()['then'](respondWithResult(_0x7f781f,null))[_0xf697('0x27')](handleError(_0x7f781f,null));};exports['addDisposition']=function(_0x18cf4b,_0x50a974,_0x34951f){if(_0x18cf4b[_0xf697('0x5a')]['id']){delete _0x18cf4b[_0xf697('0x5a')]['id'];}return db[_0xf697('0x3d')][_0xf697('0x58')]({'where':{'id':_0x18cf4b[_0xf697('0x56')]['id']}})['then'](handleEntityNotFound(_0x50a974,null))[_0xf697('0x1d')](function(_0x325161){if(_0x325161){_0x18cf4b[_0xf697('0x5a')][_0xf697('0x62')]=_0x325161['id'];return db[_0xf697('0x63')]['create'](_0x18cf4b[_0xf697('0x5a')]);}})[_0xf697('0x1d')](respondWithResult(_0x50a974,null))[_0xf697('0x27')](handleError(_0x50a974,null));};exports[_0xf697('0x64')]=function(_0x152304,_0xbab0f3,_0x328723){var _0xbef280={'raw':![],'where':{}};var _0xdace65={};var _0x4d3f9a={'count':0x0,'rows':[]};return db[_0xf697('0x3d')]['findOne']({'where':{'id':_0x152304['params']['id']}})[_0xf697('0x1d')](handleEntityNotFound(_0xbab0f3,null))[_0xf697('0x1d')](function(_0x4f53e6){if(_0x4f53e6){_0xdace65[_0xf697('0x41')]=_[_0xf697('0x42')](db[_0xf697('0x63')]['rawAttributes']);_0xdace65['query']=_['keys'](_0x152304[_0xf697('0x45')]);_0xdace65[_0xf697('0x43')]=_['intersection'](_0xdace65[_0xf697('0x41')],_0xdace65[_0xf697('0x45')]);_0xbef280[_0xf697('0x46')]=_[_0xf697('0x44')](_0xdace65[_0xf697('0x41')],qs[_0xf697('0x47')](_0x152304['query'][_0xf697('0x47')]));_0xbef280['attributes']=_0xbef280[_0xf697('0x46')][_0xf697('0x48')]?_0xbef280[_0xf697('0x46')]:_0xdace65[_0xf697('0x41')];if(!_0x152304[_0xf697('0x45')]['hasOwnProperty'](_0xf697('0x49'))){_0xbef280[_0xf697('0x2f')]=qs[_0xf697('0x2f')](_0x152304[_0xf697('0x45')][_0xf697('0x2f')]);_0xbef280[_0xf697('0x2c')]=qs[_0xf697('0x2c')](_0x152304[_0xf697('0x45')][_0xf697('0x2c')]);}_0xbef280[_0xf697('0x4a')]=qs[_0xf697('0x4b')](_0x152304[_0xf697('0x45')][_0xf697('0x4b')]);_0xbef280['where']=qs[_0xf697('0x43')](_[_0xf697('0x4c')](_0x152304[_0xf697('0x45')],_0xdace65[_0xf697('0x43')]));_0xbef280['where']['FaxAccountId']=_0x4f53e6['id'];if(_0x152304[_0xf697('0x45')][_0xf697('0x51')]){_0xbef280[_0xf697('0x4d')]=_[_0xf697('0x4e')](_0xbef280[_0xf697('0x4d')],{'$or':_[_0xf697('0x3c')](_0xbef280[_0xf697('0x46')],function(_0x23a97f){var _0x3a0736={};_0x3a0736[_0x23a97f]={'$like':'%'+_0x152304[_0xf697('0x45')][_0xf697('0x51')]+'%'};return _0x3a0736;})});}_0xbef280=_[_0xf697('0x4e')]({},_0xbef280,_0x152304[_0xf697('0x57')]);return db['Disposition'][_0xf697('0x2e')]({'where':_0xbef280['where']})[_0xf697('0x1d')](function(_0x5f2763){_0x4d3f9a[_0xf697('0x2e')]=_0x5f2763;if(_0x152304[_0xf697('0x45')][_0xf697('0x52')]){_0xbef280[_0xf697('0x53')]=[{'all':!![]}];}return db[_0xf697('0x63')][_0xf697('0x54')](_0xbef280);})[_0xf697('0x1d')](function(_0x343f50){_0x4d3f9a[_0xf697('0x65')]=_0x343f50;return _0x4d3f9a;});}})['then'](respondWithFilteredResult(_0xbab0f3,_0xbef280))[_0xf697('0x27')](handleError(_0xbab0f3,null));};exports[_0xf697('0x66')]=function(_0x2aeaa6,_0xc196e4,_0x218e44){return db[_0xf697('0x3d')][_0xf697('0x58')]({'where':{'id':_0x2aeaa6[_0xf697('0x56')]['id']}})[_0xf697('0x1d')](handleEntityNotFound(_0xc196e4,null))[_0xf697('0x1d')](function(_0x5a9311){if(_0x5a9311){return _0x5a9311[_0xf697('0x66')](_0x2aeaa6[_0xf697('0x45')][_0xf697('0x67')]);}})[_0xf697('0x1d')](respondWithStatusCode(_0xc196e4,null))[_0xf697('0x27')](handleError(_0xc196e4,null));};exports[_0xf697('0x68')]=function(_0x2e2afe,_0x5b22a1,_0x190a96){if(_0x2e2afe[_0xf697('0x5a')]['id']){delete _0x2e2afe[_0xf697('0x5a')]['id'];}return db[_0xf697('0x3d')][_0xf697('0x58')]({'where':{'id':_0x2e2afe['params']['id']}})[_0xf697('0x1d')](handleEntityNotFound(_0x5b22a1,null))[_0xf697('0x1d')](function(_0x453efb){if(_0x453efb){_0x2e2afe[_0xf697('0x5a')][_0xf697('0x62')]=_0x453efb['id'];return db[_0xf697('0x69')][_0xf697('0x59')](_0x2e2afe['body']);}})[_0xf697('0x1d')](respondWithResult(_0x5b22a1,null))[_0xf697('0x27')](handleError(_0x5b22a1,null));};exports[_0xf697('0x6a')]=function(_0x37a5a5,_0x1cba6c,_0x1fc00a){var _0x428261={'raw':![],'where':{}};var _0x5b99d7={};var _0xbf2caf={'count':0x0,'rows':[]};return db['FaxAccount'][_0xf697('0x6b')]({'where':{'id':_0x37a5a5[_0xf697('0x56')]['id']}})[_0xf697('0x1d')](handleEntityNotFound(_0x1cba6c,null))['then'](function(_0x190108){if(_0x190108){_0x5b99d7[_0xf697('0x41')]=_['keys'](db[_0xf697('0x69')]['rawAttributes']);_0x5b99d7[_0xf697('0x45')]=_[_0xf697('0x42')](_0x37a5a5['query']);_0x5b99d7[_0xf697('0x43')]=_[_0xf697('0x44')](_0x5b99d7[_0xf697('0x41')],_0x5b99d7[_0xf697('0x45')]);_0x428261[_0xf697('0x46')]=_[_0xf697('0x44')](_0x5b99d7['model'],qs[_0xf697('0x47')](_0x37a5a5[_0xf697('0x45')][_0xf697('0x47')]));_0x428261[_0xf697('0x46')]=_0x428261[_0xf697('0x46')][_0xf697('0x48')]?_0x428261['attributes']:_0x5b99d7[_0xf697('0x41')];if(!_0x37a5a5[_0xf697('0x45')][_0xf697('0x6c')](_0xf697('0x49'))){_0x428261[_0xf697('0x2f')]=qs['limit'](_0x37a5a5['query'][_0xf697('0x2f')]);_0x428261[_0xf697('0x2c')]=qs[_0xf697('0x2c')](_0x37a5a5['query'][_0xf697('0x2c')]);}_0x428261[_0xf697('0x4a')]=qs['sort'](_0x37a5a5[_0xf697('0x45')]['sort']);_0x428261[_0xf697('0x4d')]=qs[_0xf697('0x43')](_[_0xf697('0x4c')](_0x37a5a5[_0xf697('0x45')],_0x5b99d7[_0xf697('0x43')]));_0x428261[_0xf697('0x4d')][_0xf697('0x62')]=_0x190108['id'];if(_0x37a5a5[_0xf697('0x45')][_0xf697('0x51')]){_0x428261[_0xf697('0x4d')]=_['merge'](_0x428261[_0xf697('0x4d')],{'$or':_[_0xf697('0x3c')](_0x428261[_0xf697('0x46')],function(_0x18eb0f){var _0x4206c6={};_0x4206c6[_0x18eb0f]={'$like':'%'+_0x37a5a5['query']['filter']+'%'};return _0x4206c6;})});}_0x428261=_['merge']({},_0x428261,_0x37a5a5[_0xf697('0x57')]);return db[_0xf697('0x69')][_0xf697('0x2e')]({'where':_0x428261[_0xf697('0x4d')]})[_0xf697('0x1d')](function(_0x517d01){_0xbf2caf[_0xf697('0x2e')]=_0x517d01;if(_0x37a5a5[_0xf697('0x45')][_0xf697('0x52')]){_0x428261[_0xf697('0x53')]=[{'all':!![]}];}return db[_0xf697('0x69')]['findAll'](_0x428261);})['then'](function(_0x2e06e1){_0xbf2caf[_0xf697('0x65')]=_0x2e06e1;return _0xbf2caf;});}})['then'](respondWithFilteredResult(_0x1cba6c,_0x428261))[_0xf697('0x27')](handleError(_0x1cba6c,null));};exports[_0xf697('0x6d')]=function(_0x12055f,_0x3516ea,_0x134041){return db['FaxAccount'][_0xf697('0x58')]({'where':{'id':_0x12055f[_0xf697('0x56')]['id']}})[_0xf697('0x1d')](handleEntityNotFound(_0x3516ea,null))['then'](function(_0x38c8ac){if(_0x38c8ac){return _0x38c8ac[_0xf697('0x6d')](_0x12055f[_0xf697('0x45')][_0xf697('0x67')]);}})['then'](respondWithStatusCode(_0x3516ea,null))[_0xf697('0x27')](handleError(_0x3516ea,null));};exports[_0xf697('0x6e')]=function(_0x168609,_0x455a0c,_0x2f5f14){return db[_0xf697('0x6f')][_0xf697('0x58')]({'where':{'id':_0x168609[_0xf697('0x56')]['id']}})[_0xf697('0x1d')](handleEntityNotFound(_0x455a0c,null))[_0xf697('0x1d')](function(_0x4b334d){if(_0x4b334d){return _0x4b334d[_0xf697('0x6e')](_0x168609[_0xf697('0x5a')][_0xf697('0x67')],_[_0xf697('0x70')](_0x168609['body'],[_0xf697('0x67'),'id'])||{});}})[_0xf697('0x1d')](respondWithResult(_0x455a0c,null))['catch'](handleError(_0x455a0c,null));};exports[_0xf697('0x71')]=function(_0x443b7d,_0x8255c3,_0x48a1d1){var _0x5970dc={'raw':![],'where':{}};var _0x4bdce4={};var _0xdbbb61={'count':0x0,'rows':[]};return db[_0xf697('0x3d')][_0xf697('0x6b')]({'where':{'id':_0x443b7d['params']['id']}})['then'](handleEntityNotFound(_0x8255c3,null))['then'](function(_0x26b023){if(_0x26b023){_0x4bdce4[_0xf697('0x41')]=_['keys'](db['FaxInteraction'][_0xf697('0x3e')]);_0x4bdce4[_0xf697('0x45')]=_[_0xf697('0x42')](_0x443b7d[_0xf697('0x45')]);_0x4bdce4[_0xf697('0x43')]=_[_0xf697('0x44')](_0x4bdce4[_0xf697('0x41')],_0x4bdce4[_0xf697('0x45')]);_0x5970dc[_0xf697('0x46')]=_[_0xf697('0x44')](_0x4bdce4[_0xf697('0x41')],qs[_0xf697('0x47')](_0x443b7d['query'][_0xf697('0x47')]));_0x5970dc[_0xf697('0x46')]=_0x5970dc[_0xf697('0x46')][_0xf697('0x48')]?_0x5970dc[_0xf697('0x46')]:_0x4bdce4[_0xf697('0x41')];if(!_0x443b7d['query']['hasOwnProperty'](_0xf697('0x49'))){_0x5970dc['limit']=qs[_0xf697('0x2f')](_0x443b7d[_0xf697('0x45')]['limit']);_0x5970dc['offset']=qs[_0xf697('0x2c')](_0x443b7d[_0xf697('0x45')][_0xf697('0x2c')]);}_0x5970dc[_0xf697('0x4a')]=qs[_0xf697('0x4b')](_0x443b7d[_0xf697('0x45')][_0xf697('0x4b')]);_0x5970dc[_0xf697('0x4d')]=qs[_0xf697('0x43')](_['pick'](_0x443b7d[_0xf697('0x45')],_0x4bdce4[_0xf697('0x43')]));_0x5970dc[_0xf697('0x4d')][_0xf697('0x62')]=_0x26b023['id'];if(_0x443b7d['query'][_0xf697('0x51')]){_0x5970dc[_0xf697('0x4d')]=_[_0xf697('0x4e')](_0x5970dc[_0xf697('0x4d')],{'$or':_['map'](_0x5970dc[_0xf697('0x46')],function(_0x1905a5){var _0x541c0f={};_0x541c0f[_0x1905a5]={'$like':'%'+_0x443b7d[_0xf697('0x45')]['filter']+'%'};return _0x541c0f;})});}_0x5970dc=_[_0xf697('0x4e')]({},_0x5970dc,_0x443b7d[_0xf697('0x57')]);return db['FaxInteraction'][_0xf697('0x2e')]({'where':_0x5970dc[_0xf697('0x4d')]})[_0xf697('0x1d')](function(_0x52d91e){_0xdbbb61[_0xf697('0x2e')]=_0x52d91e;if(_0x443b7d['query'][_0xf697('0x52')]){_0x5970dc['include']=[{'model':db[_0xf697('0x72')],'as':_0xf697('0x73'),'required':![]},{'model':db[_0xf697('0x74')],'as':'Owner','attributes':[_0xf697('0x38'),'fullname',_0xf697('0x75')],'required':![]},{'model':db[_0xf697('0x76')],'as':_0xf697('0x77'),'attributes':['id','name',_0xf697('0x78')],'where':_0x443b7d[_0xf697('0x45')][_0xf697('0x79')]?{'id':_0x443b7d[_0xf697('0x45')][_0xf697('0x79')]}:undefined,'required':_0x443b7d['query'][_0xf697('0x79')]?!![]:![]}];}return db['FaxInteraction'][_0xf697('0x54')](_0x5970dc);})[_0xf697('0x1d')](function(_0x680ee6){_0xdbbb61[_0xf697('0x65')]=_0x680ee6;return _0xdbbb61;});}})[_0xf697('0x1d')](respondWithFilteredResult(_0x8255c3,_0x5970dc))[_0xf697('0x27')](handleError(_0x8255c3,null));};exports[_0xf697('0x7a')]=function(_0xb4861b,_0x581a27){var _0x20d380=_0xb4861b[_0xf697('0x56')]['id'];var _0x371bbb=_0xb4861b[_0xf697('0x5a')];var _0x27fd53=0xc8;var _0x2cf5f3=null;return db['sequelize'][_0xf697('0x7b')]({'isolationLevel':db[_0xf697('0x7c')][_0xf697('0x7d')]['ISOLATION_LEVELS'][_0xf697('0x7e')]},function(_0x4976c5){return db[_0xf697('0x3d')][_0xf697('0x6b')]({'where':{'id':_0x20d380},'transaction':_0x4976c5})[_0xf697('0x1d')](function(_0x1193ba){if(_0x1193ba){return db['FaxApplication'][_0xf697('0x36')]({'where':{'FaxAccountId':_0x20d380},'transaction':_0x4976c5})['then'](function(){var _0xc1d8f0=_['map'](_0x371bbb,function(_0x1dcc11){_0x1dcc11[_0xf697('0x62')]=_0x20d380;return _0x1dcc11;});return db[_0xf697('0x7f')][_0xf697('0x80')](_0xc1d8f0,{'transaction':_0x4976c5});});}else{_0x27fd53=0x194;_0x2cf5f3=[];}});})[_0xf697('0x1d')](function(){if(_0x27fd53!==0x194){return db[_0xf697('0x7f')]['findAndCountAll']({'where':{'FaxAccountId':_0x20d380},'order':_0xf697('0x81')})[_0xf697('0x1d')](function(_0x558407){_0x2cf5f3=_0x558407;});}})[_0xf697('0x27')](function(_0x40df7e){_0x27fd53=0x1f4;logger[_0xf697('0x22')](_0x40df7e[_0xf697('0x37')]);if(_0x40df7e[_0xf697('0x38')]){delete _0x40df7e['name'];}_0x2cf5f3=_0x40df7e;})[_0xf697('0x82')](function(){if(_0x2cf5f3===null){_0x581a27[_0xf697('0x28')](_0x27fd53);}else{if(_0x27fd53===0x1f4){_0x581a27[_0xf697('0x29')](_0x27fd53)[_0xf697('0x39')](_0x2cf5f3);}else{_0x581a27[_0xf697('0x29')](_0x27fd53)[_0xf697('0x2b')](_0x2cf5f3);}}});};exports[_0xf697('0x83')]=function(_0x4a8330,_0x36433a,_0x120e3c){var _0x2c33ba={};var _0x338172={};var _0x3e3163;var _0x231cea;return db['FaxAccount'][_0xf697('0x6b')]({'where':{'id':_0x4a8330['params']['id']}})[_0xf697('0x1d')](handleEntityNotFound(_0x36433a,null))['then'](function(_0x4381b2){if(_0x4381b2){_0x3e3163=_0x4381b2;_0x338172[_0xf697('0x41')]=_[_0xf697('0x42')](db['FaxApplication'][_0xf697('0x3e')]);_0x338172[_0xf697('0x45')]=_['keys'](_0x4a8330['query']);_0x338172[_0xf697('0x43')]=_['intersection'](_0x338172[_0xf697('0x41')],_0x338172[_0xf697('0x45')]);_0x2c33ba[_0xf697('0x46')]=_[_0xf697('0x44')](_0x338172[_0xf697('0x41')],qs[_0xf697('0x47')](_0x4a8330[_0xf697('0x45')][_0xf697('0x47')]));_0x2c33ba[_0xf697('0x46')]=_0x2c33ba[_0xf697('0x46')][_0xf697('0x48')]?_0x2c33ba['attributes']:_0x338172[_0xf697('0x41')];_0x2c33ba[_0xf697('0x4a')]=qs['sort'](_0x4a8330[_0xf697('0x45')][_0xf697('0x4b')]);_0x2c33ba[_0xf697('0x4d')]=qs[_0xf697('0x43')](_['pick'](_0x4a8330[_0xf697('0x45')],_0x338172[_0xf697('0x43')]));if(_0x4a8330['query']['filter']){_0x2c33ba[_0xf697('0x4d')]=_[_0xf697('0x4e')](_0x2c33ba[_0xf697('0x4d')],{'$or':_[_0xf697('0x3c')](_0x2c33ba[_0xf697('0x46')],function(_0x270c71){var _0x1128cd={};_0x1128cd[_0x270c71]={'$like':'%'+_0x4a8330[_0xf697('0x45')][_0xf697('0x51')]+'%'};return _0x1128cd;})});}_0x2c33ba=_[_0xf697('0x4e')]({},_0x2c33ba,_0x4a8330['options']);return _0x3e3163[_0xf697('0x83')](_0x2c33ba);}})[_0xf697('0x1d')](function(_0x5c4f55){if(_0x5c4f55){_0x231cea=_0x5c4f55[_0xf697('0x48')];if(!_0x4a8330['query'][_0xf697('0x6c')](_0xf697('0x49'))){_0x2c33ba[_0xf697('0x2f')]=qs[_0xf697('0x2f')](_0x4a8330[_0xf697('0x45')][_0xf697('0x2f')]);_0x2c33ba[_0xf697('0x2c')]=qs['offset'](_0x4a8330[_0xf697('0x45')][_0xf697('0x2c')]);}return _0x3e3163[_0xf697('0x83')](_0x2c33ba);}})[_0xf697('0x1d')](function(_0x45a3e6){if(_0x45a3e6){return _0x45a3e6?{'count':_0x231cea,'rows':_0x45a3e6}:null;}})['then'](respondWithResult(_0x36433a,null))[_0xf697('0x27')](handleError(_0x36433a,null));};function Extension(_0x5f2f77,_0x34d4b1,_0x138b11,_0x454831){this[_0xf697('0x84')]=_0xf697('0x85');this[_0xf697('0x86')]=_0x5f2f77[_0xf697('0x87')];this[_0xf697('0x88')]=_0x454831;this['type']=_0xf697('0x89');this[_0xf697('0x8a')]=_0xf697('0x8b');this[_0xf697('0x62')]=_0x5f2f77['id'];this[_0xf697('0x81')]=_0x34d4b1;this['appdata']=_0x138b11;}function createExtensionsReciveFax(_0xce007d){var _0x5af445=0x1;var _0x1822a4=[];_0x1822a4[_0xf697('0x8c')](new Extension(_0xce007d,_0x5af445,'',_0xf697('0x8d')));_0x5af445+=0x1;_0x1822a4['push'](new Extension(_0xce007d,_0x5af445,'CDR(type)=inbound-fax',_0xf697('0x8e')));_0x5af445+=0x1;for(var _0x322714 in _0xce007d){if(_0xce007d[_0xf697('0x6c')](_0x322714)&&(_0x322714==='ecm'||_0x322714===_0xf697('0x87')||_0x322714==='gateway'||_0x322714===_0xf697('0x8f')||_0x322714===_0xf697('0x90')||_0x322714==='maxrate'||_0x322714===_0xf697('0x91')||_0x322714==='modem'||_0x322714===_0xf697('0x92'))){_0x1822a4[_0xf697('0x8c')](new Extension(_0xce007d,_0x5af445,_0xf697('0x93')+_0x322714+')='+_0xce007d[_0x322714],_0xf697('0x8e')));_0x5af445+=0x1;}}_0x1822a4[_0xf697('0x8c')](new Extension(_0xce007d,_0x5af445,'6',_0xf697('0x94')));_0x5af445+=0x1;_0x1822a4['push'](new Extension(_0xce007d,_0x5af445,_0xf697('0x95'),_0xf697('0x96')));_0x5af445=0x0;return _0x1822a4;}exports['addAccountApplications']=function(_0xc63ba1,_0x5e318b,_0x115bf9){var _0x37c05f;return db[_0xf697('0x7c')][_0xf697('0x7b')](function(_0x33d58b){return db[_0xf697('0x3d')]['create'](_0xc63ba1['body'],{'transaction':_0x33d58b})[_0xf697('0x1d')](function(_0x4dff66){_0x37c05f=_0x4dff66[_0xf697('0x35')]({'plain':!![]});return db['VoiceExtension'][_0xf697('0x80')](createExtensionsReciveFax(_0x37c05f),{'transaction':_0x33d58b});});})[_0xf697('0x1d')](function(){return _0x37c05f;})[_0xf697('0x1d')](respondWithResult(_0x5e318b,null))[_0xf697('0x27')](handleError(_0x5e318b,null));};exports[_0xf697('0x97')]=function(_0x388a0d,_0x30a7d6,_0x59bf3b){var _0x55539b;return db[_0xf697('0x7c')][_0xf697('0x7b')](function(_0x1306db){return db[_0xf697('0x3d')][_0xf697('0x34')](_0x388a0d[_0xf697('0x5a')],{'where':{'id':_0x388a0d[_0xf697('0x5a')]['id']},'transaction':_0x1306db})[_0xf697('0x1d')](function(_0x490c88){return db['VoiceExtension']['destroy']({'where':{'FaxAccountId':_0x388a0d[_0xf697('0x5a')]['id']},'transaction':_0x1306db})['then'](function(_0x151385){return db[_0xf697('0x98')][_0xf697('0x80')](createExtensionsReciveFax(_[_0xf697('0x70')](_0x388a0d[_0xf697('0x5a')],['tech',_0xf697('0x40'),'createdAt',_0xf697('0x99'),_0xf697('0x9a'),_0xf697('0x9b')])),{'transaction':_0x1306db});});});})['then'](function(){return db[_0xf697('0x3d')][_0xf697('0x9c')](_0x388a0d[_0xf697('0x5a')]['id']);})['then'](respondWithResult(_0x30a7d6,null))['catch'](handleError(_0x30a7d6,null));};exports['getMessages']=function(_0x16f1e5,_0x25b0d5,_0x4b11ed){var _0x213ba7={'raw':!![],'where':{}};var _0x5d2fbb={};var _0x5ca29f={'count':0x0,'rows':[]};return db[_0xf697('0x3d')]['findOne']({'where':{'id':_0x16f1e5[_0xf697('0x56')]['id']}})[_0xf697('0x1d')](handleEntityNotFound(_0x25b0d5,null))[_0xf697('0x1d')](function(_0x18c85e){if(_0x18c85e){_0x5d2fbb[_0xf697('0x41')]=_[_0xf697('0x42')](db['FaxMessage'][_0xf697('0x3e')]);_0x5d2fbb[_0xf697('0x45')]=_[_0xf697('0x42')](_0x16f1e5[_0xf697('0x45')]);_0x5d2fbb['filters']=_[_0xf697('0x44')](_0x5d2fbb[_0xf697('0x41')],_0x5d2fbb[_0xf697('0x45')]);_0x213ba7['attributes']=_[_0xf697('0x44')](_0x5d2fbb[_0xf697('0x41')],qs[_0xf697('0x47')](_0x16f1e5[_0xf697('0x45')]['fields']));_0x213ba7[_0xf697('0x46')]=_0x213ba7['attributes']['length']?_0x213ba7[_0xf697('0x46')]:_0x5d2fbb[_0xf697('0x41')];if(!_0x16f1e5[_0xf697('0x45')]['hasOwnProperty'](_0xf697('0x49'))){_0x213ba7[_0xf697('0x2f')]=qs[_0xf697('0x2f')](_0x16f1e5['query'][_0xf697('0x2f')]);_0x213ba7['offset']=qs[_0xf697('0x2c')](_0x16f1e5[_0xf697('0x45')][_0xf697('0x2c')]);}_0x213ba7[_0xf697('0x4a')]=qs[_0xf697('0x4b')](_0x16f1e5[_0xf697('0x45')][_0xf697('0x4b')]);_0x213ba7[_0xf697('0x4d')]=qs[_0xf697('0x43')](_[_0xf697('0x4c')](_0x16f1e5[_0xf697('0x45')],_0x5d2fbb['filters']));_0x213ba7['where']['FaxAccountId']=_0x18c85e['id'];if(_0x16f1e5[_0xf697('0x45')][_0xf697('0x51')]){_0x213ba7['where']=_[_0xf697('0x4e')](_0x213ba7[_0xf697('0x4d')],{'$or':_[_0xf697('0x3c')](_0x213ba7[_0xf697('0x46')],function(_0x276a2a){var _0x2e9381={};_0x2e9381[_0x276a2a]={'$like':'%'+_0x16f1e5[_0xf697('0x45')][_0xf697('0x51')]+'%'};return _0x2e9381;})});}if(_0x16f1e5[_0xf697('0x45')][_0xf697('0x9d')]){var _0x4dcf6f=_0x16f1e5[_0xf697('0x45')][_0xf697('0x9d')]['split'](',');var _0x421eb2={};_0x421eb2[_0x4dcf6f[0x0]]={'$gte':moment(_0x4dcf6f[0x1])[_0xf697('0x9e')](_0xf697('0x9f'))};_0x213ba7[_0xf697('0x4d')]=_[_0xf697('0x4e')](_0x213ba7[_0xf697('0x4d')],_0x421eb2);}_0x213ba7=_[_0xf697('0x4e')]({},_0x213ba7,_0x16f1e5[_0xf697('0x57')]);return db['FaxMessage'][_0xf697('0x2e')]({'where':_0x213ba7[_0xf697('0x4d')]})['then'](function(_0x4f25f6){_0x5ca29f[_0xf697('0x2e')]=_0x4f25f6;if(_0x16f1e5[_0xf697('0x45')][_0xf697('0x52')]){_0x213ba7[_0xf697('0x53')]=[{'all':!![]}];}return db[_0xf697('0xa0')]['findAll'](_0x213ba7);})['then'](function(_0x3ed07b){_0x5ca29f[_0xf697('0x65')]=_0x3ed07b;return _0x5ca29f;});}})[_0xf697('0x1d')](respondWithFilteredResult(_0x25b0d5,_0x213ba7))['catch'](handleError(_0x25b0d5,null));};exports[_0xf697('0x39')]=function(_0x2e3ba2,_0x2c7fe3,_0x5a89db){var _0x211077,_0x1f9085={},_0x549b0c;if(_0x2e3ba2[_0xf697('0x5a')]['to']){_0x549b0c=_0x2e3ba2[_0xf697('0x5a')]['to'][0x0];}return db[_0xf697('0x3d')][_0xf697('0x58')]({'where':{'id':_0x2e3ba2[_0xf697('0x56')]['id']},'include':[{'model':db[_0xf697('0xa1')],'as':_0xf697('0xa2'),'include':[{'model':db[_0xf697('0x72')],'as':'Contacts','where':{'fax':_0x549b0c},'limit':0x1,'order':[[_0xf697('0x99'),'DESC']]}]}]})['then'](handleEntityNotFound(_0x2c7fe3,null))[_0xf697('0x1d')](function(_0x27589b){_0x211077=_0x27589b;if(_0x2e3ba2[_0xf697('0x5a')][_0xf697('0xa3')]&&_0x2e3ba2[_0xf697('0x5a')][_0xf697('0xa3')][_0xf697('0x48')]){for(var _0x52f74e=0x0;_0x52f74e<_0x2e3ba2[_0xf697('0x5a')][_0xf697('0xa3')][_0xf697('0x48')];_0x52f74e+=0x1){_0x2e3ba2[_0xf697('0x5a')][_0xf697('0xa3')][_0x52f74e]={'filename':_0x2e3ba2['body'][_0xf697('0xa3')][_0x52f74e]['name'],'id':_0x2e3ba2['body'][_0xf697('0xa3')][_0x52f74e]['id'],'path':path['join'](config[_0xf697('0xa4')],_0xf697('0xa5'),_0x2e3ba2[_0xf697('0x5a')][_0xf697('0xa3')][_0x52f74e][_0xf697('0xa6')])};}}return respondWithRpcPromise(_0xf697('0xa7'),_0xf697('0xa7'),{'FaxAccountId':_[_0xf697('0xa8')](_0x2e3ba2[_0xf697('0x56')]['id'])?undefined:_0x2e3ba2['params']['id'],'path':_[_0xf697('0xa8')](_0x2e3ba2[_0xf697('0x5a')][_0xf697('0xa3')][0x0]['path'])?undefined:_0x2e3ba2[_0xf697('0x5a')][_0xf697('0xa3')][0x0][_0xf697('0xa9')],'fax':_['isNil'](_0x2e3ba2['body']['to'][0x0])?undefined:_0x2e3ba2[_0xf697('0x5a')]['to'][0x0]},client9002);})[_0xf697('0x1d')](function(){if(_0x211077){if(_[_0xf697('0xa8')](_0x2e3ba2['body'][_0xf697('0xaa')])){_0x2e3ba2[_0xf697('0x5a')][_0xf697('0xaa')]=util[_0xf697('0x9e')](_0xf697('0xab'),_0x211077[_0xf697('0x38')],_0x211077[_0xf697('0xac')]);}if(_0x211077[_0xf697('0xa2')]){if(_0x211077['List'][_0xf697('0xad')]['length']){return _0x211077['List'][_0xf697('0xad')][0x0];}else{return db['CmContact']['create'](_[_0xf697('0xae')](_0x2e3ba2[_0xf697('0x5a')],{'firstName':_0x2e3ba2[_0xf697('0x5a')]['to'][0x0],'phone':_0x2e3ba2[_0xf697('0x5a')]['to'][0x0],'fax':_0x2e3ba2[_0xf697('0x5a')]['to'][0x0],'ListId':_0x211077[_0xf697('0x9b')]}));}}else{throw new Error(_0xf697('0xaf'));}}else{throw new Error(_0xf697('0xb0'));}})[_0xf697('0x1d')](function(_0x211208){if(_0x211208){return db['FaxInteraction'][_0xf697('0x58')]({'where':{'ContactId':_0x211208['id'],'closed':![],'FaxAccountId':_0x211077['id']}})[_0xf697('0x1d')](function(_0x40a005){if(_0x40a005){return[_0x40a005,![]];}return db['FaxInteraction']['create']({'UserId':_0x2e3ba2[_0xf697('0x5b')]['id'],'ContactId':_0x211208['id'],'FaxAccountId':_0x211077['id'],'fax':_0x2e3ba2[_0xf697('0x5a')]['to'][0x0],'firstMsgDirection':_0xf697('0xb1'),'Messages':[_['merge'](_0x2e3ba2['body'],{'read':![],'body':_0x2e3ba2[_0xf697('0x5a')][_0xf697('0xa3')][0x0][_0xf697('0xb2')],'FaxAccountId':_0x211077['id'],'UserId':_0x2e3ba2['user']['id'],'ContactId':_0x211208['id'],'AttachmentId':_0x2e3ba2[_0xf697('0x5a')][_0xf697('0xa3')][0x0]['id']})]},{'include':[{'model':db[_0xf697('0xa0')],'as':_0xf697('0xb3')}]})[_0xf697('0x1d')](function(_0x13f3b1){return[_0x13f3b1,!![]];});});}else{throw new Error(_0xf697('0xb4'));}})[_0xf697('0xb5')](function(_0x399fa0,_0x5ef56b){if(_0x5ef56b){return _0x399fa0;}return db[_0xf697('0xa0')]['create']({'direction':_0xf697('0xb1'),'read':![],'body':_0x2e3ba2[_0xf697('0x5a')][_0xf697('0xa3')][0x0][_0xf697('0xb2')],'FaxAccountId':_0x211077['id'],'FaxInteractionId':_0x399fa0['id'],'UserId':_0x2e3ba2[_0xf697('0x5b')]['id'],'ContactId':_0x399fa0[_0xf697('0xb6')],'AttachmentId':_0x2e3ba2[_0xf697('0x5a')][_0xf697('0xa3')][0x0]['id']})['then'](function(_0x205173){_0x399fa0[_0xf697('0xb7')][_0xf697('0xb3')]=[];_0x399fa0[_0xf697('0xb7')][_0xf697('0xb3')][_0xf697('0x8c')](_0x205173['dataValues']);return _0x399fa0;});})[_0xf697('0x1d')](function(_0x3af2e8){respondWithRpcPromise(_0xf697('0xb8'),_0xf697('0xb8'),{'FaxAccountId':_[_0xf697('0xa8')](_0x2e3ba2[_0xf697('0x56')]['id'])?undefined:_0x2e3ba2['params']['id'],'path':_['isNil'](_0x2e3ba2[_0xf697('0x5a')]['attachments'][0x0][_0xf697('0xa9')])?undefined:_0x2e3ba2[_0xf697('0x5a')][_0xf697('0xa3')][0x0][_0xf697('0xa9')],'fax':_[_0xf697('0xa8')](_0x2e3ba2['body']['to'][0x0])?undefined:_0x2e3ba2['body']['to'][0x0],'AttachmentId':_0x2e3ba2[_0xf697('0x5a')][_0xf697('0xa3')][0x0]['id']},client9002)[_0xf697('0x1d')](function(_0xb3b582){logger[_0xf697('0x25')]('SendFaxRpc,\x20%s',_0xb3b582);})[_0xf697('0x27')](function(_0x520048){logger[_0xf697('0x25')]('SendFaxRpc,\x20%s',_0x520048);});return _0x3af2e8;})['then'](respondWithResult(_0x2c7fe3,null))[_0xf697('0x27')](handleError(_0x2c7fe3,null));};exports[_0xf697('0xb9')]=function(_0x32405e,_0x781f28,_0x4078c0){return db[_0xf697('0x3d')][_0xf697('0x58')]({'where':{'id':_0x32405e[_0xf697('0x56')]['id']}})[_0xf697('0x1d')](handleEntityNotFound(_0x781f28,null))[_0xf697('0x1d')](function(_0x5a5f05){if(_0x5a5f05){return _0x5a5f05[_0xf697('0xb9')](_0x32405e[_0xf697('0x5a')][_0xf697('0x67')],_[_0xf697('0x70')](_0x32405e['body'],[_0xf697('0x67'),'id'])||{})[_0xf697('0xb5')](function(_0x772272){for(var _0x222a2b=0x0;_0x222a2b<_0x32405e['body'][_0xf697('0x67')][_0xf697('0x48')];_0x222a2b+=0x1){socket[_0xf697('0xba')](_0xf697('0xbb'),{'UserId':Number(_0x32405e['body'][_0xf697('0x67')][_0x222a2b]),'FaxAccountId':Number(_0x32405e[_0xf697('0x56')]['id'])});}return _0x772272;});}})['then'](respondWithResult(_0x781f28,null))[_0xf697('0x27')](handleError(_0x781f28,null));};exports[_0xf697('0xbc')]=function(_0x56862c,_0x36397c,_0x15cadc){return db[_0xf697('0x3d')][_0xf697('0x58')]({'where':{'id':_0x56862c['params']['id']}})[_0xf697('0x1d')](handleEntityNotFound(_0x36397c,null))['then'](function(_0x4ae1b9){if(_0x4ae1b9){return _0x4ae1b9[_0xf697('0xbc')](_0x56862c[_0xf697('0x45')][_0xf697('0x67')])[_0xf697('0x1d')](function(){if(_[_0xf697('0xbd')](_0x56862c[_0xf697('0x45')][_0xf697('0x67')])){for(var _0x1822ab=0x0;_0x1822ab<_0x56862c[_0xf697('0x45')]['ids'][_0xf697('0x48')];_0x1822ab+=0x1){socket[_0xf697('0xba')]('userFaxAccount:remove',{'UserId':Number(_0x56862c['query']['ids'][_0x1822ab]),'FaxAccountId':Number(_0x56862c['params']['id'])});}}else{socket[_0xf697('0xba')]('userFaxAccount:remove',{'UserId':Number(_0x56862c[_0xf697('0x45')][_0xf697('0x67')]),'FaxAccountId':Number(_0x56862c[_0xf697('0x56')]['id'])});}});}})[_0xf697('0x1d')](respondWithStatusCode(_0x36397c,null))[_0xf697('0x27')](handleError(_0x36397c,null));};exports['getAgents']=function(_0x1a9819,_0x12dca9,_0x4014d7){var _0x368f46={};var _0x40310d={};var _0x20f898;var _0x571835;return db[_0xf697('0x3d')][_0xf697('0x6b')]({'where':{'id':_0x1a9819[_0xf697('0x56')]['id']}})['then'](handleEntityNotFound(_0x12dca9,null))[_0xf697('0x1d')](function(_0x156fb5){if(_0x156fb5){_0x20f898=_0x156fb5;_0x40310d[_0xf697('0x41')]=_[_0xf697('0x42')](db['User'][_0xf697('0x3e')]);_0x40310d[_0xf697('0x45')]=_[_0xf697('0x42')](_0x1a9819['query']);_0x40310d['filters']=_[_0xf697('0x44')](_0x40310d[_0xf697('0x41')],_0x40310d[_0xf697('0x45')]);_0x368f46[_0xf697('0x46')]=_[_0xf697('0x44')](_0x40310d['model'],qs['fields'](_0x1a9819[_0xf697('0x45')][_0xf697('0x47')]));_0x368f46['attributes']=_0x368f46[_0xf697('0x46')]['length']?_0x368f46[_0xf697('0x46')]:_0x40310d[_0xf697('0x41')];_0x368f46[_0xf697('0x4a')]=qs['sort'](_0x1a9819[_0xf697('0x45')]['sort']);_0x368f46[_0xf697('0x4d')]=qs['filters'](_[_0xf697('0x4c')](_0x1a9819[_0xf697('0x45')],_0x40310d[_0xf697('0x43')]));if(_0x1a9819['query'][_0xf697('0x51')]){_0x368f46[_0xf697('0x4d')]=_['merge'](_0x368f46[_0xf697('0x4d')],{'$or':_['map'](_0x368f46[_0xf697('0x46')],function(_0xcf3226){var _0x5233c3={};_0x5233c3[_0xcf3226]={'$like':'%'+_0x1a9819[_0xf697('0x45')][_0xf697('0x51')]+'%'};return _0x5233c3;})});}_0x368f46=_[_0xf697('0x4e')]({},_0x368f46,_0x1a9819[_0xf697('0x57')]);return _0x20f898[_0xf697('0xbe')](_0x368f46);}})[_0xf697('0x1d')](function(_0xf18c3d){if(_0xf18c3d){_0x571835=_0xf18c3d['length'];if(!_0x1a9819[_0xf697('0x45')][_0xf697('0x6c')]('nolimit')){_0x368f46['limit']=qs[_0xf697('0x2f')](_0x1a9819[_0xf697('0x45')][_0xf697('0x2f')]);_0x368f46[_0xf697('0x2c')]=qs[_0xf697('0x2c')](_0x1a9819[_0xf697('0x45')][_0xf697('0x2c')]);}return _0x20f898[_0xf697('0xbe')](_0x368f46);}})[_0xf697('0x1d')](function(_0x1831ab){if(_0x1831ab){return _0x1831ab?{'count':_0x571835,'rows':_0x1831ab}:null;}})['then'](respondWithResult(_0x12dca9,null))[_0xf697('0x27')](handleError(_0x12dca9,null));};