Built motion from commit 14588770.|2.5.38
[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 _0x74b0=['findAll','rows','catch','show','length','find','create','body','user','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','addDisposition','FaxAccountId','getDispositions','sort','Disposition','removeDispositions','addAnswer','getAnswers','findOne','CannedAnswer','removeAnswers','ids','addInteraction','FaxInteraction','omit','getInteractions','CmContact','User','Owner','Tag','tag','addApplications','sequelize','Transaction','FaxApplication','bulkCreate','findAndCountAll','priority','getApplications','context','exten','localstationid','app','system','description','Fax\x20Extension','push','Answer','CDR(type)=inbound-fax','Set','ecm','headerinfo','maxrate','minrate','modem','t38timeout','Wait','/var/opt/motion2/server/files/attachments/fax-${CALLERID(num)}-${CUT(UNIQUEID,.,1)}-${CUT(UNIQUEID,.,2)}-${STRFTIME(,,%C%y%m%d%H%M%S)}-rx.tif,d','ReceiveFax','addAccountApplications','transaction','VoiceExtension','updateAccountApplications','update','tech','createdAt','updatedAt','TrunkId','ListId','findById','getMessages','FaxMessage','$gte','split','YYYY-MM-DD\x20HH:mm:ss','CmList','Contacts','DESC','attachments','join','root','server/files/attachments','basename','CheckAfterSend','isNil','from','\x22%s\x22\x20<%s>','fax','List','List\x20not\x20found','Send\x20Fax\x20failed','out','filename','Messages','spread','ContactId','dataValues','SendFax','SendFaxRpc,\x20%s','addAgents','emit','userFaxAccount:remove','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./faxAccount.socket','register','client','http','request','request\x20sent','debug','FaxAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','FaxAccount,\x20%s,\x20%s','message','info','result','sendStatus','status','json','limit','undefined','count','offset','Content-Range','apply','reject','save','then','get','FaxAccounts','UserProfileResource','destroy','end','stack','name','send','index','Pause','mandatoryDispositionPause','map','FaxAccount','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','pick','filter','where','merge','VIRTUAL','options','includeAll','include'];(function(_0x138adb,_0x193fee){var _0x1b27f2=function(_0x5e97a2){while(--_0x5e97a2){_0x138adb['push'](_0x138adb['shift']());}};_0x1b27f2(++_0x193fee);}(_0x74b0,0x135));var _0x074b=function(_0x2641e5,_0x165b4b){_0x2641e5=_0x2641e5-0x0;var _0x3831f2=_0x74b0[_0x2641e5];return _0x3831f2;};'use strict';var emlformat=require(_0x074b('0x0'));var rimraf=require(_0x074b('0x1'));var zipdir=require(_0x074b('0x2'));var jsonpatch=require(_0x074b('0x3'));var rp=require(_0x074b('0x4'));var moment=require('moment');var BPromise=require(_0x074b('0x5'));var Mustache=require('mustache');var util=require(_0x074b('0x6'));var path=require(_0x074b('0x7'));var sox=require(_0x074b('0x8'));var csv=require(_0x074b('0x9'));var ejs=require(_0x074b('0xa'));var fs=require('fs');var fs_extra=require(_0x074b('0xb'));var _=require(_0x074b('0xc'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x074b('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x074b('0x9'));var querystring=require(_0x074b('0xe'));var Papa=require(_0x074b('0xf'));var Redis=require(_0x074b('0x10'));var authService=require(_0x074b('0x11'));var qs=require(_0x074b('0x12'));var as=require(_0x074b('0x13'));var hardwareService=require(_0x074b('0x14'));var logger=require(_0x074b('0x15'))(_0x074b('0x16'));var utils=require(_0x074b('0x17'));var config=require(_0x074b('0x18'));var licenseUtil=require(_0x074b('0x19'));var db=require(_0x074b('0x1a'))['db'];config[_0x074b('0x1b')]=_[_0x074b('0x1c')](config[_0x074b('0x1b')],{'host':_0x074b('0x1d'),'port':0x18eb});var socket=require(_0x074b('0x1e'))(new Redis(config['redis']));require(_0x074b('0x1f'))[_0x074b('0x20')](socket);var jayson=require('jayson/promise');var client=jayson[_0x074b('0x21')][_0x074b('0x22')]({'port':0x232c});var client9002=jayson['client'][_0x074b('0x22')]({'port':0x232a});function respondWithRpcPromise(_0x28a9b4,_0xd61525,_0x22bead,_0x5c0057){return new BPromise(function(_0x54bc1f,_0x95445a){var _0x217459=_0x5c0057||client;return _0x217459[_0x074b('0x23')](_0x28a9b4,_0x22bead)['then'](function(_0x3be08c){logger['info']('FaxAccount,\x20%s,\x20%s',_0xd61525,_0x074b('0x24'));logger[_0x074b('0x25')](_0x074b('0x26'),_0xd61525,_0x074b('0x24'),JSON[_0x074b('0x27')](_0x3be08c));if(_0x3be08c[_0x074b('0x28')]){if(_0x3be08c[_0x074b('0x28')][_0x074b('0x29')]===0x1f4){logger[_0x074b('0x28')](_0x074b('0x2a'),_0xd61525,_0x3be08c[_0x074b('0x28')]['message']);return _0x95445a(_0x3be08c['error'][_0x074b('0x2b')]);}logger['error'](_0x074b('0x2a'),_0xd61525,_0x3be08c['error']['message']);return _0x54bc1f(_0x3be08c[_0x074b('0x28')][_0x074b('0x2b')]);}else{logger[_0x074b('0x2c')](_0x074b('0x2a'),_0xd61525,_0x074b('0x24'));_0x54bc1f(_0x3be08c[_0x074b('0x2d')][_0x074b('0x2b')]);}})['catch'](function(_0x323892){logger[_0x074b('0x28')](_0x074b('0x2a'),_0xd61525,_0x323892);_0x95445a(_0x323892);});});}function respondWithStatusCode(_0xc64e54,_0x103230){_0x103230=_0x103230||0xcc;return function(_0x2b69b7){if(_0x2b69b7){return _0xc64e54[_0x074b('0x2e')](_0x103230);}return _0xc64e54[_0x074b('0x2f')](_0x103230)['end']();};}function respondWithResult(_0xe8e2bb,_0x268e49){_0x268e49=_0x268e49||0xc8;return function(_0x47a391){if(_0x47a391){return _0xe8e2bb[_0x074b('0x2f')](_0x268e49)[_0x074b('0x30')](_0x47a391);}};}function respondWithFilteredResult(_0x2f3282,_0x56dae0){return function(_0x2184fe){if(_0x2184fe){var _0x19027b=typeof _0x56dae0['offset']==='undefined'&&typeof _0x56dae0[_0x074b('0x31')]===_0x074b('0x32');var _0x1600d8=_0x2184fe[_0x074b('0x33')];var _0x2682b0=_0x19027b?0x0:_0x56dae0[_0x074b('0x34')];var _0x489785=_0x19027b?_0x2184fe[_0x074b('0x33')]:_0x56dae0[_0x074b('0x34')]+_0x56dae0[_0x074b('0x31')];var _0x5edeea;if(_0x489785>=_0x1600d8){_0x489785=_0x1600d8;_0x5edeea=0xc8;}else{_0x5edeea=0xce;}_0x2f3282[_0x074b('0x2f')](_0x5edeea);return _0x2f3282['set'](_0x074b('0x35'),_0x2682b0+'-'+_0x489785+'/'+_0x1600d8)[_0x074b('0x30')](_0x2184fe);}return null;};}function patchUpdates(_0x21d96d){return function(_0x58f5c0){try{jsonpatch[_0x074b('0x36')](_0x58f5c0,_0x21d96d,!![]);}catch(_0x2cb6e3){return BPromise[_0x074b('0x37')](_0x2cb6e3);}return _0x58f5c0[_0x074b('0x38')]();};}function saveUpdates(_0xed2720,_0x17b0ef){return function(_0x263ae6){if(_0x263ae6){return _0x263ae6['update'](_0xed2720)['then'](function(_0x2991a2){return _0x2991a2;});}return null;};}function removeEntity(_0x406efd,_0x49fb47){return function(_0x4cc812){if(_0x4cc812){return _0x4cc812['destroy']()[_0x074b('0x39')](function(){var _0x2b88f0=_0x4cc812[_0x074b('0x3a')]({'plain':!![]});var _0x372015=_0x074b('0x3b');return db[_0x074b('0x3c')][_0x074b('0x3d')]({'where':{'type':_0x372015,'resourceId':_0x2b88f0['id']}})[_0x074b('0x39')](function(){return _0x4cc812;});})['then'](function(){_0x406efd['status'](0xcc)[_0x074b('0x3e')]();});}};}function handleEntityNotFound(_0x5baca3,_0x31df0d){return function(_0x3d02c9){if(!_0x3d02c9){_0x5baca3[_0x074b('0x2e')](0x194);}return _0x3d02c9;};}function handleError(_0x53df97,_0x383275){_0x383275=_0x383275||0x1f4;return function(_0x4cb12a){logger[_0x074b('0x28')](_0x4cb12a[_0x074b('0x3f')]);if(_0x4cb12a['name']){delete _0x4cb12a[_0x074b('0x40')];}_0x53df97['status'](_0x383275)[_0x074b('0x41')](_0x4cb12a);};}exports[_0x074b('0x42')]=function(_0x30cbbc,_0x138167){var _0x393eb0={'include':[{'model':db[_0x074b('0x43')],'as':_0x074b('0x44')}]},_0x71c9e0={},_0xdbb825={'count':0x0,'rows':[]};var _0x937e21=_[_0x074b('0x45')](db[_0x074b('0x46')][_0x074b('0x47')],function(_0x2ffc54){return{'name':_0x2ffc54[_0x074b('0x48')],'type':_0x2ffc54[_0x074b('0x49')][_0x074b('0x4a')]};});_0x71c9e0[_0x074b('0x4b')]=_['map'](_0x937e21,'name');_0x71c9e0[_0x074b('0x4c')]=_[_0x074b('0x4d')](_0x30cbbc[_0x074b('0x4c')]);_0x71c9e0[_0x074b('0x4e')]=_[_0x074b('0x4f')](_0x71c9e0[_0x074b('0x4b')],_0x71c9e0[_0x074b('0x4c')]);_0x393eb0[_0x074b('0x50')]=_['intersection'](_0x71c9e0[_0x074b('0x4b')],qs[_0x074b('0x51')](_0x30cbbc[_0x074b('0x4c')][_0x074b('0x51')]));_0x393eb0[_0x074b('0x50')]=_0x393eb0[_0x074b('0x50')]['length']?_0x393eb0[_0x074b('0x50')]:_0x71c9e0[_0x074b('0x4b')];if(!_0x30cbbc[_0x074b('0x4c')][_0x074b('0x52')](_0x074b('0x53'))){_0x393eb0[_0x074b('0x31')]=qs['limit'](_0x30cbbc[_0x074b('0x4c')][_0x074b('0x31')]);_0x393eb0[_0x074b('0x34')]=qs[_0x074b('0x34')](_0x30cbbc[_0x074b('0x4c')][_0x074b('0x34')]);}_0x393eb0[_0x074b('0x54')]=qs['sort'](_0x30cbbc[_0x074b('0x4c')]['sort']);_0x393eb0['where']=qs[_0x074b('0x4e')](_[_0x074b('0x55')](_0x30cbbc[_0x074b('0x4c')],_0x71c9e0[_0x074b('0x4e')]),_0x937e21);if(_0x30cbbc[_0x074b('0x4c')][_0x074b('0x56')]){_0x393eb0[_0x074b('0x57')]=_[_0x074b('0x58')](_0x393eb0[_0x074b('0x57')],{'$or':_[_0x074b('0x45')](_0x937e21,function(_0x5ff552){if(_0x5ff552[_0x074b('0x49')]!==_0x074b('0x59')){var _0x22ebed={};_0x22ebed[_0x5ff552['name']]={'$like':'%'+_0x30cbbc[_0x074b('0x4c')][_0x074b('0x56')]+'%'};return _0x22ebed;}})});}_0x393eb0=_[_0x074b('0x58')]({},_0x393eb0,_0x30cbbc[_0x074b('0x5a')]);var _0x3aa222={'where':_0x393eb0['where']};return db[_0x074b('0x46')][_0x074b('0x33')](_0x3aa222)[_0x074b('0x39')](function(_0x399d43){_0xdbb825[_0x074b('0x33')]=_0x399d43;if(_0x30cbbc[_0x074b('0x4c')][_0x074b('0x5b')]){_0x393eb0[_0x074b('0x5c')]=[{'all':!![]}];}return db[_0x074b('0x46')][_0x074b('0x5d')](_0x393eb0);})['then'](function(_0x3b8275){_0xdbb825[_0x074b('0x5e')]=_0x3b8275;return _0xdbb825;})[_0x074b('0x39')](respondWithFilteredResult(_0x138167,_0x393eb0))[_0x074b('0x5f')](handleError(_0x138167,null));};exports[_0x074b('0x60')]=function(_0x5af97f,_0x334dac){var _0x599a2c={'raw':![],'where':{'id':_0x5af97f['params']['id']},'include':[{'model':db['Pause'],'as':_0x074b('0x44')}]},_0x39c716={};_0x39c716['model']=_[_0x074b('0x4d')](db[_0x074b('0x46')]['rawAttributes']);_0x39c716[_0x074b('0x4c')]=_[_0x074b('0x4d')](_0x5af97f[_0x074b('0x4c')]);_0x39c716[_0x074b('0x4e')]=_['intersection'](_0x39c716[_0x074b('0x4b')],_0x39c716[_0x074b('0x4c')]);_0x599a2c[_0x074b('0x50')]=_[_0x074b('0x4f')](_0x39c716[_0x074b('0x4b')],qs[_0x074b('0x51')](_0x5af97f['query'][_0x074b('0x51')]));_0x599a2c[_0x074b('0x50')]=_0x599a2c['attributes'][_0x074b('0x61')]?_0x599a2c[_0x074b('0x50')]:_0x39c716[_0x074b('0x4b')];if(_0x5af97f[_0x074b('0x4c')]['includeAll']){_0x599a2c[_0x074b('0x5c')]=[{'all':!![]}];}_0x599a2c=_['merge']({},_0x599a2c,_0x5af97f[_0x074b('0x5a')]);return db[_0x074b('0x46')][_0x074b('0x62')](_0x599a2c)[_0x074b('0x39')](handleEntityNotFound(_0x334dac,null))[_0x074b('0x39')](respondWithResult(_0x334dac,null))[_0x074b('0x5f')](handleError(_0x334dac,null));};exports['create']=function(_0x5e6328,_0x1b0a12){return db[_0x074b('0x46')][_0x074b('0x63')](_0x5e6328[_0x074b('0x64')],{})[_0x074b('0x39')](function(_0x16b307){var _0x3dc301=_0x5e6328[_0x074b('0x65')][_0x074b('0x3a')]({'plain':!![]});if(!_0x3dc301)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x3dc301[_0x074b('0x66')]==='user'){var _0x1a8ab2=_0x16b307['get']({'plain':!![]});var _0xa95686=_0x074b('0x3b');return db[_0x074b('0x67')][_0x074b('0x62')]({'where':{'name':_0xa95686,'userProfileId':_0x3dc301['userProfileId']},'raw':!![]})[_0x074b('0x39')](function(_0x376cfd){if(_0x376cfd&&_0x376cfd[_0x074b('0x68')]===0x0){return db[_0x074b('0x3c')][_0x074b('0x63')]({'name':_0x1a8ab2[_0x074b('0x40')],'resourceId':_0x1a8ab2['id'],'type':_0x376cfd['name'],'sectionId':_0x376cfd['id']},{})[_0x074b('0x39')](function(){return _0x16b307;});}else{return _0x16b307;}})[_0x074b('0x5f')](function(_0x38f4da){logger[_0x074b('0x28')](_0x074b('0x69'),_0x38f4da);throw _0x38f4da;});}return _0x16b307;})['then'](respondWithResult(_0x1b0a12,0xc9))['catch'](handleError(_0x1b0a12,null));};exports['update']=function(_0x4f5d1c,_0x1c6603){if(_0x4f5d1c[_0x074b('0x64')]['id']){delete _0x4f5d1c[_0x074b('0x64')]['id'];}return db['FaxAccount']['find']({'where':{'id':_0x4f5d1c[_0x074b('0x6a')]['id']},'include':[{'model':db[_0x074b('0x43')],'as':'mandatoryDispositionPause'}]})[_0x074b('0x39')](handleEntityNotFound(_0x1c6603,null))[_0x074b('0x39')](saveUpdates(_0x4f5d1c[_0x074b('0x64')],null))[_0x074b('0x39')](respondWithResult(_0x1c6603,null))[_0x074b('0x5f')](handleError(_0x1c6603,null));};exports[_0x074b('0x3d')]=function(_0x147956,_0x509feb){return db[_0x074b('0x46')][_0x074b('0x62')]({'where':{'id':_0x147956['params']['id']}})[_0x074b('0x39')](handleEntityNotFound(_0x509feb,null))[_0x074b('0x39')](removeEntity(_0x509feb,null))[_0x074b('0x5f')](handleError(_0x509feb,null));};exports[_0x074b('0x6b')]=function(_0x37120d,_0x4a97f8){return db[_0x074b('0x46')][_0x074b('0x6b')]()['then'](respondWithResult(_0x4a97f8,null))[_0x074b('0x5f')](handleError(_0x4a97f8,null));};exports[_0x074b('0x6c')]=function(_0x1d0933,_0x4136a7,_0x12d800){if(_0x1d0933['body']['id']){delete _0x1d0933['body']['id'];}return db[_0x074b('0x46')][_0x074b('0x62')]({'where':{'id':_0x1d0933[_0x074b('0x6a')]['id']}})[_0x074b('0x39')](handleEntityNotFound(_0x4136a7,null))[_0x074b('0x39')](function(_0x21b482){if(_0x21b482){_0x1d0933[_0x074b('0x64')][_0x074b('0x6d')]=_0x21b482['id'];return db['Disposition'][_0x074b('0x63')](_0x1d0933[_0x074b('0x64')]);}})['then'](respondWithResult(_0x4136a7,null))['catch'](handleError(_0x4136a7,null));};exports[_0x074b('0x6e')]=function(_0x45dda9,_0x60db42,_0x2637d6){var _0x2d2a60={'raw':![],'where':{}};var _0x2f3d89={};var _0x91229b={'count':0x0,'rows':[]};return db[_0x074b('0x46')]['findOne']({'where':{'id':_0x45dda9[_0x074b('0x6a')]['id']}})[_0x074b('0x39')](handleEntityNotFound(_0x60db42,null))[_0x074b('0x39')](function(_0x569c9d){if(_0x569c9d){_0x2f3d89[_0x074b('0x4b')]=_[_0x074b('0x4d')](db['Disposition']['rawAttributes']);_0x2f3d89[_0x074b('0x4c')]=_[_0x074b('0x4d')](_0x45dda9[_0x074b('0x4c')]);_0x2f3d89['filters']=_[_0x074b('0x4f')](_0x2f3d89[_0x074b('0x4b')],_0x2f3d89[_0x074b('0x4c')]);_0x2d2a60[_0x074b('0x50')]=_['intersection'](_0x2f3d89[_0x074b('0x4b')],qs[_0x074b('0x51')](_0x45dda9[_0x074b('0x4c')]['fields']));_0x2d2a60[_0x074b('0x50')]=_0x2d2a60[_0x074b('0x50')][_0x074b('0x61')]?_0x2d2a60[_0x074b('0x50')]:_0x2f3d89[_0x074b('0x4b')];if(!_0x45dda9[_0x074b('0x4c')][_0x074b('0x52')](_0x074b('0x53'))){_0x2d2a60[_0x074b('0x31')]=qs[_0x074b('0x31')](_0x45dda9[_0x074b('0x4c')]['limit']);_0x2d2a60['offset']=qs[_0x074b('0x34')](_0x45dda9[_0x074b('0x4c')][_0x074b('0x34')]);}_0x2d2a60[_0x074b('0x54')]=qs[_0x074b('0x6f')](_0x45dda9[_0x074b('0x4c')][_0x074b('0x6f')]);_0x2d2a60['where']=qs[_0x074b('0x4e')](_[_0x074b('0x55')](_0x45dda9[_0x074b('0x4c')],_0x2f3d89[_0x074b('0x4e')]));_0x2d2a60[_0x074b('0x57')]['FaxAccountId']=_0x569c9d['id'];if(_0x45dda9[_0x074b('0x4c')][_0x074b('0x56')]){_0x2d2a60[_0x074b('0x57')]=_[_0x074b('0x58')](_0x2d2a60[_0x074b('0x57')],{'$or':_[_0x074b('0x45')](_0x2d2a60[_0x074b('0x50')],function(_0x42f9f2){var _0x26db78={};_0x26db78[_0x42f9f2]={'$like':'%'+_0x45dda9[_0x074b('0x4c')][_0x074b('0x56')]+'%'};return _0x26db78;})});}_0x2d2a60=_['merge']({},_0x2d2a60,_0x45dda9[_0x074b('0x5a')]);return db[_0x074b('0x70')]['count']({'where':_0x2d2a60[_0x074b('0x57')]})[_0x074b('0x39')](function(_0x162fec){_0x91229b['count']=_0x162fec;if(_0x45dda9['query'][_0x074b('0x5b')]){_0x2d2a60[_0x074b('0x5c')]=[{'all':!![]}];}return db['Disposition'][_0x074b('0x5d')](_0x2d2a60);})[_0x074b('0x39')](function(_0x3b9532){_0x91229b[_0x074b('0x5e')]=_0x3b9532;return _0x91229b;});}})[_0x074b('0x39')](respondWithFilteredResult(_0x60db42,_0x2d2a60))['catch'](handleError(_0x60db42,null));};exports[_0x074b('0x71')]=function(_0x5dae55,_0xab2720,_0x20b4cd){return db[_0x074b('0x46')][_0x074b('0x62')]({'where':{'id':_0x5dae55[_0x074b('0x6a')]['id']}})[_0x074b('0x39')](handleEntityNotFound(_0xab2720,null))[_0x074b('0x39')](function(_0x191031){if(_0x191031){return _0x191031[_0x074b('0x71')](_0x5dae55[_0x074b('0x4c')]['ids']);}})['then'](respondWithStatusCode(_0xab2720,null))['catch'](handleError(_0xab2720,null));};exports[_0x074b('0x72')]=function(_0x44c287,_0x3cae5a,_0x353c5e){if(_0x44c287[_0x074b('0x64')]['id']){delete _0x44c287[_0x074b('0x64')]['id'];}return db[_0x074b('0x46')][_0x074b('0x62')]({'where':{'id':_0x44c287[_0x074b('0x6a')]['id']}})[_0x074b('0x39')](handleEntityNotFound(_0x3cae5a,null))[_0x074b('0x39')](function(_0x3b259d){if(_0x3b259d){_0x44c287['body'][_0x074b('0x6d')]=_0x3b259d['id'];return db['CannedAnswer'][_0x074b('0x63')](_0x44c287['body']);}})[_0x074b('0x39')](respondWithResult(_0x3cae5a,null))[_0x074b('0x5f')](handleError(_0x3cae5a,null));};exports[_0x074b('0x73')]=function(_0xe727c9,_0x493f81,_0x9e7ff6){var _0xae8083={'raw':![],'where':{}};var _0x46e980={};var _0x5cb043={'count':0x0,'rows':[]};return db[_0x074b('0x46')][_0x074b('0x74')]({'where':{'id':_0xe727c9[_0x074b('0x6a')]['id']}})['then'](handleEntityNotFound(_0x493f81,null))[_0x074b('0x39')](function(_0x2a6e80){if(_0x2a6e80){_0x46e980[_0x074b('0x4b')]=_[_0x074b('0x4d')](db[_0x074b('0x75')][_0x074b('0x47')]);_0x46e980[_0x074b('0x4c')]=_[_0x074b('0x4d')](_0xe727c9['query']);_0x46e980['filters']=_[_0x074b('0x4f')](_0x46e980[_0x074b('0x4b')],_0x46e980[_0x074b('0x4c')]);_0xae8083[_0x074b('0x50')]=_[_0x074b('0x4f')](_0x46e980[_0x074b('0x4b')],qs['fields'](_0xe727c9[_0x074b('0x4c')][_0x074b('0x51')]));_0xae8083[_0x074b('0x50')]=_0xae8083[_0x074b('0x50')]['length']?_0xae8083[_0x074b('0x50')]:_0x46e980[_0x074b('0x4b')];if(!_0xe727c9[_0x074b('0x4c')][_0x074b('0x52')](_0x074b('0x53'))){_0xae8083[_0x074b('0x31')]=qs['limit'](_0xe727c9[_0x074b('0x4c')]['limit']);_0xae8083[_0x074b('0x34')]=qs[_0x074b('0x34')](_0xe727c9[_0x074b('0x4c')][_0x074b('0x34')]);}_0xae8083[_0x074b('0x54')]=qs[_0x074b('0x6f')](_0xe727c9[_0x074b('0x4c')][_0x074b('0x6f')]);_0xae8083[_0x074b('0x57')]=qs['filters'](_['pick'](_0xe727c9[_0x074b('0x4c')],_0x46e980[_0x074b('0x4e')]));_0xae8083['where'][_0x074b('0x6d')]=_0x2a6e80['id'];if(_0xe727c9[_0x074b('0x4c')][_0x074b('0x56')]){_0xae8083[_0x074b('0x57')]=_[_0x074b('0x58')](_0xae8083[_0x074b('0x57')],{'$or':_['map'](_0xae8083[_0x074b('0x50')],function(_0x5007c6){var _0x5c69b1={};_0x5c69b1[_0x5007c6]={'$like':'%'+_0xe727c9['query'][_0x074b('0x56')]+'%'};return _0x5c69b1;})});}_0xae8083=_['merge']({},_0xae8083,_0xe727c9[_0x074b('0x5a')]);return db[_0x074b('0x75')][_0x074b('0x33')]({'where':_0xae8083[_0x074b('0x57')]})[_0x074b('0x39')](function(_0x397a29){_0x5cb043[_0x074b('0x33')]=_0x397a29;if(_0xe727c9[_0x074b('0x4c')][_0x074b('0x5b')]){_0xae8083['include']=[{'all':!![]}];}return db['CannedAnswer'][_0x074b('0x5d')](_0xae8083);})[_0x074b('0x39')](function(_0x55466a){_0x5cb043[_0x074b('0x5e')]=_0x55466a;return _0x5cb043;});}})[_0x074b('0x39')](respondWithFilteredResult(_0x493f81,_0xae8083))[_0x074b('0x5f')](handleError(_0x493f81,null));};exports[_0x074b('0x76')]=function(_0x5ac431,_0x2a5a54,_0x54d022){return db[_0x074b('0x46')]['find']({'where':{'id':_0x5ac431[_0x074b('0x6a')]['id']}})[_0x074b('0x39')](handleEntityNotFound(_0x2a5a54,null))[_0x074b('0x39')](function(_0x1e6bf1){if(_0x1e6bf1){return _0x1e6bf1['removeAnswers'](_0x5ac431['query'][_0x074b('0x77')]);}})['then'](respondWithStatusCode(_0x2a5a54,null))[_0x074b('0x5f')](handleError(_0x2a5a54,null));};exports[_0x074b('0x78')]=function(_0x334d8e,_0x1fe1f1,_0x2720aa){return db[_0x074b('0x79')][_0x074b('0x62')]({'where':{'id':_0x334d8e[_0x074b('0x6a')]['id']}})[_0x074b('0x39')](handleEntityNotFound(_0x1fe1f1,null))['then'](function(_0x3afd84){if(_0x3afd84){return _0x3afd84[_0x074b('0x78')](_0x334d8e[_0x074b('0x64')][_0x074b('0x77')],_[_0x074b('0x7a')](_0x334d8e['body'],[_0x074b('0x77'),'id'])||{});}})['then'](respondWithResult(_0x1fe1f1,null))[_0x074b('0x5f')](handleError(_0x1fe1f1,null));};exports[_0x074b('0x7b')]=function(_0x551b58,_0x5bd8f8,_0x71ef91){var _0xb3cd84={'raw':![],'where':{}};var _0x58423b={};var _0x1f6257={'count':0x0,'rows':[]};return db['FaxAccount'][_0x074b('0x74')]({'where':{'id':_0x551b58[_0x074b('0x6a')]['id']}})[_0x074b('0x39')](handleEntityNotFound(_0x5bd8f8,null))['then'](function(_0x4ef627){if(_0x4ef627){_0x58423b['model']=_[_0x074b('0x4d')](db[_0x074b('0x79')]['rawAttributes']);_0x58423b[_0x074b('0x4c')]=_[_0x074b('0x4d')](_0x551b58[_0x074b('0x4c')]);_0x58423b[_0x074b('0x4e')]=_[_0x074b('0x4f')](_0x58423b[_0x074b('0x4b')],_0x58423b['query']);_0xb3cd84[_0x074b('0x50')]=_[_0x074b('0x4f')](_0x58423b[_0x074b('0x4b')],qs[_0x074b('0x51')](_0x551b58[_0x074b('0x4c')][_0x074b('0x51')]));_0xb3cd84['attributes']=_0xb3cd84['attributes']['length']?_0xb3cd84['attributes']:_0x58423b['model'];if(!_0x551b58[_0x074b('0x4c')]['hasOwnProperty']('nolimit')){_0xb3cd84['limit']=qs['limit'](_0x551b58['query'][_0x074b('0x31')]);_0xb3cd84[_0x074b('0x34')]=qs['offset'](_0x551b58[_0x074b('0x4c')]['offset']);}_0xb3cd84[_0x074b('0x54')]=qs[_0x074b('0x6f')](_0x551b58['query'][_0x074b('0x6f')]);_0xb3cd84[_0x074b('0x57')]=qs[_0x074b('0x4e')](_[_0x074b('0x55')](_0x551b58[_0x074b('0x4c')],_0x58423b[_0x074b('0x4e')]));_0xb3cd84[_0x074b('0x57')][_0x074b('0x6d')]=_0x4ef627['id'];if(_0x551b58['query'][_0x074b('0x56')]){_0xb3cd84[_0x074b('0x57')]=_[_0x074b('0x58')](_0xb3cd84[_0x074b('0x57')],{'$or':_[_0x074b('0x45')](_0xb3cd84[_0x074b('0x50')],function(_0x57df8b){var _0x51ef59={};_0x51ef59[_0x57df8b]={'$like':'%'+_0x551b58['query']['filter']+'%'};return _0x51ef59;})});}_0xb3cd84=_['merge']({},_0xb3cd84,_0x551b58[_0x074b('0x5a')]);return db[_0x074b('0x79')][_0x074b('0x33')]({'where':_0xb3cd84[_0x074b('0x57')]})[_0x074b('0x39')](function(_0x222fd4){_0x1f6257[_0x074b('0x33')]=_0x222fd4;if(_0x551b58[_0x074b('0x4c')][_0x074b('0x5b')]){_0xb3cd84[_0x074b('0x5c')]=[{'model':db[_0x074b('0x7c')],'as':'Contact','required':![]},{'model':db[_0x074b('0x7d')],'as':_0x074b('0x7e'),'attributes':[_0x074b('0x40'),'fullname','internal'],'required':![]},{'model':db[_0x074b('0x7f')],'as':'Tags','attributes':['id',_0x074b('0x40'),'color'],'where':_0x551b58[_0x074b('0x4c')][_0x074b('0x80')]?{'id':_0x551b58[_0x074b('0x4c')][_0x074b('0x80')]}:undefined,'required':_0x551b58['query'][_0x074b('0x80')]?!![]:![]}];}return db[_0x074b('0x79')]['findAll'](_0xb3cd84);})[_0x074b('0x39')](function(_0x482476){_0x1f6257['rows']=_0x482476;return _0x1f6257;});}})[_0x074b('0x39')](respondWithFilteredResult(_0x5bd8f8,_0xb3cd84))[_0x074b('0x5f')](handleError(_0x5bd8f8,null));};exports[_0x074b('0x81')]=function(_0x1f7c0e,_0x12a698){var _0x3ec4c1=_0x1f7c0e[_0x074b('0x6a')]['id'];var _0x5715dc=_0x1f7c0e['body'];var _0x3b4f8d=0xc8;var _0x390d0a=null;return db[_0x074b('0x82')]['transaction']({'isolationLevel':db['sequelize'][_0x074b('0x83')]['ISOLATION_LEVELS']['READ_COMMITTED']},function(_0x1bad4d){return db[_0x074b('0x46')][_0x074b('0x74')]({'where':{'id':_0x3ec4c1},'transaction':_0x1bad4d})[_0x074b('0x39')](function(_0x2c0f4f){if(_0x2c0f4f){return db[_0x074b('0x84')]['destroy']({'where':{'FaxAccountId':_0x3ec4c1},'transaction':_0x1bad4d})['then'](function(){var _0x192e64=_[_0x074b('0x45')](_0x5715dc,function(_0x3b9681){_0x3b9681[_0x074b('0x6d')]=_0x3ec4c1;return _0x3b9681;});return db[_0x074b('0x84')][_0x074b('0x85')](_0x192e64,{'transaction':_0x1bad4d});});}else{_0x3b4f8d=0x194;_0x390d0a=[];}});})['then'](function(){if(_0x3b4f8d!==0x194){return db[_0x074b('0x84')][_0x074b('0x86')]({'where':{'FaxAccountId':_0x3ec4c1},'order':_0x074b('0x87')})[_0x074b('0x39')](function(_0x35e5a2){_0x390d0a=_0x35e5a2;});}})['catch'](function(_0x40a2b9){_0x3b4f8d=0x1f4;logger['error'](_0x40a2b9[_0x074b('0x3f')]);if(_0x40a2b9[_0x074b('0x40')]){delete _0x40a2b9[_0x074b('0x40')];}_0x390d0a=_0x40a2b9;})['finally'](function(){if(_0x390d0a===null){_0x12a698[_0x074b('0x2e')](_0x3b4f8d);}else{if(_0x3b4f8d===0x1f4){_0x12a698[_0x074b('0x2f')](_0x3b4f8d)[_0x074b('0x41')](_0x390d0a);}else{_0x12a698['status'](_0x3b4f8d)[_0x074b('0x30')](_0x390d0a);}}});};exports[_0x074b('0x88')]=function(_0xfbd393,_0x4a3b82,_0x485d50){var _0x36c0ed={};var _0x15e782={};var _0x319a0f;var _0x217327;return db[_0x074b('0x46')][_0x074b('0x74')]({'where':{'id':_0xfbd393['params']['id']}})[_0x074b('0x39')](handleEntityNotFound(_0x4a3b82,null))['then'](function(_0x1e0215){if(_0x1e0215){_0x319a0f=_0x1e0215;_0x15e782['model']=_[_0x074b('0x4d')](db[_0x074b('0x84')][_0x074b('0x47')]);_0x15e782[_0x074b('0x4c')]=_['keys'](_0xfbd393[_0x074b('0x4c')]);_0x15e782[_0x074b('0x4e')]=_[_0x074b('0x4f')](_0x15e782[_0x074b('0x4b')],_0x15e782[_0x074b('0x4c')]);_0x36c0ed['attributes']=_[_0x074b('0x4f')](_0x15e782['model'],qs['fields'](_0xfbd393[_0x074b('0x4c')][_0x074b('0x51')]));_0x36c0ed[_0x074b('0x50')]=_0x36c0ed[_0x074b('0x50')][_0x074b('0x61')]?_0x36c0ed[_0x074b('0x50')]:_0x15e782[_0x074b('0x4b')];_0x36c0ed['order']=qs[_0x074b('0x6f')](_0xfbd393['query'][_0x074b('0x6f')]);_0x36c0ed[_0x074b('0x57')]=qs[_0x074b('0x4e')](_[_0x074b('0x55')](_0xfbd393[_0x074b('0x4c')],_0x15e782[_0x074b('0x4e')]));if(_0xfbd393[_0x074b('0x4c')][_0x074b('0x56')]){_0x36c0ed[_0x074b('0x57')]=_[_0x074b('0x58')](_0x36c0ed[_0x074b('0x57')],{'$or':_[_0x074b('0x45')](_0x36c0ed[_0x074b('0x50')],function(_0xb61cb2){var _0x1ffa14={};_0x1ffa14[_0xb61cb2]={'$like':'%'+_0xfbd393[_0x074b('0x4c')]['filter']+'%'};return _0x1ffa14;})});}_0x36c0ed=_['merge']({},_0x36c0ed,_0xfbd393['options']);return _0x319a0f['getApplications'](_0x36c0ed);}})[_0x074b('0x39')](function(_0x5bd3ca){if(_0x5bd3ca){_0x217327=_0x5bd3ca[_0x074b('0x61')];if(!_0xfbd393['query'][_0x074b('0x52')]('nolimit')){_0x36c0ed[_0x074b('0x31')]=qs['limit'](_0xfbd393[_0x074b('0x4c')][_0x074b('0x31')]);_0x36c0ed[_0x074b('0x34')]=qs[_0x074b('0x34')](_0xfbd393[_0x074b('0x4c')]['offset']);}return _0x319a0f[_0x074b('0x88')](_0x36c0ed);}})['then'](function(_0x440256){if(_0x440256){return _0x440256?{'count':_0x217327,'rows':_0x440256}:null;}})[_0x074b('0x39')](respondWithResult(_0x4a3b82,null))[_0x074b('0x5f')](handleError(_0x4a3b82,null));};function Extension(_0x4d4dc8,_0x4c8002,_0x4a18da,_0x32615a){this[_0x074b('0x89')]='from-voip-provider';this[_0x074b('0x8a')]=_0x4d4dc8[_0x074b('0x8b')];this[_0x074b('0x8c')]=_0x32615a;this[_0x074b('0x49')]=_0x074b('0x8d');this[_0x074b('0x8e')]=_0x074b('0x8f');this[_0x074b('0x6d')]=_0x4d4dc8['id'];this[_0x074b('0x87')]=_0x4c8002;this['appdata']=_0x4a18da;}function createExtensionsReciveFax(_0x4c6fb7){var _0x355f40=0x1;var _0x24d316=[];_0x24d316[_0x074b('0x90')](new Extension(_0x4c6fb7,_0x355f40,'',_0x074b('0x91')));_0x355f40+=0x1;_0x24d316[_0x074b('0x90')](new Extension(_0x4c6fb7,_0x355f40,_0x074b('0x92'),_0x074b('0x93')));_0x355f40+=0x1;for(var _0x4a5262 in _0x4c6fb7){if(_0x4c6fb7[_0x074b('0x52')](_0x4a5262)&&(_0x4a5262===_0x074b('0x94')||_0x4a5262==='localstationid'||_0x4a5262==='gateway'||_0x4a5262==='faxdetect'||_0x4a5262===_0x074b('0x95')||_0x4a5262===_0x074b('0x96')||_0x4a5262===_0x074b('0x97')||_0x4a5262===_0x074b('0x98')||_0x4a5262===_0x074b('0x99'))){_0x24d316[_0x074b('0x90')](new Extension(_0x4c6fb7,_0x355f40,'FAXOPT('+_0x4a5262+')='+_0x4c6fb7[_0x4a5262],'Set'));_0x355f40+=0x1;}}_0x24d316[_0x074b('0x90')](new Extension(_0x4c6fb7,_0x355f40,'6',_0x074b('0x9a')));_0x355f40+=0x1;_0x24d316[_0x074b('0x90')](new Extension(_0x4c6fb7,_0x355f40,_0x074b('0x9b'),_0x074b('0x9c')));_0x355f40=0x0;return _0x24d316;}exports[_0x074b('0x9d')]=function(_0x5c54bf,_0xa76639,_0x856c5f){var _0x1ba253;return db[_0x074b('0x82')][_0x074b('0x9e')](function(_0x457b18){return db['FaxAccount'][_0x074b('0x63')](_0x5c54bf[_0x074b('0x64')],{'transaction':_0x457b18})[_0x074b('0x39')](function(_0x5b8107){_0x1ba253=_0x5b8107[_0x074b('0x3a')]({'plain':!![]});return db[_0x074b('0x9f')][_0x074b('0x85')](createExtensionsReciveFax(_0x1ba253),{'transaction':_0x457b18});});})[_0x074b('0x39')](function(){return _0x1ba253;})[_0x074b('0x39')](respondWithResult(_0xa76639,null))[_0x074b('0x5f')](handleError(_0xa76639,null));};exports[_0x074b('0xa0')]=function(_0x510401,_0x365b27,_0x88e843){var _0x311ccc;return db[_0x074b('0x82')][_0x074b('0x9e')](function(_0x27cfb5){return db[_0x074b('0x46')][_0x074b('0xa1')](_0x510401[_0x074b('0x64')],{'where':{'id':_0x510401[_0x074b('0x64')]['id']},'transaction':_0x27cfb5})[_0x074b('0x39')](function(_0x5bcf47){return db[_0x074b('0x9f')]['destroy']({'where':{'FaxAccountId':_0x510401[_0x074b('0x64')]['id']},'transaction':_0x27cfb5})['then'](function(_0x477ee0){return db['VoiceExtension'][_0x074b('0x85')](createExtensionsReciveFax(_[_0x074b('0x7a')](_0x510401[_0x074b('0x64')],[_0x074b('0xa2'),_0x074b('0x4a'),_0x074b('0xa3'),_0x074b('0xa4'),_0x074b('0xa5'),_0x074b('0xa6')])),{'transaction':_0x27cfb5});});});})[_0x074b('0x39')](function(){return db[_0x074b('0x46')][_0x074b('0xa7')](_0x510401[_0x074b('0x64')]['id']);})[_0x074b('0x39')](respondWithResult(_0x365b27,null))[_0x074b('0x5f')](handleError(_0x365b27,null));};exports[_0x074b('0xa8')]=function(_0x1cd66f,_0x55d75a,_0x5d10dd){var _0x252f40={'raw':!![],'where':{}};var _0x2bb927={};var _0x4fb60a={'count':0x0,'rows':[]};return db[_0x074b('0x46')]['findOne']({'where':{'id':_0x1cd66f[_0x074b('0x6a')]['id']}})[_0x074b('0x39')](handleEntityNotFound(_0x55d75a,null))[_0x074b('0x39')](function(_0x59eeb1){if(_0x59eeb1){_0x2bb927[_0x074b('0x4b')]=_[_0x074b('0x4d')](db[_0x074b('0xa9')]['rawAttributes']);_0x2bb927[_0x074b('0x4c')]=_[_0x074b('0x4d')](_0x1cd66f[_0x074b('0x4c')]);_0x2bb927[_0x074b('0x4e')]=_['intersection'](_0x2bb927[_0x074b('0x4b')],_0x2bb927['query']);_0x252f40['attributes']=_[_0x074b('0x4f')](_0x2bb927['model'],qs[_0x074b('0x51')](_0x1cd66f[_0x074b('0x4c')][_0x074b('0x51')]));_0x252f40[_0x074b('0x50')]=_0x252f40[_0x074b('0x50')][_0x074b('0x61')]?_0x252f40[_0x074b('0x50')]:_0x2bb927[_0x074b('0x4b')];if(!_0x1cd66f[_0x074b('0x4c')][_0x074b('0x52')](_0x074b('0x53'))){_0x252f40['limit']=qs[_0x074b('0x31')](_0x1cd66f[_0x074b('0x4c')][_0x074b('0x31')]);_0x252f40[_0x074b('0x34')]=qs[_0x074b('0x34')](_0x1cd66f['query'][_0x074b('0x34')]);}_0x252f40['order']=qs[_0x074b('0x6f')](_0x1cd66f[_0x074b('0x4c')]['sort']);_0x252f40[_0x074b('0x57')]=qs[_0x074b('0x4e')](_['pick'](_0x1cd66f[_0x074b('0x4c')],_0x2bb927[_0x074b('0x4e')]));_0x252f40['where']['FaxAccountId']=_0x59eeb1['id'];if(_0x1cd66f[_0x074b('0x4c')][_0x074b('0x56')]){_0x252f40[_0x074b('0x57')]=_[_0x074b('0x58')](_0x252f40['where'],{'$or':_[_0x074b('0x45')](_0x252f40[_0x074b('0x50')],function(_0x2f1149){var _0x4ca154={};_0x4ca154[_0x2f1149]={'$like':'%'+_0x1cd66f[_0x074b('0x4c')][_0x074b('0x56')]+'%'};return _0x4ca154;})});}if(_0x1cd66f[_0x074b('0x4c')]['$gte']){var _0x4c7e41=_0x1cd66f[_0x074b('0x4c')][_0x074b('0xaa')][_0x074b('0xab')](',');var _0x5a3ca9={};_0x5a3ca9[_0x4c7e41[0x0]]={'$gte':moment(_0x4c7e41[0x1])['format'](_0x074b('0xac'))};_0x252f40[_0x074b('0x57')]=_[_0x074b('0x58')](_0x252f40[_0x074b('0x57')],_0x5a3ca9);}_0x252f40=_[_0x074b('0x58')]({},_0x252f40,_0x1cd66f[_0x074b('0x5a')]);return db[_0x074b('0xa9')][_0x074b('0x33')]({'where':_0x252f40[_0x074b('0x57')]})[_0x074b('0x39')](function(_0x293911){_0x4fb60a['count']=_0x293911;if(_0x1cd66f[_0x074b('0x4c')][_0x074b('0x5b')]){_0x252f40[_0x074b('0x5c')]=[{'all':!![]}];}return db['FaxMessage'][_0x074b('0x5d')](_0x252f40);})[_0x074b('0x39')](function(_0x1196d6){_0x4fb60a['rows']=_0x1196d6;return _0x4fb60a;});}})[_0x074b('0x39')](respondWithFilteredResult(_0x55d75a,_0x252f40))[_0x074b('0x5f')](handleError(_0x55d75a,null));};exports[_0x074b('0x41')]=function(_0x328764,_0x25084a,_0x357048){var _0x4e3ca1,_0x42dffe={},_0x2d0495;if(_0x328764[_0x074b('0x64')]['to']){_0x2d0495=_0x328764[_0x074b('0x64')]['to'][0x0];}return db[_0x074b('0x46')][_0x074b('0x62')]({'where':{'id':_0x328764[_0x074b('0x6a')]['id']},'include':[{'model':db[_0x074b('0xad')],'as':'List','include':[{'model':db[_0x074b('0x7c')],'as':_0x074b('0xae'),'where':{'fax':_0x2d0495},'limit':0x1,'order':[[_0x074b('0xa4'),_0x074b('0xaf')]]}]}]})[_0x074b('0x39')](handleEntityNotFound(_0x25084a,null))[_0x074b('0x39')](function(_0x4ec240){_0x4e3ca1=_0x4ec240;if(_0x328764[_0x074b('0x64')][_0x074b('0xb0')]&&_0x328764[_0x074b('0x64')]['attachments'][_0x074b('0x61')]){for(var _0x4a28a6=0x0;_0x4a28a6<_0x328764['body'][_0x074b('0xb0')][_0x074b('0x61')];_0x4a28a6+=0x1){_0x328764[_0x074b('0x64')][_0x074b('0xb0')][_0x4a28a6]={'filename':_0x328764[_0x074b('0x64')][_0x074b('0xb0')][_0x4a28a6][_0x074b('0x40')],'id':_0x328764[_0x074b('0x64')][_0x074b('0xb0')][_0x4a28a6]['id'],'path':path[_0x074b('0xb1')](config[_0x074b('0xb2')],_0x074b('0xb3'),_0x328764['body'][_0x074b('0xb0')][_0x4a28a6][_0x074b('0xb4')])};}}return respondWithRpcPromise(_0x074b('0xb5'),'CheckAfterSend',{'FaxAccountId':_[_0x074b('0xb6')](_0x328764[_0x074b('0x6a')]['id'])?undefined:_0x328764['params']['id'],'path':_[_0x074b('0xb6')](_0x328764[_0x074b('0x64')]['attachments'][0x0][_0x074b('0x7')])?undefined:_0x328764['body'][_0x074b('0xb0')][0x0]['path'],'fax':_[_0x074b('0xb6')](_0x328764[_0x074b('0x64')]['to'][0x0])?undefined:_0x328764[_0x074b('0x64')]['to'][0x0]},client9002);})['then'](function(){if(_0x4e3ca1){if(_['isNil'](_0x328764['body']['from'])){_0x328764['body'][_0x074b('0xb7')]=util['format'](_0x074b('0xb8'),_0x4e3ca1['name'],_0x4e3ca1[_0x074b('0xb9')]);}if(_0x4e3ca1[_0x074b('0xba')]){if(_0x4e3ca1[_0x074b('0xba')][_0x074b('0xae')][_0x074b('0x61')]){return _0x4e3ca1[_0x074b('0xba')]['Contacts'][0x0];}else{return db[_0x074b('0x7c')][_0x074b('0x63')](_['defaults'](_0x328764[_0x074b('0x64')],{'firstName':_0x328764[_0x074b('0x64')]['to'][0x0],'phone':_0x328764[_0x074b('0x64')]['to'][0x0],'fax':_0x328764[_0x074b('0x64')]['to'][0x0],'ListId':_0x4e3ca1[_0x074b('0xa6')]}));}}else{throw new Error(_0x074b('0xbb'));}}else{throw new Error(_0x074b('0xbc'));}})['then'](function(_0x1ccfe5){if(_0x1ccfe5){return db[_0x074b('0x79')]['find']({'where':{'ContactId':_0x1ccfe5['id'],'closed':![],'FaxAccountId':_0x4e3ca1['id']}})[_0x074b('0x39')](function(_0x47122f){if(_0x47122f){return[_0x47122f,![]];}return db[_0x074b('0x79')][_0x074b('0x63')]({'UserId':_0x328764[_0x074b('0x65')]['id'],'ContactId':_0x1ccfe5['id'],'FaxAccountId':_0x4e3ca1['id'],'fax':_0x328764[_0x074b('0x64')]['to'][0x0],'firstMsgDirection':_0x074b('0xbd'),'Messages':[_[_0x074b('0x58')](_0x328764[_0x074b('0x64')],{'read':![],'body':_0x328764['body'][_0x074b('0xb0')][0x0][_0x074b('0xbe')],'FaxAccountId':_0x4e3ca1['id'],'UserId':_0x328764[_0x074b('0x65')]['id'],'ContactId':_0x1ccfe5['id'],'AttachmentId':_0x328764[_0x074b('0x64')][_0x074b('0xb0')][0x0]['id']})]},{'include':[{'model':db['FaxMessage'],'as':_0x074b('0xbf')}]})[_0x074b('0x39')](function(_0x5d3fbc){return[_0x5d3fbc,!![]];});});}else{throw new Error('Contact\x20not\x20found');}})[_0x074b('0xc0')](function(_0xe15f20,_0x9df7bb){if(_0x9df7bb){return _0xe15f20;}return db['FaxMessage'][_0x074b('0x63')]({'direction':_0x074b('0xbd'),'read':![],'body':_0x328764[_0x074b('0x64')][_0x074b('0xb0')][0x0][_0x074b('0xbe')],'FaxAccountId':_0x4e3ca1['id'],'FaxInteractionId':_0xe15f20['id'],'UserId':_0x328764[_0x074b('0x65')]['id'],'ContactId':_0xe15f20[_0x074b('0xc1')],'AttachmentId':_0x328764[_0x074b('0x64')][_0x074b('0xb0')][0x0]['id']})[_0x074b('0x39')](function(_0x12a866){_0xe15f20['dataValues']['Messages']=[];_0xe15f20['dataValues']['Messages'][_0x074b('0x90')](_0x12a866[_0x074b('0xc2')]);return _0xe15f20;});})[_0x074b('0x39')](function(_0x1a152f){respondWithRpcPromise('SendFax',_0x074b('0xc3'),{'FaxAccountId':_['isNil'](_0x328764[_0x074b('0x6a')]['id'])?undefined:_0x328764[_0x074b('0x6a')]['id'],'path':_[_0x074b('0xb6')](_0x328764[_0x074b('0x64')][_0x074b('0xb0')][0x0][_0x074b('0x7')])?undefined:_0x328764['body'][_0x074b('0xb0')][0x0]['path'],'fax':_[_0x074b('0xb6')](_0x328764[_0x074b('0x64')]['to'][0x0])?undefined:_0x328764['body']['to'][0x0],'AttachmentId':_0x328764[_0x074b('0x64')][_0x074b('0xb0')][0x0]['id']},client9002)['then'](function(_0xb0c469){logger['info'](_0x074b('0xc4'),_0xb0c469);})['catch'](function(_0xb87ea9){logger[_0x074b('0x2c')]('SendFaxRpc,\x20%s',_0xb87ea9);});return _0x1a152f;})[_0x074b('0x39')](respondWithResult(_0x25084a,null))[_0x074b('0x5f')](handleError(_0x25084a,null));};exports['addAgents']=function(_0x726e89,_0x1105ec,_0x20feca){return db[_0x074b('0x46')]['find']({'where':{'id':_0x726e89[_0x074b('0x6a')]['id']}})[_0x074b('0x39')](handleEntityNotFound(_0x1105ec,null))['then'](function(_0x5bb1b7){if(_0x5bb1b7){return _0x5bb1b7[_0x074b('0xc5')](_0x726e89['body'][_0x074b('0x77')],_[_0x074b('0x7a')](_0x726e89[_0x074b('0x64')],[_0x074b('0x77'),'id'])||{})[_0x074b('0xc0')](function(_0x322ed3){for(var _0xe51b61=0x0;_0xe51b61<_0x726e89['body']['ids'][_0x074b('0x61')];_0xe51b61+=0x1){socket[_0x074b('0xc6')]('userFaxAccount:save',{'UserId':Number(_0x726e89[_0x074b('0x64')][_0x074b('0x77')][_0xe51b61]),'FaxAccountId':Number(_0x726e89[_0x074b('0x6a')]['id'])});}return _0x322ed3;});}})[_0x074b('0x39')](respondWithResult(_0x1105ec,null))['catch'](handleError(_0x1105ec,null));};exports['removeAgents']=function(_0x5428fa,_0x5c53c4,_0x35d884){return db[_0x074b('0x46')][_0x074b('0x62')]({'where':{'id':_0x5428fa[_0x074b('0x6a')]['id']}})[_0x074b('0x39')](handleEntityNotFound(_0x5c53c4,null))[_0x074b('0x39')](function(_0x4a98f9){if(_0x4a98f9){return _0x4a98f9['removeAgents'](_0x5428fa[_0x074b('0x4c')][_0x074b('0x77')])[_0x074b('0x39')](function(){if(_['isArray'](_0x5428fa[_0x074b('0x4c')][_0x074b('0x77')])){for(var _0x2ecaae=0x0;_0x2ecaae<_0x5428fa['query']['ids']['length'];_0x2ecaae+=0x1){socket[_0x074b('0xc6')](_0x074b('0xc7'),{'UserId':Number(_0x5428fa['query'][_0x074b('0x77')][_0x2ecaae]),'FaxAccountId':Number(_0x5428fa[_0x074b('0x6a')]['id'])});}}else{socket[_0x074b('0xc6')](_0x074b('0xc7'),{'UserId':Number(_0x5428fa[_0x074b('0x4c')]['ids']),'FaxAccountId':Number(_0x5428fa[_0x074b('0x6a')]['id'])});}});}})[_0x074b('0x39')](respondWithStatusCode(_0x5c53c4,null))['catch'](handleError(_0x5c53c4,null));};exports[_0x074b('0xc8')]=function(_0x23f35e,_0x4ac359,_0x4e261a){var _0x20979b={};var _0x59121e={};var _0x113526;var _0x517f7a;return db[_0x074b('0x46')][_0x074b('0x74')]({'where':{'id':_0x23f35e['params']['id']}})[_0x074b('0x39')](handleEntityNotFound(_0x4ac359,null))[_0x074b('0x39')](function(_0xe8354c){if(_0xe8354c){_0x113526=_0xe8354c;_0x59121e[_0x074b('0x4b')]=_[_0x074b('0x4d')](db[_0x074b('0x7d')]['rawAttributes']);_0x59121e['query']=_[_0x074b('0x4d')](_0x23f35e[_0x074b('0x4c')]);_0x59121e[_0x074b('0x4e')]=_[_0x074b('0x4f')](_0x59121e[_0x074b('0x4b')],_0x59121e[_0x074b('0x4c')]);_0x20979b[_0x074b('0x50')]=_[_0x074b('0x4f')](_0x59121e[_0x074b('0x4b')],qs['fields'](_0x23f35e[_0x074b('0x4c')][_0x074b('0x51')]));_0x20979b[_0x074b('0x50')]=_0x20979b[_0x074b('0x50')][_0x074b('0x61')]?_0x20979b['attributes']:_0x59121e[_0x074b('0x4b')];_0x20979b[_0x074b('0x54')]=qs[_0x074b('0x6f')](_0x23f35e[_0x074b('0x4c')][_0x074b('0x6f')]);_0x20979b[_0x074b('0x57')]=qs[_0x074b('0x4e')](_['pick'](_0x23f35e[_0x074b('0x4c')],_0x59121e[_0x074b('0x4e')]));if(_0x23f35e[_0x074b('0x4c')]['filter']){_0x20979b[_0x074b('0x57')]=_['merge'](_0x20979b[_0x074b('0x57')],{'$or':_[_0x074b('0x45')](_0x20979b[_0x074b('0x50')],function(_0x45d29d){var _0x36db23={};_0x36db23[_0x45d29d]={'$like':'%'+_0x23f35e['query'][_0x074b('0x56')]+'%'};return _0x36db23;})});}_0x20979b=_[_0x074b('0x58')]({},_0x20979b,_0x23f35e['options']);return _0x113526['getAgents'](_0x20979b);}})['then'](function(_0x264328){if(_0x264328){_0x517f7a=_0x264328['length'];if(!_0x23f35e[_0x074b('0x4c')]['hasOwnProperty'](_0x074b('0x53'))){_0x20979b[_0x074b('0x31')]=qs[_0x074b('0x31')](_0x23f35e[_0x074b('0x4c')][_0x074b('0x31')]);_0x20979b[_0x074b('0x34')]=qs['offset'](_0x23f35e['query']['offset']);}return _0x113526[_0x074b('0xc8')](_0x20979b);}})['then'](function(_0x446abd){if(_0x446abd){return _0x446abd?{'count':_0x517f7a,'rows':_0x446abd}:null;}})[_0x074b('0x39')](respondWithResult(_0x4ac359,null))[_0x074b('0x5f')](handleError(_0x4ac359,null));};