Built motion from commit e1760111.|2.6.18
[motion2.git] / server / api / faxInteraction / faxInteraction.controller.js
index 8af82d2..4e5665d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5ff3=['reject','update','then','destroy','error','stack','name','send','Users','map','TagIds','forEach','catch','index','rawAttributes','fieldName','type','key','query','keys','intersection','model','fields','attributes','length','nolimit','limit','order','sort','filters','pick','select','field','color','from','u.id','u.fullname','user_has_fax_interactions','users','u.id\x20=\x20ui.UserId','left_join','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','fax_accounts','a.id\x20=\x20i.FaxAccountId','fax_messages','me.FaxInteractionId\x20=\x20i.id','fax_interaction_has_tags','it.FaxInteractionId\x20=\x20i.id','tools_tags','expr','search','parseSearch','conditions','find','unreadMessages','having','`\x20=\x200','operator','$substring','value','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','buildExpression','Tag','split','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','text','start','body','some','compact','isEmpty','where','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','isArray','tag','filter','replace','isNumeric','i.id\x20LIKE\x20?','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','Sequelize','SELECT','clone','i.id','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','DESC','t.id\x20IN\x20?','resolve','FaxAccountId','journey','i.FaxAccountId\x20IS\x20NOT\x20NULL','user','agent','getFaxAccounts','i.FaxAccountId\x20IS\x20NULL','i.FaxAccountId\x20IN\x20?','sequelize','toString','keyBy','merge','FaxInteraction','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','contactName','i.*','c.firstName','c.lastName','c.phone','Contact.phone','c.fax','o.fullname','Owner.fullname','ui.FaxInteractionId\x20IN\x20?','groupBy','FaxInteractionId','all','rows','show','params','includeAll','options','create','describe','FaxMessage','addMessage','omit','getMessages','hasOwnProperty','format','YYYY-MM-DD\x20HH:mm:ss','include','findAll','addTags','ids','spread','emit','faxInteractionTags:save','removeTags','download','unix','join','root','server','files','tmp','attachments','transcript-%d-%s.zip','push','Attachment','Messages','get','mkdirSync','basename','existsSync','createReadStream','createWriteStream','log','err','unlinkSync','eml-format','zip-dir','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','crypto','desk.js','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../mysqldb','redis','defaults','socket.io-emitter','./faxInteraction.socket','sendStatus','status','end','json','count','offset','set','apply'];(function(_0x4c9eb0,_0x3a332d){var _0x25dd6b=function(_0x9e1cde){while(--_0x9e1cde){_0x4c9eb0['push'](_0x4c9eb0['shift']());}};_0x25dd6b(++_0x3a332d);}(_0x5ff3,0x17d));var _0x35ff=function(_0x415f61,_0x42e69b){_0x415f61=_0x415f61-0x0;var _0x986105=_0x5ff3[_0x415f61];return _0x986105;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x35ff('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x35ff('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x35ff('0x2'));var moment=require(_0x35ff('0x3'));var BPromise=require(_0x35ff('0x4'));var Mustache=require(_0x35ff('0x5'));var util=require('util');var path=require(_0x35ff('0x6'));var sox=require(_0x35ff('0x7'));var csv=require(_0x35ff('0x8'));var ejs=require(_0x35ff('0x9'));var fs=require('fs');var _=require(_0x35ff('0xa'));var squel=require('squel');var crypto=require(_0x35ff('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x35ff('0xc'));var toCsv=require(_0x35ff('0x8'));var querystring=require(_0x35ff('0xd'));var Papa=require('papaparse');var Redis=require(_0x35ff('0xe'));var authService=require('../../components/auth/service');var qs=require(_0x35ff('0xf'));var as=require(_0x35ff('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x35ff('0x11'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x35ff('0x12'))['db'];config[_0x35ff('0x13')]=_[_0x35ff('0x14')](config[_0x35ff('0x13')],{'host':'localhost','port':0x18eb});var socket=require(_0x35ff('0x15'))(new Redis(config[_0x35ff('0x13')]));require(_0x35ff('0x16'))['register'](socket);function respondWithStatusCode(_0xff8ac,_0xbdd133){_0xbdd133=_0xbdd133||0xcc;return function(_0x254975){if(_0x254975){return _0xff8ac[_0x35ff('0x17')](_0xbdd133);}return _0xff8ac[_0x35ff('0x18')](_0xbdd133)[_0x35ff('0x19')]();};}function respondWithResult(_0x2d4a88,_0x28def2){_0x28def2=_0x28def2||0xc8;return function(_0x30b5bf){if(_0x30b5bf){return _0x2d4a88[_0x35ff('0x18')](_0x28def2)[_0x35ff('0x1a')](_0x30b5bf);}};}function respondWithFilteredResult(_0x3430e2,_0x37ea06){return function(_0x16c803){if(_0x16c803){var _0x186f6a=_0x16c803[_0x35ff('0x1b')],_0x5f470e=_0x37ea06[_0x35ff('0x1c')],_0x2404e5=_0x37ea06['offset']+_0x37ea06['limit'],_0x1fc4b7;if(_0x2404e5>=_0x186f6a){_0x2404e5=_0x186f6a;_0x1fc4b7=0xc8;}else{_0x1fc4b7=0xce;}_0x3430e2[_0x35ff('0x18')](_0x1fc4b7);return _0x3430e2[_0x35ff('0x1d')]('Content-Range',_0x5f470e+'-'+_0x2404e5+'/'+_0x186f6a)[_0x35ff('0x1a')](_0x16c803);}return null;};}function patchUpdates(_0x224f67){return function(_0x3a87bc){try{jsonpatch[_0x35ff('0x1e')](_0x3a87bc,_0x224f67,!![]);}catch(_0x48f3bd){return BPromise[_0x35ff('0x1f')](_0x48f3bd);}return _0x3a87bc['save']();};}function saveUpdates(_0x7cc20a,_0x1a0c76){return function(_0x29cd2e){if(_0x29cd2e){return _0x29cd2e[_0x35ff('0x20')](_0x7cc20a)[_0x35ff('0x21')](function(_0x2b3782){return _0x2b3782;});}return null;};}function removeEntity(_0x347cec,_0x5914b1){return function(_0x284f39){if(_0x284f39){return _0x284f39[_0x35ff('0x22')]()['then'](function(){_0x347cec[_0x35ff('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4c46b7,_0x186768){return function(_0x9e2789){if(!_0x9e2789){_0x4c46b7[_0x35ff('0x17')](0x194);}return _0x9e2789;};}function handleError(_0x11a5eb,_0x302d5a){_0x302d5a=_0x302d5a||0x1f4;return function(_0x546ec0){logger[_0x35ff('0x23')](_0x546ec0[_0x35ff('0x24')]);if(_0x546ec0[_0x35ff('0x25')]){delete _0x546ec0['name'];}_0x11a5eb[_0x35ff('0x18')](_0x302d5a)[_0x35ff('0x26')](_0x546ec0);};}function getInteractionUsers(_0x3b4331,_0x6d5407){return new BPromise(function(_0x47fcb5,_0x61b554){try{if(_0x6d5407[_0x3b4331['id']]){_0x3b4331[_0x35ff('0x27')]=_[_0x35ff('0x28')](_0x6d5407[_0x3b4331['id']],function(_0x105e58){return{'id':_0x105e58['id'],'fullname':_0x105e58['fullname']};});}}catch(_0x3f9440){_0x61b554(_0x3f9440);}_0x47fcb5(_0x3b4331);});}function getInteractionTags(_0x57339d,_0x1cb370){return new BPromise(function(_0x257501,_0x2bc118){try{if(_0x57339d[_0x35ff('0x29')]){_0x57339d['Tags']=[];_0x57339d[_0x35ff('0x29')]['split'](',')[_0x35ff('0x2a')](function(_0xf88865){_0x57339d['Tags']['push'](_0x1cb370[_0xf88865]);});}delete _0x57339d[_0x35ff('0x29')];}catch(_0x3b3cb5){_0x2bc118(_0x3b3cb5);}_0x257501(_0x57339d);});}function updateFaxInteraction(_0x5a5396,_0x3d3d56,_0x2fd48d){return new BPromise(function(_0x4d194c,_0x59a11c){return getInteractionUsers(_0x5a5396,_0x2fd48d)[_0x35ff('0x21')](function(_0x131b22){return getInteractionTags(_0x131b22,_0x3d3d56);})[_0x35ff('0x21')](function(_0xbe84c6){_0x4d194c(_0xbe84c6);})[_0x35ff('0x2b')](function(_0x293edc){_0x59a11c(_0x293edc);});});}exports[_0x35ff('0x2c')]=function(_0x35a3c7,_0x1a5c81){var _0x2d495b={},_0x4622e3={},_0x41b48d={'count':0x0,'rows':[]};var _0x58e90f=_[_0x35ff('0x28')](db['FaxInteraction'][_0x35ff('0x2d')],function(_0x39edab){return{'name':_0x39edab[_0x35ff('0x2e')],'type':_0x39edab[_0x35ff('0x2f')][_0x35ff('0x30')]};});_0x4622e3['model']=_[_0x35ff('0x28')](_0x58e90f,_0x35ff('0x25'));_0x4622e3[_0x35ff('0x31')]=_[_0x35ff('0x32')](_0x35a3c7[_0x35ff('0x31')]);_0x4622e3['filters']=_[_0x35ff('0x33')](_0x4622e3[_0x35ff('0x34')],_0x4622e3[_0x35ff('0x31')]);_0x2d495b['attributes']=_['intersection'](_0x4622e3[_0x35ff('0x34')],qs[_0x35ff('0x35')](_0x35a3c7[_0x35ff('0x31')][_0x35ff('0x35')]));_0x2d495b[_0x35ff('0x36')]=_0x2d495b[_0x35ff('0x36')][_0x35ff('0x37')]?_0x2d495b[_0x35ff('0x36')]:_0x4622e3['model'];if(!_0x35a3c7['query']['hasOwnProperty'](_0x35ff('0x38'))){_0x2d495b[_0x35ff('0x39')]=qs[_0x35ff('0x39')](_0x35a3c7[_0x35ff('0x31')][_0x35ff('0x39')]);_0x2d495b['offset']=qs[_0x35ff('0x1c')](_0x35a3c7[_0x35ff('0x31')][_0x35ff('0x1c')]);}_0x2d495b[_0x35ff('0x3a')]=qs[_0x35ff('0x3b')](_0x35a3c7[_0x35ff('0x31')]['sort']);_0x2d495b['where']=qs[_0x35ff('0x3c')](_[_0x35ff('0x3d')](_0x35a3c7[_0x35ff('0x31')],_0x4622e3[_0x35ff('0x3c')]),_0x58e90f);var _0x4b1e3e=[];var _0x5c3476=squel[_0x35ff('0x3e')]()[_0x35ff('0x3f')]('id')[_0x35ff('0x3f')](_0x35ff('0x25'))[_0x35ff('0x3f')](_0x35ff('0x40'))[_0x35ff('0x41')]('tools_tags');var _0x52eeb8=squel[_0x35ff('0x3e')]()[_0x35ff('0x3f')](_0x35ff('0x42'))['field'](_0x35ff('0x43'))[_0x35ff('0x3f')]('ui.FaxInteractionId')['from'](_0x35ff('0x44'),'ui')['left_join'](_0x35ff('0x45'),'u',_0x35ff('0x46'));var _0x5e95ad=squel[_0x35ff('0x3e')]()['from']('fax_interactions','i')[_0x35ff('0x47')](_0x35ff('0x48'),'c',_0x35ff('0x49'))[_0x35ff('0x47')](_0x35ff('0x45'),'o',_0x35ff('0x4a'))[_0x35ff('0x47')](_0x35ff('0x4b'),'a',_0x35ff('0x4c'))[_0x35ff('0x47')](_0x35ff('0x4d'),'me',_0x35ff('0x4e'))['left_join'](_0x35ff('0x4f'),'it',_0x35ff('0x50'))[_0x35ff('0x47')](_0x35ff('0x51'),'t','t.id\x20=\x20it.TagId');var _0x59c5f7=squel[_0x35ff('0x52')]();var _0x521956=[];var _0x14cd47=squel[_0x35ff('0x52')]();var _0x14aa90;if(_0x35a3c7[_0x35ff('0x31')][_0x35ff('0x53')]){_0x14aa90=as[_0x35ff('0x54')](_0x35a3c7[_0x35ff('0x31')][_0x35ff('0x53')]);var _0x3be5fc=_0x14aa90['sqlOperator'];for(var _0x48e22b=0x0;_0x48e22b<_0x14aa90[_0x35ff('0x55')]['length'];_0x48e22b++){var _0x309fe1=_0x14aa90[_0x35ff('0x55')][_0x48e22b];var _0x944660='i';var _0x255bdc=_[_0x35ff('0x56')](_0x58e90f,[_0x35ff('0x25'),_0x309fe1[_0x35ff('0x3f')]]);if(!_0x255bdc){switch(_0x309fe1[_0x35ff('0x3f')]){case _0x35ff('0x57'):if(_0x309fe1['value']==0x1){_0x5e95ad[_0x35ff('0x58')]('`'+_0x309fe1[_0x35ff('0x3f')]+_0x35ff('0x59'));}else{_0x5e95ad[_0x35ff('0x58')]('`'+_0x309fe1['field']+'`\x20>\x200');}break;case'Contact':if(_0x309fe1[_0x35ff('0x5a')]===_0x35ff('0x5b')){if(_0x309fe1[_0x35ff('0x5c')]['split']('\x20')[_0x35ff('0x37')]>0x1){_0x59c5f7[_0x3be5fc]('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x35ff('0x5d')](_0x309fe1['value']),null);}else{var _0x3a07d4='%'+_0x309fe1[_0x35ff('0x5c')]+'%';_0x59c5f7[_0x3be5fc](_0x35ff('0x5e'),_0x3a07d4,_0x3a07d4,_0x3a07d4);}}else{_0x255bdc=_[_0x35ff('0x56')](_0x58e90f,['name','ContactId']);_0x309fe1[_0x35ff('0x3f')]='ContactId';_0x142f62=as[_0x35ff('0x5f')](_0x944660,_0x255bdc[_0x35ff('0x2f')],_0x309fe1);_0x59c5f7[_0x3be5fc](_0x142f62['text'],_0x142f62[_0x35ff('0x5c')]['start'],_0x142f62[_0x35ff('0x5c')][_0x35ff('0x19')]);}break;case _0x35ff('0x60'):var _0x10c8f1=_0x309fe1[_0x35ff('0x5c')][_0x35ff('0x61')](',')['map'](function(_0x54d949){return Number(_0x54d949);});_0x10c8f1[_0x35ff('0x2a')](function(_0x340ed8){_0x14cd47['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x340ed8+',%');});_0x521956=_[_0x35ff('0x62')](_0x521956,_0x10c8f1);break;case _0x35ff('0x63'):if(_0x309fe1['operator']===_0x35ff('0x5b')){_0x59c5f7[_0x3be5fc](_0x35ff('0x64'),'%'+_0x309fe1[_0x35ff('0x5c')]+'%',null);}else{_0x255bdc=_[_0x35ff('0x56')](_0x58e90f,[_0x35ff('0x25'),'UserId']);_0x309fe1['field']='UserId';_0x142f62=as[_0x35ff('0x5f')](_0x944660,_0x255bdc['type'],_0x309fe1);_0x59c5f7[_0x3be5fc](_0x142f62[_0x35ff('0x65')],_0x142f62['value'][_0x35ff('0x66')],_0x142f62[_0x35ff('0x5c')][_0x35ff('0x19')]);}break;case _0x35ff('0x67'):_0x142f62=as[_0x35ff('0x5f')]('me',null,_0x309fe1);_0x59c5f7[_0x3be5fc](_0x142f62[_0x35ff('0x65')],_0x142f62['value'][_0x35ff('0x66')],_0x142f62[_0x35ff('0x5c')]['end']);break;}}else{var _0x142f62=as[_0x35ff('0x5f')](_0x944660,_0x255bdc[_0x35ff('0x2f')],_0x309fe1);_0x59c5f7[_0x3be5fc](_0x142f62[_0x35ff('0x65')],_0x142f62[_0x35ff('0x5c')][_0x35ff('0x66')],_0x142f62[_0x35ff('0x5c')][_0x35ff('0x19')]);}}}else{var _0x16a9cc=_(_0x35a3c7['query'])[_0x35ff('0x32')]()[_0x35ff('0x28')](function(_0x36e8d1){return _[_0x35ff('0x68')](_0x58e90f,[_0x35ff('0x25'),_0x36e8d1])?_0x36e8d1:undefined;})[_0x35ff('0x69')]()['value']();if(!_[_0x35ff('0x6a')](_0x16a9cc)){_0x16a9cc[_0x35ff('0x2a')](function(_0xd286b5){if(_0xd286b5==='FaxAccountId'){_0x5e95ad[_0x35ff('0x6b')]('i.FaxAccountId\x20IN\x20?',[]['concat'](_0x35a3c7[_0x35ff('0x31')][_0xd286b5]));}else if(_0xd286b5===_0x35ff('0x6c')){var _0x4a8907=JSON[_0x35ff('0x6d')](_0x35a3c7[_0x35ff('0x31')][_0xd286b5])[_0x35ff('0x6e')];var _0x974edb=JSON[_0x35ff('0x6d')](_0x35a3c7[_0x35ff('0x31')][_0xd286b5])[_0x35ff('0x6f')];_0x5e95ad[_0x35ff('0x6b')](_0x35ff('0x70'),_0x4a8907,_0x974edb);}else{if(_0x35a3c7[_0x35ff('0x31')][_0xd286b5]===_0x35ff('0x71')){_0x5e95ad[_0x35ff('0x6b')]('i.'+_0xd286b5+_0x35ff('0x72'));}else{_0x5e95ad[_0x35ff('0x6b')]('i.'+_0xd286b5+_0x35ff('0x73'),_0x35a3c7[_0x35ff('0x31')][_0xd286b5]);}}});}if(_0x35a3c7['query'][_0x35ff('0x74')]){if(_0x35a3c7[_0x35ff('0x31')]['read']==0x1){_0x5e95ad[_0x35ff('0x58')](_0x35ff('0x75'));}else{_0x5e95ad['having']('`unreadMessages`\x20>\x200');}}if(_0x35a3c7[_0x35ff('0x31')]['tag']){_0x521956=_[_0x35ff('0x76')](_0x35a3c7[_0x35ff('0x31')][_0x35ff('0x77')])?_0x35a3c7[_0x35ff('0x31')][_0x35ff('0x77')]:new Array(_0x35a3c7[_0x35ff('0x31')][_0x35ff('0x77')]);_0x521956[_0x35ff('0x2a')](function(_0x7ea9b0){_0x14cd47['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x7ea9b0+',%');});}if(_0x35a3c7[_0x35ff('0x31')]['filter']){var _0x249d3e=_0x35a3c7['query'][_0x35ff('0x78')][_0x35ff('0x79')]('\x5c','\x5c\x5c')[_0x35ff('0x79')](/'/g,'\x27\x27');if(qs[_0x35ff('0x7a')](_0x249d3e)){_0x59c5f7['or'](_0x35ff('0x7b'),_0x249d3e+'%')['or']('i.fax\x20LIKE\x20?',_0x249d3e+'%');}_0x59c5f7['or'](_0x35ff('0x7c'),_0x249d3e+'%');}}_0x5e95ad[_0x35ff('0x6b')](_0x59c5f7);_0x5e95ad['group']('i.id');var _0x3ba507={'type':db[_0x35ff('0x7d')]['QueryTypes'][_0x35ff('0x7e')],'raw':!![]};var _0x2f4c76=_0x5e95ad[_0x35ff('0x7f')]();_0x2f4c76['field'](_0x35ff('0x80'));_0x2f4c76[_0x35ff('0x3f')](_0x35ff('0x81'),'unreadMessages');if(_0x2d495b[_0x35ff('0x3a')]){_0x2d495b[_0x35ff('0x3a')][_0x35ff('0x2a')](function(_0x419346){var _0x34f30e=_0x419346[0x0]==='contactName'?_0x419346[0x0]:'i.'+_0x419346[0x0];_0x5e95ad[_0x35ff('0x3a')](_0x34f30e,_0x419346[0x1]===_0x35ff('0x82')?![]:!![]);});}if(!_[_0x35ff('0x6a')](_0x521956)){_0x5e95ad[_0x35ff('0x58')](_0x14cd47);_0x2f4c76[_0x35ff('0x6b')](_0x35ff('0x83'),_0x521956);}BPromise[_0x35ff('0x84')]()['then'](function(){if(!_0x14aa90){if(_0x35a3c7[_0x35ff('0x31')][_0x35ff('0x85')]||_0x35a3c7[_0x35ff('0x31')][_0x35ff('0x86')])return;_0x2f4c76[_0x35ff('0x6b')](_0x35ff('0x87'));_0x5e95ad[_0x35ff('0x6b')]('i.FaxAccountId\x20IS\x20NOT\x20NULL');return;}if(_0x35a3c7[_0x35ff('0x88')]['role']!==_0x35ff('0x89'))return;return _0x35a3c7[_0x35ff('0x88')][_0x35ff('0x8a')]({'attributes':['id'],'raw':!![]})[_0x35ff('0x21')](function(_0x1d5df8){if(_['isEmpty'](_0x1d5df8)){_0x2f4c76['where'](_0x35ff('0x8b'));_0x5e95ad['where'](_0x35ff('0x8b'));}else{_0x2f4c76[_0x35ff('0x6b')](_0x35ff('0x8c'),_[_0x35ff('0x28')](_0x1d5df8,'id'));_0x5e95ad[_0x35ff('0x6b')](_0x35ff('0x8c'),_[_0x35ff('0x28')](_0x1d5df8,'id'));}});})['then'](function(){if(_0x35a3c7[_0x35ff('0x88')]['role']===_0x35ff('0x89')&&!_0x14aa90&&!_0x35a3c7['query'][_0x35ff('0x85')])return[];return db[_0x35ff('0x8d')][_0x35ff('0x31')](_0x2f4c76['toString'](),_0x3ba507);})['then'](function(_0x8e891c){_0x41b48d[_0x35ff('0x1b')]=_0x8e891c['length'];if(_0x41b48d[_0x35ff('0x1b')]===0x0)return[];return db[_0x35ff('0x8d')]['query'](_0x5c3476[_0x35ff('0x8e')](),_0x3ba507)[_0x35ff('0x21')](function(_0x471878){_0x4b1e3e=_[_0x35ff('0x8f')](_0x471878,'id');_0x3ba507=_[_0x35ff('0x90')](_0x3ba507,{'model':db[_0x35ff('0x91')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x35a3c7[_0x35ff('0x31')][_0x35ff('0x35')]){_0x2d495b['attributes'][_0x35ff('0x2a')](function(_0x298566){_0x5e95ad['field']('i.'+_0x298566);});}else{_0x5e95ad[_0x35ff('0x3f')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x35ff('0x57'));_0x5e95ad['field'](_0x35ff('0x92'),_0x35ff('0x93'));_0x5e95ad[_0x35ff('0x3f')](_0x35ff('0x94'),_0x35ff('0x95'));_0x5e95ad[_0x35ff('0x3f')]('CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END',_0x35ff('0x96'));_0x5e95ad['field'](_0x35ff('0x97'));_0x5e95ad[_0x35ff('0x3f')](_0x35ff('0x98'),'Contact.firstName');_0x5e95ad[_0x35ff('0x3f')](_0x35ff('0x99'),'Contact.lastName');_0x5e95ad[_0x35ff('0x3f')]('c.email','Contact.email');_0x5e95ad[_0x35ff('0x3f')](_0x35ff('0x9a'),_0x35ff('0x9b'));_0x5e95ad[_0x35ff('0x3f')]('c.mobile','Contact.mobile');_0x5e95ad['field'](_0x35ff('0x9c'),'Contact.fax');_0x5e95ad[_0x35ff('0x3f')](_0x35ff('0x9d'),_0x35ff('0x9e'));_0x5e95ad[_0x35ff('0x3f')]('o.internal','Owner.internal');_0x5e95ad[_0x35ff('0x3f')]('GROUP_CONCAT(DISTINCT\x20t.id)','TagIds');}if(_0x2d495b[_0x35ff('0x39')])_0x5e95ad[_0x35ff('0x39')](_0x2d495b['limit']);if(_0x2d495b['offset'])_0x5e95ad['offset'](_0x2d495b[_0x35ff('0x1c')]);return db['sequelize'][_0x35ff('0x31')](_0x5e95ad[_0x35ff('0x8e')](),_0x3ba507);})[_0x35ff('0x21')](function(_0x13e2f1){_0x52eeb8[_0x35ff('0x6b')](_0x35ff('0x9f'),_[_0x35ff('0x28')](_0x13e2f1,'id'));return db[_0x35ff('0x8d')]['query'](_0x52eeb8[_0x35ff('0x8e')](),_0x3ba507)[_0x35ff('0x21')](function(_0x5cda93){var _0x5c68c4=_[_0x35ff('0xa0')](_0x5cda93,_0x35ff('0xa1'));var _0xe3db4c=[];_0x13e2f1['forEach'](function(_0x14f646){_0xe3db4c['push'](updateFaxInteraction(_0x14f646,_0x4b1e3e,_0x5c68c4));});return BPromise[_0x35ff('0xa2')](_0xe3db4c);});});})[_0x35ff('0x21')](function(_0x44dcaf){_0x41b48d[_0x35ff('0xa3')]=_0x44dcaf;return _0x41b48d;})['then'](respondWithFilteredResult(_0x1a5c81,_0x2d495b))['catch'](handleError(_0x1a5c81,null));};exports[_0x35ff('0xa4')]=function(_0x20f925,_0x31501d){var _0x5c76a5={'raw':![],'where':{'id':_0x20f925[_0x35ff('0xa5')]['id']}},_0x398268={};_0x398268[_0x35ff('0x34')]=_[_0x35ff('0x32')](db[_0x35ff('0x91')][_0x35ff('0x2d')]);_0x398268[_0x35ff('0x31')]=_[_0x35ff('0x32')](_0x20f925[_0x35ff('0x31')]);_0x398268[_0x35ff('0x3c')]=_[_0x35ff('0x33')](_0x398268['model'],_0x398268['query']);_0x5c76a5[_0x35ff('0x36')]=_['intersection'](_0x398268[_0x35ff('0x34')],qs[_0x35ff('0x35')](_0x20f925[_0x35ff('0x31')][_0x35ff('0x35')]));_0x5c76a5['attributes']=_0x5c76a5[_0x35ff('0x36')][_0x35ff('0x37')]?_0x5c76a5[_0x35ff('0x36')]:_0x398268[_0x35ff('0x34')];if(_0x20f925['query'][_0x35ff('0xa6')]){_0x5c76a5['include']=[{'all':!![]}];}_0x5c76a5=_[_0x35ff('0x90')]({},_0x5c76a5,_0x20f925[_0x35ff('0xa7')]);return db[_0x35ff('0x91')][_0x35ff('0x56')](_0x5c76a5)[_0x35ff('0x21')](handleEntityNotFound(_0x31501d,null))[_0x35ff('0x21')](respondWithResult(_0x31501d,null))[_0x35ff('0x2b')](handleError(_0x31501d,null));};exports[_0x35ff('0xa8')]=function(_0xf18743,_0x20691f){return db['FaxInteraction']['create'](_0xf18743[_0x35ff('0x67')],{})[_0x35ff('0x21')](respondWithResult(_0x20691f,0xc9))[_0x35ff('0x2b')](handleError(_0x20691f,null));};exports[_0x35ff('0x20')]=function(_0x473003,_0x2b8548){if(_0x473003[_0x35ff('0x67')]['id']){delete _0x473003[_0x35ff('0x67')]['id'];}return db['FaxInteraction']['find']({'where':{'id':_0x473003[_0x35ff('0xa5')]['id']}})['then'](handleEntityNotFound(_0x2b8548,null))[_0x35ff('0x21')](saveUpdates(_0x473003['body'],null))['then'](respondWithResult(_0x2b8548,null))[_0x35ff('0x2b')](handleError(_0x2b8548,null));};exports[_0x35ff('0x22')]=function(_0x22eb42,_0x1616a2){return db[_0x35ff('0x91')]['find']({'where':{'id':_0x22eb42['params']['id']}})[_0x35ff('0x21')](handleEntityNotFound(_0x1616a2,null))['then'](removeEntity(_0x1616a2,null))[_0x35ff('0x2b')](handleError(_0x1616a2,null));};exports[_0x35ff('0xa9')]=function(_0x2fadbf,_0x22c3e6){return db['FaxInteraction']['describe']()['then'](respondWithResult(_0x22c3e6,null))[_0x35ff('0x2b')](handleError(_0x22c3e6,null));};exports['addMessage']=function(_0x3b14e2,_0x40ba53,_0x294854){return db[_0x35ff('0xaa')][_0x35ff('0x56')]({'where':{'id':_0x3b14e2['params']['id']}})[_0x35ff('0x21')](handleEntityNotFound(_0x40ba53,null))[_0x35ff('0x21')](function(_0x4e7ee6){if(_0x4e7ee6){return _0x4e7ee6[_0x35ff('0xab')](_0x3b14e2['body']['ids'],_[_0x35ff('0xac')](_0x3b14e2['body'],['ids','id'])||{});}})[_0x35ff('0x21')](respondWithResult(_0x40ba53,null))[_0x35ff('0x2b')](handleError(_0x40ba53,null));};exports[_0x35ff('0xad')]=function(_0x277117,_0x28aed0,_0x4123e9){var _0x2834e7={'raw':![],'where':{}};var _0xec33d5={};var _0x5ecde1={'count':0x0,'rows':[]};return db[_0x35ff('0x91')]['findOne']({'where':{'id':_0x277117['params']['id']}})[_0x35ff('0x21')](handleEntityNotFound(_0x28aed0,null))[_0x35ff('0x21')](function(_0x199519){if(_0x199519){_0xec33d5[_0x35ff('0x34')]=_[_0x35ff('0x32')](db[_0x35ff('0xaa')][_0x35ff('0x2d')]);_0xec33d5['query']=_[_0x35ff('0x32')](_0x277117['query']);_0xec33d5[_0x35ff('0x3c')]=_[_0x35ff('0x33')](_0xec33d5[_0x35ff('0x34')],_0xec33d5[_0x35ff('0x31')]);_0x2834e7['attributes']=_[_0x35ff('0x33')](_0xec33d5[_0x35ff('0x34')],qs['fields'](_0x277117[_0x35ff('0x31')][_0x35ff('0x35')]));_0x2834e7[_0x35ff('0x36')]=_0x2834e7[_0x35ff('0x36')][_0x35ff('0x37')]?_0x2834e7['attributes']:_0xec33d5[_0x35ff('0x34')];if(!_0x277117[_0x35ff('0x31')][_0x35ff('0xae')](_0x35ff('0x38'))){_0x2834e7[_0x35ff('0x39')]=qs[_0x35ff('0x39')](_0x277117[_0x35ff('0x31')][_0x35ff('0x39')]);_0x2834e7[_0x35ff('0x1c')]=qs[_0x35ff('0x1c')](_0x277117[_0x35ff('0x31')][_0x35ff('0x1c')]);}_0x2834e7[_0x35ff('0x3a')]=qs['sort'](_0x277117[_0x35ff('0x31')][_0x35ff('0x3b')]);_0x2834e7[_0x35ff('0x6b')]=qs[_0x35ff('0x3c')](_[_0x35ff('0x3d')](_0x277117[_0x35ff('0x31')],_0xec33d5[_0x35ff('0x3c')]));_0x2834e7['where'][_0x35ff('0xa1')]=_0x199519['id'];if(_0x277117[_0x35ff('0x31')][_0x35ff('0x78')]){_0x2834e7[_0x35ff('0x6b')]=_['merge'](_0x2834e7[_0x35ff('0x6b')],{'$or':_[_0x35ff('0x28')](_0x2834e7[_0x35ff('0x36')],function(_0xcdfdef){var _0x3a3935={};_0x3a3935[_0xcdfdef]={'$like':'%'+_0x277117[_0x35ff('0x31')]['filter']+'%'};return _0x3a3935;})});}if(_0x277117[_0x35ff('0x31')][_0x35ff('0x6e')]){var _0x33f5dc=_0x277117[_0x35ff('0x31')]['$gte'][_0x35ff('0x61')](',');var _0x130ac4={};_0x130ac4[_0x33f5dc[0x0]]={'$gte':moment(_0x33f5dc[0x1])[_0x35ff('0xaf')](_0x35ff('0xb0'))};_0x2834e7['where']=_[_0x35ff('0x90')](_0x2834e7['where'],_0x130ac4);}_0x2834e7=_[_0x35ff('0x90')]({},_0x2834e7,_0x277117[_0x35ff('0xa7')]);return db['FaxMessage'][_0x35ff('0x1b')]({'where':_0x2834e7[_0x35ff('0x6b')]})['then'](function(_0x1c4967){_0x5ecde1['count']=_0x1c4967;if(_0x277117[_0x35ff('0x31')][_0x35ff('0xa6')]){_0x2834e7[_0x35ff('0xb1')]=[{'all':!![]}];}return db['FaxMessage'][_0x35ff('0xb2')](_0x2834e7);})[_0x35ff('0x21')](function(_0x2b5a00){_0x5ecde1['rows']=_0x2b5a00;return _0x5ecde1;});}})[_0x35ff('0x21')](respondWithFilteredResult(_0x28aed0,_0x2834e7))[_0x35ff('0x2b')](handleError(_0x28aed0,null));};exports[_0x35ff('0xb3')]=function(_0x2da27b,_0x3b531c,_0x5c6e9d){return db[_0x35ff('0x91')][_0x35ff('0x56')]({'where':{'id':_0x2da27b['params']['id']}})[_0x35ff('0x21')](handleEntityNotFound(_0x3b531c,null))[_0x35ff('0x21')](function(_0x57862f){if(_0x57862f){return _0x57862f['setTags'](_0x2da27b['body'][_0x35ff('0xb4')],_['omit'](_0x2da27b[_0x35ff('0x67')],['ids','id'])||{})[_0x35ff('0xb5')](function(){return db[_0x35ff('0x60')][_0x35ff('0xb2')]({'attributes':['id',_0x35ff('0x25'),_0x35ff('0x40')],'where':{'id':_0x2da27b[_0x35ff('0x67')]['ids']}});})['then'](function(_0x9f3157){socket[_0x35ff('0xb6')](_0x35ff('0xb7'),{'id':Number(_0x2da27b[_0x35ff('0xa5')]['id']),'tags':_0x9f3157||[]});return{'id':Number(_0x2da27b['params']['id']),'tags':_0x9f3157||[]};});}})['then'](respondWithResult(_0x3b531c,null))[_0x35ff('0x2b')](handleError(_0x3b531c,null));};exports[_0x35ff('0xb8')]=function(_0x49b09d,_0xff29fd,_0x5166b5){return db[_0x35ff('0x91')][_0x35ff('0x56')]({'where':{'id':_0x49b09d[_0x35ff('0xa5')]['id']}})[_0x35ff('0x21')](handleEntityNotFound(_0xff29fd,null))['then'](function(_0x2d48ba){if(_0x2d48ba){return _0x2d48ba[_0x35ff('0xb8')](_0x49b09d['query'][_0x35ff('0xb4')]);}})['then'](respondWithStatusCode(_0xff29fd,null))[_0x35ff('0x2b')](handleError(_0xff29fd,null));};exports[_0x35ff('0xb9')]=function(_0x568428,_0x47a780){var _0x4fc402=moment()[_0x35ff('0xba')]()[_0x35ff('0x8e')]();var _0xf33aed=path[_0x35ff('0xbb')](config[_0x35ff('0xbc')],_0x35ff('0xbd'),_0x35ff('0xbe'),_0x35ff('0xbf'));var _0x45c65c=path[_0x35ff('0xbb')](config['root'],_0x35ff('0xbd'),_0x35ff('0xbe'),_0x35ff('0xc0'));var _0x1ee068=path[_0x35ff('0xbb')](_0xf33aed,_0x4fc402);var _0xd73e42=util[_0x35ff('0xaf')](_0x35ff('0xc1'),_0x568428['params']['id'],_0x4fc402);var _0x407858=path['join'](_0xf33aed,_0xd73e42);var _0x5190fa=[];_0x5190fa[_0x35ff('0xc2')]({'model':db[_0x35ff('0xc3')],'as':'Attachment','raw':!![]});var _0x59501f=[{'model':db['FaxMessage'],'as':_0x35ff('0xc4'),'attributes':['id',_0x35ff('0x67'),_0x35ff('0x6c')],'include':_0x5190fa}];return db[_0x35ff('0x91')]['find']({'where':{'id':_0x568428[_0x35ff('0xa5')]['id']},'include':_0x59501f})[_0x35ff('0x21')](handleEntityNotFound(_0x47a780,null))[_0x35ff('0x21')](function(_0x583a1a){if(_0x583a1a&&_0x583a1a['Messages']){var _0x2e1e4b=_0x583a1a[_0x35ff('0xc5')]({'plain':!![]});fs[_0x35ff('0xc6')](_0x1ee068);for(var _0x1b394d=0x0;_0x1b394d<_0x2e1e4b[_0x35ff('0xc4')][_0x35ff('0x37')];_0x1b394d++){var _0x5ce332=_0x2e1e4b[_0x35ff('0xc4')][_0x1b394d][_0x35ff('0xc3')];if(_0x5ce332){var _0x113800=path['join'](_0x45c65c,_0x5ce332[_0x35ff('0xc7')]);if(fs[_0x35ff('0xc8')](_0x113800)){fs[_0x35ff('0xc9')](_0x113800)['pipe'](fs[_0x35ff('0xca')](path[_0x35ff('0xbb')](_0x1ee068,_0x5ce332['basename'])));}}}return BPromise['resolve']()[_0x35ff('0x21')](function(){return new BPromise(function(_0x57ba52,_0x10bb86){zipdir(_0x1ee068,{'saveTo':_0x407858},function(_0x86274,_0x2ee232){if(_0x86274)return _0x10bb86(_0x86274);return _0x57ba52(_0x2ee232);});})['then'](function(){return new BPromise(function(_0x53e1c0,_0x5455d5){rimraf(_0x1ee068,function(_0x464ab8){if(_0x464ab8)_0x5455d5(_0x464ab8);return _0x53e1c0();});});})[_0x35ff('0x21')](function(){return _0x47a780[_0x35ff('0xb9')](_0x407858,_0xd73e42,function(_0x334375){if(_0x334375){console[_0x35ff('0xcb')](_0x35ff('0xcc'),_0x334375);}else{fs[_0x35ff('0xcd')](_0x407858);}});});});}else{return _0x47a780[_0x35ff('0x17')](0xc8);}})[_0x35ff('0x2b')](handleError(_0x47a780,null));};
\ No newline at end of file
+var _0x6de9=['json','offset','undefined','limit','count','Content-Range','update','then','end','error','stack','name','send','index','map','FaxInteraction','rawAttributes','fieldName','type','key','getOptions','findAll','query','user','show','params','model','keys','filters','intersection','attributes','fields','length','include','merge','options','find','catch','create','body','destroy','describe','FaxMessage','addMessage','ids','omit','getMessages','findOne','nolimit','order','sort','where','FaxInteractionId','filter','$gte','format','YYYY-MM-DD\x20HH:mm:ss','includeAll','rows','addTags','Tag','emit','faxInteractionTags:save','removeTags','download','unix','toString','join','root','server','files','tmp','transcript-%d-%s.zip','push','Attachment','Messages','createdAt','get','mkdirSync','basename','existsSync','pipe','createWriteStream','log','err','unlinkSync','rimraf','zip-dir','bluebird','util','path','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../config/logger','api','../../config/environment','redis','defaults','localhost','socket.io-emitter','./faxInteraction.socket','sendStatus','status'];(function(_0x22e679,_0x39a6c5){var _0x3b793b=function(_0x25f580){while(--_0x25f580){_0x22e679['push'](_0x22e679['shift']());}};_0x3b793b(++_0x39a6c5);}(_0x6de9,0x191));var _0x96de=function(_0x618414,_0x1a7a60){_0x618414=_0x618414-0x0;var _0x21c19a=_0x6de9[_0x618414];return _0x21c19a;};'use strict';var rimraf=require(_0x96de('0x0'));var zipdir=require(_0x96de('0x1'));var moment=require('moment');var BPromise=require(_0x96de('0x2'));var util=require(_0x96de('0x3'));var path=require(_0x96de('0x4'));var fs=require('fs');var _=require(_0x96de('0x5'));var Redis=require(_0x96de('0x6'));var interaction=require(_0x96de('0x7'));var qs=require(_0x96de('0x8'));var logger=require(_0x96de('0x9'))(_0x96de('0xa'));var config=require(_0x96de('0xb'));var db=require('../../mysqldb')['db'];config[_0x96de('0xc')]=_[_0x96de('0xd')](config['redis'],{'host':_0x96de('0xe'),'port':0x18eb});var socket=require(_0x96de('0xf'))(new Redis(config[_0x96de('0xc')]));require(_0x96de('0x10'))['register'](socket);function respondWithStatusCode(_0x219079,_0x2f048d){_0x2f048d=_0x2f048d||0xcc;return function(_0x5191b8){if(_0x5191b8){return _0x219079[_0x96de('0x11')](_0x2f048d);}return _0x219079[_0x96de('0x12')](_0x2f048d)['end']();};}function respondWithResult(_0xab73f3,_0x3de513){_0x3de513=_0x3de513||0xc8;return function(_0x5dc791){if(_0x5dc791){return _0xab73f3['status'](_0x3de513)[_0x96de('0x13')](_0x5dc791);}};}function respondWithFilteredResult(_0x4dccde,_0x52454f){return function(_0x18a49f){if(_0x18a49f){var _0xf21fb4=typeof _0x52454f[_0x96de('0x14')]===_0x96de('0x15')&&typeof _0x52454f[_0x96de('0x16')]===_0x96de('0x15');var _0x47980f=_0x18a49f[_0x96de('0x17')];var _0x13efc5=_0xf21fb4?0x0:_0x52454f[_0x96de('0x14')];var _0x3042d1=_0xf21fb4?_0x18a49f[_0x96de('0x17')]:_0x52454f[_0x96de('0x14')]+_0x52454f[_0x96de('0x16')];var _0x84390a;if(_0x3042d1>=_0x47980f){_0x3042d1=_0x47980f;_0x84390a=0xc8;}else{_0x84390a=0xce;}_0x4dccde['status'](_0x84390a);return _0x4dccde['set'](_0x96de('0x18'),_0x13efc5+'-'+_0x3042d1+'/'+_0x47980f)[_0x96de('0x13')](_0x18a49f);}return null;};}function saveUpdates(_0x47966c){return function(_0x48de62){if(_0x48de62){return _0x48de62[_0x96de('0x19')](_0x47966c)[_0x96de('0x1a')](function(_0x22cc47){return _0x22cc47;});}return null;};}function removeEntity(_0x2a3d13){return function(_0x10465a){if(_0x10465a){return _0x10465a['destroy']()['then'](function(){_0x2a3d13[_0x96de('0x12')](0xcc)[_0x96de('0x1b')]();});}};}function handleEntityNotFound(_0x443265){return function(_0x3674a2){if(!_0x3674a2){_0x443265['sendStatus'](0x194);}return _0x3674a2;};}function handleError(_0x420f85,_0x520fe4){_0x520fe4=_0x520fe4||0x1f4;return function(_0x36a7c6){logger[_0x96de('0x1c')](_0x36a7c6[_0x96de('0x1d')]);if(_0x36a7c6['name']){delete _0x36a7c6[_0x96de('0x1e')];}_0x420f85[_0x96de('0x12')](_0x520fe4)[_0x96de('0x1f')](_0x36a7c6);};}exports[_0x96de('0x20')]=function(_0x2da196,_0x4e9b9d){var _0x4b8eb9={};var _0xf0074=_[_0x96de('0x21')](db[_0x96de('0x22')][_0x96de('0x23')],function(_0x1ead38){return{'name':_0x1ead38[_0x96de('0x24')],'type':_0x1ead38[_0x96de('0x25')][_0x96de('0x26')]};});_0x4b8eb9=qs[_0x96de('0x27')](_0xf0074,_0x2da196);return interaction[_0x96de('0x28')]('fax',_0x2da196[_0x96de('0x29')],_0x2da196[_0x96de('0x2a')],_0x4b8eb9,_0xf0074)[_0x96de('0x1a')](respondWithFilteredResult(_0x4e9b9d,_0x4b8eb9))['catch'](handleError(_0x4e9b9d,null));};exports[_0x96de('0x2b')]=function(_0x2b4eac,_0x279d53){var _0x257859={'raw':![],'where':{'id':_0x2b4eac[_0x96de('0x2c')]['id']}},_0xc3f37f={};_0xc3f37f[_0x96de('0x2d')]=_[_0x96de('0x2e')](db['FaxInteraction'][_0x96de('0x23')]);_0xc3f37f[_0x96de('0x29')]=_[_0x96de('0x2e')](_0x2b4eac['query']);_0xc3f37f[_0x96de('0x2f')]=_[_0x96de('0x30')](_0xc3f37f[_0x96de('0x2d')],_0xc3f37f['query']);_0x257859[_0x96de('0x31')]=_[_0x96de('0x30')](_0xc3f37f[_0x96de('0x2d')],qs[_0x96de('0x32')](_0x2b4eac[_0x96de('0x29')][_0x96de('0x32')]));_0x257859[_0x96de('0x31')]=_0x257859[_0x96de('0x31')][_0x96de('0x33')]?_0x257859[_0x96de('0x31')]:_0xc3f37f[_0x96de('0x2d')];if(_0x2b4eac[_0x96de('0x29')]['includeAll']){_0x257859[_0x96de('0x34')]=[{'all':!![]}];}_0x257859=_[_0x96de('0x35')]({},_0x257859,_0x2b4eac[_0x96de('0x36')]);return db[_0x96de('0x22')][_0x96de('0x37')](_0x257859)['then'](handleEntityNotFound(_0x279d53,null))[_0x96de('0x1a')](respondWithResult(_0x279d53,null))[_0x96de('0x38')](handleError(_0x279d53,null));};exports['create']=function(_0x29ac66,_0x33ee3a){return db[_0x96de('0x22')][_0x96de('0x39')](_0x29ac66[_0x96de('0x3a')],{})['then'](respondWithResult(_0x33ee3a,0xc9))[_0x96de('0x38')](handleError(_0x33ee3a,null));};exports[_0x96de('0x19')]=function(_0x3e3cfd,_0x304198){if(_0x3e3cfd['body']['id']){delete _0x3e3cfd[_0x96de('0x3a')]['id'];}return db[_0x96de('0x22')][_0x96de('0x37')]({'where':{'id':_0x3e3cfd[_0x96de('0x2c')]['id']}})[_0x96de('0x1a')](handleEntityNotFound(_0x304198,null))['then'](saveUpdates(_0x3e3cfd[_0x96de('0x3a')],null))[_0x96de('0x1a')](respondWithResult(_0x304198,null))['catch'](handleError(_0x304198,null));};exports[_0x96de('0x3b')]=function(_0x35a2f4,_0xb02711){return db[_0x96de('0x22')][_0x96de('0x37')]({'where':{'id':_0x35a2f4[_0x96de('0x2c')]['id']}})['then'](handleEntityNotFound(_0xb02711,null))[_0x96de('0x1a')](removeEntity(_0xb02711,null))[_0x96de('0x38')](handleError(_0xb02711,null));};exports['describe']=function(_0x3b5ac5,_0x472988){return db[_0x96de('0x22')][_0x96de('0x3c')]()[_0x96de('0x1a')](respondWithResult(_0x472988,null))[_0x96de('0x38')](handleError(_0x472988,null));};exports['addMessage']=function(_0x24963b,_0x53c85c){return db[_0x96de('0x3d')][_0x96de('0x37')]({'where':{'id':_0x24963b[_0x96de('0x2c')]['id']}})['then'](handleEntityNotFound(_0x53c85c,null))[_0x96de('0x1a')](function(_0x5124dd){if(_0x5124dd){return _0x5124dd[_0x96de('0x3e')](_0x24963b[_0x96de('0x3a')][_0x96de('0x3f')],_[_0x96de('0x40')](_0x24963b[_0x96de('0x3a')],[_0x96de('0x3f'),'id'])||{});}})[_0x96de('0x1a')](respondWithResult(_0x53c85c,null))['catch'](handleError(_0x53c85c,null));};exports[_0x96de('0x41')]=function(_0x485bc6,_0xf871fc){var _0x3e2f6b={'raw':![],'where':{}};var _0x4a5c12={};var _0x1cfda3={'count':0x0,'rows':[]};return db['FaxInteraction'][_0x96de('0x42')]({'where':{'id':_0x485bc6['params']['id']}})[_0x96de('0x1a')](handleEntityNotFound(_0xf871fc,null))['then'](function(_0x2c4b2a){if(_0x2c4b2a){_0x4a5c12[_0x96de('0x2d')]=_[_0x96de('0x2e')](db[_0x96de('0x3d')][_0x96de('0x23')]);_0x4a5c12[_0x96de('0x29')]=_[_0x96de('0x2e')](_0x485bc6[_0x96de('0x29')]);_0x4a5c12[_0x96de('0x2f')]=_[_0x96de('0x30')](_0x4a5c12[_0x96de('0x2d')],_0x4a5c12[_0x96de('0x29')]);_0x3e2f6b[_0x96de('0x31')]=_[_0x96de('0x30')](_0x4a5c12[_0x96de('0x2d')],qs['fields'](_0x485bc6[_0x96de('0x29')]['fields']));_0x3e2f6b['attributes']=_0x3e2f6b['attributes'][_0x96de('0x33')]?_0x3e2f6b[_0x96de('0x31')]:_0x4a5c12[_0x96de('0x2d')];if(!_0x485bc6[_0x96de('0x29')]['hasOwnProperty'](_0x96de('0x43'))){_0x3e2f6b[_0x96de('0x16')]=qs[_0x96de('0x16')](_0x485bc6[_0x96de('0x29')]['limit']);_0x3e2f6b['offset']=qs[_0x96de('0x14')](_0x485bc6[_0x96de('0x29')][_0x96de('0x14')]);}_0x3e2f6b[_0x96de('0x44')]=qs['sort'](_0x485bc6[_0x96de('0x29')][_0x96de('0x45')]);_0x3e2f6b['where']=qs[_0x96de('0x2f')](_['pick'](_0x485bc6[_0x96de('0x29')],_0x4a5c12[_0x96de('0x2f')]));_0x3e2f6b[_0x96de('0x46')][_0x96de('0x47')]=_0x2c4b2a['id'];if(_0x485bc6[_0x96de('0x29')][_0x96de('0x48')]){_0x3e2f6b[_0x96de('0x46')]=_[_0x96de('0x35')](_0x3e2f6b[_0x96de('0x46')],{'$or':_[_0x96de('0x21')](_0x3e2f6b[_0x96de('0x31')],function(_0x8120e1){var _0x2c1ea6={};_0x2c1ea6[_0x8120e1]={'$like':'%'+_0x485bc6[_0x96de('0x29')][_0x96de('0x48')]+'%'};return _0x2c1ea6;})});}if(_0x485bc6[_0x96de('0x29')][_0x96de('0x49')]){var _0x53ec75=_0x485bc6['query'][_0x96de('0x49')]['split'](',');var _0x1b76eb={};_0x1b76eb[_0x53ec75[0x0]]={'$gte':moment(_0x53ec75[0x1])[_0x96de('0x4a')](_0x96de('0x4b'))};_0x3e2f6b['where']=_[_0x96de('0x35')](_0x3e2f6b[_0x96de('0x46')],_0x1b76eb);}_0x3e2f6b=_[_0x96de('0x35')]({},_0x3e2f6b,_0x485bc6[_0x96de('0x36')]);return db['FaxMessage'][_0x96de('0x17')]({'where':_0x3e2f6b[_0x96de('0x46')]})[_0x96de('0x1a')](function(_0x144d79){_0x1cfda3['count']=_0x144d79;if(_0x485bc6['query'][_0x96de('0x4c')]){_0x3e2f6b['include']=[{'all':!![]}];}return db[_0x96de('0x3d')][_0x96de('0x28')](_0x3e2f6b);})[_0x96de('0x1a')](function(_0x5068f2){_0x1cfda3[_0x96de('0x4d')]=_0x5068f2;return _0x1cfda3;});}})['then'](respondWithFilteredResult(_0xf871fc,_0x3e2f6b))['catch'](handleError(_0xf871fc,null));};exports[_0x96de('0x4e')]=function(_0x4e584d,_0x49b650){return db[_0x96de('0x22')]['find']({'where':{'id':_0x4e584d[_0x96de('0x2c')]['id']}})[_0x96de('0x1a')](handleEntityNotFound(_0x49b650,null))[_0x96de('0x1a')](function(_0x1a59c1){if(_0x1a59c1){return _0x1a59c1['setTags'](_0x4e584d[_0x96de('0x3a')][_0x96de('0x3f')],_[_0x96de('0x40')](_0x4e584d[_0x96de('0x3a')],['ids','id'])||{})['spread'](function(){return db[_0x96de('0x4f')][_0x96de('0x28')]({'attributes':['id',_0x96de('0x1e'),'color'],'where':{'id':_0x4e584d[_0x96de('0x3a')][_0x96de('0x3f')]}});})[_0x96de('0x1a')](function(_0x5bc07a){socket[_0x96de('0x50')](_0x96de('0x51'),{'id':Number(_0x4e584d[_0x96de('0x2c')]['id']),'tags':_0x5bc07a||[]});return{'id':Number(_0x4e584d[_0x96de('0x2c')]['id']),'tags':_0x5bc07a||[]};});}})['then'](respondWithResult(_0x49b650,null))[_0x96de('0x38')](handleError(_0x49b650,null));};exports[_0x96de('0x52')]=function(_0x8f260f,_0x57f675){return db['FaxInteraction'][_0x96de('0x37')]({'where':{'id':_0x8f260f['params']['id']}})[_0x96de('0x1a')](handleEntityNotFound(_0x57f675,null))['then'](function(_0x5602a3){if(_0x5602a3){return _0x5602a3[_0x96de('0x52')](_0x8f260f[_0x96de('0x29')][_0x96de('0x3f')]);}})[_0x96de('0x1a')](respondWithStatusCode(_0x57f675,null))['catch'](handleError(_0x57f675,null));};exports[_0x96de('0x53')]=function(_0x4ca14a,_0x27a81a){var _0x2b7a07=moment()[_0x96de('0x54')]()[_0x96de('0x55')]();var _0x3724fc=path[_0x96de('0x56')](config[_0x96de('0x57')],_0x96de('0x58'),_0x96de('0x59'),_0x96de('0x5a'));var _0xf2690d=path[_0x96de('0x56')](config['root'],'server',_0x96de('0x59'),'attachments');var _0x1fd7b8=path[_0x96de('0x56')](_0x3724fc,_0x2b7a07);var _0x60dc6b=util[_0x96de('0x4a')](_0x96de('0x5b'),_0x4ca14a[_0x96de('0x2c')]['id'],_0x2b7a07);var _0x3ceb48=path[_0x96de('0x56')](_0x3724fc,_0x60dc6b);var _0x505ffe=[];_0x505ffe[_0x96de('0x5c')]({'model':db[_0x96de('0x5d')],'as':_0x96de('0x5d'),'raw':!![]});var _0x3cff7b=[{'model':db[_0x96de('0x3d')],'as':_0x96de('0x5e'),'attributes':['id',_0x96de('0x3a'),_0x96de('0x5f')],'include':_0x505ffe}];return db['FaxInteraction'][_0x96de('0x37')]({'where':{'id':_0x4ca14a['params']['id']},'include':_0x3cff7b})[_0x96de('0x1a')](handleEntityNotFound(_0x27a81a,null))[_0x96de('0x1a')](function(_0x3d4983){if(_0x3d4983&&_0x3d4983['Messages']){var _0x4742e2=_0x3d4983[_0x96de('0x60')]({'plain':!![]});fs[_0x96de('0x61')](_0x1fd7b8);for(var _0x5bca7c=0x0;_0x5bca7c<_0x4742e2[_0x96de('0x5e')][_0x96de('0x33')];_0x5bca7c++){var _0x2d38f8=_0x4742e2[_0x96de('0x5e')][_0x5bca7c]['Attachment'];if(_0x2d38f8){var _0x2e76dc=path[_0x96de('0x56')](_0xf2690d,_0x2d38f8[_0x96de('0x62')]);if(fs[_0x96de('0x63')](_0x2e76dc)){fs['createReadStream'](_0x2e76dc)[_0x96de('0x64')](fs[_0x96de('0x65')](path[_0x96de('0x56')](_0x1fd7b8,_0x2d38f8[_0x96de('0x62')])));}}}return BPromise['resolve']()[_0x96de('0x1a')](function(){return new BPromise(function(_0x54c447,_0x5daa10){zipdir(_0x1fd7b8,{'saveTo':_0x3ceb48},function(_0x22d208,_0x4f0b47){if(_0x22d208)return _0x5daa10(_0x22d208);return _0x54c447(_0x4f0b47);});})[_0x96de('0x1a')](function(){return new BPromise(function(_0x4ffba6,_0x4d3521){rimraf(_0x1fd7b8,function(_0x240b9f){if(_0x240b9f)_0x4d3521(_0x240b9f);return _0x4ffba6();});});})['then'](function(){return _0x27a81a['download'](_0x3ceb48,_0x60dc6b,function(_0x2ceb19){if(_0x2ceb19){console[_0x96de('0x66')](_0x96de('0x67'),_0x2ceb19);}else{fs[_0x96de('0x68')](_0x3ceb48);}});});});}else{return _0x27a81a[_0x96de('0x11')](0xc8);}})['catch'](handleError(_0x27a81a,null));};
\ No newline at end of file