Built motion from commit 9c91e9f5.|2.6.29
[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 _0xf741=['addInteraction','omit','getInteractions','FaxInteraction','length','CmContact','Contact','User','Owner','fullname','internal','Tag','Tags','color','tag','sequelize','transaction','Transaction','READ_COMMITTED','FaxApplication','bulkCreate','findAndCountAll','priority','finally','getApplications','context','localstationid','app','system','Fax\x20Extension','appdata','push','Answer','Set','ecm','gateway','faxdetect','headerinfo','maxrate','minrate','modem','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','VoiceExtension','updateAccountApplications','tech','createdAt','FaxMessage','split','format','List','Contacts','updatedAt','attachments','join','root','server/files/attachments','basename','isNil','from','\x22%s\x22\x20<%s>','fax','defaults','List\x20not\x20found','Send\x20Fax\x20failed','out','filename','Contact\x20not\x20found','ContactId','dataValues','Messages','SendFax','path','SendFaxRpc,\x20%s','addAgents','spread','emit','userFaxAccount:save','removeAgents','userFaxAccount:remove','getAgents','eml-format','zip-dir','fast-json-patch','moment','bluebird','mustache','util','ejs','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','redis','localhost','socket.io-emitter','./faxAccount.socket','register','jayson/promise','client','http','request','then','FaxAccount,\x20%s,\x20%s','request\x20sent','FaxAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','info','sendStatus','status','end','json','offset','undefined','limit','count','set','reject','save','update','destroy','FaxAccounts','UserProfileResource','stack','name','send','Pause','mandatoryDispositionPause','map','FaxAccount','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','merge','VIRTUAL','options','include','rows','catch','show','find','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','params','describe','addDisposition','FaxAccountId','findOne','Disposition','order','pick','filter','includeAll','findAll','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers'];(function(_0x1b69d0,_0x22791d){var _0x4f3891=function(_0x533553){while(--_0x533553){_0x1b69d0['push'](_0x1b69d0['shift']());}};_0x4f3891(++_0x22791d);}(_0xf741,0x1d7));var _0x1f74=function(_0x279333,_0x408607){_0x279333=_0x279333-0x0;var _0x137ca9=_0xf741[_0x279333];return _0x137ca9;};'use strict';var emlformat=require(_0x1f74('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x1f74('0x1'));var jsonpatch=require(_0x1f74('0x2'));var rp=require('request-promise');var moment=require(_0x1f74('0x3'));var BPromise=require(_0x1f74('0x4'));var Mustache=require(_0x1f74('0x5'));var util=require(_0x1f74('0x6'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x1f74('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x1f74('0x8'));var squel=require(_0x1f74('0x9'));var crypto=require(_0x1f74('0xa'));var jsforce=require(_0x1f74('0xb'));var deskjs=require('desk.js');var toCsv=require(_0x1f74('0xc'));var querystring=require(_0x1f74('0xd'));var Papa=require(_0x1f74('0xe'));var Redis=require(_0x1f74('0xf'));var authService=require(_0x1f74('0x10'));var qs=require(_0x1f74('0x11'));var as=require(_0x1f74('0x12'));var hardwareService=require(_0x1f74('0x13'));var logger=require('../../config/logger')(_0x1f74('0x14'));var utils=require(_0x1f74('0x15'));var config=require(_0x1f74('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0x1f74('0x17'))['db'];config[_0x1f74('0x18')]=_['defaults'](config[_0x1f74('0x18')],{'host':_0x1f74('0x19'),'port':0x18eb});var socket=require(_0x1f74('0x1a'))(new Redis(config['redis']));require(_0x1f74('0x1b'))[_0x1f74('0x1c')](socket);var jayson=require(_0x1f74('0x1d'));var client=jayson[_0x1f74('0x1e')][_0x1f74('0x1f')]({'port':0x232c});var client9002=jayson[_0x1f74('0x1e')][_0x1f74('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x2b7430,_0x44d7c1,_0x3f3094,_0x2eaee4){return new BPromise(function(_0x2626d8,_0x5940ce){var _0x7d2652=_0x2eaee4||client;return _0x7d2652[_0x1f74('0x20')](_0x2b7430,_0x3f3094)[_0x1f74('0x21')](function(_0x24930f){logger['info'](_0x1f74('0x22'),_0x44d7c1,_0x1f74('0x23'));logger['debug'](_0x1f74('0x24'),_0x44d7c1,'request\x20sent',JSON[_0x1f74('0x25')](_0x24930f));if(_0x24930f[_0x1f74('0x26')]){if(_0x24930f['error']['code']===0x1f4){logger[_0x1f74('0x26')](_0x1f74('0x22'),_0x44d7c1,_0x24930f['error'][_0x1f74('0x27')]);return _0x5940ce(_0x24930f[_0x1f74('0x26')][_0x1f74('0x27')]);}logger[_0x1f74('0x26')](_0x1f74('0x22'),_0x44d7c1,_0x24930f[_0x1f74('0x26')][_0x1f74('0x27')]);return _0x2626d8(_0x24930f[_0x1f74('0x26')][_0x1f74('0x27')]);}else{logger[_0x1f74('0x28')]('FaxAccount,\x20%s,\x20%s',_0x44d7c1,_0x1f74('0x23'));_0x2626d8(_0x24930f['result'][_0x1f74('0x27')]);}})['catch'](function(_0xb73623){logger[_0x1f74('0x26')]('FaxAccount,\x20%s,\x20%s',_0x44d7c1,_0xb73623);_0x5940ce(_0xb73623);});});}function respondWithStatusCode(_0x2741cb,_0x3faeba){_0x3faeba=_0x3faeba||0xcc;return function(_0x1d71b8){if(_0x1d71b8){return _0x2741cb[_0x1f74('0x29')](_0x3faeba);}return _0x2741cb[_0x1f74('0x2a')](_0x3faeba)[_0x1f74('0x2b')]();};}function respondWithResult(_0x270d4a,_0xc311a8){_0xc311a8=_0xc311a8||0xc8;return function(_0x3e7078){if(_0x3e7078){return _0x270d4a[_0x1f74('0x2a')](_0xc311a8)[_0x1f74('0x2c')](_0x3e7078);}};}function respondWithFilteredResult(_0x380c29,_0x1d0de1){return function(_0x5ae5a1){if(_0x5ae5a1){var _0x1c080d=typeof _0x1d0de1[_0x1f74('0x2d')]===_0x1f74('0x2e')&&typeof _0x1d0de1[_0x1f74('0x2f')]===_0x1f74('0x2e');var _0x5729f6=_0x5ae5a1['count'];var _0x4838be=_0x1c080d?0x0:_0x1d0de1[_0x1f74('0x2d')];var _0x1cfa60=_0x1c080d?_0x5ae5a1[_0x1f74('0x30')]:_0x1d0de1['offset']+_0x1d0de1[_0x1f74('0x2f')];var _0x445760;if(_0x1cfa60>=_0x5729f6){_0x1cfa60=_0x5729f6;_0x445760=0xc8;}else{_0x445760=0xce;}_0x380c29[_0x1f74('0x2a')](_0x445760);return _0x380c29[_0x1f74('0x31')]('Content-Range',_0x4838be+'-'+_0x1cfa60+'/'+_0x5729f6)[_0x1f74('0x2c')](_0x5ae5a1);}return null;};}function patchUpdates(_0x4c1fd5){return function(_0x4be563){try{jsonpatch['apply'](_0x4be563,_0x4c1fd5,!![]);}catch(_0x2ee4a4){return BPromise[_0x1f74('0x32')](_0x2ee4a4);}return _0x4be563[_0x1f74('0x33')]();};}function saveUpdates(_0x1edaa6,_0x303f00){return function(_0x5cd996){if(_0x5cd996){return _0x5cd996[_0x1f74('0x34')](_0x1edaa6)[_0x1f74('0x21')](function(_0x1d3a77){return _0x1d3a77;});}return null;};}function removeEntity(_0x44a38f,_0x489e9d){return function(_0x2e9a30){if(_0x2e9a30){return _0x2e9a30[_0x1f74('0x35')]()[_0x1f74('0x21')](function(){var _0x63b24e=_0x2e9a30['get']({'plain':!![]});var _0x57ce21=_0x1f74('0x36');return db[_0x1f74('0x37')][_0x1f74('0x35')]({'where':{'type':_0x57ce21,'resourceId':_0x63b24e['id']}})['then'](function(){return _0x2e9a30;});})[_0x1f74('0x21')](function(){_0x44a38f[_0x1f74('0x2a')](0xcc)[_0x1f74('0x2b')]();});}};}function handleEntityNotFound(_0x16bacf,_0x5a8c4e){return function(_0x1f3cb2){if(!_0x1f3cb2){_0x16bacf[_0x1f74('0x29')](0x194);}return _0x1f3cb2;};}function handleError(_0x192e0e,_0x5ee2cd){_0x5ee2cd=_0x5ee2cd||0x1f4;return function(_0x1c5e52){logger[_0x1f74('0x26')](_0x1c5e52[_0x1f74('0x38')]);if(_0x1c5e52[_0x1f74('0x39')]){delete _0x1c5e52[_0x1f74('0x39')];}_0x192e0e[_0x1f74('0x2a')](_0x5ee2cd)[_0x1f74('0x3a')](_0x1c5e52);};}exports['index']=function(_0x1b48af,_0x2b8913){var _0x481f9e={'include':[{'model':db[_0x1f74('0x3b')],'as':_0x1f74('0x3c')}]},_0x5ccc25={},_0x3f36b2={'count':0x0,'rows':[]};var _0x37e139=_[_0x1f74('0x3d')](db[_0x1f74('0x3e')][_0x1f74('0x3f')],function(_0x59d29a){return{'name':_0x59d29a[_0x1f74('0x40')],'type':_0x59d29a[_0x1f74('0x41')][_0x1f74('0x42')]};});_0x5ccc25[_0x1f74('0x43')]=_[_0x1f74('0x3d')](_0x37e139,_0x1f74('0x39'));_0x5ccc25[_0x1f74('0x44')]=_[_0x1f74('0x45')](_0x1b48af[_0x1f74('0x44')]);_0x5ccc25[_0x1f74('0x46')]=_[_0x1f74('0x47')](_0x5ccc25['model'],_0x5ccc25['query']);_0x481f9e[_0x1f74('0x48')]=_[_0x1f74('0x47')](_0x5ccc25[_0x1f74('0x43')],qs['fields'](_0x1b48af[_0x1f74('0x44')][_0x1f74('0x49')]));_0x481f9e[_0x1f74('0x48')]=_0x481f9e[_0x1f74('0x48')]['length']?_0x481f9e[_0x1f74('0x48')]:_0x5ccc25[_0x1f74('0x43')];if(!_0x1b48af[_0x1f74('0x44')][_0x1f74('0x4a')](_0x1f74('0x4b'))){_0x481f9e[_0x1f74('0x2f')]=qs[_0x1f74('0x2f')](_0x1b48af['query']['limit']);_0x481f9e[_0x1f74('0x2d')]=qs['offset'](_0x1b48af[_0x1f74('0x44')][_0x1f74('0x2d')]);}_0x481f9e['order']=qs[_0x1f74('0x4c')](_0x1b48af[_0x1f74('0x44')]['sort']);_0x481f9e[_0x1f74('0x4d')]=qs[_0x1f74('0x46')](_['pick'](_0x1b48af['query'],_0x5ccc25[_0x1f74('0x46')]),_0x37e139);if(_0x1b48af[_0x1f74('0x44')]['filter']){_0x481f9e['where']=_[_0x1f74('0x4e')](_0x481f9e[_0x1f74('0x4d')],{'$or':_[_0x1f74('0x3d')](_0x37e139,function(_0x49df99){if(_0x49df99[_0x1f74('0x41')]!==_0x1f74('0x4f')){var _0x5e877f={};_0x5e877f[_0x49df99[_0x1f74('0x39')]]={'$like':'%'+_0x1b48af[_0x1f74('0x44')]['filter']+'%'};return _0x5e877f;}})});}_0x481f9e=_[_0x1f74('0x4e')]({},_0x481f9e,_0x1b48af[_0x1f74('0x50')]);var _0xf81027={'where':_0x481f9e[_0x1f74('0x4d')]};return db[_0x1f74('0x3e')]['count'](_0xf81027)[_0x1f74('0x21')](function(_0xdb116e){_0x3f36b2[_0x1f74('0x30')]=_0xdb116e;if(_0x1b48af[_0x1f74('0x44')]['includeAll']){_0x481f9e[_0x1f74('0x51')]=[{'all':!![]}];}return db[_0x1f74('0x3e')]['findAll'](_0x481f9e);})['then'](function(_0x5c4710){_0x3f36b2[_0x1f74('0x52')]=_0x5c4710;return _0x3f36b2;})[_0x1f74('0x21')](respondWithFilteredResult(_0x2b8913,_0x481f9e))[_0x1f74('0x53')](handleError(_0x2b8913,null));};exports[_0x1f74('0x54')]=function(_0xe93996,_0x5936ab){var _0x4b9523={'raw':![],'where':{'id':_0xe93996['params']['id']},'include':[{'model':db[_0x1f74('0x3b')],'as':_0x1f74('0x3c')}]},_0x5b81b5={};_0x5b81b5[_0x1f74('0x43')]=_[_0x1f74('0x45')](db[_0x1f74('0x3e')][_0x1f74('0x3f')]);_0x5b81b5['query']=_[_0x1f74('0x45')](_0xe93996[_0x1f74('0x44')]);_0x5b81b5[_0x1f74('0x46')]=_[_0x1f74('0x47')](_0x5b81b5['model'],_0x5b81b5['query']);_0x4b9523[_0x1f74('0x48')]=_['intersection'](_0x5b81b5[_0x1f74('0x43')],qs[_0x1f74('0x49')](_0xe93996[_0x1f74('0x44')][_0x1f74('0x49')]));_0x4b9523[_0x1f74('0x48')]=_0x4b9523[_0x1f74('0x48')]['length']?_0x4b9523[_0x1f74('0x48')]:_0x5b81b5['model'];if(_0xe93996[_0x1f74('0x44')]['includeAll']){_0x4b9523[_0x1f74('0x51')]=[{'all':!![]}];}_0x4b9523=_['merge']({},_0x4b9523,_0xe93996[_0x1f74('0x50')]);return db[_0x1f74('0x3e')][_0x1f74('0x55')](_0x4b9523)[_0x1f74('0x21')](handleEntityNotFound(_0x5936ab,null))[_0x1f74('0x21')](respondWithResult(_0x5936ab,null))[_0x1f74('0x53')](handleError(_0x5936ab,null));};exports[_0x1f74('0x56')]=function(_0x256c42,_0x5927ff){return db[_0x1f74('0x3e')]['create'](_0x256c42[_0x1f74('0x57')],{})[_0x1f74('0x21')](function(_0x1b377c){var _0x179e70=_0x256c42[_0x1f74('0x58')][_0x1f74('0x59')]({'plain':!![]});if(!_0x179e70)throw new Error(_0x1f74('0x5a'));if(_0x179e70[_0x1f74('0x5b')]===_0x1f74('0x58')){var _0x227180=_0x1b377c[_0x1f74('0x59')]({'plain':!![]});var _0x59a950=_0x1f74('0x36');return db[_0x1f74('0x5c')][_0x1f74('0x55')]({'where':{'name':_0x59a950,'userProfileId':_0x179e70['userProfileId']},'raw':!![]})['then'](function(_0x346775){if(_0x346775&&_0x346775[_0x1f74('0x5d')]===0x0){return db[_0x1f74('0x37')][_0x1f74('0x56')]({'name':_0x227180[_0x1f74('0x39')],'resourceId':_0x227180['id'],'type':_0x346775[_0x1f74('0x39')],'sectionId':_0x346775['id']},{})[_0x1f74('0x21')](function(){return _0x1b377c;});}else{return _0x1b377c;}})[_0x1f74('0x53')](function(_0x3a1c81){logger[_0x1f74('0x26')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x3a1c81);throw _0x3a1c81;});}return _0x1b377c;})[_0x1f74('0x21')](respondWithResult(_0x5927ff,0xc9))[_0x1f74('0x53')](handleError(_0x5927ff,null));};exports[_0x1f74('0x34')]=function(_0x217e6d,_0x534ebf){if(_0x217e6d[_0x1f74('0x57')]['id']){delete _0x217e6d[_0x1f74('0x57')]['id'];}return db[_0x1f74('0x3e')][_0x1f74('0x55')]({'where':{'id':_0x217e6d[_0x1f74('0x5e')]['id']},'include':[{'model':db[_0x1f74('0x3b')],'as':'mandatoryDispositionPause'}]})[_0x1f74('0x21')](handleEntityNotFound(_0x534ebf,null))[_0x1f74('0x21')](saveUpdates(_0x217e6d['body'],null))[_0x1f74('0x21')](respondWithResult(_0x534ebf,null))[_0x1f74('0x53')](handleError(_0x534ebf,null));};exports['destroy']=function(_0x37b157,_0x4fd4bd){return db[_0x1f74('0x3e')][_0x1f74('0x55')]({'where':{'id':_0x37b157['params']['id']}})[_0x1f74('0x21')](handleEntityNotFound(_0x4fd4bd,null))[_0x1f74('0x21')](removeEntity(_0x4fd4bd,null))[_0x1f74('0x53')](handleError(_0x4fd4bd,null));};exports[_0x1f74('0x5f')]=function(_0x28a8f6,_0x31e1ec){return db[_0x1f74('0x3e')][_0x1f74('0x5f')]()[_0x1f74('0x21')](respondWithResult(_0x31e1ec,null))[_0x1f74('0x53')](handleError(_0x31e1ec,null));};exports[_0x1f74('0x60')]=function(_0x51a48a,_0x28111f,_0x43be64){if(_0x51a48a[_0x1f74('0x57')]['id']){delete _0x51a48a['body']['id'];}return db[_0x1f74('0x3e')][_0x1f74('0x55')]({'where':{'id':_0x51a48a[_0x1f74('0x5e')]['id']}})['then'](handleEntityNotFound(_0x28111f,null))['then'](function(_0x432e89){if(_0x432e89){_0x51a48a[_0x1f74('0x57')][_0x1f74('0x61')]=_0x432e89['id'];return db['Disposition'][_0x1f74('0x56')](_0x51a48a[_0x1f74('0x57')]);}})['then'](respondWithResult(_0x28111f,null))[_0x1f74('0x53')](handleError(_0x28111f,null));};exports['getDispositions']=function(_0x517066,_0x32ce2b,_0x5437e7){var _0x3335ec={'raw':![],'where':{}};var _0x4709d3={};var _0x206351={'count':0x0,'rows':[]};return db[_0x1f74('0x3e')][_0x1f74('0x62')]({'where':{'id':_0x517066[_0x1f74('0x5e')]['id']}})['then'](handleEntityNotFound(_0x32ce2b,null))[_0x1f74('0x21')](function(_0x22b734){if(_0x22b734){_0x4709d3[_0x1f74('0x43')]=_[_0x1f74('0x45')](db[_0x1f74('0x63')][_0x1f74('0x3f')]);_0x4709d3[_0x1f74('0x44')]=_['keys'](_0x517066['query']);_0x4709d3['filters']=_['intersection'](_0x4709d3[_0x1f74('0x43')],_0x4709d3[_0x1f74('0x44')]);_0x3335ec['attributes']=_[_0x1f74('0x47')](_0x4709d3['model'],qs['fields'](_0x517066[_0x1f74('0x44')][_0x1f74('0x49')]));_0x3335ec['attributes']=_0x3335ec[_0x1f74('0x48')]['length']?_0x3335ec['attributes']:_0x4709d3['model'];if(!_0x517066[_0x1f74('0x44')][_0x1f74('0x4a')](_0x1f74('0x4b'))){_0x3335ec[_0x1f74('0x2f')]=qs['limit'](_0x517066[_0x1f74('0x44')][_0x1f74('0x2f')]);_0x3335ec[_0x1f74('0x2d')]=qs['offset'](_0x517066[_0x1f74('0x44')][_0x1f74('0x2d')]);}_0x3335ec[_0x1f74('0x64')]=qs['sort'](_0x517066[_0x1f74('0x44')][_0x1f74('0x4c')]);_0x3335ec[_0x1f74('0x4d')]=qs[_0x1f74('0x46')](_[_0x1f74('0x65')](_0x517066['query'],_0x4709d3[_0x1f74('0x46')]));_0x3335ec['where']['FaxAccountId']=_0x22b734['id'];if(_0x517066[_0x1f74('0x44')][_0x1f74('0x66')]){_0x3335ec[_0x1f74('0x4d')]=_[_0x1f74('0x4e')](_0x3335ec['where'],{'$or':_[_0x1f74('0x3d')](_0x3335ec['attributes'],function(_0x1a2b98){var _0x478cf9={};_0x478cf9[_0x1a2b98]={'$like':'%'+_0x517066[_0x1f74('0x44')][_0x1f74('0x66')]+'%'};return _0x478cf9;})});}_0x3335ec=_[_0x1f74('0x4e')]({},_0x3335ec,_0x517066[_0x1f74('0x50')]);return db[_0x1f74('0x63')][_0x1f74('0x30')]({'where':_0x3335ec[_0x1f74('0x4d')]})['then'](function(_0x23ac62){_0x206351[_0x1f74('0x30')]=_0x23ac62;if(_0x517066['query'][_0x1f74('0x67')]){_0x3335ec['include']=[{'all':!![]}];}return db[_0x1f74('0x63')][_0x1f74('0x68')](_0x3335ec);})['then'](function(_0x5dbe5b){_0x206351['rows']=_0x5dbe5b;return _0x206351;});}})[_0x1f74('0x21')](respondWithFilteredResult(_0x32ce2b,_0x3335ec))[_0x1f74('0x53')](handleError(_0x32ce2b,null));};exports[_0x1f74('0x69')]=function(_0x38da9f,_0x47d052,_0x371636){return db['FaxAccount']['find']({'where':{'id':_0x38da9f[_0x1f74('0x5e')]['id']}})[_0x1f74('0x21')](handleEntityNotFound(_0x47d052,null))[_0x1f74('0x21')](function(_0x53b3cd){if(_0x53b3cd){return _0x53b3cd[_0x1f74('0x69')](_0x38da9f[_0x1f74('0x44')][_0x1f74('0x6a')]);}})[_0x1f74('0x21')](respondWithStatusCode(_0x47d052,null))[_0x1f74('0x53')](handleError(_0x47d052,null));};exports[_0x1f74('0x6b')]=function(_0x1a2147,_0x2b214a,_0x5d78d8){if(_0x1a2147[_0x1f74('0x57')]['id']){delete _0x1a2147[_0x1f74('0x57')]['id'];}return db[_0x1f74('0x3e')][_0x1f74('0x55')]({'where':{'id':_0x1a2147[_0x1f74('0x5e')]['id']}})[_0x1f74('0x21')](handleEntityNotFound(_0x2b214a,null))['then'](function(_0x3fce1b){if(_0x3fce1b){_0x1a2147['body'][_0x1f74('0x61')]=_0x3fce1b['id'];return db[_0x1f74('0x6c')]['create'](_0x1a2147[_0x1f74('0x57')]);}})[_0x1f74('0x21')](respondWithResult(_0x2b214a,null))['catch'](handleError(_0x2b214a,null));};exports[_0x1f74('0x6d')]=function(_0x5b2647,_0x10b454,_0x10378d){var _0x3da8b4={'raw':![],'where':{}};var _0xeabedc={};var _0x2620b6={'count':0x0,'rows':[]};return db[_0x1f74('0x3e')]['findOne']({'where':{'id':_0x5b2647[_0x1f74('0x5e')]['id']}})['then'](handleEntityNotFound(_0x10b454,null))[_0x1f74('0x21')](function(_0x339609){if(_0x339609){_0xeabedc[_0x1f74('0x43')]=_[_0x1f74('0x45')](db[_0x1f74('0x6c')][_0x1f74('0x3f')]);_0xeabedc['query']=_['keys'](_0x5b2647[_0x1f74('0x44')]);_0xeabedc['filters']=_[_0x1f74('0x47')](_0xeabedc[_0x1f74('0x43')],_0xeabedc[_0x1f74('0x44')]);_0x3da8b4[_0x1f74('0x48')]=_[_0x1f74('0x47')](_0xeabedc['model'],qs[_0x1f74('0x49')](_0x5b2647[_0x1f74('0x44')][_0x1f74('0x49')]));_0x3da8b4[_0x1f74('0x48')]=_0x3da8b4['attributes']['length']?_0x3da8b4[_0x1f74('0x48')]:_0xeabedc[_0x1f74('0x43')];if(!_0x5b2647[_0x1f74('0x44')][_0x1f74('0x4a')]('nolimit')){_0x3da8b4[_0x1f74('0x2f')]=qs['limit'](_0x5b2647[_0x1f74('0x44')][_0x1f74('0x2f')]);_0x3da8b4[_0x1f74('0x2d')]=qs[_0x1f74('0x2d')](_0x5b2647[_0x1f74('0x44')]['offset']);}_0x3da8b4[_0x1f74('0x64')]=qs[_0x1f74('0x4c')](_0x5b2647[_0x1f74('0x44')][_0x1f74('0x4c')]);_0x3da8b4['where']=qs[_0x1f74('0x46')](_[_0x1f74('0x65')](_0x5b2647[_0x1f74('0x44')],_0xeabedc[_0x1f74('0x46')]));_0x3da8b4['where'][_0x1f74('0x61')]=_0x339609['id'];if(_0x5b2647[_0x1f74('0x44')][_0x1f74('0x66')]){_0x3da8b4[_0x1f74('0x4d')]=_[_0x1f74('0x4e')](_0x3da8b4[_0x1f74('0x4d')],{'$or':_[_0x1f74('0x3d')](_0x3da8b4[_0x1f74('0x48')],function(_0x5a7868){var _0x3a0eb5={};_0x3a0eb5[_0x5a7868]={'$like':'%'+_0x5b2647[_0x1f74('0x44')][_0x1f74('0x66')]+'%'};return _0x3a0eb5;})});}_0x3da8b4=_['merge']({},_0x3da8b4,_0x5b2647[_0x1f74('0x50')]);return db['CannedAnswer'][_0x1f74('0x30')]({'where':_0x3da8b4[_0x1f74('0x4d')]})[_0x1f74('0x21')](function(_0x4a3adf){_0x2620b6[_0x1f74('0x30')]=_0x4a3adf;if(_0x5b2647['query'][_0x1f74('0x67')]){_0x3da8b4[_0x1f74('0x51')]=[{'all':!![]}];}return db[_0x1f74('0x6c')][_0x1f74('0x68')](_0x3da8b4);})[_0x1f74('0x21')](function(_0xd4ad85){_0x2620b6['rows']=_0xd4ad85;return _0x2620b6;});}})[_0x1f74('0x21')](respondWithFilteredResult(_0x10b454,_0x3da8b4))['catch'](handleError(_0x10b454,null));};exports[_0x1f74('0x6e')]=function(_0x9c135,_0x142e8d,_0x3e7378){return db['FaxAccount']['find']({'where':{'id':_0x9c135[_0x1f74('0x5e')]['id']}})[_0x1f74('0x21')](handleEntityNotFound(_0x142e8d,null))[_0x1f74('0x21')](function(_0x7a31f6){if(_0x7a31f6){return _0x7a31f6[_0x1f74('0x6e')](_0x9c135['query'][_0x1f74('0x6a')]);}})['then'](respondWithStatusCode(_0x142e8d,null))[_0x1f74('0x53')](handleError(_0x142e8d,null));};exports[_0x1f74('0x6f')]=function(_0x3e69bc,_0xb77e2b,_0x285c37){return db['FaxInteraction'][_0x1f74('0x55')]({'where':{'id':_0x3e69bc[_0x1f74('0x5e')]['id']}})[_0x1f74('0x21')](handleEntityNotFound(_0xb77e2b,null))[_0x1f74('0x21')](function(_0x247e92){if(_0x247e92){return _0x247e92[_0x1f74('0x6f')](_0x3e69bc[_0x1f74('0x57')][_0x1f74('0x6a')],_[_0x1f74('0x70')](_0x3e69bc['body'],['ids','id'])||{});}})['then'](respondWithResult(_0xb77e2b,null))['catch'](handleError(_0xb77e2b,null));};exports[_0x1f74('0x71')]=function(_0x52ecb9,_0x3450ff,_0x381c0d){var _0x31ee22={'raw':![],'where':{}};var _0x435880={};var _0x52fdbf={'count':0x0,'rows':[]};return db[_0x1f74('0x3e')][_0x1f74('0x62')]({'where':{'id':_0x52ecb9['params']['id']}})[_0x1f74('0x21')](handleEntityNotFound(_0x3450ff,null))[_0x1f74('0x21')](function(_0x5aa42c){if(_0x5aa42c){_0x435880[_0x1f74('0x43')]=_[_0x1f74('0x45')](db[_0x1f74('0x72')][_0x1f74('0x3f')]);_0x435880[_0x1f74('0x44')]=_[_0x1f74('0x45')](_0x52ecb9[_0x1f74('0x44')]);_0x435880[_0x1f74('0x46')]=_[_0x1f74('0x47')](_0x435880[_0x1f74('0x43')],_0x435880['query']);_0x31ee22[_0x1f74('0x48')]=_[_0x1f74('0x47')](_0x435880[_0x1f74('0x43')],qs[_0x1f74('0x49')](_0x52ecb9[_0x1f74('0x44')][_0x1f74('0x49')]));_0x31ee22['attributes']=_0x31ee22['attributes'][_0x1f74('0x73')]?_0x31ee22[_0x1f74('0x48')]:_0x435880[_0x1f74('0x43')];if(!_0x52ecb9[_0x1f74('0x44')][_0x1f74('0x4a')](_0x1f74('0x4b'))){_0x31ee22[_0x1f74('0x2f')]=qs[_0x1f74('0x2f')](_0x52ecb9[_0x1f74('0x44')]['limit']);_0x31ee22['offset']=qs[_0x1f74('0x2d')](_0x52ecb9[_0x1f74('0x44')][_0x1f74('0x2d')]);}_0x31ee22[_0x1f74('0x64')]=qs[_0x1f74('0x4c')](_0x52ecb9[_0x1f74('0x44')][_0x1f74('0x4c')]);_0x31ee22[_0x1f74('0x4d')]=qs['filters'](_[_0x1f74('0x65')](_0x52ecb9[_0x1f74('0x44')],_0x435880['filters']));_0x31ee22[_0x1f74('0x4d')][_0x1f74('0x61')]=_0x5aa42c['id'];if(_0x52ecb9['query'][_0x1f74('0x66')]){_0x31ee22[_0x1f74('0x4d')]=_[_0x1f74('0x4e')](_0x31ee22[_0x1f74('0x4d')],{'$or':_[_0x1f74('0x3d')](_0x31ee22[_0x1f74('0x48')],function(_0x52c907){var _0x2dcaab={};_0x2dcaab[_0x52c907]={'$like':'%'+_0x52ecb9[_0x1f74('0x44')][_0x1f74('0x66')]+'%'};return _0x2dcaab;})});}_0x31ee22=_['merge']({},_0x31ee22,_0x52ecb9['options']);return db[_0x1f74('0x72')][_0x1f74('0x30')]({'where':_0x31ee22[_0x1f74('0x4d')]})[_0x1f74('0x21')](function(_0x2b4f27){_0x52fdbf[_0x1f74('0x30')]=_0x2b4f27;if(_0x52ecb9[_0x1f74('0x44')][_0x1f74('0x67')]){_0x31ee22[_0x1f74('0x51')]=[{'model':db[_0x1f74('0x74')],'as':_0x1f74('0x75'),'required':![]},{'model':db[_0x1f74('0x76')],'as':_0x1f74('0x77'),'attributes':[_0x1f74('0x39'),_0x1f74('0x78'),_0x1f74('0x79')],'required':![]},{'model':db[_0x1f74('0x7a')],'as':_0x1f74('0x7b'),'attributes':['id',_0x1f74('0x39'),_0x1f74('0x7c')],'where':_0x52ecb9[_0x1f74('0x44')][_0x1f74('0x7d')]?{'id':_0x52ecb9[_0x1f74('0x44')][_0x1f74('0x7d')]}:undefined,'required':_0x52ecb9['query'][_0x1f74('0x7d')]?!![]:![]}];}return db[_0x1f74('0x72')]['findAll'](_0x31ee22);})[_0x1f74('0x21')](function(_0x5cdd1f){_0x52fdbf['rows']=_0x5cdd1f;return _0x52fdbf;});}})[_0x1f74('0x21')](respondWithFilteredResult(_0x3450ff,_0x31ee22))['catch'](handleError(_0x3450ff,null));};exports['addApplications']=function(_0x36ee87,_0x544c61){var _0x3b7fe5=_0x36ee87['params']['id'];var _0xb1aed8=_0x36ee87[_0x1f74('0x57')];var _0x5bff9b=0xc8;var _0x18d2f3=null;return db[_0x1f74('0x7e')][_0x1f74('0x7f')]({'isolationLevel':db[_0x1f74('0x7e')][_0x1f74('0x80')]['ISOLATION_LEVELS'][_0x1f74('0x81')]},function(_0x331253){return db['FaxAccount'][_0x1f74('0x62')]({'where':{'id':_0x3b7fe5},'transaction':_0x331253})['then'](function(_0x3d280f){if(_0x3d280f){return db[_0x1f74('0x82')][_0x1f74('0x35')]({'where':{'FaxAccountId':_0x3b7fe5},'transaction':_0x331253})[_0x1f74('0x21')](function(){var _0x250faf=_[_0x1f74('0x3d')](_0xb1aed8,function(_0x741c92){_0x741c92[_0x1f74('0x61')]=_0x3b7fe5;return _0x741c92;});return db[_0x1f74('0x82')][_0x1f74('0x83')](_0x250faf,{'transaction':_0x331253});});}else{_0x5bff9b=0x194;_0x18d2f3=[];}});})[_0x1f74('0x21')](function(){if(_0x5bff9b!==0x194){return db[_0x1f74('0x82')][_0x1f74('0x84')]({'where':{'FaxAccountId':_0x3b7fe5},'order':_0x1f74('0x85')})[_0x1f74('0x21')](function(_0x4aac8e){_0x18d2f3=_0x4aac8e;});}})[_0x1f74('0x53')](function(_0x193887){_0x5bff9b=0x1f4;logger[_0x1f74('0x26')](_0x193887[_0x1f74('0x38')]);if(_0x193887[_0x1f74('0x39')]){delete _0x193887[_0x1f74('0x39')];}_0x18d2f3=_0x193887;})[_0x1f74('0x86')](function(){if(_0x18d2f3===null){_0x544c61['sendStatus'](_0x5bff9b);}else{if(_0x5bff9b===0x1f4){_0x544c61[_0x1f74('0x2a')](_0x5bff9b)['send'](_0x18d2f3);}else{_0x544c61['status'](_0x5bff9b)[_0x1f74('0x2c')](_0x18d2f3);}}});};exports['getApplications']=function(_0x1b5df2,_0x4c0b44,_0x12bae4){var _0x1d502a={};var _0x566bb5={};var _0xdfd49d;var _0x2f4774;return db[_0x1f74('0x3e')][_0x1f74('0x62')]({'where':{'id':_0x1b5df2['params']['id']}})[_0x1f74('0x21')](handleEntityNotFound(_0x4c0b44,null))['then'](function(_0x5a263a){if(_0x5a263a){_0xdfd49d=_0x5a263a;_0x566bb5['model']=_[_0x1f74('0x45')](db[_0x1f74('0x82')]['rawAttributes']);_0x566bb5[_0x1f74('0x44')]=_[_0x1f74('0x45')](_0x1b5df2[_0x1f74('0x44')]);_0x566bb5[_0x1f74('0x46')]=_[_0x1f74('0x47')](_0x566bb5[_0x1f74('0x43')],_0x566bb5[_0x1f74('0x44')]);_0x1d502a[_0x1f74('0x48')]=_['intersection'](_0x566bb5['model'],qs[_0x1f74('0x49')](_0x1b5df2['query'][_0x1f74('0x49')]));_0x1d502a[_0x1f74('0x48')]=_0x1d502a[_0x1f74('0x48')]['length']?_0x1d502a[_0x1f74('0x48')]:_0x566bb5['model'];_0x1d502a[_0x1f74('0x64')]=qs[_0x1f74('0x4c')](_0x1b5df2['query'][_0x1f74('0x4c')]);_0x1d502a[_0x1f74('0x4d')]=qs['filters'](_[_0x1f74('0x65')](_0x1b5df2[_0x1f74('0x44')],_0x566bb5[_0x1f74('0x46')]));if(_0x1b5df2[_0x1f74('0x44')][_0x1f74('0x66')]){_0x1d502a['where']=_[_0x1f74('0x4e')](_0x1d502a['where'],{'$or':_[_0x1f74('0x3d')](_0x1d502a[_0x1f74('0x48')],function(_0x548b56){var _0x46561f={};_0x46561f[_0x548b56]={'$like':'%'+_0x1b5df2[_0x1f74('0x44')][_0x1f74('0x66')]+'%'};return _0x46561f;})});}_0x1d502a=_[_0x1f74('0x4e')]({},_0x1d502a,_0x1b5df2['options']);return _0xdfd49d['getApplications'](_0x1d502a);}})[_0x1f74('0x21')](function(_0x177336){if(_0x177336){_0x2f4774=_0x177336[_0x1f74('0x73')];if(!_0x1b5df2[_0x1f74('0x44')][_0x1f74('0x4a')](_0x1f74('0x4b'))){_0x1d502a[_0x1f74('0x2f')]=qs[_0x1f74('0x2f')](_0x1b5df2[_0x1f74('0x44')][_0x1f74('0x2f')]);_0x1d502a[_0x1f74('0x2d')]=qs[_0x1f74('0x2d')](_0x1b5df2[_0x1f74('0x44')][_0x1f74('0x2d')]);}return _0xdfd49d[_0x1f74('0x87')](_0x1d502a);}})[_0x1f74('0x21')](function(_0x345bc7){if(_0x345bc7){return _0x345bc7?{'count':_0x2f4774,'rows':_0x345bc7}:null;}})['then'](respondWithResult(_0x4c0b44,null))['catch'](handleError(_0x4c0b44,null));};function Extension(_0x3731f6,_0x402c40,_0x506c04,_0x3e11c3){this[_0x1f74('0x88')]='from-voip-provider';this['exten']=_0x3731f6[_0x1f74('0x89')];this[_0x1f74('0x8a')]=_0x3e11c3;this[_0x1f74('0x41')]=_0x1f74('0x8b');this['description']=_0x1f74('0x8c');this[_0x1f74('0x61')]=_0x3731f6['id'];this[_0x1f74('0x85')]=_0x402c40;this[_0x1f74('0x8d')]=_0x506c04;}function createExtensionsReciveFax(_0x3f1ae2){var _0x2debaa=0x1;var _0x3e38a2=[];_0x3e38a2[_0x1f74('0x8e')](new Extension(_0x3f1ae2,_0x2debaa,'',_0x1f74('0x8f')));_0x2debaa+=0x1;_0x3e38a2[_0x1f74('0x8e')](new Extension(_0x3f1ae2,_0x2debaa,'CDR(type)=inbound-fax',_0x1f74('0x90')));_0x2debaa+=0x1;for(var _0x187269 in _0x3f1ae2){if(_0x3f1ae2['hasOwnProperty'](_0x187269)&&(_0x187269===_0x1f74('0x91')||_0x187269===_0x1f74('0x89')||_0x187269===_0x1f74('0x92')||_0x187269===_0x1f74('0x93')||_0x187269===_0x1f74('0x94')||_0x187269===_0x1f74('0x95')||_0x187269===_0x1f74('0x96')||_0x187269===_0x1f74('0x97')||_0x187269==='t38timeout')){_0x3e38a2[_0x1f74('0x8e')](new Extension(_0x3f1ae2,_0x2debaa,_0x1f74('0x98')+_0x187269+')='+_0x3f1ae2[_0x187269],_0x1f74('0x90')));_0x2debaa+=0x1;}}_0x3e38a2[_0x1f74('0x8e')](new Extension(_0x3f1ae2,_0x2debaa,'6',_0x1f74('0x99')));_0x2debaa+=0x1;_0x3e38a2['push'](new Extension(_0x3f1ae2,_0x2debaa,_0x1f74('0x9a'),_0x1f74('0x9b')));_0x2debaa=0x0;return _0x3e38a2;}exports['addAccountApplications']=function(_0xebfb03,_0x50c3ae,_0x42e63c){var _0x50a6c1;return db[_0x1f74('0x7e')]['transaction'](function(_0x31fec6){return db[_0x1f74('0x3e')][_0x1f74('0x56')](_0xebfb03[_0x1f74('0x57')],{'transaction':_0x31fec6})[_0x1f74('0x21')](function(_0x27cf46){_0x50a6c1=_0x27cf46[_0x1f74('0x59')]({'plain':!![]});return db[_0x1f74('0x9c')][_0x1f74('0x83')](createExtensionsReciveFax(_0x50a6c1),{'transaction':_0x31fec6});});})['then'](function(){return _0x50a6c1;})['then'](respondWithResult(_0x50c3ae,null))['catch'](handleError(_0x50c3ae,null));};exports[_0x1f74('0x9d')]=function(_0x35365f,_0x25ee76,_0x40ed8c){var _0x57ae7d;return db[_0x1f74('0x7e')][_0x1f74('0x7f')](function(_0x72d08f){return db[_0x1f74('0x3e')]['update'](_0x35365f[_0x1f74('0x57')],{'where':{'id':_0x35365f[_0x1f74('0x57')]['id']},'transaction':_0x72d08f})['then'](function(_0x338202){return db[_0x1f74('0x9c')][_0x1f74('0x35')]({'where':{'FaxAccountId':_0x35365f['body']['id']},'transaction':_0x72d08f})[_0x1f74('0x21')](function(_0x1263f9){return db[_0x1f74('0x9c')][_0x1f74('0x83')](createExtensionsReciveFax(_[_0x1f74('0x70')](_0x35365f[_0x1f74('0x57')],[_0x1f74('0x9e'),'key',_0x1f74('0x9f'),'updatedAt','TrunkId','ListId'])),{'transaction':_0x72d08f});});});})[_0x1f74('0x21')](function(){return db[_0x1f74('0x3e')]['findById'](_0x35365f['body']['id']);})[_0x1f74('0x21')](respondWithResult(_0x25ee76,null))['catch'](handleError(_0x25ee76,null));};exports['getMessages']=function(_0x244043,_0x5d884e,_0x14a3a8){var _0x145348={'raw':!![],'where':{}};var _0x1a043e={};var _0x5c740a={'count':0x0,'rows':[]};return db['FaxAccount'][_0x1f74('0x62')]({'where':{'id':_0x244043['params']['id']}})[_0x1f74('0x21')](handleEntityNotFound(_0x5d884e,null))[_0x1f74('0x21')](function(_0x167273){if(_0x167273){_0x1a043e[_0x1f74('0x43')]=_['keys'](db[_0x1f74('0xa0')][_0x1f74('0x3f')]);_0x1a043e[_0x1f74('0x44')]=_[_0x1f74('0x45')](_0x244043[_0x1f74('0x44')]);_0x1a043e['filters']=_[_0x1f74('0x47')](_0x1a043e[_0x1f74('0x43')],_0x1a043e[_0x1f74('0x44')]);_0x145348[_0x1f74('0x48')]=_[_0x1f74('0x47')](_0x1a043e[_0x1f74('0x43')],qs[_0x1f74('0x49')](_0x244043[_0x1f74('0x44')][_0x1f74('0x49')]));_0x145348[_0x1f74('0x48')]=_0x145348[_0x1f74('0x48')]['length']?_0x145348[_0x1f74('0x48')]:_0x1a043e[_0x1f74('0x43')];if(!_0x244043[_0x1f74('0x44')][_0x1f74('0x4a')](_0x1f74('0x4b'))){_0x145348[_0x1f74('0x2f')]=qs[_0x1f74('0x2f')](_0x244043[_0x1f74('0x44')]['limit']);_0x145348[_0x1f74('0x2d')]=qs[_0x1f74('0x2d')](_0x244043[_0x1f74('0x44')][_0x1f74('0x2d')]);}_0x145348[_0x1f74('0x64')]=qs['sort'](_0x244043[_0x1f74('0x44')][_0x1f74('0x4c')]);_0x145348[_0x1f74('0x4d')]=qs[_0x1f74('0x46')](_[_0x1f74('0x65')](_0x244043[_0x1f74('0x44')],_0x1a043e[_0x1f74('0x46')]));_0x145348[_0x1f74('0x4d')][_0x1f74('0x61')]=_0x167273['id'];if(_0x244043['query'][_0x1f74('0x66')]){_0x145348[_0x1f74('0x4d')]=_[_0x1f74('0x4e')](_0x145348[_0x1f74('0x4d')],{'$or':_[_0x1f74('0x3d')](_0x145348[_0x1f74('0x48')],function(_0x2e28dd){var _0x18dc11={};_0x18dc11[_0x2e28dd]={'$like':'%'+_0x244043['query'][_0x1f74('0x66')]+'%'};return _0x18dc11;})});}if(_0x244043[_0x1f74('0x44')]['$gte']){var _0x3cd4c1=_0x244043[_0x1f74('0x44')]['$gte'][_0x1f74('0xa1')](',');var _0xf313b4={};_0xf313b4[_0x3cd4c1[0x0]]={'$gte':moment(_0x3cd4c1[0x1])[_0x1f74('0xa2')]('YYYY-MM-DD\x20HH:mm:ss')};_0x145348[_0x1f74('0x4d')]=_[_0x1f74('0x4e')](_0x145348[_0x1f74('0x4d')],_0xf313b4);}_0x145348=_[_0x1f74('0x4e')]({},_0x145348,_0x244043[_0x1f74('0x50')]);return db[_0x1f74('0xa0')][_0x1f74('0x30')]({'where':_0x145348[_0x1f74('0x4d')]})[_0x1f74('0x21')](function(_0x2c20aa){_0x5c740a[_0x1f74('0x30')]=_0x2c20aa;if(_0x244043[_0x1f74('0x44')][_0x1f74('0x67')]){_0x145348['include']=[{'all':!![]}];}return db['FaxMessage'][_0x1f74('0x68')](_0x145348);})[_0x1f74('0x21')](function(_0x248716){_0x5c740a[_0x1f74('0x52')]=_0x248716;return _0x5c740a;});}})[_0x1f74('0x21')](respondWithFilteredResult(_0x5d884e,_0x145348))['catch'](handleError(_0x5d884e,null));};exports[_0x1f74('0x3a')]=function(_0x211ae2,_0x482d6c,_0x44ea54){var _0x2f3c55,_0x5c44af={},_0x40c6c5;if(_0x211ae2[_0x1f74('0x57')]['to']){_0x40c6c5=_0x211ae2[_0x1f74('0x57')]['to'][0x0];}return db[_0x1f74('0x3e')][_0x1f74('0x55')]({'where':{'id':_0x211ae2['params']['id']},'include':[{'model':db['CmList'],'as':_0x1f74('0xa3'),'include':[{'model':db[_0x1f74('0x74')],'as':_0x1f74('0xa4'),'where':{'fax':_0x40c6c5},'limit':0x1,'order':[[_0x1f74('0xa5'),'DESC']]}]}]})[_0x1f74('0x21')](handleEntityNotFound(_0x482d6c,null))[_0x1f74('0x21')](function(_0x1c68a8){_0x2f3c55=_0x1c68a8;if(_0x211ae2[_0x1f74('0x57')]['attachments']&&_0x211ae2[_0x1f74('0x57')][_0x1f74('0xa6')][_0x1f74('0x73')]){for(var _0x5258c0=0x0;_0x5258c0<_0x211ae2['body'][_0x1f74('0xa6')][_0x1f74('0x73')];_0x5258c0+=0x1){_0x211ae2[_0x1f74('0x57')][_0x1f74('0xa6')][_0x5258c0]={'filename':_0x211ae2[_0x1f74('0x57')][_0x1f74('0xa6')][_0x5258c0][_0x1f74('0x39')],'id':_0x211ae2[_0x1f74('0x57')]['attachments'][_0x5258c0]['id'],'path':path[_0x1f74('0xa7')](config[_0x1f74('0xa8')],_0x1f74('0xa9'),_0x211ae2['body'][_0x1f74('0xa6')][_0x5258c0][_0x1f74('0xaa')])};}}return respondWithRpcPromise('CheckAfterSend','CheckAfterSend',{'FaxAccountId':_[_0x1f74('0xab')](_0x211ae2['params']['id'])?undefined:_0x211ae2[_0x1f74('0x5e')]['id'],'path':_['isNil'](_0x211ae2[_0x1f74('0x57')][_0x1f74('0xa6')][0x0]['path'])?undefined:_0x211ae2[_0x1f74('0x57')]['attachments'][0x0]['path'],'fax':_[_0x1f74('0xab')](_0x211ae2[_0x1f74('0x57')]['to'][0x0])?undefined:_0x211ae2[_0x1f74('0x57')]['to'][0x0]},client9002);})['then'](function(){if(_0x2f3c55){if(_['isNil'](_0x211ae2['body']['from'])){_0x211ae2['body'][_0x1f74('0xac')]=util[_0x1f74('0xa2')](_0x1f74('0xad'),_0x2f3c55[_0x1f74('0x39')],_0x2f3c55[_0x1f74('0xae')]);}if(_0x2f3c55[_0x1f74('0xa3')]){if(_0x2f3c55[_0x1f74('0xa3')][_0x1f74('0xa4')][_0x1f74('0x73')]){return _0x2f3c55[_0x1f74('0xa3')][_0x1f74('0xa4')][0x0];}else{return db[_0x1f74('0x74')][_0x1f74('0x56')](_[_0x1f74('0xaf')](_0x211ae2[_0x1f74('0x57')],{'firstName':_0x211ae2[_0x1f74('0x57')]['to'][0x0],'phone':_0x211ae2[_0x1f74('0x57')]['to'][0x0],'fax':_0x211ae2[_0x1f74('0x57')]['to'][0x0],'ListId':_0x2f3c55['ListId']}));}}else{throw new Error(_0x1f74('0xb0'));}}else{throw new Error(_0x1f74('0xb1'));}})[_0x1f74('0x21')](function(_0x2eb219){if(_0x2eb219){return db['FaxInteraction'][_0x1f74('0x55')]({'where':{'ContactId':_0x2eb219['id'],'closed':![],'FaxAccountId':_0x2f3c55['id']}})[_0x1f74('0x21')](function(_0x3fd080){if(_0x3fd080){return[_0x3fd080,![]];}return db[_0x1f74('0x72')][_0x1f74('0x56')]({'UserId':_0x211ae2[_0x1f74('0x58')]['id'],'ContactId':_0x2eb219['id'],'FaxAccountId':_0x2f3c55['id'],'fax':_0x211ae2['body']['to'][0x0],'firstMsgDirection':_0x1f74('0xb2'),'Messages':[_[_0x1f74('0x4e')](_0x211ae2[_0x1f74('0x57')],{'read':![],'body':_0x211ae2[_0x1f74('0x57')][_0x1f74('0xa6')][0x0][_0x1f74('0xb3')],'FaxAccountId':_0x2f3c55['id'],'UserId':_0x211ae2[_0x1f74('0x58')]['id'],'ContactId':_0x2eb219['id'],'AttachmentId':_0x211ae2[_0x1f74('0x57')][_0x1f74('0xa6')][0x0]['id']})]},{'include':[{'model':db[_0x1f74('0xa0')],'as':'Messages'}]})['then'](function(_0x4e4fc4){return[_0x4e4fc4,!![]];});});}else{throw new Error(_0x1f74('0xb4'));}})['spread'](function(_0x429951,_0x40b11e){if(_0x40b11e){return _0x429951;}return db[_0x1f74('0xa0')]['create']({'direction':'out','read':![],'body':_0x211ae2[_0x1f74('0x57')][_0x1f74('0xa6')][0x0][_0x1f74('0xb3')],'FaxAccountId':_0x2f3c55['id'],'FaxInteractionId':_0x429951['id'],'UserId':_0x211ae2['user']['id'],'ContactId':_0x429951[_0x1f74('0xb5')],'AttachmentId':_0x211ae2['body'][_0x1f74('0xa6')][0x0]['id']})[_0x1f74('0x21')](function(_0x5ac89f){_0x429951[_0x1f74('0xb6')][_0x1f74('0xb7')]=[];_0x429951['dataValues']['Messages']['push'](_0x5ac89f[_0x1f74('0xb6')]);return _0x429951;});})[_0x1f74('0x21')](function(_0x2b473a){respondWithRpcPromise(_0x1f74('0xb8'),_0x1f74('0xb8'),{'FaxAccountId':_[_0x1f74('0xab')](_0x211ae2[_0x1f74('0x5e')]['id'])?undefined:_0x211ae2[_0x1f74('0x5e')]['id'],'path':_[_0x1f74('0xab')](_0x211ae2[_0x1f74('0x57')][_0x1f74('0xa6')][0x0]['path'])?undefined:_0x211ae2[_0x1f74('0x57')]['attachments'][0x0][_0x1f74('0xb9')],'fax':_[_0x1f74('0xab')](_0x211ae2[_0x1f74('0x57')]['to'][0x0])?undefined:_0x211ae2[_0x1f74('0x57')]['to'][0x0],'AttachmentId':_0x211ae2['body'][_0x1f74('0xa6')][0x0]['id']},client9002)[_0x1f74('0x21')](function(_0x8df7be){logger[_0x1f74('0x28')]('SendFaxRpc,\x20%s',_0x8df7be);})[_0x1f74('0x53')](function(_0x128514){logger['info'](_0x1f74('0xba'),_0x128514);});return _0x2b473a;})[_0x1f74('0x21')](respondWithResult(_0x482d6c,null))[_0x1f74('0x53')](handleError(_0x482d6c,null));};exports[_0x1f74('0xbb')]=function(_0x178120,_0x32d40e,_0xc9c5ea){return db['FaxAccount']['find']({'where':{'id':_0x178120[_0x1f74('0x5e')]['id']}})['then'](handleEntityNotFound(_0x32d40e,null))[_0x1f74('0x21')](function(_0x4e91d2){if(_0x4e91d2){return _0x4e91d2[_0x1f74('0xbb')](_0x178120[_0x1f74('0x57')][_0x1f74('0x6a')],_[_0x1f74('0x70')](_0x178120['body'],[_0x1f74('0x6a'),'id'])||{})[_0x1f74('0xbc')](function(_0x452629){for(var _0x5fb51=0x0;_0x5fb51<_0x178120[_0x1f74('0x57')][_0x1f74('0x6a')][_0x1f74('0x73')];_0x5fb51+=0x1){socket[_0x1f74('0xbd')](_0x1f74('0xbe'),{'UserId':Number(_0x178120[_0x1f74('0x57')][_0x1f74('0x6a')][_0x5fb51]),'FaxAccountId':Number(_0x178120[_0x1f74('0x5e')]['id'])});}return _0x452629;});}})[_0x1f74('0x21')](respondWithResult(_0x32d40e,null))[_0x1f74('0x53')](handleError(_0x32d40e,null));};exports[_0x1f74('0xbf')]=function(_0xaf92d9,_0x1a1b12,_0x3f24ee){return db['FaxAccount']['find']({'where':{'id':_0xaf92d9['params']['id']}})[_0x1f74('0x21')](handleEntityNotFound(_0x1a1b12,null))[_0x1f74('0x21')](function(_0x122eee){if(_0x122eee){return _0x122eee['removeAgents'](_0xaf92d9[_0x1f74('0x44')]['ids'])[_0x1f74('0x21')](function(){if(_['isArray'](_0xaf92d9[_0x1f74('0x44')]['ids'])){for(var _0x4e340d=0x0;_0x4e340d<_0xaf92d9[_0x1f74('0x44')][_0x1f74('0x6a')][_0x1f74('0x73')];_0x4e340d+=0x1){socket[_0x1f74('0xbd')](_0x1f74('0xc0'),{'UserId':Number(_0xaf92d9['query'][_0x1f74('0x6a')][_0x4e340d]),'FaxAccountId':Number(_0xaf92d9[_0x1f74('0x5e')]['id'])});}}else{socket['emit'](_0x1f74('0xc0'),{'UserId':Number(_0xaf92d9['query']['ids']),'FaxAccountId':Number(_0xaf92d9['params']['id'])});}});}})[_0x1f74('0x21')](respondWithStatusCode(_0x1a1b12,null))[_0x1f74('0x53')](handleError(_0x1a1b12,null));};exports[_0x1f74('0xc1')]=function(_0x388204,_0xfa0a60,_0x276761){var _0x2bdf46={};var _0xec575e={};var _0x3a0fd6;var _0x40ee44;return db[_0x1f74('0x3e')][_0x1f74('0x62')]({'where':{'id':_0x388204['params']['id']}})['then'](handleEntityNotFound(_0xfa0a60,null))[_0x1f74('0x21')](function(_0x40f7e2){if(_0x40f7e2){_0x3a0fd6=_0x40f7e2;_0xec575e[_0x1f74('0x43')]=_[_0x1f74('0x45')](db[_0x1f74('0x76')][_0x1f74('0x3f')]);_0xec575e['query']=_[_0x1f74('0x45')](_0x388204[_0x1f74('0x44')]);_0xec575e[_0x1f74('0x46')]=_[_0x1f74('0x47')](_0xec575e[_0x1f74('0x43')],_0xec575e[_0x1f74('0x44')]);_0x2bdf46[_0x1f74('0x48')]=_[_0x1f74('0x47')](_0xec575e['model'],qs[_0x1f74('0x49')](_0x388204[_0x1f74('0x44')][_0x1f74('0x49')]));_0x2bdf46[_0x1f74('0x48')]=_0x2bdf46['attributes'][_0x1f74('0x73')]?_0x2bdf46['attributes']:_0xec575e['model'];_0x2bdf46[_0x1f74('0x64')]=qs[_0x1f74('0x4c')](_0x388204['query'][_0x1f74('0x4c')]);_0x2bdf46[_0x1f74('0x4d')]=qs[_0x1f74('0x46')](_[_0x1f74('0x65')](_0x388204[_0x1f74('0x44')],_0xec575e[_0x1f74('0x46')]));if(_0x388204['query'][_0x1f74('0x66')]){_0x2bdf46[_0x1f74('0x4d')]=_[_0x1f74('0x4e')](_0x2bdf46['where'],{'$or':_[_0x1f74('0x3d')](_0x2bdf46[_0x1f74('0x48')],function(_0x369e0f){var _0x31e347={};_0x31e347[_0x369e0f]={'$like':'%'+_0x388204[_0x1f74('0x44')][_0x1f74('0x66')]+'%'};return _0x31e347;})});}_0x2bdf46=_[_0x1f74('0x4e')]({},_0x2bdf46,_0x388204[_0x1f74('0x50')]);return _0x3a0fd6[_0x1f74('0xc1')](_0x2bdf46);}})['then'](function(_0x1456ee){if(_0x1456ee){_0x40ee44=_0x1456ee['length'];if(!_0x388204[_0x1f74('0x44')][_0x1f74('0x4a')]('nolimit')){_0x2bdf46[_0x1f74('0x2f')]=qs[_0x1f74('0x2f')](_0x388204[_0x1f74('0x44')][_0x1f74('0x2f')]);_0x2bdf46[_0x1f74('0x2d')]=qs[_0x1f74('0x2d')](_0x388204[_0x1f74('0x44')]['offset']);}return _0x3a0fd6[_0x1f74('0xc1')](_0x2bdf46);}})['then'](function(_0x33665b){if(_0x33665b){return _0x33665b?{'count':_0x40ee44,'rows':_0x33665b}:null;}})[_0x1f74('0x21')](respondWithResult(_0xfa0a60,null))[_0x1f74('0x53')](handleError(_0xfa0a60,null));};