7976eb8ae415b55ec6e477bb9fb5361277212909
[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 _0xea29=['FaxAccountId','Disposition','getDispositions','findOne','hasOwnProperty','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','addInteraction','FaxInteraction','omit','User','Owner','fullname','internal','Tag','Tags','color','tag','addApplications','sequelize','Transaction','ISOLATION_LEVELS','READ_COMMITTED','bulkCreate','FaxApplication','priority','finally','getApplications','from-voip-provider','exten','localstationid','app','system','Fax\x20Extension','appdata','push','Answer','CDR(type)=inbound-fax','gateway','faxdetect','headerinfo','maxrate','minrate','modem','t38timeout','FAXOPT(','Set','Wait','/var/opt/motion2/server/files/attachments/fax-${CALLERID(num)}-${CUT(UNIQUEID,.,1)}-${CUT(UNIQUEID,.,2)}-${STRFTIME(,,%C%y%m%d%H%M%S)}-rx.tif,d','ReceiveFax','addAccountApplications','VoiceExtension','updateAccountApplications','TrunkId','getMessages','$gte','format','YYYY-MM-DD\x20HH:mm:ss','FaxMessage','CmList','List','Contacts','attachments','join','root','basename','CheckAfterSend','isNil','path','from','\x22%s\x22\x20<%s>','fax','CmContact','ListId','List\x20not\x20found','Send\x20Fax\x20failed','out','Messages','Contact\x20not\x20found','spread','filename','dataValues','SendFax','SendFaxRpc,\x20%s','addAgents','userFaxAccount:save','removeAgents','emit','getAgents','eml-format','rimraf','zip-dir','request-promise','bluebird','mustache','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','./faxAccount.socket','register','jayson/promise','http','client','request','info','FaxAccount,\x20%s,\x20%s','request\x20sent','FaxAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','status','end','json','offset','undefined','limit','count','set','apply','reject','save','update','then','destroy','FaxAccounts','UserProfileResource','sendStatus','stack','name','send','index','Pause','mandatoryDispositionPause','FaxAccount','fieldName','key','map','query','model','attributes','intersection','fields','length','nolimit','order','sort','where','filters','pick','merge','filter','options','includeAll','include','findAll','rows','show','params','rawAttributes','keys','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','get','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition'];(function(_0x1ce979,_0x1dc8aa){var _0x5cd3f1=function(_0xcf768){while(--_0xcf768){_0x1ce979['push'](_0x1ce979['shift']());}};_0x5cd3f1(++_0x1dc8aa);}(_0xea29,0x1ed));var _0x9ea2=function(_0x494368,_0x56d9a3){_0x494368=_0x494368-0x0;var _0x1491a3=_0xea29[_0x494368];return _0x1491a3;};'use strict';var emlformat=require(_0x9ea2('0x0'));var rimraf=require(_0x9ea2('0x1'));var zipdir=require(_0x9ea2('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x9ea2('0x3'));var moment=require('moment');var BPromise=require(_0x9ea2('0x4'));var Mustache=require(_0x9ea2('0x5'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require(_0x9ea2('0x6'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x9ea2('0x7'));var _=require(_0x9ea2('0x8'));var squel=require(_0x9ea2('0x9'));var crypto=require(_0x9ea2('0xa'));var jsforce=require(_0x9ea2('0xb'));var deskjs=require(_0x9ea2('0xc'));var toCsv=require(_0x9ea2('0x6'));var querystring=require(_0x9ea2('0xd'));var Papa=require(_0x9ea2('0xe'));var Redis=require(_0x9ea2('0xf'));var authService=require(_0x9ea2('0x10'));var qs=require(_0x9ea2('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x9ea2('0x12'));var logger=require(_0x9ea2('0x13'))(_0x9ea2('0x14'));var utils=require(_0x9ea2('0x15'));var config=require(_0x9ea2('0x16'));var licenseUtil=require(_0x9ea2('0x17'));var db=require(_0x9ea2('0x18'))['db'];config[_0x9ea2('0x19')]=_[_0x9ea2('0x1a')](config['redis'],{'host':_0x9ea2('0x1b'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x9ea2('0x19')]));require(_0x9ea2('0x1c'))[_0x9ea2('0x1d')](socket);var jayson=require(_0x9ea2('0x1e'));var client=jayson['client'][_0x9ea2('0x1f')]({'port':0x232c});var client9002=jayson[_0x9ea2('0x20')][_0x9ea2('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x366766,_0x15ca6a,_0x2dca0b,_0x172489){return new BPromise(function(_0x3cdf7c,_0x3b6fd4){var _0x49487a=_0x172489||client;return _0x49487a[_0x9ea2('0x21')](_0x366766,_0x2dca0b)['then'](function(_0x56515a){logger[_0x9ea2('0x22')](_0x9ea2('0x23'),_0x15ca6a,_0x9ea2('0x24'));logger['debug'](_0x9ea2('0x25'),_0x15ca6a,_0x9ea2('0x24'),JSON[_0x9ea2('0x26')](_0x56515a));if(_0x56515a[_0x9ea2('0x27')]){if(_0x56515a['error'][_0x9ea2('0x28')]===0x1f4){logger[_0x9ea2('0x27')](_0x9ea2('0x23'),_0x15ca6a,_0x56515a[_0x9ea2('0x27')][_0x9ea2('0x29')]);return _0x3b6fd4(_0x56515a['error'][_0x9ea2('0x29')]);}logger['error'](_0x9ea2('0x23'),_0x15ca6a,_0x56515a['error'][_0x9ea2('0x29')]);return _0x3cdf7c(_0x56515a[_0x9ea2('0x27')][_0x9ea2('0x29')]);}else{logger['info'](_0x9ea2('0x23'),_0x15ca6a,_0x9ea2('0x24'));_0x3cdf7c(_0x56515a[_0x9ea2('0x2a')]['message']);}})[_0x9ea2('0x2b')](function(_0x3265ff){logger[_0x9ea2('0x27')](_0x9ea2('0x23'),_0x15ca6a,_0x3265ff);_0x3b6fd4(_0x3265ff);});});}function respondWithStatusCode(_0x425768,_0x4f57ca){_0x4f57ca=_0x4f57ca||0xcc;return function(_0x5875c8){if(_0x5875c8){return _0x425768['sendStatus'](_0x4f57ca);}return _0x425768[_0x9ea2('0x2c')](_0x4f57ca)[_0x9ea2('0x2d')]();};}function respondWithResult(_0x49f22c,_0x36576e){_0x36576e=_0x36576e||0xc8;return function(_0xfcb9f0){if(_0xfcb9f0){return _0x49f22c[_0x9ea2('0x2c')](_0x36576e)[_0x9ea2('0x2e')](_0xfcb9f0);}};}function respondWithFilteredResult(_0x22fc3d,_0x2a38ae){return function(_0x1a69b3){if(_0x1a69b3){var _0x5dc8e7=typeof _0x2a38ae[_0x9ea2('0x2f')]===_0x9ea2('0x30')&&typeof _0x2a38ae[_0x9ea2('0x31')]===_0x9ea2('0x30');var _0x198223=_0x1a69b3[_0x9ea2('0x32')];var _0x27b96f=_0x5dc8e7?0x0:_0x2a38ae[_0x9ea2('0x2f')];var _0x526e18=_0x5dc8e7?_0x1a69b3[_0x9ea2('0x32')]:_0x2a38ae[_0x9ea2('0x2f')]+_0x2a38ae[_0x9ea2('0x31')];var _0x3b8c28;if(_0x526e18>=_0x198223){_0x526e18=_0x198223;_0x3b8c28=0xc8;}else{_0x3b8c28=0xce;}_0x22fc3d[_0x9ea2('0x2c')](_0x3b8c28);return _0x22fc3d[_0x9ea2('0x33')]('Content-Range',_0x27b96f+'-'+_0x526e18+'/'+_0x198223)[_0x9ea2('0x2e')](_0x1a69b3);}return null;};}function patchUpdates(_0x1e2b3b){return function(_0x12e453){try{jsonpatch[_0x9ea2('0x34')](_0x12e453,_0x1e2b3b,!![]);}catch(_0x4926db){return BPromise[_0x9ea2('0x35')](_0x4926db);}return _0x12e453[_0x9ea2('0x36')]();};}function saveUpdates(_0x52ffa1,_0x38cf07){return function(_0x3d9d4a){if(_0x3d9d4a){return _0x3d9d4a[_0x9ea2('0x37')](_0x52ffa1)[_0x9ea2('0x38')](function(_0x3d9098){return _0x3d9098;});}return null;};}function removeEntity(_0x2e21f3,_0x5e34de){return function(_0x432651){if(_0x432651){return _0x432651[_0x9ea2('0x39')]()[_0x9ea2('0x38')](function(){var _0x4d04ae=_0x432651['get']({'plain':!![]});var _0x2daeb3=_0x9ea2('0x3a');return db[_0x9ea2('0x3b')]['destroy']({'where':{'type':_0x2daeb3,'resourceId':_0x4d04ae['id']}})[_0x9ea2('0x38')](function(){return _0x432651;});})[_0x9ea2('0x38')](function(){_0x2e21f3[_0x9ea2('0x2c')](0xcc)[_0x9ea2('0x2d')]();});}};}function handleEntityNotFound(_0x48fc8b,_0x2489da){return function(_0x2733d2){if(!_0x2733d2){_0x48fc8b[_0x9ea2('0x3c')](0x194);}return _0x2733d2;};}function handleError(_0xfa8d7,_0x14a5eb){_0x14a5eb=_0x14a5eb||0x1f4;return function(_0xede113){logger[_0x9ea2('0x27')](_0xede113[_0x9ea2('0x3d')]);if(_0xede113[_0x9ea2('0x3e')]){delete _0xede113[_0x9ea2('0x3e')];}_0xfa8d7[_0x9ea2('0x2c')](_0x14a5eb)[_0x9ea2('0x3f')](_0xede113);};}exports[_0x9ea2('0x40')]=function(_0x328436,_0x3ea8e4){var _0x1cf82c={'include':[{'model':db[_0x9ea2('0x41')],'as':_0x9ea2('0x42')}]},_0x49481c={},_0x1f2f70={'count':0x0,'rows':[]};var _0x1762e1=_['map'](db[_0x9ea2('0x43')]['rawAttributes'],function(_0x413667){return{'name':_0x413667[_0x9ea2('0x44')],'type':_0x413667['type'][_0x9ea2('0x45')]};});_0x49481c['model']=_[_0x9ea2('0x46')](_0x1762e1,_0x9ea2('0x3e'));_0x49481c['query']=_['keys'](_0x328436[_0x9ea2('0x47')]);_0x49481c['filters']=_['intersection'](_0x49481c[_0x9ea2('0x48')],_0x49481c[_0x9ea2('0x47')]);_0x1cf82c[_0x9ea2('0x49')]=_[_0x9ea2('0x4a')](_0x49481c[_0x9ea2('0x48')],qs[_0x9ea2('0x4b')](_0x328436['query']['fields']));_0x1cf82c['attributes']=_0x1cf82c[_0x9ea2('0x49')][_0x9ea2('0x4c')]?_0x1cf82c[_0x9ea2('0x49')]:_0x49481c[_0x9ea2('0x48')];if(!_0x328436[_0x9ea2('0x47')]['hasOwnProperty'](_0x9ea2('0x4d'))){_0x1cf82c['limit']=qs[_0x9ea2('0x31')](_0x328436[_0x9ea2('0x47')][_0x9ea2('0x31')]);_0x1cf82c[_0x9ea2('0x2f')]=qs['offset'](_0x328436[_0x9ea2('0x47')][_0x9ea2('0x2f')]);}_0x1cf82c[_0x9ea2('0x4e')]=qs[_0x9ea2('0x4f')](_0x328436[_0x9ea2('0x47')][_0x9ea2('0x4f')]);_0x1cf82c[_0x9ea2('0x50')]=qs[_0x9ea2('0x51')](_[_0x9ea2('0x52')](_0x328436['query'],_0x49481c[_0x9ea2('0x51')]),_0x1762e1);if(_0x328436[_0x9ea2('0x47')]['filter']){_0x1cf82c[_0x9ea2('0x50')]=_[_0x9ea2('0x53')](_0x1cf82c[_0x9ea2('0x50')],{'$or':_[_0x9ea2('0x46')](_0x1762e1,function(_0x282e62){if(_0x282e62['type']!=='VIRTUAL'){var _0xf548fa={};_0xf548fa[_0x282e62[_0x9ea2('0x3e')]]={'$like':'%'+_0x328436[_0x9ea2('0x47')][_0x9ea2('0x54')]+'%'};return _0xf548fa;}})});}_0x1cf82c=_['merge']({},_0x1cf82c,_0x328436[_0x9ea2('0x55')]);var _0x40fbf8={'where':_0x1cf82c[_0x9ea2('0x50')]};return db['FaxAccount'][_0x9ea2('0x32')](_0x40fbf8)[_0x9ea2('0x38')](function(_0x5e03d7){_0x1f2f70[_0x9ea2('0x32')]=_0x5e03d7;if(_0x328436['query'][_0x9ea2('0x56')]){_0x1cf82c[_0x9ea2('0x57')]=[{'all':!![]}];}return db[_0x9ea2('0x43')][_0x9ea2('0x58')](_0x1cf82c);})[_0x9ea2('0x38')](function(_0xa3879f){_0x1f2f70[_0x9ea2('0x59')]=_0xa3879f;return _0x1f2f70;})['then'](respondWithFilteredResult(_0x3ea8e4,_0x1cf82c))[_0x9ea2('0x2b')](handleError(_0x3ea8e4,null));};exports[_0x9ea2('0x5a')]=function(_0x3aa84f,_0x304177){var _0x5f8b9c={'raw':![],'where':{'id':_0x3aa84f[_0x9ea2('0x5b')]['id']},'include':[{'model':db[_0x9ea2('0x41')],'as':_0x9ea2('0x42')}]},_0x26f465={};_0x26f465[_0x9ea2('0x48')]=_['keys'](db['FaxAccount'][_0x9ea2('0x5c')]);_0x26f465[_0x9ea2('0x47')]=_[_0x9ea2('0x5d')](_0x3aa84f[_0x9ea2('0x47')]);_0x26f465['filters']=_['intersection'](_0x26f465[_0x9ea2('0x48')],_0x26f465[_0x9ea2('0x47')]);_0x5f8b9c[_0x9ea2('0x49')]=_['intersection'](_0x26f465['model'],qs[_0x9ea2('0x4b')](_0x3aa84f['query'][_0x9ea2('0x4b')]));_0x5f8b9c[_0x9ea2('0x49')]=_0x5f8b9c[_0x9ea2('0x49')][_0x9ea2('0x4c')]?_0x5f8b9c[_0x9ea2('0x49')]:_0x26f465['model'];if(_0x3aa84f[_0x9ea2('0x47')][_0x9ea2('0x56')]){_0x5f8b9c[_0x9ea2('0x57')]=[{'all':!![]}];}_0x5f8b9c=_[_0x9ea2('0x53')]({},_0x5f8b9c,_0x3aa84f[_0x9ea2('0x55')]);return db['FaxAccount'][_0x9ea2('0x5e')](_0x5f8b9c)[_0x9ea2('0x38')](handleEntityNotFound(_0x304177,null))[_0x9ea2('0x38')](respondWithResult(_0x304177,null))[_0x9ea2('0x2b')](handleError(_0x304177,null));};exports[_0x9ea2('0x5f')]=function(_0x140112,_0x2961a2){return db[_0x9ea2('0x43')]['create'](_0x140112[_0x9ea2('0x60')],{})[_0x9ea2('0x38')](function(_0x10d6c4){var _0x56adee=_0x140112[_0x9ea2('0x61')]['get']({'plain':!![]});if(!_0x56adee)throw new Error(_0x9ea2('0x62'));if(_0x56adee[_0x9ea2('0x63')]===_0x9ea2('0x61')){var _0x54a2fc=_0x10d6c4[_0x9ea2('0x64')]({'plain':!![]});var _0x47fc2a=_0x9ea2('0x3a');return db[_0x9ea2('0x65')][_0x9ea2('0x5e')]({'where':{'name':_0x47fc2a,'userProfileId':_0x56adee[_0x9ea2('0x66')]},'raw':!![]})[_0x9ea2('0x38')](function(_0x43a305){if(_0x43a305&&_0x43a305[_0x9ea2('0x67')]===0x0){return db[_0x9ea2('0x3b')][_0x9ea2('0x5f')]({'name':_0x54a2fc['name'],'resourceId':_0x54a2fc['id'],'type':_0x43a305['name'],'sectionId':_0x43a305['id']},{})['then'](function(){return _0x10d6c4;});}else{return _0x10d6c4;}})[_0x9ea2('0x2b')](function(_0x5df2ed){logger[_0x9ea2('0x27')](_0x9ea2('0x68'),_0x5df2ed);throw _0x5df2ed;});}return _0x10d6c4;})[_0x9ea2('0x38')](respondWithResult(_0x2961a2,0xc9))[_0x9ea2('0x2b')](handleError(_0x2961a2,null));};exports[_0x9ea2('0x37')]=function(_0x52d1b7,_0x414f54){if(_0x52d1b7[_0x9ea2('0x60')]['id']){delete _0x52d1b7[_0x9ea2('0x60')]['id'];}return db[_0x9ea2('0x43')][_0x9ea2('0x5e')]({'where':{'id':_0x52d1b7[_0x9ea2('0x5b')]['id']},'include':[{'model':db[_0x9ea2('0x41')],'as':_0x9ea2('0x42')}]})[_0x9ea2('0x38')](handleEntityNotFound(_0x414f54,null))[_0x9ea2('0x38')](saveUpdates(_0x52d1b7[_0x9ea2('0x60')],null))[_0x9ea2('0x38')](respondWithResult(_0x414f54,null))[_0x9ea2('0x2b')](handleError(_0x414f54,null));};exports[_0x9ea2('0x39')]=function(_0x20e2a6,_0x55c73c){return db['FaxAccount'][_0x9ea2('0x5e')]({'where':{'id':_0x20e2a6[_0x9ea2('0x5b')]['id']}})[_0x9ea2('0x38')](handleEntityNotFound(_0x55c73c,null))[_0x9ea2('0x38')](removeEntity(_0x55c73c,null))['catch'](handleError(_0x55c73c,null));};exports[_0x9ea2('0x69')]=function(_0x284c35,_0x57d482){return db[_0x9ea2('0x43')][_0x9ea2('0x69')]()[_0x9ea2('0x38')](respondWithResult(_0x57d482,null))[_0x9ea2('0x2b')](handleError(_0x57d482,null));};exports[_0x9ea2('0x6a')]=function(_0x5ce0c6,_0x5a3c26,_0x312579){if(_0x5ce0c6[_0x9ea2('0x60')]['id']){delete _0x5ce0c6[_0x9ea2('0x60')]['id'];}return db[_0x9ea2('0x43')][_0x9ea2('0x5e')]({'where':{'id':_0x5ce0c6['params']['id']}})[_0x9ea2('0x38')](handleEntityNotFound(_0x5a3c26,null))[_0x9ea2('0x38')](function(_0x1c229c){if(_0x1c229c){_0x5ce0c6[_0x9ea2('0x60')][_0x9ea2('0x6b')]=_0x1c229c['id'];return db[_0x9ea2('0x6c')]['create'](_0x5ce0c6['body']);}})[_0x9ea2('0x38')](respondWithResult(_0x5a3c26,null))[_0x9ea2('0x2b')](handleError(_0x5a3c26,null));};exports[_0x9ea2('0x6d')]=function(_0x200d59,_0x2ae061,_0x4a7c75){var _0x3333b9={'raw':![],'where':{}};var _0x2039ba={};var _0x24f517={'count':0x0,'rows':[]};return db[_0x9ea2('0x43')][_0x9ea2('0x6e')]({'where':{'id':_0x200d59[_0x9ea2('0x5b')]['id']}})['then'](handleEntityNotFound(_0x2ae061,null))[_0x9ea2('0x38')](function(_0x2c6696){if(_0x2c6696){_0x2039ba[_0x9ea2('0x48')]=_[_0x9ea2('0x5d')](db[_0x9ea2('0x6c')]['rawAttributes']);_0x2039ba[_0x9ea2('0x47')]=_[_0x9ea2('0x5d')](_0x200d59[_0x9ea2('0x47')]);_0x2039ba[_0x9ea2('0x51')]=_[_0x9ea2('0x4a')](_0x2039ba[_0x9ea2('0x48')],_0x2039ba[_0x9ea2('0x47')]);_0x3333b9[_0x9ea2('0x49')]=_[_0x9ea2('0x4a')](_0x2039ba[_0x9ea2('0x48')],qs[_0x9ea2('0x4b')](_0x200d59['query'][_0x9ea2('0x4b')]));_0x3333b9['attributes']=_0x3333b9['attributes']['length']?_0x3333b9[_0x9ea2('0x49')]:_0x2039ba[_0x9ea2('0x48')];if(!_0x200d59['query'][_0x9ea2('0x6f')](_0x9ea2('0x4d'))){_0x3333b9[_0x9ea2('0x31')]=qs[_0x9ea2('0x31')](_0x200d59['query'][_0x9ea2('0x31')]);_0x3333b9['offset']=qs[_0x9ea2('0x2f')](_0x200d59[_0x9ea2('0x47')][_0x9ea2('0x2f')]);}_0x3333b9['order']=qs[_0x9ea2('0x4f')](_0x200d59[_0x9ea2('0x47')][_0x9ea2('0x4f')]);_0x3333b9[_0x9ea2('0x50')]=qs[_0x9ea2('0x51')](_[_0x9ea2('0x52')](_0x200d59[_0x9ea2('0x47')],_0x2039ba[_0x9ea2('0x51')]));_0x3333b9[_0x9ea2('0x50')]['FaxAccountId']=_0x2c6696['id'];if(_0x200d59[_0x9ea2('0x47')][_0x9ea2('0x54')]){_0x3333b9[_0x9ea2('0x50')]=_['merge'](_0x3333b9[_0x9ea2('0x50')],{'$or':_[_0x9ea2('0x46')](_0x3333b9[_0x9ea2('0x49')],function(_0x285cc6){var _0x1f9955={};_0x1f9955[_0x285cc6]={'$like':'%'+_0x200d59[_0x9ea2('0x47')]['filter']+'%'};return _0x1f9955;})});}_0x3333b9=_[_0x9ea2('0x53')]({},_0x3333b9,_0x200d59['options']);return db['Disposition'][_0x9ea2('0x32')]({'where':_0x3333b9['where']})[_0x9ea2('0x38')](function(_0x2e926e){_0x24f517[_0x9ea2('0x32')]=_0x2e926e;if(_0x200d59[_0x9ea2('0x47')]['includeAll']){_0x3333b9['include']=[{'all':!![]}];}return db[_0x9ea2('0x6c')][_0x9ea2('0x58')](_0x3333b9);})[_0x9ea2('0x38')](function(_0x5d4b28){_0x24f517[_0x9ea2('0x59')]=_0x5d4b28;return _0x24f517;});}})[_0x9ea2('0x38')](respondWithFilteredResult(_0x2ae061,_0x3333b9))[_0x9ea2('0x2b')](handleError(_0x2ae061,null));};exports[_0x9ea2('0x70')]=function(_0x1346c2,_0x2b92f2,_0x22148d){return db[_0x9ea2('0x43')][_0x9ea2('0x5e')]({'where':{'id':_0x1346c2[_0x9ea2('0x5b')]['id']}})[_0x9ea2('0x38')](handleEntityNotFound(_0x2b92f2,null))[_0x9ea2('0x38')](function(_0xde7b46){if(_0xde7b46){return _0xde7b46[_0x9ea2('0x70')](_0x1346c2[_0x9ea2('0x47')][_0x9ea2('0x71')]);}})['then'](respondWithStatusCode(_0x2b92f2,null))[_0x9ea2('0x2b')](handleError(_0x2b92f2,null));};exports[_0x9ea2('0x72')]=function(_0x18540d,_0x5643e1,_0x3b880e){if(_0x18540d[_0x9ea2('0x60')]['id']){delete _0x18540d[_0x9ea2('0x60')]['id'];}return db['FaxAccount'][_0x9ea2('0x5e')]({'where':{'id':_0x18540d[_0x9ea2('0x5b')]['id']}})[_0x9ea2('0x38')](handleEntityNotFound(_0x5643e1,null))[_0x9ea2('0x38')](function(_0x5c80a4){if(_0x5c80a4){_0x18540d['body'][_0x9ea2('0x6b')]=_0x5c80a4['id'];return db[_0x9ea2('0x73')]['create'](_0x18540d[_0x9ea2('0x60')]);}})[_0x9ea2('0x38')](respondWithResult(_0x5643e1,null))[_0x9ea2('0x2b')](handleError(_0x5643e1,null));};exports[_0x9ea2('0x74')]=function(_0x7bdbb5,_0x3c2cff,_0x44b2b0){var _0x12fae4={'raw':![],'where':{}};var _0x4e3cf2={};var _0x6ec025={'count':0x0,'rows':[]};return db[_0x9ea2('0x43')]['findOne']({'where':{'id':_0x7bdbb5['params']['id']}})['then'](handleEntityNotFound(_0x3c2cff,null))[_0x9ea2('0x38')](function(_0x49aae5){if(_0x49aae5){_0x4e3cf2[_0x9ea2('0x48')]=_[_0x9ea2('0x5d')](db['CannedAnswer']['rawAttributes']);_0x4e3cf2[_0x9ea2('0x47')]=_[_0x9ea2('0x5d')](_0x7bdbb5[_0x9ea2('0x47')]);_0x4e3cf2[_0x9ea2('0x51')]=_['intersection'](_0x4e3cf2[_0x9ea2('0x48')],_0x4e3cf2[_0x9ea2('0x47')]);_0x12fae4[_0x9ea2('0x49')]=_[_0x9ea2('0x4a')](_0x4e3cf2['model'],qs[_0x9ea2('0x4b')](_0x7bdbb5[_0x9ea2('0x47')][_0x9ea2('0x4b')]));_0x12fae4[_0x9ea2('0x49')]=_0x12fae4[_0x9ea2('0x49')][_0x9ea2('0x4c')]?_0x12fae4['attributes']:_0x4e3cf2[_0x9ea2('0x48')];if(!_0x7bdbb5['query'][_0x9ea2('0x6f')](_0x9ea2('0x4d'))){_0x12fae4['limit']=qs['limit'](_0x7bdbb5['query']['limit']);_0x12fae4[_0x9ea2('0x2f')]=qs[_0x9ea2('0x2f')](_0x7bdbb5[_0x9ea2('0x47')][_0x9ea2('0x2f')]);}_0x12fae4[_0x9ea2('0x4e')]=qs[_0x9ea2('0x4f')](_0x7bdbb5[_0x9ea2('0x47')][_0x9ea2('0x4f')]);_0x12fae4[_0x9ea2('0x50')]=qs[_0x9ea2('0x51')](_[_0x9ea2('0x52')](_0x7bdbb5[_0x9ea2('0x47')],_0x4e3cf2[_0x9ea2('0x51')]));_0x12fae4[_0x9ea2('0x50')][_0x9ea2('0x6b')]=_0x49aae5['id'];if(_0x7bdbb5[_0x9ea2('0x47')][_0x9ea2('0x54')]){_0x12fae4[_0x9ea2('0x50')]=_[_0x9ea2('0x53')](_0x12fae4[_0x9ea2('0x50')],{'$or':_['map'](_0x12fae4[_0x9ea2('0x49')],function(_0x1a52a3){var _0x5cf0c3={};_0x5cf0c3[_0x1a52a3]={'$like':'%'+_0x7bdbb5['query'][_0x9ea2('0x54')]+'%'};return _0x5cf0c3;})});}_0x12fae4=_[_0x9ea2('0x53')]({},_0x12fae4,_0x7bdbb5[_0x9ea2('0x55')]);return db[_0x9ea2('0x73')][_0x9ea2('0x32')]({'where':_0x12fae4[_0x9ea2('0x50')]})['then'](function(_0x574a10){_0x6ec025[_0x9ea2('0x32')]=_0x574a10;if(_0x7bdbb5[_0x9ea2('0x47')]['includeAll']){_0x12fae4[_0x9ea2('0x57')]=[{'all':!![]}];}return db[_0x9ea2('0x73')][_0x9ea2('0x58')](_0x12fae4);})[_0x9ea2('0x38')](function(_0x49f965){_0x6ec025[_0x9ea2('0x59')]=_0x49f965;return _0x6ec025;});}})[_0x9ea2('0x38')](respondWithFilteredResult(_0x3c2cff,_0x12fae4))['catch'](handleError(_0x3c2cff,null));};exports['removeAnswers']=function(_0x3aedbb,_0x1b3904,_0x12575f){return db[_0x9ea2('0x43')]['find']({'where':{'id':_0x3aedbb['params']['id']}})[_0x9ea2('0x38')](handleEntityNotFound(_0x1b3904,null))[_0x9ea2('0x38')](function(_0x557704){if(_0x557704){return _0x557704[_0x9ea2('0x75')](_0x3aedbb['query'][_0x9ea2('0x71')]);}})[_0x9ea2('0x38')](respondWithStatusCode(_0x1b3904,null))['catch'](handleError(_0x1b3904,null));};exports[_0x9ea2('0x76')]=function(_0x3beb42,_0x22ebe6,_0x1a9f44){return db[_0x9ea2('0x77')][_0x9ea2('0x5e')]({'where':{'id':_0x3beb42[_0x9ea2('0x5b')]['id']}})['then'](handleEntityNotFound(_0x22ebe6,null))[_0x9ea2('0x38')](function(_0x309094){if(_0x309094){return _0x309094[_0x9ea2('0x76')](_0x3beb42['body'][_0x9ea2('0x71')],_[_0x9ea2('0x78')](_0x3beb42[_0x9ea2('0x60')],[_0x9ea2('0x71'),'id'])||{});}})[_0x9ea2('0x38')](respondWithResult(_0x22ebe6,null))[_0x9ea2('0x2b')](handleError(_0x22ebe6,null));};exports['getInteractions']=function(_0x3ef466,_0x99304c,_0x2eaff5){var _0x29f947={'raw':![],'where':{}};var _0x27ba65={};var _0x3675aa={'count':0x0,'rows':[]};return db[_0x9ea2('0x43')][_0x9ea2('0x6e')]({'where':{'id':_0x3ef466['params']['id']}})['then'](handleEntityNotFound(_0x99304c,null))[_0x9ea2('0x38')](function(_0x486b9c){if(_0x486b9c){_0x27ba65[_0x9ea2('0x48')]=_[_0x9ea2('0x5d')](db[_0x9ea2('0x77')][_0x9ea2('0x5c')]);_0x27ba65[_0x9ea2('0x47')]=_[_0x9ea2('0x5d')](_0x3ef466[_0x9ea2('0x47')]);_0x27ba65[_0x9ea2('0x51')]=_[_0x9ea2('0x4a')](_0x27ba65[_0x9ea2('0x48')],_0x27ba65['query']);_0x29f947['attributes']=_[_0x9ea2('0x4a')](_0x27ba65[_0x9ea2('0x48')],qs[_0x9ea2('0x4b')](_0x3ef466[_0x9ea2('0x47')]['fields']));_0x29f947[_0x9ea2('0x49')]=_0x29f947[_0x9ea2('0x49')][_0x9ea2('0x4c')]?_0x29f947[_0x9ea2('0x49')]:_0x27ba65['model'];if(!_0x3ef466[_0x9ea2('0x47')][_0x9ea2('0x6f')]('nolimit')){_0x29f947[_0x9ea2('0x31')]=qs[_0x9ea2('0x31')](_0x3ef466[_0x9ea2('0x47')][_0x9ea2('0x31')]);_0x29f947['offset']=qs[_0x9ea2('0x2f')](_0x3ef466[_0x9ea2('0x47')]['offset']);}_0x29f947[_0x9ea2('0x4e')]=qs[_0x9ea2('0x4f')](_0x3ef466[_0x9ea2('0x47')][_0x9ea2('0x4f')]);_0x29f947[_0x9ea2('0x50')]=qs['filters'](_['pick'](_0x3ef466[_0x9ea2('0x47')],_0x27ba65['filters']));_0x29f947[_0x9ea2('0x50')][_0x9ea2('0x6b')]=_0x486b9c['id'];if(_0x3ef466[_0x9ea2('0x47')][_0x9ea2('0x54')]){_0x29f947[_0x9ea2('0x50')]=_[_0x9ea2('0x53')](_0x29f947[_0x9ea2('0x50')],{'$or':_['map'](_0x29f947['attributes'],function(_0xf8c456){var _0x58977={};_0x58977[_0xf8c456]={'$like':'%'+_0x3ef466[_0x9ea2('0x47')][_0x9ea2('0x54')]+'%'};return _0x58977;})});}_0x29f947=_['merge']({},_0x29f947,_0x3ef466['options']);return db[_0x9ea2('0x77')][_0x9ea2('0x32')]({'where':_0x29f947[_0x9ea2('0x50')]})[_0x9ea2('0x38')](function(_0x3c0fd5){_0x3675aa[_0x9ea2('0x32')]=_0x3c0fd5;if(_0x3ef466[_0x9ea2('0x47')][_0x9ea2('0x56')]){_0x29f947[_0x9ea2('0x57')]=[{'model':db['CmContact'],'as':'Contact','required':![]},{'model':db[_0x9ea2('0x79')],'as':_0x9ea2('0x7a'),'attributes':['name',_0x9ea2('0x7b'),_0x9ea2('0x7c')],'required':![]},{'model':db[_0x9ea2('0x7d')],'as':_0x9ea2('0x7e'),'attributes':['id',_0x9ea2('0x3e'),_0x9ea2('0x7f')],'where':_0x3ef466[_0x9ea2('0x47')][_0x9ea2('0x80')]?{'id':_0x3ef466[_0x9ea2('0x47')]['tag']}:undefined,'required':_0x3ef466['query'][_0x9ea2('0x80')]?!![]:![]}];}return db[_0x9ea2('0x77')][_0x9ea2('0x58')](_0x29f947);})[_0x9ea2('0x38')](function(_0x25f297){_0x3675aa[_0x9ea2('0x59')]=_0x25f297;return _0x3675aa;});}})[_0x9ea2('0x38')](respondWithFilteredResult(_0x99304c,_0x29f947))[_0x9ea2('0x2b')](handleError(_0x99304c,null));};exports[_0x9ea2('0x81')]=function(_0x5e79f2,_0x3cb70e){var _0x205c7a=_0x5e79f2[_0x9ea2('0x5b')]['id'];var _0x55effb=_0x5e79f2[_0x9ea2('0x60')];var _0xf835c4=0xc8;var _0x22e671=null;return db[_0x9ea2('0x82')]['transaction']({'isolationLevel':db[_0x9ea2('0x82')][_0x9ea2('0x83')][_0x9ea2('0x84')][_0x9ea2('0x85')]},function(_0x1c1749){return db['FaxAccount']['findOne']({'where':{'id':_0x205c7a},'transaction':_0x1c1749})[_0x9ea2('0x38')](function(_0x483fed){if(_0x483fed){return db['FaxApplication'][_0x9ea2('0x39')]({'where':{'FaxAccountId':_0x205c7a},'transaction':_0x1c1749})[_0x9ea2('0x38')](function(){var _0x6197d4=_[_0x9ea2('0x46')](_0x55effb,function(_0xad8c78){_0xad8c78[_0x9ea2('0x6b')]=_0x205c7a;return _0xad8c78;});return db['FaxApplication'][_0x9ea2('0x86')](_0x6197d4,{'transaction':_0x1c1749});});}else{_0xf835c4=0x194;_0x22e671=[];}});})['then'](function(){if(_0xf835c4!==0x194){return db[_0x9ea2('0x87')]['findAndCountAll']({'where':{'FaxAccountId':_0x205c7a},'order':_0x9ea2('0x88')})['then'](function(_0x14bd59){_0x22e671=_0x14bd59;});}})[_0x9ea2('0x2b')](function(_0x3ceeb6){_0xf835c4=0x1f4;logger[_0x9ea2('0x27')](_0x3ceeb6[_0x9ea2('0x3d')]);if(_0x3ceeb6['name']){delete _0x3ceeb6[_0x9ea2('0x3e')];}_0x22e671=_0x3ceeb6;})[_0x9ea2('0x89')](function(){if(_0x22e671===null){_0x3cb70e[_0x9ea2('0x3c')](_0xf835c4);}else{if(_0xf835c4===0x1f4){_0x3cb70e[_0x9ea2('0x2c')](_0xf835c4)[_0x9ea2('0x3f')](_0x22e671);}else{_0x3cb70e[_0x9ea2('0x2c')](_0xf835c4)['json'](_0x22e671);}}});};exports[_0x9ea2('0x8a')]=function(_0x1d924a,_0x76a550,_0x4fc877){var _0x3d25e9={};var _0x825188={};var _0x157be0;var _0x308768;return db['FaxAccount'][_0x9ea2('0x6e')]({'where':{'id':_0x1d924a['params']['id']}})[_0x9ea2('0x38')](handleEntityNotFound(_0x76a550,null))[_0x9ea2('0x38')](function(_0x52ca79){if(_0x52ca79){_0x157be0=_0x52ca79;_0x825188[_0x9ea2('0x48')]=_[_0x9ea2('0x5d')](db['FaxApplication'][_0x9ea2('0x5c')]);_0x825188[_0x9ea2('0x47')]=_['keys'](_0x1d924a[_0x9ea2('0x47')]);_0x825188['filters']=_[_0x9ea2('0x4a')](_0x825188[_0x9ea2('0x48')],_0x825188[_0x9ea2('0x47')]);_0x3d25e9[_0x9ea2('0x49')]=_[_0x9ea2('0x4a')](_0x825188['model'],qs[_0x9ea2('0x4b')](_0x1d924a[_0x9ea2('0x47')]['fields']));_0x3d25e9[_0x9ea2('0x49')]=_0x3d25e9[_0x9ea2('0x49')]['length']?_0x3d25e9[_0x9ea2('0x49')]:_0x825188[_0x9ea2('0x48')];_0x3d25e9['order']=qs[_0x9ea2('0x4f')](_0x1d924a[_0x9ea2('0x47')][_0x9ea2('0x4f')]);_0x3d25e9[_0x9ea2('0x50')]=qs[_0x9ea2('0x51')](_[_0x9ea2('0x52')](_0x1d924a[_0x9ea2('0x47')],_0x825188[_0x9ea2('0x51')]));if(_0x1d924a[_0x9ea2('0x47')]['filter']){_0x3d25e9[_0x9ea2('0x50')]=_[_0x9ea2('0x53')](_0x3d25e9['where'],{'$or':_[_0x9ea2('0x46')](_0x3d25e9[_0x9ea2('0x49')],function(_0x2e8acb){var _0x257acb={};_0x257acb[_0x2e8acb]={'$like':'%'+_0x1d924a[_0x9ea2('0x47')][_0x9ea2('0x54')]+'%'};return _0x257acb;})});}_0x3d25e9=_[_0x9ea2('0x53')]({},_0x3d25e9,_0x1d924a[_0x9ea2('0x55')]);return _0x157be0[_0x9ea2('0x8a')](_0x3d25e9);}})[_0x9ea2('0x38')](function(_0x3cab2c){if(_0x3cab2c){_0x308768=_0x3cab2c[_0x9ea2('0x4c')];if(!_0x1d924a[_0x9ea2('0x47')]['hasOwnProperty'](_0x9ea2('0x4d'))){_0x3d25e9[_0x9ea2('0x31')]=qs['limit'](_0x1d924a['query'][_0x9ea2('0x31')]);_0x3d25e9[_0x9ea2('0x2f')]=qs[_0x9ea2('0x2f')](_0x1d924a[_0x9ea2('0x47')][_0x9ea2('0x2f')]);}return _0x157be0[_0x9ea2('0x8a')](_0x3d25e9);}})['then'](function(_0x382f11){if(_0x382f11){return _0x382f11?{'count':_0x308768,'rows':_0x382f11}:null;}})['then'](respondWithResult(_0x76a550,null))[_0x9ea2('0x2b')](handleError(_0x76a550,null));};function Extension(_0x5a733d,_0x374fd2,_0x2f5c60,_0x4f3301){this['context']=_0x9ea2('0x8b');this[_0x9ea2('0x8c')]=_0x5a733d[_0x9ea2('0x8d')];this[_0x9ea2('0x8e')]=_0x4f3301;this['type']=_0x9ea2('0x8f');this['description']=_0x9ea2('0x90');this[_0x9ea2('0x6b')]=_0x5a733d['id'];this[_0x9ea2('0x88')]=_0x374fd2;this[_0x9ea2('0x91')]=_0x2f5c60;}function createExtensionsReciveFax(_0x38f74f){var _0x13fd84=0x1;var _0x34e4a4=[];_0x34e4a4[_0x9ea2('0x92')](new Extension(_0x38f74f,_0x13fd84,'',_0x9ea2('0x93')));_0x13fd84+=0x1;_0x34e4a4[_0x9ea2('0x92')](new Extension(_0x38f74f,_0x13fd84,_0x9ea2('0x94'),'Set'));_0x13fd84+=0x1;for(var _0x2eeab4 in _0x38f74f){if(_0x38f74f[_0x9ea2('0x6f')](_0x2eeab4)&&(_0x2eeab4==='ecm'||_0x2eeab4===_0x9ea2('0x8d')||_0x2eeab4===_0x9ea2('0x95')||_0x2eeab4===_0x9ea2('0x96')||_0x2eeab4===_0x9ea2('0x97')||_0x2eeab4===_0x9ea2('0x98')||_0x2eeab4===_0x9ea2('0x99')||_0x2eeab4===_0x9ea2('0x9a')||_0x2eeab4===_0x9ea2('0x9b'))){_0x34e4a4[_0x9ea2('0x92')](new Extension(_0x38f74f,_0x13fd84,_0x9ea2('0x9c')+_0x2eeab4+')='+_0x38f74f[_0x2eeab4],_0x9ea2('0x9d')));_0x13fd84+=0x1;}}_0x34e4a4[_0x9ea2('0x92')](new Extension(_0x38f74f,_0x13fd84,'6',_0x9ea2('0x9e')));_0x13fd84+=0x1;_0x34e4a4[_0x9ea2('0x92')](new Extension(_0x38f74f,_0x13fd84,_0x9ea2('0x9f'),_0x9ea2('0xa0')));_0x13fd84=0x0;return _0x34e4a4;}exports[_0x9ea2('0xa1')]=function(_0x14ba7a,_0x47ff6b,_0x2701c3){var _0x4d5318;return db[_0x9ea2('0x82')]['transaction'](function(_0x2b92cf){return db[_0x9ea2('0x43')][_0x9ea2('0x5f')](_0x14ba7a[_0x9ea2('0x60')],{'transaction':_0x2b92cf})['then'](function(_0x4716f9){_0x4d5318=_0x4716f9[_0x9ea2('0x64')]({'plain':!![]});return db[_0x9ea2('0xa2')]['bulkCreate'](createExtensionsReciveFax(_0x4d5318),{'transaction':_0x2b92cf});});})[_0x9ea2('0x38')](function(){return _0x4d5318;})[_0x9ea2('0x38')](respondWithResult(_0x47ff6b,null))[_0x9ea2('0x2b')](handleError(_0x47ff6b,null));};exports[_0x9ea2('0xa3')]=function(_0xe5a30a,_0x30f8ea,_0x4b6396){var _0x2fa701;return db[_0x9ea2('0x82')]['transaction'](function(_0x1a8c7b){return db[_0x9ea2('0x43')][_0x9ea2('0x37')](_0xe5a30a['body'],{'where':{'id':_0xe5a30a[_0x9ea2('0x60')]['id']},'transaction':_0x1a8c7b})[_0x9ea2('0x38')](function(_0x1dc66a){return db[_0x9ea2('0xa2')][_0x9ea2('0x39')]({'where':{'FaxAccountId':_0xe5a30a['body']['id']},'transaction':_0x1a8c7b})['then'](function(_0x54c751){return db[_0x9ea2('0xa2')][_0x9ea2('0x86')](createExtensionsReciveFax(_[_0x9ea2('0x78')](_0xe5a30a['body'],['tech',_0x9ea2('0x45'),'createdAt','updatedAt',_0x9ea2('0xa4'),'ListId'])),{'transaction':_0x1a8c7b});});});})['then'](function(){return db[_0x9ea2('0x43')]['findById'](_0xe5a30a[_0x9ea2('0x60')]['id']);})['then'](respondWithResult(_0x30f8ea,null))['catch'](handleError(_0x30f8ea,null));};exports[_0x9ea2('0xa5')]=function(_0x38b89c,_0x51ea74,_0x2d7cfe){var _0x4dbab7={'raw':!![],'where':{}};var _0x496a5f={};var _0x33e1fe={'count':0x0,'rows':[]};return db[_0x9ea2('0x43')][_0x9ea2('0x6e')]({'where':{'id':_0x38b89c['params']['id']}})[_0x9ea2('0x38')](handleEntityNotFound(_0x51ea74,null))[_0x9ea2('0x38')](function(_0x57506a){if(_0x57506a){_0x496a5f[_0x9ea2('0x48')]=_[_0x9ea2('0x5d')](db['FaxMessage'][_0x9ea2('0x5c')]);_0x496a5f[_0x9ea2('0x47')]=_['keys'](_0x38b89c[_0x9ea2('0x47')]);_0x496a5f[_0x9ea2('0x51')]=_['intersection'](_0x496a5f['model'],_0x496a5f[_0x9ea2('0x47')]);_0x4dbab7[_0x9ea2('0x49')]=_[_0x9ea2('0x4a')](_0x496a5f[_0x9ea2('0x48')],qs[_0x9ea2('0x4b')](_0x38b89c[_0x9ea2('0x47')]['fields']));_0x4dbab7[_0x9ea2('0x49')]=_0x4dbab7[_0x9ea2('0x49')][_0x9ea2('0x4c')]?_0x4dbab7[_0x9ea2('0x49')]:_0x496a5f[_0x9ea2('0x48')];if(!_0x38b89c[_0x9ea2('0x47')][_0x9ea2('0x6f')](_0x9ea2('0x4d'))){_0x4dbab7[_0x9ea2('0x31')]=qs[_0x9ea2('0x31')](_0x38b89c[_0x9ea2('0x47')][_0x9ea2('0x31')]);_0x4dbab7[_0x9ea2('0x2f')]=qs[_0x9ea2('0x2f')](_0x38b89c[_0x9ea2('0x47')][_0x9ea2('0x2f')]);}_0x4dbab7[_0x9ea2('0x4e')]=qs['sort'](_0x38b89c[_0x9ea2('0x47')]['sort']);_0x4dbab7[_0x9ea2('0x50')]=qs['filters'](_[_0x9ea2('0x52')](_0x38b89c['query'],_0x496a5f[_0x9ea2('0x51')]));_0x4dbab7['where']['FaxAccountId']=_0x57506a['id'];if(_0x38b89c['query'][_0x9ea2('0x54')]){_0x4dbab7['where']=_[_0x9ea2('0x53')](_0x4dbab7[_0x9ea2('0x50')],{'$or':_['map'](_0x4dbab7[_0x9ea2('0x49')],function(_0x4eb1c7){var _0x50b102={};_0x50b102[_0x4eb1c7]={'$like':'%'+_0x38b89c[_0x9ea2('0x47')]['filter']+'%'};return _0x50b102;})});}if(_0x38b89c[_0x9ea2('0x47')][_0x9ea2('0xa6')]){var _0x4a7f07=_0x38b89c[_0x9ea2('0x47')][_0x9ea2('0xa6')]['split'](',');var _0x5c9f56={};_0x5c9f56[_0x4a7f07[0x0]]={'$gte':moment(_0x4a7f07[0x1])[_0x9ea2('0xa7')](_0x9ea2('0xa8'))};_0x4dbab7[_0x9ea2('0x50')]=_['merge'](_0x4dbab7[_0x9ea2('0x50')],_0x5c9f56);}_0x4dbab7=_[_0x9ea2('0x53')]({},_0x4dbab7,_0x38b89c[_0x9ea2('0x55')]);return db[_0x9ea2('0xa9')][_0x9ea2('0x32')]({'where':_0x4dbab7[_0x9ea2('0x50')]})[_0x9ea2('0x38')](function(_0x143abd){_0x33e1fe[_0x9ea2('0x32')]=_0x143abd;if(_0x38b89c[_0x9ea2('0x47')][_0x9ea2('0x56')]){_0x4dbab7[_0x9ea2('0x57')]=[{'all':!![]}];}return db[_0x9ea2('0xa9')][_0x9ea2('0x58')](_0x4dbab7);})[_0x9ea2('0x38')](function(_0x42da60){_0x33e1fe['rows']=_0x42da60;return _0x33e1fe;});}})['then'](respondWithFilteredResult(_0x51ea74,_0x4dbab7))[_0x9ea2('0x2b')](handleError(_0x51ea74,null));};exports[_0x9ea2('0x3f')]=function(_0x4a8f3a,_0xd27033,_0x6a42da){var _0xe9aff7,_0x5d0109={},_0x43187b;if(_0x4a8f3a[_0x9ea2('0x60')]['to']){_0x43187b=_0x4a8f3a['body']['to'][0x0];}return db[_0x9ea2('0x43')][_0x9ea2('0x5e')]({'where':{'id':_0x4a8f3a[_0x9ea2('0x5b')]['id']},'include':[{'model':db[_0x9ea2('0xaa')],'as':_0x9ea2('0xab'),'include':[{'model':db['CmContact'],'as':_0x9ea2('0xac'),'where':{'fax':_0x43187b},'limit':0x1,'order':[['updatedAt','DESC']]}]}]})[_0x9ea2('0x38')](handleEntityNotFound(_0xd27033,null))[_0x9ea2('0x38')](function(_0x43d14a){_0xe9aff7=_0x43d14a;if(_0x4a8f3a['body'][_0x9ea2('0xad')]&&_0x4a8f3a[_0x9ea2('0x60')][_0x9ea2('0xad')][_0x9ea2('0x4c')]){for(var _0x215111=0x0;_0x215111<_0x4a8f3a[_0x9ea2('0x60')][_0x9ea2('0xad')][_0x9ea2('0x4c')];_0x215111+=0x1){_0x4a8f3a['body'][_0x9ea2('0xad')][_0x215111]={'filename':_0x4a8f3a['body'][_0x9ea2('0xad')][_0x215111][_0x9ea2('0x3e')],'id':_0x4a8f3a[_0x9ea2('0x60')]['attachments'][_0x215111]['id'],'path':path[_0x9ea2('0xae')](config[_0x9ea2('0xaf')],'server/files/attachments',_0x4a8f3a[_0x9ea2('0x60')][_0x9ea2('0xad')][_0x215111][_0x9ea2('0xb0')])};}}return respondWithRpcPromise(_0x9ea2('0xb1'),_0x9ea2('0xb1'),{'FaxAccountId':_[_0x9ea2('0xb2')](_0x4a8f3a[_0x9ea2('0x5b')]['id'])?undefined:_0x4a8f3a[_0x9ea2('0x5b')]['id'],'path':_[_0x9ea2('0xb2')](_0x4a8f3a[_0x9ea2('0x60')]['attachments'][0x0][_0x9ea2('0xb3')])?undefined:_0x4a8f3a[_0x9ea2('0x60')][_0x9ea2('0xad')][0x0][_0x9ea2('0xb3')],'fax':_[_0x9ea2('0xb2')](_0x4a8f3a[_0x9ea2('0x60')]['to'][0x0])?undefined:_0x4a8f3a['body']['to'][0x0]},client9002);})[_0x9ea2('0x38')](function(){if(_0xe9aff7){if(_['isNil'](_0x4a8f3a[_0x9ea2('0x60')]['from'])){_0x4a8f3a['body'][_0x9ea2('0xb4')]=util[_0x9ea2('0xa7')](_0x9ea2('0xb5'),_0xe9aff7[_0x9ea2('0x3e')],_0xe9aff7[_0x9ea2('0xb6')]);}if(_0xe9aff7[_0x9ea2('0xab')]){if(_0xe9aff7[_0x9ea2('0xab')][_0x9ea2('0xac')]['length']){return _0xe9aff7[_0x9ea2('0xab')][_0x9ea2('0xac')][0x0];}else{return db[_0x9ea2('0xb7')][_0x9ea2('0x5f')](_[_0x9ea2('0x1a')](_0x4a8f3a[_0x9ea2('0x60')],{'firstName':_0x4a8f3a[_0x9ea2('0x60')]['to'][0x0],'phone':_0x4a8f3a[_0x9ea2('0x60')]['to'][0x0],'fax':_0x4a8f3a[_0x9ea2('0x60')]['to'][0x0],'ListId':_0xe9aff7[_0x9ea2('0xb8')]}));}}else{throw new Error(_0x9ea2('0xb9'));}}else{throw new Error(_0x9ea2('0xba'));}})[_0x9ea2('0x38')](function(_0x2ba120){if(_0x2ba120){return db[_0x9ea2('0x77')][_0x9ea2('0x5e')]({'where':{'ContactId':_0x2ba120['id'],'closed':![],'FaxAccountId':_0xe9aff7['id']}})['then'](function(_0x46a3f7){if(_0x46a3f7){return[_0x46a3f7,![]];}return db['FaxInteraction'][_0x9ea2('0x5f')]({'UserId':_0x4a8f3a[_0x9ea2('0x61')]['id'],'ContactId':_0x2ba120['id'],'FaxAccountId':_0xe9aff7['id'],'fax':_0x4a8f3a['body']['to'][0x0],'firstMsgDirection':_0x9ea2('0xbb'),'Messages':[_[_0x9ea2('0x53')](_0x4a8f3a[_0x9ea2('0x60')],{'read':![],'body':_0x4a8f3a[_0x9ea2('0x60')][_0x9ea2('0xad')][0x0]['filename'],'FaxAccountId':_0xe9aff7['id'],'UserId':_0x4a8f3a[_0x9ea2('0x61')]['id'],'ContactId':_0x2ba120['id'],'AttachmentId':_0x4a8f3a['body'][_0x9ea2('0xad')][0x0]['id']})]},{'include':[{'model':db[_0x9ea2('0xa9')],'as':_0x9ea2('0xbc')}]})[_0x9ea2('0x38')](function(_0x2b9e82){return[_0x2b9e82,!![]];});});}else{throw new Error(_0x9ea2('0xbd'));}})[_0x9ea2('0xbe')](function(_0x3f3b9a,_0x2ebfed){if(_0x2ebfed){return _0x3f3b9a;}return db[_0x9ea2('0xa9')]['create']({'direction':_0x9ea2('0xbb'),'read':![],'body':_0x4a8f3a['body']['attachments'][0x0][_0x9ea2('0xbf')],'FaxAccountId':_0xe9aff7['id'],'FaxInteractionId':_0x3f3b9a['id'],'UserId':_0x4a8f3a[_0x9ea2('0x61')]['id'],'ContactId':_0x3f3b9a['ContactId'],'AttachmentId':_0x4a8f3a[_0x9ea2('0x60')][_0x9ea2('0xad')][0x0]['id']})[_0x9ea2('0x38')](function(_0x53ff23){_0x3f3b9a[_0x9ea2('0xc0')][_0x9ea2('0xbc')]=[];_0x3f3b9a[_0x9ea2('0xc0')]['Messages'][_0x9ea2('0x92')](_0x53ff23['dataValues']);return _0x3f3b9a;});})[_0x9ea2('0x38')](function(_0x4f5d0c){respondWithRpcPromise(_0x9ea2('0xc1'),_0x9ea2('0xc1'),{'FaxAccountId':_[_0x9ea2('0xb2')](_0x4a8f3a[_0x9ea2('0x5b')]['id'])?undefined:_0x4a8f3a['params']['id'],'path':_[_0x9ea2('0xb2')](_0x4a8f3a['body'][_0x9ea2('0xad')][0x0][_0x9ea2('0xb3')])?undefined:_0x4a8f3a['body'][_0x9ea2('0xad')][0x0][_0x9ea2('0xb3')],'fax':_[_0x9ea2('0xb2')](_0x4a8f3a[_0x9ea2('0x60')]['to'][0x0])?undefined:_0x4a8f3a[_0x9ea2('0x60')]['to'][0x0],'AttachmentId':_0x4a8f3a[_0x9ea2('0x60')]['attachments'][0x0]['id']},client9002)['then'](function(_0x131012){logger[_0x9ea2('0x22')]('SendFaxRpc,\x20%s',_0x131012);})['catch'](function(_0x2bbe67){logger[_0x9ea2('0x22')](_0x9ea2('0xc2'),_0x2bbe67);});return _0x4f5d0c;})[_0x9ea2('0x38')](respondWithResult(_0xd27033,null))['catch'](handleError(_0xd27033,null));};exports['addAgents']=function(_0x16a584,_0x52cf68,_0x5b6799){return db['FaxAccount']['find']({'where':{'id':_0x16a584['params']['id']}})[_0x9ea2('0x38')](handleEntityNotFound(_0x52cf68,null))['then'](function(_0x5265ba){if(_0x5265ba){return _0x5265ba[_0x9ea2('0xc3')](_0x16a584['body'][_0x9ea2('0x71')],_[_0x9ea2('0x78')](_0x16a584[_0x9ea2('0x60')],[_0x9ea2('0x71'),'id'])||{})[_0x9ea2('0xbe')](function(_0x280d7e){for(var _0x87831=0x0;_0x87831<_0x16a584[_0x9ea2('0x60')][_0x9ea2('0x71')]['length'];_0x87831+=0x1){socket['emit'](_0x9ea2('0xc4'),{'UserId':Number(_0x16a584[_0x9ea2('0x60')]['ids'][_0x87831]),'FaxAccountId':Number(_0x16a584[_0x9ea2('0x5b')]['id'])});}return _0x280d7e;});}})[_0x9ea2('0x38')](respondWithResult(_0x52cf68,null))['catch'](handleError(_0x52cf68,null));};exports[_0x9ea2('0xc5')]=function(_0x3ca842,_0x1dad9f,_0x345f91){return db[_0x9ea2('0x43')]['find']({'where':{'id':_0x3ca842['params']['id']}})[_0x9ea2('0x38')](handleEntityNotFound(_0x1dad9f,null))['then'](function(_0x10b659){if(_0x10b659){return _0x10b659[_0x9ea2('0xc5')](_0x3ca842['query'][_0x9ea2('0x71')])[_0x9ea2('0x38')](function(){if(_['isArray'](_0x3ca842[_0x9ea2('0x47')][_0x9ea2('0x71')])){for(var _0x32a774=0x0;_0x32a774<_0x3ca842[_0x9ea2('0x47')][_0x9ea2('0x71')][_0x9ea2('0x4c')];_0x32a774+=0x1){socket[_0x9ea2('0xc6')]('userFaxAccount:remove',{'UserId':Number(_0x3ca842[_0x9ea2('0x47')][_0x9ea2('0x71')][_0x32a774]),'FaxAccountId':Number(_0x3ca842[_0x9ea2('0x5b')]['id'])});}}else{socket[_0x9ea2('0xc6')]('userFaxAccount:remove',{'UserId':Number(_0x3ca842['query'][_0x9ea2('0x71')]),'FaxAccountId':Number(_0x3ca842['params']['id'])});}});}})[_0x9ea2('0x38')](respondWithStatusCode(_0x1dad9f,null))[_0x9ea2('0x2b')](handleError(_0x1dad9f,null));};exports[_0x9ea2('0xc7')]=function(_0x1fb5eb,_0x52c50b,_0x371cd1){var _0x567bcc={};var _0x1aa9dd={};var _0x24125c;var _0xfa20ba;return db[_0x9ea2('0x43')][_0x9ea2('0x6e')]({'where':{'id':_0x1fb5eb[_0x9ea2('0x5b')]['id']}})[_0x9ea2('0x38')](handleEntityNotFound(_0x52c50b,null))['then'](function(_0x340ff2){if(_0x340ff2){_0x24125c=_0x340ff2;_0x1aa9dd['model']=_[_0x9ea2('0x5d')](db['User'][_0x9ea2('0x5c')]);_0x1aa9dd[_0x9ea2('0x47')]=_['keys'](_0x1fb5eb['query']);_0x1aa9dd['filters']=_['intersection'](_0x1aa9dd[_0x9ea2('0x48')],_0x1aa9dd[_0x9ea2('0x47')]);_0x567bcc[_0x9ea2('0x49')]=_['intersection'](_0x1aa9dd[_0x9ea2('0x48')],qs['fields'](_0x1fb5eb[_0x9ea2('0x47')][_0x9ea2('0x4b')]));_0x567bcc[_0x9ea2('0x49')]=_0x567bcc[_0x9ea2('0x49')][_0x9ea2('0x4c')]?_0x567bcc['attributes']:_0x1aa9dd[_0x9ea2('0x48')];_0x567bcc['order']=qs['sort'](_0x1fb5eb[_0x9ea2('0x47')][_0x9ea2('0x4f')]);_0x567bcc['where']=qs[_0x9ea2('0x51')](_[_0x9ea2('0x52')](_0x1fb5eb[_0x9ea2('0x47')],_0x1aa9dd[_0x9ea2('0x51')]));if(_0x1fb5eb['query'][_0x9ea2('0x54')]){_0x567bcc['where']=_[_0x9ea2('0x53')](_0x567bcc[_0x9ea2('0x50')],{'$or':_[_0x9ea2('0x46')](_0x567bcc[_0x9ea2('0x49')],function(_0x484ade){var _0x2a9977={};_0x2a9977[_0x484ade]={'$like':'%'+_0x1fb5eb[_0x9ea2('0x47')][_0x9ea2('0x54')]+'%'};return _0x2a9977;})});}_0x567bcc=_[_0x9ea2('0x53')]({},_0x567bcc,_0x1fb5eb[_0x9ea2('0x55')]);return _0x24125c[_0x9ea2('0xc7')](_0x567bcc);}})['then'](function(_0x584d79){if(_0x584d79){_0xfa20ba=_0x584d79['length'];if(!_0x1fb5eb[_0x9ea2('0x47')][_0x9ea2('0x6f')](_0x9ea2('0x4d'))){_0x567bcc[_0x9ea2('0x31')]=qs[_0x9ea2('0x31')](_0x1fb5eb['query']['limit']);_0x567bcc[_0x9ea2('0x2f')]=qs[_0x9ea2('0x2f')](_0x1fb5eb[_0x9ea2('0x47')]['offset']);}return _0x24125c[_0x9ea2('0xc7')](_0x567bcc);}})[_0x9ea2('0x38')](function(_0x56a1b7){if(_0x56a1b7){return _0x56a1b7?{'count':_0xfa20ba,'rows':_0x56a1b7}:null;}})[_0x9ea2('0x38')](respondWithResult(_0x52c50b,null))[_0x9ea2('0x2b')](handleError(_0x52c50b,null));};