1e805514af6ba4493c657463b1601dbaa08f9cbd
[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 _0x2b36=['../../config/utils','../../config/environment','../../config/license/util','redis','defaults','localhost','jayson/promise','http','request','then','info','FaxAccount,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','sendStatus','status','end','undefined','limit','count','offset','set','json','apply','save','destroy','get','FaxAccounts','UserProfileResource','stack','name','send','render','merge','contact','agent','account','index','Pause','map','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','pick','filter','where','type','VIRTUAL','options','includeAll','include','FaxAccount','findAll','rows','show','params','mandatoryDispositionPause','rawAttributes','find','catch','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','autoAssociation','update','describe','addDisposition','FaxAccountId','Disposition','getDispositions','findOne','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','addInteraction','FaxInteraction','getInteractions','CmContact','Contact','User','Owner','fullname','Tag','color','tag','sequelize','transaction','FaxApplication','findAndCountAll','priority','getApplications','order','context','localstationid','system','Fax\x20Extension','appdata','push','Answer','CDR(type)=inbound-fax','Set','ecm','faxdetect','headerinfo','maxrate','minrate','modem','t38timeout','FAXOPT(','Wait','/var/opt/motion2/server/files/attachments/fax-${CALLERID(num)}-${CUT(UNIQUEID,.,1)}-${CUT(UNIQUEID,.,2)}-${STRFTIME(,,%C%y%m%d%H%M%S)}-rx.tif,d','ReceiveFax','addAccountApplications','VoiceExtension','bulkCreate','updateAccountApplications','omit','tech','key','createdAt','updatedAt','TrunkId','ListId','getMessages','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','FaxMessage','List','Contacts','DESC','attachments','join','root','server/files/attachments','basename','CheckAfterSend','isNil','from','\x22%s\x22\x20<%s>','fax','List\x20not\x20found','Send\x20Fax\x20failed','out','filename','spread','ContactId','dataValues','Messages','SendFax','SendFaxRpc,\x20%s','addAgents','userFaxAccount:save','removeAgents','isArray','emit','userFaxAccount:remove','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api'];(function(_0x3a6e02,_0x302489){var _0x270437=function(_0x3ca1fd){while(--_0x3ca1fd){_0x3a6e02['push'](_0x3a6e02['shift']());}};_0x270437(++_0x302489);}(_0x2b36,0x17d));var _0x62b3=function(_0x5f1dbf,_0x418b27){_0x5f1dbf=_0x5f1dbf-0x0;var _0x81790b=_0x2b36[_0x5f1dbf];return _0x81790b;};'use strict';var emlformat=require(_0x62b3('0x0'));var rimraf=require(_0x62b3('0x1'));var zipdir=require(_0x62b3('0x2'));var jsonpatch=require(_0x62b3('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x62b3('0x4'));var Mustache=require(_0x62b3('0x5'));var util=require(_0x62b3('0x6'));var path=require(_0x62b3('0x7'));var sox=require(_0x62b3('0x8'));var csv=require(_0x62b3('0x9'));var ejs=require(_0x62b3('0xa'));var fs=require('fs');var fs_extra=require(_0x62b3('0xb'));var _=require(_0x62b3('0xc'));var squel=require(_0x62b3('0xd'));var crypto=require(_0x62b3('0xe'));var jsforce=require(_0x62b3('0xf'));var deskjs=require(_0x62b3('0x10'));var toCsv=require('to-csv');var querystring=require(_0x62b3('0x11'));var Papa=require(_0x62b3('0x12'));var Redis=require(_0x62b3('0x13'));var authService=require('../../components/auth/service');var qs=require(_0x62b3('0x14'));var as=require(_0x62b3('0x15'));var hardwareService=require(_0x62b3('0x16'));var logger=require(_0x62b3('0x17'))(_0x62b3('0x18'));var utils=require(_0x62b3('0x19'));var config=require(_0x62b3('0x1a'));var licenseUtil=require(_0x62b3('0x1b'));var db=require('../../mysqldb')['db'];config[_0x62b3('0x1c')]=_[_0x62b3('0x1d')](config[_0x62b3('0x1c')],{'host':_0x62b3('0x1e'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x62b3('0x1c')]));require('./faxAccount.socket')['register'](socket);var jayson=require(_0x62b3('0x1f'));var client=jayson['client']['http']({'port':0x232c});var client9002=jayson['client'][_0x62b3('0x20')]({'port':0x232a});function respondWithRpcPromise(_0x6049da,_0x28474d,_0x3fe5c7,_0x39de23){return new BPromise(function(_0x573196,_0x1fc958){var _0x5ee995=_0x39de23||client;return _0x5ee995[_0x62b3('0x21')](_0x6049da,_0x3fe5c7)[_0x62b3('0x22')](function(_0x5d9dd7){logger[_0x62b3('0x23')](_0x62b3('0x24'),_0x28474d,_0x62b3('0x25'));logger[_0x62b3('0x26')]('FaxAccount,\x20%s,\x20%s,\x20%s',_0x28474d,_0x62b3('0x25'),JSON[_0x62b3('0x27')](_0x5d9dd7));if(_0x5d9dd7[_0x62b3('0x28')]){if(_0x5d9dd7[_0x62b3('0x28')][_0x62b3('0x29')]===0x1f4){logger['error'](_0x62b3('0x24'),_0x28474d,_0x5d9dd7['error'][_0x62b3('0x2a')]);return _0x1fc958(_0x5d9dd7[_0x62b3('0x28')][_0x62b3('0x2a')]);}logger['error'](_0x62b3('0x24'),_0x28474d,_0x5d9dd7[_0x62b3('0x28')][_0x62b3('0x2a')]);return _0x573196(_0x5d9dd7[_0x62b3('0x28')]['message']);}else{logger[_0x62b3('0x23')](_0x62b3('0x24'),_0x28474d,_0x62b3('0x25'));_0x573196(_0x5d9dd7[_0x62b3('0x2b')][_0x62b3('0x2a')]);}})['catch'](function(_0x1019a0){logger['error'](_0x62b3('0x24'),_0x28474d,_0x1019a0);_0x1fc958(_0x1019a0);});});}function respondWithStatusCode(_0x136d7f,_0x56c772){_0x56c772=_0x56c772||0xcc;return function(_0x419151){if(_0x419151){return _0x136d7f[_0x62b3('0x2c')](_0x56c772);}return _0x136d7f[_0x62b3('0x2d')](_0x56c772)[_0x62b3('0x2e')]();};}function respondWithResult(_0x461de4,_0x209670){_0x209670=_0x209670||0xc8;return function(_0x1ff77c){if(_0x1ff77c){return _0x461de4[_0x62b3('0x2d')](_0x209670)['json'](_0x1ff77c);}};}function respondWithFilteredResult(_0x12fbdd,_0x1606b3){return function(_0x1724a8){if(_0x1724a8){var _0x5f118a=typeof _0x1606b3['offset']===_0x62b3('0x2f')&&typeof _0x1606b3[_0x62b3('0x30')]===_0x62b3('0x2f');var _0x2d1cb2=_0x1724a8[_0x62b3('0x31')];var _0x382119=_0x5f118a?0x0:_0x1606b3[_0x62b3('0x32')];var _0x460030=_0x5f118a?_0x1724a8[_0x62b3('0x31')]:_0x1606b3['offset']+_0x1606b3[_0x62b3('0x30')];var _0x2ff733;if(_0x460030>=_0x2d1cb2){_0x460030=_0x2d1cb2;_0x2ff733=0xc8;}else{_0x2ff733=0xce;}_0x12fbdd['status'](_0x2ff733);return _0x12fbdd[_0x62b3('0x33')]('Content-Range',_0x382119+'-'+_0x460030+'/'+_0x2d1cb2)[_0x62b3('0x34')](_0x1724a8);}return null;};}function patchUpdates(_0x45187e){return function(_0xffffcc){try{jsonpatch[_0x62b3('0x35')](_0xffffcc,_0x45187e,!![]);}catch(_0x2b101b){return BPromise['reject'](_0x2b101b);}return _0xffffcc[_0x62b3('0x36')]();};}function saveUpdates(_0x4268d8,_0x2e96d0){return function(_0x26a842){if(_0x26a842){return _0x26a842['update'](_0x4268d8)[_0x62b3('0x22')](function(_0x3d9eed){return _0x3d9eed;});}return null;};}function removeEntity(_0x4c102e,_0x1d5e95){return function(_0x180697){if(_0x180697){return _0x180697[_0x62b3('0x37')]()[_0x62b3('0x22')](function(){var _0x350993=_0x180697[_0x62b3('0x38')]({'plain':!![]});var _0x18d38f=_0x62b3('0x39');return db[_0x62b3('0x3a')]['destroy']({'where':{'type':_0x18d38f,'resourceId':_0x350993['id']}})['then'](function(){return _0x180697;});})[_0x62b3('0x22')](function(){_0x4c102e[_0x62b3('0x2d')](0xcc)[_0x62b3('0x2e')]();});}};}function handleEntityNotFound(_0x1aefa1,_0x55b665){return function(_0x86ec73){if(!_0x86ec73){_0x1aefa1[_0x62b3('0x2c')](0x194);}return _0x86ec73;};}function handleError(_0x46c9d3,_0x8361b3){_0x8361b3=_0x8361b3||0x1f4;return function(_0x3657ec){logger[_0x62b3('0x28')](_0x3657ec[_0x62b3('0x3b')]);if(_0x3657ec[_0x62b3('0x3c')]){delete _0x3657ec['name'];}_0x46c9d3[_0x62b3('0x2d')](_0x8361b3)[_0x62b3('0x3d')](_0x3657ec);};}function getMustacheRender(_0x373aa6,_0xa080e){return Mustache[_0x62b3('0x3e')](_0x373aa6,_[_0x62b3('0x3f')](_0xa080e['body'],{'contact':_0xa080e[_0x62b3('0x40')],'message':_0xa080e[_0x62b3('0x2a')],'agent':_0xa080e[_0x62b3('0x41')],'interaction':_0xa080e['interaction'],'account':_0xa080e[_0x62b3('0x42')]}))||'';}exports[_0x62b3('0x43')]=function(_0x55a893,_0x17566b){var _0x5ceaba={'include':[{'model':db[_0x62b3('0x44')],'as':'mandatoryDispositionPause'}]},_0x23c5c3={},_0x424536={'count':0x0,'rows':[]};var _0x53283a=_[_0x62b3('0x45')](db['FaxAccount']['rawAttributes'],function(_0x1519cc){return{'name':_0x1519cc['fieldName'],'type':_0x1519cc['type']['key']};});_0x23c5c3[_0x62b3('0x46')]=_[_0x62b3('0x45')](_0x53283a,_0x62b3('0x3c'));_0x23c5c3[_0x62b3('0x47')]=_[_0x62b3('0x48')](_0x55a893[_0x62b3('0x47')]);_0x23c5c3[_0x62b3('0x49')]=_[_0x62b3('0x4a')](_0x23c5c3['model'],_0x23c5c3['query']);_0x5ceaba[_0x62b3('0x4b')]=_[_0x62b3('0x4a')](_0x23c5c3[_0x62b3('0x46')],qs[_0x62b3('0x4c')](_0x55a893['query'][_0x62b3('0x4c')]));_0x5ceaba['attributes']=_0x5ceaba[_0x62b3('0x4b')][_0x62b3('0x4d')]?_0x5ceaba['attributes']:_0x23c5c3['model'];if(!_0x55a893[_0x62b3('0x47')][_0x62b3('0x4e')](_0x62b3('0x4f'))){_0x5ceaba[_0x62b3('0x30')]=qs['limit'](_0x55a893[_0x62b3('0x47')][_0x62b3('0x30')]);_0x5ceaba[_0x62b3('0x32')]=qs[_0x62b3('0x32')](_0x55a893[_0x62b3('0x47')][_0x62b3('0x32')]);}_0x5ceaba['order']=qs[_0x62b3('0x50')](_0x55a893[_0x62b3('0x47')]['sort']);_0x5ceaba['where']=qs[_0x62b3('0x49')](_[_0x62b3('0x51')](_0x55a893['query'],_0x23c5c3['filters']),_0x53283a);if(_0x55a893[_0x62b3('0x47')][_0x62b3('0x52')]){_0x5ceaba[_0x62b3('0x53')]=_[_0x62b3('0x3f')](_0x5ceaba['where'],{'$or':_['map'](_0x53283a,function(_0x355ca8){if(_0x355ca8[_0x62b3('0x54')]!==_0x62b3('0x55')){var _0x24b99f={};_0x24b99f[_0x355ca8['name']]={'$like':'%'+_0x55a893[_0x62b3('0x47')][_0x62b3('0x52')]+'%'};return _0x24b99f;}})});}_0x5ceaba=_['merge']({},_0x5ceaba,_0x55a893[_0x62b3('0x56')]);var _0x47c147={'where':_0x5ceaba[_0x62b3('0x53')]};return db['FaxAccount'][_0x62b3('0x31')](_0x47c147)[_0x62b3('0x22')](function(_0x21b6b6){_0x424536[_0x62b3('0x31')]=_0x21b6b6;if(_0x55a893[_0x62b3('0x47')][_0x62b3('0x57')]){_0x5ceaba[_0x62b3('0x58')]=[{'all':!![]}];}return db[_0x62b3('0x59')][_0x62b3('0x5a')](_0x5ceaba);})[_0x62b3('0x22')](function(_0x1a7b05){_0x424536[_0x62b3('0x5b')]=_0x1a7b05;return _0x424536;})[_0x62b3('0x22')](respondWithFilteredResult(_0x17566b,_0x5ceaba))['catch'](handleError(_0x17566b,null));};exports[_0x62b3('0x5c')]=function(_0x4d96c2,_0x3a40bd){var _0x59b367={'raw':![],'where':{'id':_0x4d96c2[_0x62b3('0x5d')]['id']},'include':[{'model':db[_0x62b3('0x44')],'as':_0x62b3('0x5e')}]},_0xeeb95c={};_0xeeb95c[_0x62b3('0x46')]=_[_0x62b3('0x48')](db[_0x62b3('0x59')][_0x62b3('0x5f')]);_0xeeb95c['query']=_['keys'](_0x4d96c2[_0x62b3('0x47')]);_0xeeb95c[_0x62b3('0x49')]=_['intersection'](_0xeeb95c[_0x62b3('0x46')],_0xeeb95c['query']);_0x59b367['attributes']=_[_0x62b3('0x4a')](_0xeeb95c[_0x62b3('0x46')],qs[_0x62b3('0x4c')](_0x4d96c2[_0x62b3('0x47')][_0x62b3('0x4c')]));_0x59b367[_0x62b3('0x4b')]=_0x59b367[_0x62b3('0x4b')][_0x62b3('0x4d')]?_0x59b367[_0x62b3('0x4b')]:_0xeeb95c['model'];if(_0x4d96c2[_0x62b3('0x47')]['includeAll']){_0x59b367[_0x62b3('0x58')]=[{'all':!![]}];}_0x59b367=_[_0x62b3('0x3f')]({},_0x59b367,_0x4d96c2['options']);return db['FaxAccount'][_0x62b3('0x60')](_0x59b367)[_0x62b3('0x22')](handleEntityNotFound(_0x3a40bd,null))[_0x62b3('0x22')](respondWithResult(_0x3a40bd,null))[_0x62b3('0x61')](handleError(_0x3a40bd,null));};exports['create']=function(_0x23f049,_0x587d7a){return db[_0x62b3('0x59')][_0x62b3('0x62')](_0x23f049[_0x62b3('0x63')],{})[_0x62b3('0x22')](function(_0x4eadc4){var _0x1f26c0=_0x23f049[_0x62b3('0x64')]['get']({'plain':!![]});if(!_0x1f26c0)throw new Error(_0x62b3('0x65'));if(_0x1f26c0[_0x62b3('0x66')]===_0x62b3('0x64')){var _0x34f6f8=_0x4eadc4[_0x62b3('0x38')]({'plain':!![]});var _0x1d1a00=_0x62b3('0x39');return db['UserProfileSection'][_0x62b3('0x60')]({'where':{'name':_0x1d1a00,'userProfileId':_0x1f26c0[_0x62b3('0x67')]},'raw':!![]})[_0x62b3('0x22')](function(_0x418fdd){if(_0x418fdd&&_0x418fdd[_0x62b3('0x68')]===0x0){return db[_0x62b3('0x3a')][_0x62b3('0x62')]({'name':_0x34f6f8[_0x62b3('0x3c')],'resourceId':_0x34f6f8['id'],'type':_0x418fdd[_0x62b3('0x3c')],'sectionId':_0x418fdd['id']},{})[_0x62b3('0x22')](function(){return _0x4eadc4;});}else{return _0x4eadc4;}})[_0x62b3('0x61')](function(_0x2a6b20){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x2a6b20);throw _0x2a6b20;});}return _0x4eadc4;})['then'](respondWithResult(_0x587d7a,0xc9))[_0x62b3('0x61')](handleError(_0x587d7a,null));};exports[_0x62b3('0x69')]=function(_0x41e9dc,_0x55a647){if(_0x41e9dc['body']['id']){delete _0x41e9dc[_0x62b3('0x63')]['id'];}return db[_0x62b3('0x59')][_0x62b3('0x60')]({'where':{'id':_0x41e9dc[_0x62b3('0x5d')]['id']},'include':[{'model':db[_0x62b3('0x44')],'as':_0x62b3('0x5e')}]})[_0x62b3('0x22')](handleEntityNotFound(_0x55a647,null))[_0x62b3('0x22')](saveUpdates(_0x41e9dc[_0x62b3('0x63')],null))[_0x62b3('0x22')](respondWithResult(_0x55a647,null))[_0x62b3('0x61')](handleError(_0x55a647,null));};exports[_0x62b3('0x37')]=function(_0x1c6192,_0x25f738){return db[_0x62b3('0x59')]['find']({'where':{'id':_0x1c6192['params']['id']}})['then'](handleEntityNotFound(_0x25f738,null))[_0x62b3('0x22')](removeEntity(_0x25f738,null))[_0x62b3('0x61')](handleError(_0x25f738,null));};exports[_0x62b3('0x6a')]=function(_0x329ee9,_0x188322){return db['FaxAccount']['describe']()[_0x62b3('0x22')](respondWithResult(_0x188322,null))[_0x62b3('0x61')](handleError(_0x188322,null));};exports[_0x62b3('0x6b')]=function(_0x578325,_0x350d32,_0xcb1011){if(_0x578325[_0x62b3('0x63')]['id']){delete _0x578325[_0x62b3('0x63')]['id'];}return db[_0x62b3('0x59')]['find']({'where':{'id':_0x578325[_0x62b3('0x5d')]['id']}})[_0x62b3('0x22')](handleEntityNotFound(_0x350d32,null))[_0x62b3('0x22')](function(_0x56e4e8){if(_0x56e4e8){_0x578325[_0x62b3('0x63')][_0x62b3('0x6c')]=_0x56e4e8['id'];return db[_0x62b3('0x6d')]['create'](_0x578325[_0x62b3('0x63')]);}})[_0x62b3('0x22')](respondWithResult(_0x350d32,null))[_0x62b3('0x61')](handleError(_0x350d32,null));};exports[_0x62b3('0x6e')]=function(_0x47d9e5,_0x481281,_0x4c9c7f){var _0x28f208={'raw':![],'where':{}};var _0x3e63b9={};var _0x1617ff={'count':0x0,'rows':[]};return db['FaxAccount'][_0x62b3('0x6f')]({'where':{'id':_0x47d9e5[_0x62b3('0x5d')]['id']}})[_0x62b3('0x22')](handleEntityNotFound(_0x481281,null))[_0x62b3('0x22')](function(_0x5cf3c1){if(_0x5cf3c1){_0x3e63b9[_0x62b3('0x46')]=_['keys'](db[_0x62b3('0x6d')][_0x62b3('0x5f')]);_0x3e63b9['query']=_[_0x62b3('0x48')](_0x47d9e5[_0x62b3('0x47')]);_0x3e63b9[_0x62b3('0x49')]=_[_0x62b3('0x4a')](_0x3e63b9[_0x62b3('0x46')],_0x3e63b9['query']);_0x28f208[_0x62b3('0x4b')]=_[_0x62b3('0x4a')](_0x3e63b9['model'],qs[_0x62b3('0x4c')](_0x47d9e5[_0x62b3('0x47')][_0x62b3('0x4c')]));_0x28f208[_0x62b3('0x4b')]=_0x28f208[_0x62b3('0x4b')][_0x62b3('0x4d')]?_0x28f208[_0x62b3('0x4b')]:_0x3e63b9[_0x62b3('0x46')];if(!_0x47d9e5[_0x62b3('0x47')]['hasOwnProperty'](_0x62b3('0x4f'))){_0x28f208[_0x62b3('0x30')]=qs[_0x62b3('0x30')](_0x47d9e5[_0x62b3('0x47')][_0x62b3('0x30')]);_0x28f208[_0x62b3('0x32')]=qs[_0x62b3('0x32')](_0x47d9e5[_0x62b3('0x47')][_0x62b3('0x32')]);}_0x28f208['order']=qs[_0x62b3('0x50')](_0x47d9e5[_0x62b3('0x47')][_0x62b3('0x50')]);_0x28f208[_0x62b3('0x53')]=qs[_0x62b3('0x49')](_[_0x62b3('0x51')](_0x47d9e5['query'],_0x3e63b9[_0x62b3('0x49')]));_0x28f208[_0x62b3('0x53')][_0x62b3('0x6c')]=_0x5cf3c1['id'];if(_0x47d9e5[_0x62b3('0x47')][_0x62b3('0x52')]){_0x28f208['where']=_['merge'](_0x28f208[_0x62b3('0x53')],{'$or':_[_0x62b3('0x45')](_0x28f208[_0x62b3('0x4b')],function(_0x34b096){var _0x2ef0db={};_0x2ef0db[_0x34b096]={'$like':'%'+_0x47d9e5['query'][_0x62b3('0x52')]+'%'};return _0x2ef0db;})});}_0x28f208=_[_0x62b3('0x3f')]({},_0x28f208,_0x47d9e5['options']);return db['Disposition'][_0x62b3('0x31')]({'where':_0x28f208[_0x62b3('0x53')]})[_0x62b3('0x22')](function(_0x270833){_0x1617ff[_0x62b3('0x31')]=_0x270833;if(_0x47d9e5[_0x62b3('0x47')][_0x62b3('0x57')]){_0x28f208['include']=[{'all':!![]}];}return db['Disposition'][_0x62b3('0x5a')](_0x28f208);})['then'](function(_0x3fba82){_0x1617ff[_0x62b3('0x5b')]=_0x3fba82;return _0x1617ff;});}})[_0x62b3('0x22')](respondWithFilteredResult(_0x481281,_0x28f208))[_0x62b3('0x61')](handleError(_0x481281,null));};exports[_0x62b3('0x70')]=function(_0x11f1ce,_0x4ff644,_0x22eb12){return db['FaxAccount'][_0x62b3('0x60')]({'where':{'id':_0x11f1ce[_0x62b3('0x5d')]['id']}})[_0x62b3('0x22')](handleEntityNotFound(_0x4ff644,null))['then'](function(_0x3ff8c4){if(_0x3ff8c4){return _0x3ff8c4[_0x62b3('0x70')](_0x11f1ce[_0x62b3('0x47')][_0x62b3('0x71')]);}})['then'](respondWithStatusCode(_0x4ff644,null))[_0x62b3('0x61')](handleError(_0x4ff644,null));};exports[_0x62b3('0x72')]=function(_0x53a3a9,_0x3324c0,_0x5486bc){if(_0x53a3a9['body']['id']){delete _0x53a3a9['body']['id'];}return db['FaxAccount'][_0x62b3('0x60')]({'where':{'id':_0x53a3a9[_0x62b3('0x5d')]['id']}})[_0x62b3('0x22')](handleEntityNotFound(_0x3324c0,null))[_0x62b3('0x22')](function(_0x34befc){if(_0x34befc){_0x53a3a9['body'][_0x62b3('0x6c')]=_0x34befc['id'];return db[_0x62b3('0x73')]['create'](_0x53a3a9['body']);}})['then'](respondWithResult(_0x3324c0,null))[_0x62b3('0x61')](handleError(_0x3324c0,null));};exports[_0x62b3('0x74')]=function(_0x254e12,_0x2b17ff,_0x2e419b){var _0x4ed0a5={'raw':![],'where':{}};var _0x233c9f={};var _0x3c3e22={'count':0x0,'rows':[]};return db['FaxAccount']['findOne']({'where':{'id':_0x254e12[_0x62b3('0x5d')]['id']}})[_0x62b3('0x22')](handleEntityNotFound(_0x2b17ff,null))[_0x62b3('0x22')](function(_0x1b9112){if(_0x1b9112){_0x233c9f[_0x62b3('0x46')]=_[_0x62b3('0x48')](db[_0x62b3('0x73')][_0x62b3('0x5f')]);_0x233c9f[_0x62b3('0x47')]=_[_0x62b3('0x48')](_0x254e12['query']);_0x233c9f[_0x62b3('0x49')]=_[_0x62b3('0x4a')](_0x233c9f[_0x62b3('0x46')],_0x233c9f[_0x62b3('0x47')]);_0x4ed0a5[_0x62b3('0x4b')]=_[_0x62b3('0x4a')](_0x233c9f[_0x62b3('0x46')],qs[_0x62b3('0x4c')](_0x254e12['query'][_0x62b3('0x4c')]));_0x4ed0a5[_0x62b3('0x4b')]=_0x4ed0a5[_0x62b3('0x4b')][_0x62b3('0x4d')]?_0x4ed0a5[_0x62b3('0x4b')]:_0x233c9f[_0x62b3('0x46')];if(!_0x254e12[_0x62b3('0x47')][_0x62b3('0x4e')](_0x62b3('0x4f'))){_0x4ed0a5[_0x62b3('0x30')]=qs[_0x62b3('0x30')](_0x254e12[_0x62b3('0x47')]['limit']);_0x4ed0a5[_0x62b3('0x32')]=qs[_0x62b3('0x32')](_0x254e12[_0x62b3('0x47')][_0x62b3('0x32')]);}_0x4ed0a5['order']=qs['sort'](_0x254e12['query']['sort']);_0x4ed0a5['where']=qs[_0x62b3('0x49')](_['pick'](_0x254e12[_0x62b3('0x47')],_0x233c9f[_0x62b3('0x49')]));_0x4ed0a5[_0x62b3('0x53')][_0x62b3('0x6c')]=_0x1b9112['id'];if(_0x254e12[_0x62b3('0x47')]['filter']){_0x4ed0a5[_0x62b3('0x53')]=_['merge'](_0x4ed0a5[_0x62b3('0x53')],{'$or':_[_0x62b3('0x45')](_0x4ed0a5[_0x62b3('0x4b')],function(_0x327c83){var _0x3fab51={};_0x3fab51[_0x327c83]={'$like':'%'+_0x254e12['query'][_0x62b3('0x52')]+'%'};return _0x3fab51;})});}_0x4ed0a5=_['merge']({},_0x4ed0a5,_0x254e12['options']);return db[_0x62b3('0x73')]['count']({'where':_0x4ed0a5['where']})['then'](function(_0x459034){_0x3c3e22[_0x62b3('0x31')]=_0x459034;if(_0x254e12[_0x62b3('0x47')]['includeAll']){_0x4ed0a5['include']=[{'all':!![]}];}return db[_0x62b3('0x73')][_0x62b3('0x5a')](_0x4ed0a5);})[_0x62b3('0x22')](function(_0x1a6fe0){_0x3c3e22['rows']=_0x1a6fe0;return _0x3c3e22;});}})[_0x62b3('0x22')](respondWithFilteredResult(_0x2b17ff,_0x4ed0a5))[_0x62b3('0x61')](handleError(_0x2b17ff,null));};exports[_0x62b3('0x75')]=function(_0x56ba78,_0x19c37d,_0x22b632){return db[_0x62b3('0x59')][_0x62b3('0x60')]({'where':{'id':_0x56ba78[_0x62b3('0x5d')]['id']}})['then'](handleEntityNotFound(_0x19c37d,null))['then'](function(_0x23961f){if(_0x23961f){return _0x23961f[_0x62b3('0x75')](_0x56ba78[_0x62b3('0x47')][_0x62b3('0x71')]);}})[_0x62b3('0x22')](respondWithStatusCode(_0x19c37d,null))[_0x62b3('0x61')](handleError(_0x19c37d,null));};exports[_0x62b3('0x76')]=function(_0x18b951,_0x1006ec,_0x4007a1){return db[_0x62b3('0x77')]['find']({'where':{'id':_0x18b951[_0x62b3('0x5d')]['id']}})[_0x62b3('0x22')](handleEntityNotFound(_0x1006ec,null))[_0x62b3('0x22')](function(_0x1ca01c){if(_0x1ca01c){return _0x1ca01c['addInteraction'](_0x18b951[_0x62b3('0x63')][_0x62b3('0x71')],_['omit'](_0x18b951['body'],[_0x62b3('0x71'),'id'])||{});}})['then'](respondWithResult(_0x1006ec,null))[_0x62b3('0x61')](handleError(_0x1006ec,null));};exports[_0x62b3('0x78')]=function(_0x5dee6f,_0x4cf670,_0x11e8d6){var _0x49a343={'raw':![],'where':{}};var _0x19a34c={};var _0x4ab237={'count':0x0,'rows':[]};return db['FaxAccount'][_0x62b3('0x6f')]({'where':{'id':_0x5dee6f[_0x62b3('0x5d')]['id']}})[_0x62b3('0x22')](handleEntityNotFound(_0x4cf670,null))[_0x62b3('0x22')](function(_0x346d64){if(_0x346d64){_0x19a34c[_0x62b3('0x46')]=_[_0x62b3('0x48')](db['FaxInteraction'][_0x62b3('0x5f')]);_0x19a34c[_0x62b3('0x47')]=_['keys'](_0x5dee6f[_0x62b3('0x47')]);_0x19a34c[_0x62b3('0x49')]=_['intersection'](_0x19a34c[_0x62b3('0x46')],_0x19a34c['query']);_0x49a343[_0x62b3('0x4b')]=_[_0x62b3('0x4a')](_0x19a34c[_0x62b3('0x46')],qs[_0x62b3('0x4c')](_0x5dee6f[_0x62b3('0x47')][_0x62b3('0x4c')]));_0x49a343['attributes']=_0x49a343[_0x62b3('0x4b')]['length']?_0x49a343[_0x62b3('0x4b')]:_0x19a34c[_0x62b3('0x46')];if(!_0x5dee6f['query'][_0x62b3('0x4e')](_0x62b3('0x4f'))){_0x49a343['limit']=qs['limit'](_0x5dee6f[_0x62b3('0x47')][_0x62b3('0x30')]);_0x49a343['offset']=qs[_0x62b3('0x32')](_0x5dee6f[_0x62b3('0x47')][_0x62b3('0x32')]);}_0x49a343['order']=qs[_0x62b3('0x50')](_0x5dee6f['query'][_0x62b3('0x50')]);_0x49a343['where']=qs[_0x62b3('0x49')](_[_0x62b3('0x51')](_0x5dee6f[_0x62b3('0x47')],_0x19a34c[_0x62b3('0x49')]));_0x49a343[_0x62b3('0x53')][_0x62b3('0x6c')]=_0x346d64['id'];if(_0x5dee6f['query'][_0x62b3('0x52')]){_0x49a343[_0x62b3('0x53')]=_['merge'](_0x49a343[_0x62b3('0x53')],{'$or':_['map'](_0x49a343[_0x62b3('0x4b')],function(_0xb901b8){var _0x2baef7={};_0x2baef7[_0xb901b8]={'$like':'%'+_0x5dee6f['query'][_0x62b3('0x52')]+'%'};return _0x2baef7;})});}_0x49a343=_['merge']({},_0x49a343,_0x5dee6f[_0x62b3('0x56')]);return db['FaxInteraction']['count']({'where':_0x49a343[_0x62b3('0x53')]})[_0x62b3('0x22')](function(_0x394f3c){_0x4ab237[_0x62b3('0x31')]=_0x394f3c;if(_0x5dee6f[_0x62b3('0x47')][_0x62b3('0x57')]){_0x49a343['include']=[{'model':db[_0x62b3('0x79')],'as':_0x62b3('0x7a'),'required':![]},{'model':db[_0x62b3('0x7b')],'as':_0x62b3('0x7c'),'attributes':[_0x62b3('0x3c'),_0x62b3('0x7d'),'internal'],'required':![]},{'model':db[_0x62b3('0x7e')],'as':'Tags','attributes':['id',_0x62b3('0x3c'),_0x62b3('0x7f')],'where':_0x5dee6f['query'][_0x62b3('0x80')]?{'id':_0x5dee6f['query'][_0x62b3('0x80')]}:undefined,'required':_0x5dee6f['query'][_0x62b3('0x80')]?!![]:![]}];}return db[_0x62b3('0x77')][_0x62b3('0x5a')](_0x49a343);})[_0x62b3('0x22')](function(_0x3b6384){_0x4ab237[_0x62b3('0x5b')]=_0x3b6384;return _0x4ab237;});}})[_0x62b3('0x22')](respondWithFilteredResult(_0x4cf670,_0x49a343))[_0x62b3('0x61')](handleError(_0x4cf670,null));};exports['addApplications']=function(_0x8d18fc,_0x246cf7,_0x29314e){return db[_0x62b3('0x59')][_0x62b3('0x6f')]({'where':{'id':_0x8d18fc[_0x62b3('0x5d')]['id']}})['then'](handleEntityNotFound(_0x246cf7,null))[_0x62b3('0x22')](function(_0x1bf6b5){if(_0x1bf6b5){return db[_0x62b3('0x81')][_0x62b3('0x82')](function(_0x4fb013){return db[_0x62b3('0x83')][_0x62b3('0x37')]({'where':{'FaxAccountId':_0x8d18fc[_0x62b3('0x5d')]['id']},'transaction':_0x4fb013})[_0x62b3('0x22')](function(_0x18e7f7){var _0x6acb37=_['map'](_0x8d18fc['body'],function(_0x55015a){_0x55015a['FaxAccountId']=_0x8d18fc[_0x62b3('0x5d')]['id'];return _0x55015a;});return db[_0x62b3('0x83')]['bulkCreate'](_0x6acb37,{'transaction':_0x4fb013});});})[_0x62b3('0x22')](function(){return db['FaxApplication'][_0x62b3('0x84')]({'where':{'FaxAccountId':_0x8d18fc[_0x62b3('0x5d')]['id']},'order':_0x62b3('0x85')});});}})[_0x62b3('0x22')](respondWithResult(_0x246cf7,null))[_0x62b3('0x61')](handleError(_0x246cf7,null));};exports[_0x62b3('0x86')]=function(_0x5a0410,_0x22719a,_0x5a1561){var _0x2fe2d8={};var _0x17e907={};var _0x27becc;var _0x90993;return db[_0x62b3('0x59')][_0x62b3('0x6f')]({'where':{'id':_0x5a0410['params']['id']}})['then'](handleEntityNotFound(_0x22719a,null))[_0x62b3('0x22')](function(_0x27aa6b){if(_0x27aa6b){_0x27becc=_0x27aa6b;_0x17e907['model']=_['keys'](db[_0x62b3('0x83')][_0x62b3('0x5f')]);_0x17e907[_0x62b3('0x47')]=_[_0x62b3('0x48')](_0x5a0410[_0x62b3('0x47')]);_0x17e907[_0x62b3('0x49')]=_[_0x62b3('0x4a')](_0x17e907[_0x62b3('0x46')],_0x17e907[_0x62b3('0x47')]);_0x2fe2d8[_0x62b3('0x4b')]=_[_0x62b3('0x4a')](_0x17e907['model'],qs[_0x62b3('0x4c')](_0x5a0410[_0x62b3('0x47')][_0x62b3('0x4c')]));_0x2fe2d8[_0x62b3('0x4b')]=_0x2fe2d8['attributes'][_0x62b3('0x4d')]?_0x2fe2d8['attributes']:_0x17e907[_0x62b3('0x46')];_0x2fe2d8[_0x62b3('0x87')]=qs[_0x62b3('0x50')](_0x5a0410[_0x62b3('0x47')][_0x62b3('0x50')]);_0x2fe2d8[_0x62b3('0x53')]=qs['filters'](_[_0x62b3('0x51')](_0x5a0410[_0x62b3('0x47')],_0x17e907['filters']));if(_0x5a0410[_0x62b3('0x47')][_0x62b3('0x52')]){_0x2fe2d8[_0x62b3('0x53')]=_['merge'](_0x2fe2d8[_0x62b3('0x53')],{'$or':_['map'](_0x2fe2d8['attributes'],function(_0x12b491){var _0x8d85e0={};_0x8d85e0[_0x12b491]={'$like':'%'+_0x5a0410[_0x62b3('0x47')][_0x62b3('0x52')]+'%'};return _0x8d85e0;})});}_0x2fe2d8=_['merge']({},_0x2fe2d8,_0x5a0410[_0x62b3('0x56')]);return _0x27becc[_0x62b3('0x86')](_0x2fe2d8);}})[_0x62b3('0x22')](function(_0x46732e){if(_0x46732e){_0x90993=_0x46732e[_0x62b3('0x4d')];if(!_0x5a0410[_0x62b3('0x47')][_0x62b3('0x4e')](_0x62b3('0x4f'))){_0x2fe2d8[_0x62b3('0x30')]=qs[_0x62b3('0x30')](_0x5a0410[_0x62b3('0x47')]['limit']);_0x2fe2d8[_0x62b3('0x32')]=qs[_0x62b3('0x32')](_0x5a0410['query']['offset']);}return _0x27becc[_0x62b3('0x86')](_0x2fe2d8);}})[_0x62b3('0x22')](function(_0x4591e7){if(_0x4591e7){return _0x4591e7?{'count':_0x90993,'rows':_0x4591e7}:null;}})['then'](respondWithResult(_0x22719a,null))['catch'](handleError(_0x22719a,null));};function Extension(_0x41b5ae,_0x5af35a,_0x4baff0,_0x2bb91a){this[_0x62b3('0x88')]='from-voip-provider';this['exten']=_0x41b5ae[_0x62b3('0x89')];this['app']=_0x2bb91a;this[_0x62b3('0x54')]=_0x62b3('0x8a');this['description']=_0x62b3('0x8b');this[_0x62b3('0x6c')]=_0x41b5ae['id'];this[_0x62b3('0x85')]=_0x5af35a;this[_0x62b3('0x8c')]=_0x4baff0;}function createExtensionsReciveFax(_0x45e4b){var _0x211862=0x1;var _0x6f2c53=[];_0x6f2c53[_0x62b3('0x8d')](new Extension(_0x45e4b,_0x211862,'',_0x62b3('0x8e')));_0x211862+=0x1;_0x6f2c53[_0x62b3('0x8d')](new Extension(_0x45e4b,_0x211862,_0x62b3('0x8f'),_0x62b3('0x90')));_0x211862+=0x1;for(var _0x581ae5 in _0x45e4b){if(_0x45e4b[_0x62b3('0x4e')](_0x581ae5)&&(_0x581ae5===_0x62b3('0x91')||_0x581ae5==='localstationid'||_0x581ae5==='gateway'||_0x581ae5===_0x62b3('0x92')||_0x581ae5===_0x62b3('0x93')||_0x581ae5===_0x62b3('0x94')||_0x581ae5===_0x62b3('0x95')||_0x581ae5===_0x62b3('0x96')||_0x581ae5===_0x62b3('0x97'))){_0x6f2c53['push'](new Extension(_0x45e4b,_0x211862,_0x62b3('0x98')+_0x581ae5+')='+_0x45e4b[_0x581ae5],_0x62b3('0x90')));_0x211862+=0x1;}}_0x6f2c53[_0x62b3('0x8d')](new Extension(_0x45e4b,_0x211862,'6',_0x62b3('0x99')));_0x211862+=0x1;_0x6f2c53[_0x62b3('0x8d')](new Extension(_0x45e4b,_0x211862,_0x62b3('0x9a'),_0x62b3('0x9b')));_0x211862=0x0;return _0x6f2c53;}exports[_0x62b3('0x9c')]=function(_0x28c7a0,_0x244f07,_0x37726b){var _0x3dfec4;return db[_0x62b3('0x81')]['transaction'](function(_0x158404){return db['FaxAccount'][_0x62b3('0x62')](_0x28c7a0['body'],{'transaction':_0x158404})[_0x62b3('0x22')](function(_0x3b7f59){_0x3dfec4=_0x3b7f59['get']({'plain':!![]});return db[_0x62b3('0x9d')][_0x62b3('0x9e')](createExtensionsReciveFax(_0x3dfec4),{'transaction':_0x158404});});})[_0x62b3('0x22')](function(){return _0x3dfec4;})[_0x62b3('0x22')](respondWithResult(_0x244f07,null))[_0x62b3('0x61')](handleError(_0x244f07,null));};exports[_0x62b3('0x9f')]=function(_0x581c7a,_0x12ac45,_0x501775){var _0x42adbe;return db['sequelize'][_0x62b3('0x82')](function(_0x4ce863){return db[_0x62b3('0x59')][_0x62b3('0x69')](_0x581c7a[_0x62b3('0x63')],{'where':{'id':_0x581c7a['body']['id']},'transaction':_0x4ce863})['then'](function(_0x200f2d){return db[_0x62b3('0x9d')]['destroy']({'where':{'FaxAccountId':_0x581c7a[_0x62b3('0x63')]['id']},'transaction':_0x4ce863})[_0x62b3('0x22')](function(_0x5cb5fb){return db[_0x62b3('0x9d')]['bulkCreate'](createExtensionsReciveFax(_[_0x62b3('0xa0')](_0x581c7a['body'],[_0x62b3('0xa1'),_0x62b3('0xa2'),_0x62b3('0xa3'),_0x62b3('0xa4'),_0x62b3('0xa5'),_0x62b3('0xa6')])),{'transaction':_0x4ce863});});});})[_0x62b3('0x22')](function(){return db[_0x62b3('0x59')]['findById'](_0x581c7a[_0x62b3('0x63')]['id']);})[_0x62b3('0x22')](respondWithResult(_0x12ac45,null))['catch'](handleError(_0x12ac45,null));};exports[_0x62b3('0xa7')]=function(_0x10fc80,_0x5c3b58,_0x34ace3){var _0x165e91={'raw':!![],'where':{}};var _0x13cb71={};var _0x54e88d={'count':0x0,'rows':[]};return db['FaxAccount'][_0x62b3('0x6f')]({'where':{'id':_0x10fc80[_0x62b3('0x5d')]['id']}})[_0x62b3('0x22')](handleEntityNotFound(_0x5c3b58,null))[_0x62b3('0x22')](function(_0x3ca3c7){if(_0x3ca3c7){_0x13cb71['model']=_[_0x62b3('0x48')](db['FaxMessage'][_0x62b3('0x5f')]);_0x13cb71[_0x62b3('0x47')]=_[_0x62b3('0x48')](_0x10fc80[_0x62b3('0x47')]);_0x13cb71['filters']=_[_0x62b3('0x4a')](_0x13cb71[_0x62b3('0x46')],_0x13cb71['query']);_0x165e91[_0x62b3('0x4b')]=_[_0x62b3('0x4a')](_0x13cb71[_0x62b3('0x46')],qs[_0x62b3('0x4c')](_0x10fc80[_0x62b3('0x47')][_0x62b3('0x4c')]));_0x165e91[_0x62b3('0x4b')]=_0x165e91[_0x62b3('0x4b')][_0x62b3('0x4d')]?_0x165e91['attributes']:_0x13cb71[_0x62b3('0x46')];if(!_0x10fc80[_0x62b3('0x47')][_0x62b3('0x4e')]('nolimit')){_0x165e91[_0x62b3('0x30')]=qs[_0x62b3('0x30')](_0x10fc80[_0x62b3('0x47')][_0x62b3('0x30')]);_0x165e91[_0x62b3('0x32')]=qs[_0x62b3('0x32')](_0x10fc80[_0x62b3('0x47')][_0x62b3('0x32')]);}_0x165e91[_0x62b3('0x87')]=qs['sort'](_0x10fc80[_0x62b3('0x47')][_0x62b3('0x50')]);_0x165e91[_0x62b3('0x53')]=qs[_0x62b3('0x49')](_[_0x62b3('0x51')](_0x10fc80['query'],_0x13cb71['filters']));_0x165e91['where'][_0x62b3('0x6c')]=_0x3ca3c7['id'];if(_0x10fc80[_0x62b3('0x47')]['filter']){_0x165e91[_0x62b3('0x53')]=_[_0x62b3('0x3f')](_0x165e91['where'],{'$or':_[_0x62b3('0x45')](_0x165e91[_0x62b3('0x4b')],function(_0x22e31f){var _0x412c7d={};_0x412c7d[_0x22e31f]={'$like':'%'+_0x10fc80['query'][_0x62b3('0x52')]+'%'};return _0x412c7d;})});}if(_0x10fc80[_0x62b3('0x47')][_0x62b3('0xa8')]){var _0x1ee644=_0x10fc80[_0x62b3('0x47')]['$gte'][_0x62b3('0xa9')](',');var _0x4df9a8={};_0x4df9a8[_0x1ee644[0x0]]={'$gte':moment(_0x1ee644[0x1])[_0x62b3('0xaa')](_0x62b3('0xab'))};_0x165e91['where']=_[_0x62b3('0x3f')](_0x165e91[_0x62b3('0x53')],_0x4df9a8);}_0x165e91=_[_0x62b3('0x3f')]({},_0x165e91,_0x10fc80[_0x62b3('0x56')]);return db[_0x62b3('0xac')][_0x62b3('0x31')]({'where':_0x165e91['where']})[_0x62b3('0x22')](function(_0x37756d){_0x54e88d['count']=_0x37756d;if(_0x10fc80[_0x62b3('0x47')][_0x62b3('0x57')]){_0x165e91[_0x62b3('0x58')]=[{'all':!![]}];}return db[_0x62b3('0xac')]['findAll'](_0x165e91);})[_0x62b3('0x22')](function(_0x14d702){_0x54e88d[_0x62b3('0x5b')]=_0x14d702;return _0x54e88d;});}})[_0x62b3('0x22')](respondWithFilteredResult(_0x5c3b58,_0x165e91))[_0x62b3('0x61')](handleError(_0x5c3b58,null));};exports[_0x62b3('0x3d')]=function(_0x333174,_0x1c54d5,_0x382e96){var _0x58c410,_0x1aeebb={},_0xb1dd68;if(_0x333174[_0x62b3('0x63')]['to']){_0xb1dd68=_0x333174[_0x62b3('0x63')]['to'][0x0];}return db[_0x62b3('0x59')]['find']({'where':{'id':_0x333174[_0x62b3('0x5d')]['id']},'include':[{'model':db['CmList'],'as':_0x62b3('0xad'),'include':[{'model':db[_0x62b3('0x79')],'as':_0x62b3('0xae'),'where':{'fax':_0xb1dd68},'limit':0x1,'order':[[_0x62b3('0xa4'),_0x62b3('0xaf')]]}]}]})[_0x62b3('0x22')](handleEntityNotFound(_0x1c54d5,null))['then'](function(_0x489db5){_0x58c410=_0x489db5;if(_0x333174[_0x62b3('0x63')][_0x62b3('0xb0')]&&_0x333174[_0x62b3('0x63')][_0x62b3('0xb0')][_0x62b3('0x4d')]){for(var _0x1194b9=0x0;_0x1194b9<_0x333174[_0x62b3('0x63')]['attachments'][_0x62b3('0x4d')];_0x1194b9+=0x1){_0x333174['body'][_0x62b3('0xb0')][_0x1194b9]={'filename':_0x333174[_0x62b3('0x63')][_0x62b3('0xb0')][_0x1194b9]['name'],'id':_0x333174[_0x62b3('0x63')][_0x62b3('0xb0')][_0x1194b9]['id'],'path':path[_0x62b3('0xb1')](config[_0x62b3('0xb2')],_0x62b3('0xb3'),_0x333174[_0x62b3('0x63')][_0x62b3('0xb0')][_0x1194b9][_0x62b3('0xb4')])};}}return respondWithRpcPromise(_0x62b3('0xb5'),_0x62b3('0xb5'),{'FaxAccountId':_[_0x62b3('0xb6')](_0x333174[_0x62b3('0x5d')]['id'])?undefined:_0x333174[_0x62b3('0x5d')]['id'],'path':_['isNil'](_0x333174[_0x62b3('0x63')]['attachments'][0x0][_0x62b3('0x7')])?undefined:_0x333174[_0x62b3('0x63')][_0x62b3('0xb0')][0x0][_0x62b3('0x7')],'fax':_[_0x62b3('0xb6')](_0x333174['body']['to'][0x0])?undefined:_0x333174[_0x62b3('0x63')]['to'][0x0]},client9002);})[_0x62b3('0x22')](function(){if(_0x58c410){if(_[_0x62b3('0xb6')](_0x333174[_0x62b3('0x63')][_0x62b3('0xb7')])){_0x333174[_0x62b3('0x63')][_0x62b3('0xb7')]=util['format'](_0x62b3('0xb8'),_0x58c410[_0x62b3('0x3c')],_0x58c410[_0x62b3('0xb9')]);}if(_0x58c410[_0x62b3('0xad')]){if(_0x58c410[_0x62b3('0xad')][_0x62b3('0xae')]['length']){return _0x58c410['List']['Contacts'][0x0];}else{return db[_0x62b3('0x79')]['create'](_[_0x62b3('0x1d')](_0x333174[_0x62b3('0x63')],{'firstName':_0x333174[_0x62b3('0x63')]['to'][0x0],'phone':_0x333174[_0x62b3('0x63')]['to'][0x0],'fax':_0x333174[_0x62b3('0x63')]['to'][0x0],'ListId':_0x58c410['ListId']}));}}else{throw new Error(_0x62b3('0xba'));}}else{throw new Error(_0x62b3('0xbb'));}})[_0x62b3('0x22')](function(_0x4ac4be){if(_0x4ac4be){return db[_0x62b3('0x77')][_0x62b3('0x60')]({'where':{'ContactId':_0x4ac4be['id'],'closed':![],'FaxAccountId':_0x58c410['id']}})[_0x62b3('0x22')](function(_0x5280bd){if(_0x5280bd){return[_0x5280bd,![]];}return db[_0x62b3('0x77')][_0x62b3('0x62')]({'UserId':_0x333174[_0x62b3('0x64')]['id'],'ContactId':_0x4ac4be['id'],'FaxAccountId':_0x58c410['id'],'fax':_0x333174['body']['to'][0x0],'firstMsgDirection':_0x62b3('0xbc'),'Messages':[_['merge'](_0x333174[_0x62b3('0x63')],{'read':![],'body':_0x333174[_0x62b3('0x63')][_0x62b3('0xb0')][0x0][_0x62b3('0xbd')],'FaxAccountId':_0x58c410['id'],'UserId':_0x333174[_0x62b3('0x64')]['id'],'ContactId':_0x4ac4be['id'],'AttachmentId':_0x333174[_0x62b3('0x63')]['attachments'][0x0]['id']})]},{'include':[{'model':db[_0x62b3('0xac')],'as':'Messages'}]})[_0x62b3('0x22')](function(_0x96abaa){return[_0x96abaa,!![]];});});}else{throw new Error('Contact\x20not\x20found');}})[_0x62b3('0xbe')](function(_0x4325fa,_0xa0c59e){if(_0xa0c59e){return _0x4325fa;}return db[_0x62b3('0xac')][_0x62b3('0x62')]({'direction':_0x62b3('0xbc'),'read':![],'body':_0x333174['body'][_0x62b3('0xb0')][0x0][_0x62b3('0xbd')],'FaxAccountId':_0x58c410['id'],'FaxInteractionId':_0x4325fa['id'],'UserId':_0x333174[_0x62b3('0x64')]['id'],'ContactId':_0x4325fa[_0x62b3('0xbf')],'AttachmentId':_0x333174['body'][_0x62b3('0xb0')][0x0]['id']})[_0x62b3('0x22')](function(_0x4ea27d){_0x4325fa[_0x62b3('0xc0')][_0x62b3('0xc1')]=[];_0x4325fa[_0x62b3('0xc0')][_0x62b3('0xc1')]['push'](_0x4ea27d[_0x62b3('0xc0')]);return _0x4325fa;});})[_0x62b3('0x22')](function(_0x23479c){respondWithRpcPromise(_0x62b3('0xc2'),'SendFax',{'FaxAccountId':_[_0x62b3('0xb6')](_0x333174['params']['id'])?undefined:_0x333174[_0x62b3('0x5d')]['id'],'path':_[_0x62b3('0xb6')](_0x333174[_0x62b3('0x63')]['attachments'][0x0][_0x62b3('0x7')])?undefined:_0x333174['body'][_0x62b3('0xb0')][0x0][_0x62b3('0x7')],'fax':_['isNil'](_0x333174[_0x62b3('0x63')]['to'][0x0])?undefined:_0x333174[_0x62b3('0x63')]['to'][0x0],'AttachmentId':_0x333174[_0x62b3('0x63')][_0x62b3('0xb0')][0x0]['id']},client9002)['then'](function(_0x3bcf9a){logger['info'](_0x62b3('0xc3'),_0x3bcf9a);})[_0x62b3('0x61')](function(_0xa74708){logger[_0x62b3('0x23')](_0x62b3('0xc3'),_0xa74708);});return _0x23479c;})[_0x62b3('0x22')](respondWithResult(_0x1c54d5,null))[_0x62b3('0x61')](handleError(_0x1c54d5,null));};exports[_0x62b3('0xc4')]=function(_0x15fe0e,_0x8b1492,_0x2bab2c){return db[_0x62b3('0x59')]['find']({'where':{'id':_0x15fe0e['params']['id']}})[_0x62b3('0x22')](handleEntityNotFound(_0x8b1492,null))[_0x62b3('0x22')](function(_0x27ecbe){if(_0x27ecbe){return _0x27ecbe[_0x62b3('0xc4')](_0x15fe0e[_0x62b3('0x63')][_0x62b3('0x71')],_[_0x62b3('0xa0')](_0x15fe0e['body'],[_0x62b3('0x71'),'id'])||{})[_0x62b3('0xbe')](function(_0x4653c1){for(var _0x9a6fd6=0x0;_0x9a6fd6<_0x15fe0e[_0x62b3('0x63')]['ids'][_0x62b3('0x4d')];_0x9a6fd6+=0x1){socket['emit'](_0x62b3('0xc5'),{'UserId':_0x15fe0e[_0x62b3('0x63')][_0x62b3('0x71')][_0x9a6fd6],'FaxAccountId':_0x15fe0e[_0x62b3('0x5d')]['id']});}return _0x4653c1;});}})[_0x62b3('0x22')](respondWithResult(_0x8b1492,null))['catch'](handleError(_0x8b1492,null));};exports[_0x62b3('0xc6')]=function(_0x3b9dbd,_0x3166df,_0x406a20){return db[_0x62b3('0x59')][_0x62b3('0x60')]({'where':{'id':_0x3b9dbd['params']['id']}})[_0x62b3('0x22')](handleEntityNotFound(_0x3166df,null))[_0x62b3('0x22')](function(_0x4d3f81){if(_0x4d3f81){return _0x4d3f81[_0x62b3('0xc6')](_0x3b9dbd[_0x62b3('0x47')][_0x62b3('0x71')])[_0x62b3('0x22')](function(){if(_[_0x62b3('0xc7')](_0x3b9dbd[_0x62b3('0x47')][_0x62b3('0x71')])){for(var _0x3127e2=0x0;_0x3127e2<_0x3b9dbd['query']['ids'][_0x62b3('0x4d')];_0x3127e2+=0x1){socket[_0x62b3('0xc8')]('userFaxAccount:remove',{'UserId':Number(_0x3b9dbd['query'][_0x62b3('0x71')][_0x3127e2]),'FaxAccountId':Number(_0x3b9dbd[_0x62b3('0x5d')]['id'])});}}else{socket[_0x62b3('0xc8')](_0x62b3('0xc9'),{'UserId':Number(_0x3b9dbd[_0x62b3('0x47')][_0x62b3('0x71')]),'FaxAccountId':Number(_0x3b9dbd[_0x62b3('0x5d')]['id'])});}});}})['then'](respondWithStatusCode(_0x3166df,null))[_0x62b3('0x61')](handleError(_0x3166df,null));};exports[_0x62b3('0xca')]=function(_0x5adbc7,_0x31c359,_0x43b16a){var _0x3b084d={};var _0xe97418={};var _0x4a8c2b;var _0x3a7cbb;return db[_0x62b3('0x59')][_0x62b3('0x6f')]({'where':{'id':_0x5adbc7[_0x62b3('0x5d')]['id']}})[_0x62b3('0x22')](handleEntityNotFound(_0x31c359,null))[_0x62b3('0x22')](function(_0x112259){if(_0x112259){_0x4a8c2b=_0x112259;_0xe97418['model']=_['keys'](db['User'][_0x62b3('0x5f')]);_0xe97418[_0x62b3('0x47')]=_[_0x62b3('0x48')](_0x5adbc7[_0x62b3('0x47')]);_0xe97418['filters']=_['intersection'](_0xe97418[_0x62b3('0x46')],_0xe97418[_0x62b3('0x47')]);_0x3b084d[_0x62b3('0x4b')]=_['intersection'](_0xe97418[_0x62b3('0x46')],qs[_0x62b3('0x4c')](_0x5adbc7[_0x62b3('0x47')][_0x62b3('0x4c')]));_0x3b084d[_0x62b3('0x4b')]=_0x3b084d['attributes']['length']?_0x3b084d[_0x62b3('0x4b')]:_0xe97418['model'];_0x3b084d[_0x62b3('0x87')]=qs[_0x62b3('0x50')](_0x5adbc7[_0x62b3('0x47')][_0x62b3('0x50')]);_0x3b084d[_0x62b3('0x53')]=qs[_0x62b3('0x49')](_[_0x62b3('0x51')](_0x5adbc7['query'],_0xe97418['filters']));if(_0x5adbc7[_0x62b3('0x47')][_0x62b3('0x52')]){_0x3b084d['where']=_[_0x62b3('0x3f')](_0x3b084d[_0x62b3('0x53')],{'$or':_[_0x62b3('0x45')](_0x3b084d[_0x62b3('0x4b')],function(_0x43346a){var _0x22f8ae={};_0x22f8ae[_0x43346a]={'$like':'%'+_0x5adbc7[_0x62b3('0x47')][_0x62b3('0x52')]+'%'};return _0x22f8ae;})});}_0x3b084d=_[_0x62b3('0x3f')]({},_0x3b084d,_0x5adbc7['options']);return _0x4a8c2b[_0x62b3('0xca')](_0x3b084d);}})[_0x62b3('0x22')](function(_0x53f3e4){if(_0x53f3e4){_0x3a7cbb=_0x53f3e4[_0x62b3('0x4d')];if(!_0x5adbc7[_0x62b3('0x47')][_0x62b3('0x4e')](_0x62b3('0x4f'))){_0x3b084d[_0x62b3('0x30')]=qs[_0x62b3('0x30')](_0x5adbc7[_0x62b3('0x47')][_0x62b3('0x30')]);_0x3b084d[_0x62b3('0x32')]=qs[_0x62b3('0x32')](_0x5adbc7[_0x62b3('0x47')]['offset']);}return _0x4a8c2b[_0x62b3('0xca')](_0x3b084d);}})[_0x62b3('0x22')](function(_0x1379f4){if(_0x1379f4){return _0x1379f4?{'count':_0x3a7cbb,'rows':_0x1379f4}:null;}})[_0x62b3('0x22')](respondWithResult(_0x31c359,null))[_0x62b3('0x61')](handleError(_0x31c359,null));};