Built motion from commit eddce310.|2.6.12
[motion2.git] / server / api / faxInteraction / faxInteraction.controller.js
index 8af82d2..7e7f3db 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 _0x81cf=['undefined','limit','set','Content-Range','update','then','destroy','stack','name','send','index','FaxInteraction','rawAttributes','fieldName','type','key','fax','query','user','show','model','keys','filters','intersection','attributes','fields','length','includeAll','include','merge','options','catch','create','body','find','params','describe','addMessage','FaxMessage','ids','findOne','hasOwnProperty','nolimit','order','sort','pick','where','map','$gte','split','count','findAll','rows','addTags','setTags','omit','spread','Tag','color','faxInteractionTags:save','download','unix','join','root','server','files','tmp','attachments','format','transcript-%d-%s.zip','push','Attachment','createdAt','get','mkdirSync','Messages','basename','existsSync','createReadStream','createWriteStream','resolve','log','err','unlinkSync','rimraf','moment','util','path','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../config/logger','../../config/environment','defaults','localhost','socket.io-emitter','./faxInteraction.socket','sendStatus','end','status','json','offset'];(function(_0x41a3af,_0x35694d){var _0x2075ec=function(_0x36dffb){while(--_0x36dffb){_0x41a3af['push'](_0x41a3af['shift']());}};_0x2075ec(++_0x35694d);}(_0x81cf,0x1f0));var _0xf81c=function(_0x423edc,_0x1ec185){_0x423edc=_0x423edc-0x0;var _0x3d6101=_0x81cf[_0x423edc];return _0x3d6101;};'use strict';var rimraf=require(_0xf81c('0x0'));var zipdir=require('zip-dir');var moment=require(_0xf81c('0x1'));var BPromise=require('bluebird');var util=require(_0xf81c('0x2'));var path=require(_0xf81c('0x3'));var fs=require('fs');var _=require(_0xf81c('0x4'));var Redis=require(_0xf81c('0x5'));var interaction=require(_0xf81c('0x6'));var qs=require(_0xf81c('0x7'));var logger=require(_0xf81c('0x8'))('api');var config=require(_0xf81c('0x9'));var db=require('../../mysqldb')['db'];config['redis']=_[_0xf81c('0xa')](config['redis'],{'host':_0xf81c('0xb'),'port':0x18eb});var socket=require(_0xf81c('0xc'))(new Redis(config['redis']));require(_0xf81c('0xd'))['register'](socket);function respondWithStatusCode(_0x21a2b6,_0x5ae3db){_0x5ae3db=_0x5ae3db||0xcc;return function(_0x1fafb6){if(_0x1fafb6){return _0x21a2b6[_0xf81c('0xe')](_0x5ae3db);}return _0x21a2b6['status'](_0x5ae3db)[_0xf81c('0xf')]();};}function respondWithResult(_0x2adebb,_0x59ee9b){_0x59ee9b=_0x59ee9b||0xc8;return function(_0x40230b){if(_0x40230b){return _0x2adebb[_0xf81c('0x10')](_0x59ee9b)[_0xf81c('0x11')](_0x40230b);}};}function respondWithFilteredResult(_0x3470f0,_0x32e454){return function(_0x4756dd){if(_0x4756dd){var _0x594d4d=typeof _0x32e454[_0xf81c('0x12')]===_0xf81c('0x13')&&typeof _0x32e454[_0xf81c('0x14')]===_0xf81c('0x13');var _0x22ce73=_0x4756dd['count'];var _0x5528d5=_0x594d4d?0x0:_0x32e454[_0xf81c('0x12')];var _0x72f842=_0x594d4d?_0x4756dd['count']:_0x32e454[_0xf81c('0x12')]+_0x32e454[_0xf81c('0x14')];var _0x2ca4e2;if(_0x72f842>=_0x22ce73){_0x72f842=_0x22ce73;_0x2ca4e2=0xc8;}else{_0x2ca4e2=0xce;}_0x3470f0[_0xf81c('0x10')](_0x2ca4e2);return _0x3470f0[_0xf81c('0x15')](_0xf81c('0x16'),_0x5528d5+'-'+_0x72f842+'/'+_0x22ce73)[_0xf81c('0x11')](_0x4756dd);}return null;};}function saveUpdates(_0x2b339c){return function(_0x1fe6ad){if(_0x1fe6ad){return _0x1fe6ad[_0xf81c('0x17')](_0x2b339c)[_0xf81c('0x18')](function(_0x34f2a5){return _0x34f2a5;});}return null;};}function removeEntity(_0x2ce548){return function(_0x4dffa0){if(_0x4dffa0){return _0x4dffa0[_0xf81c('0x19')]()['then'](function(){_0x2ce548[_0xf81c('0x10')](0xcc)[_0xf81c('0xf')]();});}};}function handleEntityNotFound(_0x18df54){return function(_0x5aee2b){if(!_0x5aee2b){_0x18df54[_0xf81c('0xe')](0x194);}return _0x5aee2b;};}function handleError(_0x12eb16,_0x2f3b2f){_0x2f3b2f=_0x2f3b2f||0x1f4;return function(_0x4904ab){logger['error'](_0x4904ab[_0xf81c('0x1a')]);if(_0x4904ab[_0xf81c('0x1b')]){delete _0x4904ab[_0xf81c('0x1b')];}_0x12eb16[_0xf81c('0x10')](_0x2f3b2f)[_0xf81c('0x1c')](_0x4904ab);};}exports[_0xf81c('0x1d')]=function(_0x115265,_0x16dacd){var _0x270aaa={};var _0x207251=_['map'](db[_0xf81c('0x1e')][_0xf81c('0x1f')],function(_0x2438f4){return{'name':_0x2438f4[_0xf81c('0x20')],'type':_0x2438f4[_0xf81c('0x21')][_0xf81c('0x22')]};});_0x270aaa=qs['getOptions'](_0x207251,_0x115265);return interaction['findAll'](_0xf81c('0x23'),_0x115265[_0xf81c('0x24')],_0x115265[_0xf81c('0x25')],_0x270aaa,_0x207251)[_0xf81c('0x18')](respondWithFilteredResult(_0x16dacd,_0x270aaa))['catch'](handleError(_0x16dacd,null));};exports[_0xf81c('0x26')]=function(_0x5e0996,_0x118190){var _0x391501={'raw':![],'where':{'id':_0x5e0996['params']['id']}},_0x382a3b={};_0x382a3b[_0xf81c('0x27')]=_[_0xf81c('0x28')](db['FaxInteraction'][_0xf81c('0x1f')]);_0x382a3b['query']=_[_0xf81c('0x28')](_0x5e0996[_0xf81c('0x24')]);_0x382a3b[_0xf81c('0x29')]=_[_0xf81c('0x2a')](_0x382a3b[_0xf81c('0x27')],_0x382a3b['query']);_0x391501[_0xf81c('0x2b')]=_['intersection'](_0x382a3b[_0xf81c('0x27')],qs[_0xf81c('0x2c')](_0x5e0996[_0xf81c('0x24')][_0xf81c('0x2c')]));_0x391501[_0xf81c('0x2b')]=_0x391501[_0xf81c('0x2b')][_0xf81c('0x2d')]?_0x391501[_0xf81c('0x2b')]:_0x382a3b[_0xf81c('0x27')];if(_0x5e0996[_0xf81c('0x24')][_0xf81c('0x2e')]){_0x391501[_0xf81c('0x2f')]=[{'all':!![]}];}_0x391501=_[_0xf81c('0x30')]({},_0x391501,_0x5e0996[_0xf81c('0x31')]);return db[_0xf81c('0x1e')]['find'](_0x391501)[_0xf81c('0x18')](handleEntityNotFound(_0x118190,null))[_0xf81c('0x18')](respondWithResult(_0x118190,null))[_0xf81c('0x32')](handleError(_0x118190,null));};exports[_0xf81c('0x33')]=function(_0x40b77c,_0x37ced1){return db[_0xf81c('0x1e')][_0xf81c('0x33')](_0x40b77c[_0xf81c('0x34')],{})[_0xf81c('0x18')](respondWithResult(_0x37ced1,0xc9))[_0xf81c('0x32')](handleError(_0x37ced1,null));};exports['update']=function(_0x1663af,_0x19b56f){if(_0x1663af['body']['id']){delete _0x1663af[_0xf81c('0x34')]['id'];}return db['FaxInteraction'][_0xf81c('0x35')]({'where':{'id':_0x1663af[_0xf81c('0x36')]['id']}})[_0xf81c('0x18')](handleEntityNotFound(_0x19b56f,null))[_0xf81c('0x18')](saveUpdates(_0x1663af[_0xf81c('0x34')],null))[_0xf81c('0x18')](respondWithResult(_0x19b56f,null))[_0xf81c('0x32')](handleError(_0x19b56f,null));};exports['destroy']=function(_0x2afdf2,_0x58eebe){return db['FaxInteraction'][_0xf81c('0x35')]({'where':{'id':_0x2afdf2[_0xf81c('0x36')]['id']}})[_0xf81c('0x18')](handleEntityNotFound(_0x58eebe,null))[_0xf81c('0x18')](removeEntity(_0x58eebe,null))[_0xf81c('0x32')](handleError(_0x58eebe,null));};exports[_0xf81c('0x37')]=function(_0x14b1a5,_0x5eb873){return db[_0xf81c('0x1e')][_0xf81c('0x37')]()[_0xf81c('0x18')](respondWithResult(_0x5eb873,null))[_0xf81c('0x32')](handleError(_0x5eb873,null));};exports[_0xf81c('0x38')]=function(_0x5c7111,_0x4e6953){return db[_0xf81c('0x39')]['find']({'where':{'id':_0x5c7111[_0xf81c('0x36')]['id']}})['then'](handleEntityNotFound(_0x4e6953,null))[_0xf81c('0x18')](function(_0x54fff7){if(_0x54fff7){return _0x54fff7[_0xf81c('0x38')](_0x5c7111[_0xf81c('0x34')][_0xf81c('0x3a')],_['omit'](_0x5c7111[_0xf81c('0x34')],['ids','id'])||{});}})[_0xf81c('0x18')](respondWithResult(_0x4e6953,null))[_0xf81c('0x32')](handleError(_0x4e6953,null));};exports['getMessages']=function(_0x395ea3,_0xb7a94c){var _0x12c6c7={'raw':![],'where':{}};var _0x4e58b5={};var _0xb8b846={'count':0x0,'rows':[]};return db[_0xf81c('0x1e')][_0xf81c('0x3b')]({'where':{'id':_0x395ea3['params']['id']}})['then'](handleEntityNotFound(_0xb7a94c,null))['then'](function(_0x3cb87e){if(_0x3cb87e){_0x4e58b5[_0xf81c('0x27')]=_[_0xf81c('0x28')](db[_0xf81c('0x39')][_0xf81c('0x1f')]);_0x4e58b5['query']=_[_0xf81c('0x28')](_0x395ea3[_0xf81c('0x24')]);_0x4e58b5[_0xf81c('0x29')]=_[_0xf81c('0x2a')](_0x4e58b5[_0xf81c('0x27')],_0x4e58b5[_0xf81c('0x24')]);_0x12c6c7[_0xf81c('0x2b')]=_[_0xf81c('0x2a')](_0x4e58b5[_0xf81c('0x27')],qs['fields'](_0x395ea3[_0xf81c('0x24')][_0xf81c('0x2c')]));_0x12c6c7[_0xf81c('0x2b')]=_0x12c6c7[_0xf81c('0x2b')][_0xf81c('0x2d')]?_0x12c6c7[_0xf81c('0x2b')]:_0x4e58b5[_0xf81c('0x27')];if(!_0x395ea3[_0xf81c('0x24')][_0xf81c('0x3c')](_0xf81c('0x3d'))){_0x12c6c7[_0xf81c('0x14')]=qs[_0xf81c('0x14')](_0x395ea3[_0xf81c('0x24')][_0xf81c('0x14')]);_0x12c6c7[_0xf81c('0x12')]=qs[_0xf81c('0x12')](_0x395ea3[_0xf81c('0x24')][_0xf81c('0x12')]);}_0x12c6c7[_0xf81c('0x3e')]=qs[_0xf81c('0x3f')](_0x395ea3[_0xf81c('0x24')][_0xf81c('0x3f')]);_0x12c6c7['where']=qs[_0xf81c('0x29')](_[_0xf81c('0x40')](_0x395ea3[_0xf81c('0x24')],_0x4e58b5[_0xf81c('0x29')]));_0x12c6c7['where']['FaxInteractionId']=_0x3cb87e['id'];if(_0x395ea3['query']['filter']){_0x12c6c7[_0xf81c('0x41')]=_[_0xf81c('0x30')](_0x12c6c7[_0xf81c('0x41')],{'$or':_[_0xf81c('0x42')](_0x12c6c7[_0xf81c('0x2b')],function(_0x45d1dd){var _0x3fac6e={};_0x3fac6e[_0x45d1dd]={'$like':'%'+_0x395ea3[_0xf81c('0x24')]['filter']+'%'};return _0x3fac6e;})});}if(_0x395ea3[_0xf81c('0x24')]['$gte']){var _0x283b00=_0x395ea3[_0xf81c('0x24')][_0xf81c('0x43')][_0xf81c('0x44')](',');var _0x54f0b9={};_0x54f0b9[_0x283b00[0x0]]={'$gte':moment(_0x283b00[0x1])['format']('YYYY-MM-DD\x20HH:mm:ss')};_0x12c6c7[_0xf81c('0x41')]=_[_0xf81c('0x30')](_0x12c6c7['where'],_0x54f0b9);}_0x12c6c7=_[_0xf81c('0x30')]({},_0x12c6c7,_0x395ea3['options']);return db[_0xf81c('0x39')][_0xf81c('0x45')]({'where':_0x12c6c7[_0xf81c('0x41')]})['then'](function(_0x8814af){_0xb8b846['count']=_0x8814af;if(_0x395ea3[_0xf81c('0x24')]['includeAll']){_0x12c6c7[_0xf81c('0x2f')]=[{'all':!![]}];}return db[_0xf81c('0x39')][_0xf81c('0x46')](_0x12c6c7);})[_0xf81c('0x18')](function(_0x1bcf6a){_0xb8b846[_0xf81c('0x47')]=_0x1bcf6a;return _0xb8b846;});}})[_0xf81c('0x18')](respondWithFilteredResult(_0xb7a94c,_0x12c6c7))[_0xf81c('0x32')](handleError(_0xb7a94c,null));};exports[_0xf81c('0x48')]=function(_0x3b7a9f,_0x44dadd){return db[_0xf81c('0x1e')][_0xf81c('0x35')]({'where':{'id':_0x3b7a9f[_0xf81c('0x36')]['id']}})[_0xf81c('0x18')](handleEntityNotFound(_0x44dadd,null))[_0xf81c('0x18')](function(_0x277598){if(_0x277598){return _0x277598[_0xf81c('0x49')](_0x3b7a9f[_0xf81c('0x34')][_0xf81c('0x3a')],_[_0xf81c('0x4a')](_0x3b7a9f[_0xf81c('0x34')],[_0xf81c('0x3a'),'id'])||{})[_0xf81c('0x4b')](function(){return db[_0xf81c('0x4c')]['findAll']({'attributes':['id',_0xf81c('0x1b'),_0xf81c('0x4d')],'where':{'id':_0x3b7a9f['body'][_0xf81c('0x3a')]}});})[_0xf81c('0x18')](function(_0x27abee){socket['emit'](_0xf81c('0x4e'),{'id':Number(_0x3b7a9f[_0xf81c('0x36')]['id']),'tags':_0x27abee||[]});return{'id':Number(_0x3b7a9f[_0xf81c('0x36')]['id']),'tags':_0x27abee||[]};});}})[_0xf81c('0x18')](respondWithResult(_0x44dadd,null))['catch'](handleError(_0x44dadd,null));};exports['removeTags']=function(_0x28d028,_0x211524){return db[_0xf81c('0x1e')][_0xf81c('0x35')]({'where':{'id':_0x28d028[_0xf81c('0x36')]['id']}})[_0xf81c('0x18')](handleEntityNotFound(_0x211524,null))[_0xf81c('0x18')](function(_0x2a39a6){if(_0x2a39a6){return _0x2a39a6['removeTags'](_0x28d028['query'][_0xf81c('0x3a')]);}})[_0xf81c('0x18')](respondWithStatusCode(_0x211524,null))[_0xf81c('0x32')](handleError(_0x211524,null));};exports[_0xf81c('0x4f')]=function(_0x1a2150,_0xf8b5db){var _0x565dd1=moment()[_0xf81c('0x50')]()['toString']();var _0x8272ed=path[_0xf81c('0x51')](config[_0xf81c('0x52')],_0xf81c('0x53'),_0xf81c('0x54'),_0xf81c('0x55'));var _0x20daca=path[_0xf81c('0x51')](config['root'],_0xf81c('0x53'),_0xf81c('0x54'),_0xf81c('0x56'));var _0x132ae8=path[_0xf81c('0x51')](_0x8272ed,_0x565dd1);var _0x52ecd0=util[_0xf81c('0x57')](_0xf81c('0x58'),_0x1a2150[_0xf81c('0x36')]['id'],_0x565dd1);var _0x29701e=path['join'](_0x8272ed,_0x52ecd0);var _0x4d5854=[];_0x4d5854[_0xf81c('0x59')]({'model':db[_0xf81c('0x5a')],'as':_0xf81c('0x5a'),'raw':!![]});var _0x222300=[{'model':db[_0xf81c('0x39')],'as':'Messages','attributes':['id',_0xf81c('0x34'),_0xf81c('0x5b')],'include':_0x4d5854}];return db['FaxInteraction'][_0xf81c('0x35')]({'where':{'id':_0x1a2150[_0xf81c('0x36')]['id']},'include':_0x222300})[_0xf81c('0x18')](handleEntityNotFound(_0xf8b5db,null))[_0xf81c('0x18')](function(_0x2df6fb){if(_0x2df6fb&&_0x2df6fb['Messages']){var _0x114765=_0x2df6fb[_0xf81c('0x5c')]({'plain':!![]});fs[_0xf81c('0x5d')](_0x132ae8);for(var _0x675e9a=0x0;_0x675e9a<_0x114765[_0xf81c('0x5e')][_0xf81c('0x2d')];_0x675e9a++){var _0x44b7ae=_0x114765['Messages'][_0x675e9a][_0xf81c('0x5a')];if(_0x44b7ae){var _0x5a6af8=path[_0xf81c('0x51')](_0x20daca,_0x44b7ae[_0xf81c('0x5f')]);if(fs[_0xf81c('0x60')](_0x5a6af8)){fs[_0xf81c('0x61')](_0x5a6af8)['pipe'](fs[_0xf81c('0x62')](path[_0xf81c('0x51')](_0x132ae8,_0x44b7ae[_0xf81c('0x5f')])));}}}return BPromise[_0xf81c('0x63')]()['then'](function(){return new BPromise(function(_0x575de5,_0x2d6e4d){zipdir(_0x132ae8,{'saveTo':_0x29701e},function(_0x190e23,_0x3146c7){if(_0x190e23)return _0x2d6e4d(_0x190e23);return _0x575de5(_0x3146c7);});})['then'](function(){return new BPromise(function(_0x414a75,_0x3dccdc){rimraf(_0x132ae8,function(_0xbf6e96){if(_0xbf6e96)_0x3dccdc(_0xbf6e96);return _0x414a75();});});})[_0xf81c('0x18')](function(){return _0xf8b5db[_0xf81c('0x4f')](_0x29701e,_0x52ecd0,function(_0x29159b){if(_0x29159b){console[_0xf81c('0x64')](_0xf81c('0x65'),_0x29159b);}else{fs[_0xf81c('0x66')](_0x29701e);}});});});}else{return _0xf8b5db[_0xf81c('0xe')](0xc8);}})[_0xf81c('0x32')](handleError(_0xf8b5db,null));};
\ No newline at end of file