Built motion from commit 14588770.|2.5.38
[motion2.git] / server / api / faxInteraction / faxInteraction.controller.js
index 605efc5..7663a15 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xbaad=['groupBy','FaxInteractionId','show','params','includeAll','include','options','create','describe','addMessage','FaxMessage','omit','ids','getMessages','findOne','hasOwnProperty','$gte','format','YYYY-MM-DD\x20HH:mm:ss','findAll','rows','addTags','setTags','spread','emit','faxInteractionTags:save','removeTags','root','files','join','server','attachments','Attachment','Messages','get','mkdirSync','basename','existsSync','createReadStream','pipe','createWriteStream','resolve','log','err','unlinkSync','html-pdf','eml-format','rimraf','zip-dir','request-promise','moment','mustache','path','ejs','squel','crypto','jsforce','to-csv','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../mysqldb','redis','localhost','socket.io-emitter','./faxInteraction.socket','sendStatus','status','end','offset','limit','set','Content-Range','json','apply','reject','save','update','destroy','then','error','stack','name','Users','map','fullname','TagIds','Tags','split','push','catch','index','rawAttributes','fieldName','type','query','keys','intersection','model','fields','attributes','length','nolimit','order','sort','where','filters','pick','select','field','color','from','tools_tags','u.id','u.fullname','users','u.id\x20=\x20ui.UserId','fax_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','left_join','fax_accounts','fax_messages','me.FaxInteractionId\x20=\x20i.id','fax_interaction_has_tags','it.FaxInteractionId\x20=\x20i.id','search','parseSearch','conditions','find','unreadMessages','value','having','`\x20=\x200','operator','$substring','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','start','Tag','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','text','body','some','compact','isEmpty','FaxAccountId','i.FaxAccountId\x20IN\x20?','concat','createdAt','parse','$lte','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','isArray','tag','filter','replace','\x27\x27\x27\x27','isNumeric','i.id\x20LIKE\x20?','i.fax\x20LIKE\x20?','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','Sequelize','QueryTypes','SELECT','clone','DESC','i.FaxAccountId\x20IS\x20NOT\x20NULL','user','getFaxAccounts','sequelize','toString','count','keyBy','merge','FaxInteraction','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','i.*','c.firstName','Contact.firstName','Contact.phone','c.mobile','Contact.mobile','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.FaxInteractionId\x20IN\x20?'];(function(_0x413efc,_0x383595){var _0x2bd0ba=function(_0x3bff59){while(--_0x3bff59){_0x413efc['push'](_0x413efc['shift']());}};_0x2bd0ba(++_0x383595);}(_0xbaad,0x1d1));var _0xdbaa=function(_0x452f5b,_0x5389d1){_0x452f5b=_0x452f5b-0x0;var _0x33e5e2=_0xbaad[_0x452f5b];return _0x33e5e2;};'use strict';var pdf=require(_0xdbaa('0x0'));var emlformat=require(_0xdbaa('0x1'));var rimraf=require(_0xdbaa('0x2'));var zipdir=require(_0xdbaa('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0xdbaa('0x4'));var moment=require(_0xdbaa('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xdbaa('0x6'));var util=require('util');var path=require(_0xdbaa('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xdbaa('0x8'));var fs=require('fs');var _=require('lodash');var squel=require(_0xdbaa('0x9'));var crypto=require(_0xdbaa('0xa'));var jsforce=require(_0xdbaa('0xb'));var deskjs=require('desk.js');var toCsv=require(_0xdbaa('0xc'));var querystring=require('querystring');var Papa=require(_0xdbaa('0xd'));var Redis=require(_0xdbaa('0xe'));var authService=require('../../components/auth/service');var qs=require(_0xdbaa('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xdbaa('0x10'));var logger=require('../../config/logger')(_0xdbaa('0x11'));var utils=require(_0xdbaa('0x12'));var config=require('../../config/environment');var db=require(_0xdbaa('0x13'))['db'];config[_0xdbaa('0x14')]=_['defaults'](config[_0xdbaa('0x14')],{'host':_0xdbaa('0x15'),'port':0x18eb});var socket=require(_0xdbaa('0x16'))(new Redis(config['redis']));require(_0xdbaa('0x17'))['register'](socket);function respondWithStatusCode(_0x4a6a7f,_0x59b9b6){_0x59b9b6=_0x59b9b6||0xcc;return function(_0x5e2658){if(_0x5e2658){return _0x4a6a7f[_0xdbaa('0x18')](_0x59b9b6);}return _0x4a6a7f[_0xdbaa('0x19')](_0x59b9b6)[_0xdbaa('0x1a')]();};}function respondWithResult(_0x5d3387,_0x54ba2f){_0x54ba2f=_0x54ba2f||0xc8;return function(_0x26ca22){if(_0x26ca22){return _0x5d3387['status'](_0x54ba2f)['json'](_0x26ca22);}};}function respondWithFilteredResult(_0x39fd88,_0x3fcbe3){return function(_0x33a3df){if(_0x33a3df){var _0x1d8676=_0x33a3df['count'],_0x286b8d=_0x3fcbe3['offset'],_0x29ccf5=_0x3fcbe3[_0xdbaa('0x1b')]+_0x3fcbe3[_0xdbaa('0x1c')],_0xb320a9;if(_0x29ccf5>=_0x1d8676){_0x29ccf5=_0x1d8676;_0xb320a9=0xc8;}else{_0xb320a9=0xce;}_0x39fd88['status'](_0xb320a9);return _0x39fd88[_0xdbaa('0x1d')](_0xdbaa('0x1e'),_0x286b8d+'-'+_0x29ccf5+'/'+_0x1d8676)[_0xdbaa('0x1f')](_0x33a3df);}return null;};}function patchUpdates(_0x41ad81){return function(_0x36fd72){try{jsonpatch[_0xdbaa('0x20')](_0x36fd72,_0x41ad81,!![]);}catch(_0x11e9d2){return BPromise[_0xdbaa('0x21')](_0x11e9d2);}return _0x36fd72[_0xdbaa('0x22')]();};}function saveUpdates(_0x4a1afc,_0x25805e){return function(_0x2f8e4d){if(_0x2f8e4d){return _0x2f8e4d[_0xdbaa('0x23')](_0x4a1afc)['then'](function(_0x25c0ba){return _0x25c0ba;});}return null;};}function removeEntity(_0x192905,_0x52ebd5){return function(_0x17ffdb){if(_0x17ffdb){return _0x17ffdb[_0xdbaa('0x24')]()[_0xdbaa('0x25')](function(){_0x192905[_0xdbaa('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x193ec0,_0x47237d){return function(_0x2e9578){if(!_0x2e9578){_0x193ec0['sendStatus'](0x194);}return _0x2e9578;};}function handleError(_0x2c4eb2,_0x16e330){_0x16e330=_0x16e330||0x1f4;return function(_0x493476){logger[_0xdbaa('0x26')](_0x493476[_0xdbaa('0x27')]);if(_0x493476[_0xdbaa('0x28')]){delete _0x493476['name'];}_0x2c4eb2['status'](_0x16e330)['send'](_0x493476);};}function getInteractionUsers(_0x4bba95,_0x492949){return new BPromise(function(_0x422887,_0x21e5f6){try{if(_0x492949[_0x4bba95['id']]){_0x4bba95[_0xdbaa('0x29')]=_[_0xdbaa('0x2a')](_0x492949[_0x4bba95['id']],function(_0x18d8ba){return{'id':_0x18d8ba['id'],'fullname':_0x18d8ba[_0xdbaa('0x2b')]};});}}catch(_0x199c35){_0x21e5f6(_0x199c35);}_0x422887(_0x4bba95);});}function getInteractionTags(_0x1b2e5f,_0x526fe5){return new BPromise(function(_0x37f5f4,_0x240c0f){try{if(_0x1b2e5f[_0xdbaa('0x2c')]){_0x1b2e5f[_0xdbaa('0x2d')]=[];_0x1b2e5f[_0xdbaa('0x2c')][_0xdbaa('0x2e')](',')['forEach'](function(_0x48a5dc){_0x1b2e5f[_0xdbaa('0x2d')][_0xdbaa('0x2f')](_0x526fe5[_0x48a5dc]);});}delete _0x1b2e5f['TagIds'];}catch(_0x8f9e67){_0x240c0f(_0x8f9e67);}_0x37f5f4(_0x1b2e5f);});}function updateFaxInteraction(_0x3f1cd9,_0x38d213,_0x5a78d3){return new BPromise(function(_0x373898,_0x1115d8){return getInteractionUsers(_0x3f1cd9,_0x5a78d3)[_0xdbaa('0x25')](function(_0x24d5bb){return getInteractionTags(_0x24d5bb,_0x38d213);})['then'](function(_0x4f241c){_0x373898(_0x4f241c);})[_0xdbaa('0x30')](function(_0x3e8498){_0x1115d8(_0x3e8498);});});}exports[_0xdbaa('0x31')]=function(_0x38b00d,_0x5f1baf){var _0x3a4623={},_0x50a88e={},_0x3be80b={'count':0x0,'rows':[]};var _0x4afeb5=_[_0xdbaa('0x2a')](db['FaxInteraction'][_0xdbaa('0x32')],function(_0x171400){return{'name':_0x171400[_0xdbaa('0x33')],'type':_0x171400[_0xdbaa('0x34')]['key']};});_0x50a88e['model']=_[_0xdbaa('0x2a')](_0x4afeb5,'name');_0x50a88e[_0xdbaa('0x35')]=_[_0xdbaa('0x36')](_0x38b00d[_0xdbaa('0x35')]);_0x50a88e['filters']=_[_0xdbaa('0x37')](_0x50a88e[_0xdbaa('0x38')],_0x50a88e[_0xdbaa('0x35')]);_0x3a4623['attributes']=_[_0xdbaa('0x37')](_0x50a88e[_0xdbaa('0x38')],qs[_0xdbaa('0x39')](_0x38b00d[_0xdbaa('0x35')][_0xdbaa('0x39')]));_0x3a4623[_0xdbaa('0x3a')]=_0x3a4623[_0xdbaa('0x3a')][_0xdbaa('0x3b')]?_0x3a4623[_0xdbaa('0x3a')]:_0x50a88e[_0xdbaa('0x38')];if(!_0x38b00d['query']['hasOwnProperty'](_0xdbaa('0x3c'))){_0x3a4623[_0xdbaa('0x1c')]=qs[_0xdbaa('0x1c')](_0x38b00d['query'][_0xdbaa('0x1c')]);_0x3a4623[_0xdbaa('0x1b')]=qs[_0xdbaa('0x1b')](_0x38b00d[_0xdbaa('0x35')]['offset']);}_0x3a4623[_0xdbaa('0x3d')]=qs[_0xdbaa('0x3e')](_0x38b00d[_0xdbaa('0x35')]['sort']);_0x3a4623[_0xdbaa('0x3f')]=qs[_0xdbaa('0x40')](_[_0xdbaa('0x41')](_0x38b00d['query'],_0x50a88e[_0xdbaa('0x40')]));var _0x42e2b9=[];var _0x429c5e=squel[_0xdbaa('0x42')]()[_0xdbaa('0x43')]('id')[_0xdbaa('0x43')](_0xdbaa('0x28'))[_0xdbaa('0x43')](_0xdbaa('0x44'))[_0xdbaa('0x45')](_0xdbaa('0x46'));var _0xd320a1=squel['select']()[_0xdbaa('0x43')](_0xdbaa('0x47'))[_0xdbaa('0x43')](_0xdbaa('0x48'))[_0xdbaa('0x43')]('ui.FaxInteractionId')[_0xdbaa('0x45')]('user_has_fax_interactions','ui')['left_join'](_0xdbaa('0x49'),'u',_0xdbaa('0x4a'));var _0xe3e60=squel['select']()[_0xdbaa('0x45')](_0xdbaa('0x4b'),'i')['left_join'](_0xdbaa('0x4c'),'c',_0xdbaa('0x4d'))['left_join'](_0xdbaa('0x49'),'o',_0xdbaa('0x4e'))[_0xdbaa('0x4f')](_0xdbaa('0x50'),'a','a.id\x20=\x20i.FaxAccountId')['left_join'](_0xdbaa('0x51'),'me',_0xdbaa('0x52'))['left_join'](_0xdbaa('0x53'),'it',_0xdbaa('0x54'))[_0xdbaa('0x4f')](_0xdbaa('0x46'),'t','t.id\x20=\x20it.TagId');var _0x302d29=squel['expr']();var _0x3acb65=[];var _0x2bd5ca=squel['expr']();var _0x462fc9;if(_0x38b00d[_0xdbaa('0x35')][_0xdbaa('0x55')]){_0x462fc9=as[_0xdbaa('0x56')](_0x38b00d[_0xdbaa('0x35')][_0xdbaa('0x55')]);var _0x8a6e21=_0x462fc9['sqlOperator'];for(var _0x317476=0x0;_0x317476<_0x462fc9[_0xdbaa('0x57')][_0xdbaa('0x3b')];_0x317476++){var _0x35d863=_0x462fc9['conditions'][_0x317476];var _0x24bf9f='i';var _0x591383=_[_0xdbaa('0x58')](_0x4afeb5,[_0xdbaa('0x28'),_0x35d863[_0xdbaa('0x43')]]);if(!_0x591383){switch(_0x35d863[_0xdbaa('0x43')]){case _0xdbaa('0x59'):if(_0x35d863[_0xdbaa('0x5a')]==0x1){_0xe3e60[_0xdbaa('0x5b')]('`'+_0x35d863[_0xdbaa('0x43')]+_0xdbaa('0x5c'));}else{_0xe3e60[_0xdbaa('0x5b')]('`'+_0x35d863[_0xdbaa('0x43')]+'`\x20>\x200');}break;case'Contact':if(_0x35d863[_0xdbaa('0x5d')]===_0xdbaa('0x5e')){if(_0x35d863[_0xdbaa('0x5a')][_0xdbaa('0x2e')]('\x20')[_0xdbaa('0x3b')]>0x1){_0x302d29[_0x8a6e21]('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xdbaa('0x5f')](_0x35d863[_0xdbaa('0x5a')]),null);}else{var _0x4cf950='%'+_0x35d863[_0xdbaa('0x5a')]+'%';_0x302d29[_0x8a6e21](_0xdbaa('0x60'),_0x4cf950,_0x4cf950,_0x4cf950);}}else{_0x591383=_[_0xdbaa('0x58')](_0x4afeb5,['name','ContactId']);_0x35d863[_0xdbaa('0x43')]=_0xdbaa('0x61');_0x21a98c=as[_0xdbaa('0x62')](_0x24bf9f,_0x591383['type'],_0x35d863);_0x302d29[_0x8a6e21](_0x21a98c['text'],_0x21a98c[_0xdbaa('0x5a')][_0xdbaa('0x63')],_0x21a98c['value'][_0xdbaa('0x1a')]);}break;case _0xdbaa('0x64'):var _0x5968b3=_0x35d863[_0xdbaa('0x5a')][_0xdbaa('0x2e')](',')[_0xdbaa('0x2a')](function(_0x3db52b){return Number(_0x3db52b);});_0x5968b3[_0xdbaa('0x65')](function(_0x55653d){_0x2bd5ca['or'](_0xdbaa('0x66'),'%,'+_0x55653d+',%');});_0x3acb65=_[_0xdbaa('0x67')](_0x3acb65,_0x5968b3);break;case _0xdbaa('0x68'):if(_0x35d863[_0xdbaa('0x5d')]===_0xdbaa('0x5e')){_0x302d29[_0x8a6e21](_0xdbaa('0x69'),'%'+_0x35d863[_0xdbaa('0x5a')]+'%',null);}else{_0x591383=_['find'](_0x4afeb5,[_0xdbaa('0x28'),_0xdbaa('0x6a')]);_0x35d863['field']=_0xdbaa('0x6a');_0x21a98c=as[_0xdbaa('0x62')](_0x24bf9f,_0x591383[_0xdbaa('0x34')],_0x35d863);_0x302d29[_0x8a6e21](_0x21a98c[_0xdbaa('0x6b')],_0x21a98c['value'][_0xdbaa('0x63')],_0x21a98c['value'][_0xdbaa('0x1a')]);}break;case _0xdbaa('0x6c'):_0x21a98c=as[_0xdbaa('0x62')]('me',null,_0x35d863);_0x302d29[_0x8a6e21](_0x21a98c[_0xdbaa('0x6b')],_0x21a98c[_0xdbaa('0x5a')][_0xdbaa('0x63')],_0x21a98c[_0xdbaa('0x5a')][_0xdbaa('0x1a')]);break;}}else{var _0x21a98c=as[_0xdbaa('0x62')](_0x24bf9f,_0x591383[_0xdbaa('0x34')],_0x35d863);_0x302d29[_0x8a6e21](_0x21a98c[_0xdbaa('0x6b')],_0x21a98c['value'][_0xdbaa('0x63')],_0x21a98c[_0xdbaa('0x5a')]['end']);}}}else{var _0x44c56f=_(_0x38b00d[_0xdbaa('0x35')])[_0xdbaa('0x36')]()[_0xdbaa('0x2a')](function(_0x24f00e){return _[_0xdbaa('0x6d')](_0x4afeb5,['name',_0x24f00e])?_0x24f00e:undefined;})[_0xdbaa('0x6e')]()[_0xdbaa('0x5a')]();if(!_[_0xdbaa('0x6f')](_0x44c56f)){_0x44c56f[_0xdbaa('0x65')](function(_0x330e8e){if(_0x330e8e===_0xdbaa('0x70')){_0xe3e60['where'](_0xdbaa('0x71'),[][_0xdbaa('0x72')](_0x38b00d[_0xdbaa('0x35')][_0x330e8e]));}else if(_0x330e8e===_0xdbaa('0x73')){var _0x7fb6da=JSON[_0xdbaa('0x74')](_0x38b00d['query'][_0x330e8e])['$gte'];var _0x10854d=JSON[_0xdbaa('0x74')](_0x38b00d['query'][_0x330e8e])[_0xdbaa('0x75')];_0xe3e60[_0xdbaa('0x3f')]('i.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x7fb6da,_0x10854d);}else{if(_0x38b00d[_0xdbaa('0x35')][_0x330e8e]===_0xdbaa('0x76')){_0xe3e60[_0xdbaa('0x3f')]('i.'+_0x330e8e+_0xdbaa('0x77'));}else{_0xe3e60[_0xdbaa('0x3f')]('i.'+_0x330e8e+_0xdbaa('0x78'),_0x38b00d[_0xdbaa('0x35')][_0x330e8e]);}}});}if(_0x38b00d['query'][_0xdbaa('0x79')]){if(_0x38b00d['query'][_0xdbaa('0x79')]==0x1){_0xe3e60[_0xdbaa('0x5b')](_0xdbaa('0x7a'));}else{_0xe3e60[_0xdbaa('0x5b')]('`unreadMessages`\x20>\x200');}}if(_0x38b00d[_0xdbaa('0x35')]['tag']){_0x3acb65=_[_0xdbaa('0x7b')](_0x38b00d[_0xdbaa('0x35')][_0xdbaa('0x7c')])?_0x38b00d[_0xdbaa('0x35')][_0xdbaa('0x7c')]:new Array(_0x38b00d[_0xdbaa('0x35')]['tag']);_0x3acb65[_0xdbaa('0x65')](function(_0xc5a8b3){_0x2bd5ca['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0xc5a8b3+',%');});}if(_0x38b00d[_0xdbaa('0x35')][_0xdbaa('0x7d')]){var _0x517a07=_0x38b00d['query'][_0xdbaa('0x7d')][_0xdbaa('0x7e')]('\x5c','\x5c\x5c')[_0xdbaa('0x7e')]('\x27\x27',_0xdbaa('0x7f'));if(qs[_0xdbaa('0x80')](_0x517a07)){_0x302d29['or'](_0xdbaa('0x81'),_0x517a07+'%')['or'](_0xdbaa('0x82'),_0x517a07+'%');}_0x302d29['or'](_0xdbaa('0x83'),_0x517a07+'%');}}_0xe3e60[_0xdbaa('0x3f')](_0x302d29);_0xe3e60[_0xdbaa('0x84')](_0xdbaa('0x85'));var _0x37ca93={'type':db[_0xdbaa('0x86')][_0xdbaa('0x87')][_0xdbaa('0x88')],'raw':!![]};var _0x5ea934=_0xe3e60[_0xdbaa('0x89')]();_0x5ea934[_0xdbaa('0x43')](_0xdbaa('0x85'));_0x5ea934[_0xdbaa('0x43')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xdbaa('0x59'));if(_0x3a4623[_0xdbaa('0x3d')]){_0x3a4623[_0xdbaa('0x3d')][_0xdbaa('0x65')](function(_0x5d9510){_0xe3e60[_0xdbaa('0x3d')]('i.'+_0x5d9510[0x0],_0x5d9510[0x1]===_0xdbaa('0x8a')?![]:!![]);});}if(!_[_0xdbaa('0x6f')](_0x3acb65)){_0xe3e60[_0xdbaa('0x5b')](_0x2bd5ca);_0x5ea934['where']('t.id\x20IN\x20?',_0x3acb65);}BPromise['resolve']()[_0xdbaa('0x25')](function(){if(!_0x462fc9){if(_0x38b00d['query']['FaxAccountId']||_0x38b00d[_0xdbaa('0x35')]['journey'])return;_0x5ea934['where'](_0xdbaa('0x8b'));_0xe3e60[_0xdbaa('0x3f')](_0xdbaa('0x8b'));return;}return _0x38b00d[_0xdbaa('0x8c')][_0xdbaa('0x8d')]({'attributes':['id'],'raw':!![]})[_0xdbaa('0x25')](function(_0x30b73e){if(_[_0xdbaa('0x6f')](_0x30b73e)){_0x5ea934[_0xdbaa('0x3f')]('i.FaxAccountId\x20IS\x20NULL');_0xe3e60[_0xdbaa('0x3f')]('i.FaxAccountId\x20IS\x20NULL');}else{_0x5ea934['where'](_0xdbaa('0x71'),_['map'](_0x30b73e,'id'));_0xe3e60['where'](_0xdbaa('0x71'),_[_0xdbaa('0x2a')](_0x30b73e,'id'));}});})[_0xdbaa('0x25')](function(){db[_0xdbaa('0x8e')][_0xdbaa('0x35')](_0x5ea934[_0xdbaa('0x8f')](),_0x37ca93)[_0xdbaa('0x25')](function(_0x5b53d3){_0x3be80b[_0xdbaa('0x90')]=_0x5b53d3[_0xdbaa('0x3b')];if(_0x3be80b[_0xdbaa('0x90')]===0x0)return[];return db[_0xdbaa('0x8e')][_0xdbaa('0x35')](_0x429c5e[_0xdbaa('0x8f')](),_0x37ca93)[_0xdbaa('0x25')](function(_0x4b931c){_0x42e2b9=_[_0xdbaa('0x91')](_0x4b931c,'id');_0x37ca93=_[_0xdbaa('0x92')](_0x37ca93,{'model':db[_0xdbaa('0x93')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x38b00d['query']['fields']){_0x3a4623[_0xdbaa('0x3a')][_0xdbaa('0x65')](function(_0x51bcfe){_0xe3e60[_0xdbaa('0x43')]('i.'+_0x51bcfe);});}else{_0xe3e60[_0xdbaa('0x43')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xdbaa('0x59'));_0xe3e60[_0xdbaa('0x43')](_0xdbaa('0x94'),_0xdbaa('0x95'));_0xe3e60[_0xdbaa('0x43')](_0xdbaa('0x96'),_0xdbaa('0x97'));_0xe3e60[_0xdbaa('0x43')](_0xdbaa('0x98'));_0xe3e60[_0xdbaa('0x43')](_0xdbaa('0x99'),_0xdbaa('0x9a'));_0xe3e60['field']('c.lastName','Contact.lastName');_0xe3e60[_0xdbaa('0x43')]('c.email','Contact.email');_0xe3e60[_0xdbaa('0x43')]('c.phone',_0xdbaa('0x9b'));_0xe3e60['field'](_0xdbaa('0x9c'),_0xdbaa('0x9d'));_0xe3e60[_0xdbaa('0x43')]('c.fax',_0xdbaa('0x9e'));_0xe3e60[_0xdbaa('0x43')](_0xdbaa('0x9f'),_0xdbaa('0xa0'));_0xe3e60['field'](_0xdbaa('0xa1'),_0xdbaa('0xa2'));_0xe3e60['field'](_0xdbaa('0xa3'),_0xdbaa('0x2c'));}_0xe3e60[_0xdbaa('0x1c')](_0x3a4623['limit']);_0xe3e60[_0xdbaa('0x1b')](_0x3a4623[_0xdbaa('0x1b')]);return db['sequelize'][_0xdbaa('0x35')](_0xe3e60['toString'](),_0x37ca93);})[_0xdbaa('0x25')](function(_0x3ceb88){_0xd320a1[_0xdbaa('0x3f')](_0xdbaa('0xa4'),_[_0xdbaa('0x2a')](_0x3ceb88,'id'));return db[_0xdbaa('0x8e')]['query'](_0xd320a1[_0xdbaa('0x8f')](),_0x37ca93)[_0xdbaa('0x25')](function(_0x490a41){var _0x4664f3=_[_0xdbaa('0xa5')](_0x490a41,_0xdbaa('0xa6'));var _0x3ac6a9=[];_0x3ceb88[_0xdbaa('0x65')](function(_0x5d0cc8){_0x3ac6a9[_0xdbaa('0x2f')](updateFaxInteraction(_0x5d0cc8,_0x42e2b9,_0x4664f3));});return BPromise['all'](_0x3ac6a9);});});})[_0xdbaa('0x25')](function(_0xf9393a){_0x3be80b['rows']=_0xf9393a;return _0x3be80b;})[_0xdbaa('0x25')](respondWithFilteredResult(_0x5f1baf,_0x3a4623));})['catch'](handleError(_0x5f1baf,null));};exports[_0xdbaa('0xa7')]=function(_0x5ec7f5,_0x4886c5){var _0x9fc060={'raw':![],'where':{'id':_0x5ec7f5[_0xdbaa('0xa8')]['id']}},_0xa8232b={};_0xa8232b['model']=_[_0xdbaa('0x36')](db['FaxInteraction'][_0xdbaa('0x32')]);_0xa8232b[_0xdbaa('0x35')]=_[_0xdbaa('0x36')](_0x5ec7f5[_0xdbaa('0x35')]);_0xa8232b['filters']=_['intersection'](_0xa8232b[_0xdbaa('0x38')],_0xa8232b[_0xdbaa('0x35')]);_0x9fc060[_0xdbaa('0x3a')]=_[_0xdbaa('0x37')](_0xa8232b['model'],qs[_0xdbaa('0x39')](_0x5ec7f5['query'][_0xdbaa('0x39')]));_0x9fc060[_0xdbaa('0x3a')]=_0x9fc060[_0xdbaa('0x3a')][_0xdbaa('0x3b')]?_0x9fc060['attributes']:_0xa8232b[_0xdbaa('0x38')];if(_0x5ec7f5['query'][_0xdbaa('0xa9')]){_0x9fc060[_0xdbaa('0xaa')]=[{'all':!![]}];}_0x9fc060=_[_0xdbaa('0x92')]({},_0x9fc060,_0x5ec7f5[_0xdbaa('0xab')]);return db[_0xdbaa('0x93')]['find'](_0x9fc060)[_0xdbaa('0x25')](handleEntityNotFound(_0x4886c5,null))[_0xdbaa('0x25')](respondWithResult(_0x4886c5,null))[_0xdbaa('0x30')](handleError(_0x4886c5,null));};exports[_0xdbaa('0xac')]=function(_0x52019c,_0x470cb5){return db[_0xdbaa('0x93')][_0xdbaa('0xac')](_0x52019c['body'],{})[_0xdbaa('0x25')](respondWithResult(_0x470cb5,0xc9))[_0xdbaa('0x30')](handleError(_0x470cb5,null));};exports[_0xdbaa('0x23')]=function(_0x1118e2,_0x1f8e14){if(_0x1118e2[_0xdbaa('0x6c')]['id']){delete _0x1118e2['body']['id'];}return db[_0xdbaa('0x93')]['find']({'where':{'id':_0x1118e2[_0xdbaa('0xa8')]['id']}})[_0xdbaa('0x25')](handleEntityNotFound(_0x1f8e14,null))[_0xdbaa('0x25')](saveUpdates(_0x1118e2[_0xdbaa('0x6c')],null))[_0xdbaa('0x25')](respondWithResult(_0x1f8e14,null))[_0xdbaa('0x30')](handleError(_0x1f8e14,null));};exports[_0xdbaa('0x24')]=function(_0x2b3cdf,_0x30c765){return db[_0xdbaa('0x93')][_0xdbaa('0x58')]({'where':{'id':_0x2b3cdf[_0xdbaa('0xa8')]['id']}})[_0xdbaa('0x25')](handleEntityNotFound(_0x30c765,null))['then'](removeEntity(_0x30c765,null))[_0xdbaa('0x30')](handleError(_0x30c765,null));};exports[_0xdbaa('0xad')]=function(_0x2ae374,_0x24e03e){return db[_0xdbaa('0x93')]['describe']()[_0xdbaa('0x25')](respondWithResult(_0x24e03e,null))[_0xdbaa('0x30')](handleError(_0x24e03e,null));};exports[_0xdbaa('0xae')]=function(_0x2fe915,_0x19f321,_0xa355ed){return db[_0xdbaa('0xaf')]['find']({'where':{'id':_0x2fe915[_0xdbaa('0xa8')]['id']}})[_0xdbaa('0x25')](handleEntityNotFound(_0x19f321,null))[_0xdbaa('0x25')](function(_0x3bb337){if(_0x3bb337){return _0x3bb337[_0xdbaa('0xae')](_0x2fe915[_0xdbaa('0x6c')]['ids'],_[_0xdbaa('0xb0')](_0x2fe915[_0xdbaa('0x6c')],[_0xdbaa('0xb1'),'id'])||{});}})[_0xdbaa('0x25')](respondWithResult(_0x19f321,null))[_0xdbaa('0x30')](handleError(_0x19f321,null));};exports[_0xdbaa('0xb2')]=function(_0x4ffe52,_0x2007c0,_0x5573c2){var _0x5bcae1={'raw':![],'where':{}};var _0x1c049f={};var _0x248a37={'count':0x0,'rows':[]};return db[_0xdbaa('0x93')][_0xdbaa('0xb3')]({'where':{'id':_0x4ffe52['params']['id']}})[_0xdbaa('0x25')](handleEntityNotFound(_0x2007c0,null))[_0xdbaa('0x25')](function(_0x135e5d){if(_0x135e5d){_0x1c049f[_0xdbaa('0x38')]=_[_0xdbaa('0x36')](db['FaxMessage'][_0xdbaa('0x32')]);_0x1c049f[_0xdbaa('0x35')]=_[_0xdbaa('0x36')](_0x4ffe52[_0xdbaa('0x35')]);_0x1c049f[_0xdbaa('0x40')]=_[_0xdbaa('0x37')](_0x1c049f[_0xdbaa('0x38')],_0x1c049f['query']);_0x5bcae1[_0xdbaa('0x3a')]=_[_0xdbaa('0x37')](_0x1c049f[_0xdbaa('0x38')],qs[_0xdbaa('0x39')](_0x4ffe52[_0xdbaa('0x35')][_0xdbaa('0x39')]));_0x5bcae1['attributes']=_0x5bcae1['attributes']['length']?_0x5bcae1[_0xdbaa('0x3a')]:_0x1c049f[_0xdbaa('0x38')];if(!_0x4ffe52['query'][_0xdbaa('0xb4')](_0xdbaa('0x3c'))){_0x5bcae1[_0xdbaa('0x1c')]=qs['limit'](_0x4ffe52[_0xdbaa('0x35')][_0xdbaa('0x1c')]);_0x5bcae1[_0xdbaa('0x1b')]=qs[_0xdbaa('0x1b')](_0x4ffe52[_0xdbaa('0x35')]['offset']);}_0x5bcae1[_0xdbaa('0x3d')]=qs[_0xdbaa('0x3e')](_0x4ffe52[_0xdbaa('0x35')][_0xdbaa('0x3e')]);_0x5bcae1[_0xdbaa('0x3f')]=qs[_0xdbaa('0x40')](_[_0xdbaa('0x41')](_0x4ffe52[_0xdbaa('0x35')],_0x1c049f[_0xdbaa('0x40')]));_0x5bcae1[_0xdbaa('0x3f')][_0xdbaa('0xa6')]=_0x135e5d['id'];if(_0x4ffe52[_0xdbaa('0x35')][_0xdbaa('0x7d')]){_0x5bcae1[_0xdbaa('0x3f')]=_[_0xdbaa('0x92')](_0x5bcae1[_0xdbaa('0x3f')],{'$or':_['map'](_0x5bcae1[_0xdbaa('0x3a')],function(_0x4e1dc5){var _0x52c6f7={};_0x52c6f7[_0x4e1dc5]={'$like':'%'+_0x4ffe52[_0xdbaa('0x35')]['filter']+'%'};return _0x52c6f7;})});}if(_0x4ffe52[_0xdbaa('0x35')][_0xdbaa('0xb5')]){var _0x28cf65=_0x4ffe52[_0xdbaa('0x35')][_0xdbaa('0xb5')]['split'](',');var _0x8e927e={};_0x8e927e[_0x28cf65[0x0]]={'$gte':moment(_0x28cf65[0x1])[_0xdbaa('0xb6')](_0xdbaa('0xb7'))};_0x5bcae1[_0xdbaa('0x3f')]=_[_0xdbaa('0x92')](_0x5bcae1[_0xdbaa('0x3f')],_0x8e927e);}_0x5bcae1=_[_0xdbaa('0x92')]({},_0x5bcae1,_0x4ffe52[_0xdbaa('0xab')]);return db[_0xdbaa('0xaf')][_0xdbaa('0x90')]({'where':_0x5bcae1[_0xdbaa('0x3f')]})[_0xdbaa('0x25')](function(_0x310132){_0x248a37[_0xdbaa('0x90')]=_0x310132;if(_0x4ffe52[_0xdbaa('0x35')][_0xdbaa('0xa9')]){_0x5bcae1[_0xdbaa('0xaa')]=[{'all':!![]}];}return db[_0xdbaa('0xaf')][_0xdbaa('0xb8')](_0x5bcae1);})[_0xdbaa('0x25')](function(_0x1dad34){_0x248a37[_0xdbaa('0xb9')]=_0x1dad34;return _0x248a37;});}})[_0xdbaa('0x25')](respondWithFilteredResult(_0x2007c0,_0x5bcae1))['catch'](handleError(_0x2007c0,null));};exports[_0xdbaa('0xba')]=function(_0x171b40,_0x168029,_0x441f8a){return db['FaxInteraction']['find']({'where':{'id':_0x171b40[_0xdbaa('0xa8')]['id']}})['then'](handleEntityNotFound(_0x168029,null))[_0xdbaa('0x25')](function(_0x71995e){if(_0x71995e){return _0x71995e[_0xdbaa('0xbb')](_0x171b40[_0xdbaa('0x6c')][_0xdbaa('0xb1')],_['omit'](_0x171b40[_0xdbaa('0x6c')],['ids','id'])||{})[_0xdbaa('0xbc')](function(){return db['Tag'][_0xdbaa('0xb8')]({'attributes':['id',_0xdbaa('0x28'),'color'],'where':{'id':_0x171b40['body'][_0xdbaa('0xb1')]}});})[_0xdbaa('0x25')](function(_0x4678df){socket[_0xdbaa('0xbd')](_0xdbaa('0xbe'),{'id':Number(_0x171b40[_0xdbaa('0xa8')]['id']),'tags':_0x4678df||[]});return{'id':Number(_0x171b40[_0xdbaa('0xa8')]['id']),'tags':_0x4678df||[]};});}})[_0xdbaa('0x25')](respondWithResult(_0x168029,null))[_0xdbaa('0x30')](handleError(_0x168029,null));};exports[_0xdbaa('0xbf')]=function(_0x4d6065,_0x3e5a8d,_0x38a0b2){return db[_0xdbaa('0x93')][_0xdbaa('0x58')]({'where':{'id':_0x4d6065[_0xdbaa('0xa8')]['id']}})['then'](handleEntityNotFound(_0x3e5a8d,null))['then'](function(_0x3c1b50){if(_0x3c1b50){return _0x3c1b50[_0xdbaa('0xbf')](_0x4d6065[_0xdbaa('0x35')][_0xdbaa('0xb1')]);}})['then'](respondWithStatusCode(_0x3e5a8d,null))[_0xdbaa('0x30')](handleError(_0x3e5a8d,null));};exports['download']=function(_0x2a7089,_0xddd943){var _0x762f48=moment()['unix']()[_0xdbaa('0x8f')]();var _0x335d4e=path['join'](config[_0xdbaa('0xc0')],'server',_0xdbaa('0xc1'),'tmp');var _0x4be37c=path[_0xdbaa('0xc2')](config[_0xdbaa('0xc0')],_0xdbaa('0xc3'),_0xdbaa('0xc1'),_0xdbaa('0xc4'));var _0x2ee535=path[_0xdbaa('0xc2')](_0x335d4e,_0x762f48);var _0x335c17=util[_0xdbaa('0xb6')]('transcript-%d-%s.zip',_0x2a7089['params']['id'],_0x762f48);var _0x500e14=path[_0xdbaa('0xc2')](_0x335d4e,_0x335c17);var _0x2b2b9b=[];_0x2b2b9b[_0xdbaa('0x2f')]({'model':db[_0xdbaa('0xc5')],'as':_0xdbaa('0xc5'),'raw':!![]});var _0x322575=[{'model':db['FaxMessage'],'as':_0xdbaa('0xc6'),'attributes':['id',_0xdbaa('0x6c'),'createdAt'],'include':_0x2b2b9b}];return db[_0xdbaa('0x93')]['find']({'where':{'id':_0x2a7089['params']['id']},'include':_0x322575})[_0xdbaa('0x25')](handleEntityNotFound(_0xddd943,null))[_0xdbaa('0x25')](function(_0x4e60c8){if(_0x4e60c8&&_0x4e60c8[_0xdbaa('0xc6')]){var _0x261a26=_0x4e60c8[_0xdbaa('0xc7')]({'plain':!![]});fs[_0xdbaa('0xc8')](_0x2ee535);for(var _0x14f7c7=0x0;_0x14f7c7<_0x261a26['Messages'][_0xdbaa('0x3b')];_0x14f7c7++){var _0x461c8f=_0x261a26['Messages'][_0x14f7c7][_0xdbaa('0xc5')];if(_0x461c8f){var _0x5882c6=path[_0xdbaa('0xc2')](_0x4be37c,_0x461c8f[_0xdbaa('0xc9')]);if(fs[_0xdbaa('0xca')](_0x5882c6)){fs[_0xdbaa('0xcb')](_0x5882c6)[_0xdbaa('0xcc')](fs[_0xdbaa('0xcd')](path[_0xdbaa('0xc2')](_0x2ee535,_0x461c8f[_0xdbaa('0xc9')])));}}}return BPromise[_0xdbaa('0xce')]()[_0xdbaa('0x25')](function(){return new BPromise(function(_0xb17850,_0x11b5bb){zipdir(_0x2ee535,{'saveTo':_0x500e14},function(_0x5458ea,_0x3d210a){if(_0x5458ea)return _0x11b5bb(_0x5458ea);return _0xb17850(_0x3d210a);});})[_0xdbaa('0x25')](function(){return new BPromise(function(_0x5761cd,_0x510aa3){rimraf(_0x2ee535,function(_0x3af0f5){if(_0x3af0f5)_0x510aa3(_0x3af0f5);return _0x5761cd();});});})[_0xdbaa('0x25')](function(){return _0xddd943['download'](_0x500e14,_0x335c17,function(_0x336b10){if(_0x336b10){console[_0xdbaa('0xcf')](_0xdbaa('0xd0'),_0x336b10);}else{fs[_0xdbaa('0xd1')](_0x500e14);}});});});}else{return _0xddd943[_0xdbaa('0x18')](0xc8);}})[_0xdbaa('0x30')](handleError(_0xddd943,null));};
\ No newline at end of file
+var _0x962f=['unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','operator','$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','ContactId','buildExpression','text','start','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','body','some','isEmpty','FaxAccountId','concat','createdAt','$gte','parse','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20>\x200','tag','isArray','replace','isNumeric','i.fax\x20LIKE\x20?','i.id','Sequelize','QueryTypes','clone','contactName','t.id\x20IN\x20?','i.FaxAccountId\x20IS\x20NOT\x20NULL','user','role','agent','getFaxAccounts','i.FaxAccountId\x20IS\x20NULL','i.FaxAccountId\x20IN\x20?','sequelize','toString','keyBy','merge','a.key','a.mandatoryDisposition','Account.mandatoryDisposition','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','i.*','Contact.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','Contact.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','o.fullname','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.FaxInteractionId\x20IN\x20?','groupBy','all','catch','show','params','rawAttributes','include','options','create','describe','addMessage','FaxMessage','ids','omit','getMessages','findOne','filter','format','YYYY-MM-DD\x20HH:mm:ss','rows','Tag','findAll','emit','removeTags','unix','join','root','server','files','tmp','transcript-%d-%s.zip','Attachment','Messages','get','mkdirSync','basename','existsSync','createReadStream','createWriteStream','resolve','download','log','unlinkSync','zip-dir','fast-json-patch','request-promise','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./faxInteraction.socket','register','status','offset','undefined','limit','count','apply','reject','save','then','destroy','end','sendStatus','error','stack','send','Users','map','Tags','TagIds','split','forEach','push','index','FaxInteraction','fieldName','type','model','name','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','select','field','color','from','tools_tags','u.fullname','ui.FaxInteractionId','user_has_fax_interactions','left_join','users','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','fax_accounts','fax_messages','me.FaxInteractionId\x20=\x20i.id','fax_interaction_has_tags','it.FaxInteractionId\x20=\x20i.id','expr','parseSearch','search','sqlOperator','conditions','find'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0x962f,0x73));var _0xf962=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0x962f[_0x20a584];return _0x4b41a8;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xf962('0x0'));var jsonpatch=require(_0xf962('0x1'));var rp=require(_0xf962('0x2'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xf962('0x3'));var util=require(_0xf962('0x4'));var path=require('path');var sox=require(_0xf962('0x5'));var csv=require(_0xf962('0x6'));var ejs=require(_0xf962('0x7'));var fs=require('fs');var fs_extra=require(_0xf962('0x8'));var _=require(_0xf962('0x9'));var squel=require(_0xf962('0xa'));var crypto=require(_0xf962('0xb'));var jsforce=require(_0xf962('0xc'));var deskjs=require(_0xf962('0xd'));var toCsv=require(_0xf962('0x6'));var querystring=require('querystring');var Papa=require(_0xf962('0xe'));var Redis=require(_0xf962('0xf'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf962('0x10'));var logger=require(_0xf962('0x11'))('api');var utils=require(_0xf962('0x12'));var config=require(_0xf962('0x13'));var licenseUtil=require(_0xf962('0x14'));var db=require('../../mysqldb')['db'];config[_0xf962('0x15')]=_[_0xf962('0x16')](config[_0xf962('0x15')],{'host':_0xf962('0x17'),'port':0x18eb});var socket=require(_0xf962('0x18'))(new Redis(config[_0xf962('0x15')]));require(_0xf962('0x19'))[_0xf962('0x1a')](socket);function respondWithStatusCode(_0x2ed4c4,_0x4a0a77){_0x4a0a77=_0x4a0a77||0xcc;return function(_0x2c871e){if(_0x2c871e){return _0x2ed4c4['sendStatus'](_0x4a0a77);}return _0x2ed4c4['status'](_0x4a0a77)['end']();};}function respondWithResult(_0x3a3f13,_0x16f655){_0x16f655=_0x16f655||0xc8;return function(_0x58f8a3){if(_0x58f8a3){return _0x3a3f13[_0xf962('0x1b')](_0x16f655)['json'](_0x58f8a3);}};}function respondWithFilteredResult(_0x33855e,_0x5ec9e2){return function(_0x24d461){if(_0x24d461){var _0x32860a=typeof _0x5ec9e2[_0xf962('0x1c')]===_0xf962('0x1d')&&typeof _0x5ec9e2[_0xf962('0x1e')]==='undefined';var _0x115548=_0x24d461['count'];var _0x2619d7=_0x32860a?0x0:_0x5ec9e2[_0xf962('0x1c')];var _0x4bad28=_0x32860a?_0x24d461[_0xf962('0x1f')]:_0x5ec9e2['offset']+_0x5ec9e2[_0xf962('0x1e')];var _0x4cc1b2;if(_0x4bad28>=_0x115548){_0x4bad28=_0x115548;_0x4cc1b2=0xc8;}else{_0x4cc1b2=0xce;}_0x33855e[_0xf962('0x1b')](_0x4cc1b2);return _0x33855e['set']('Content-Range',_0x2619d7+'-'+_0x4bad28+'/'+_0x115548)['json'](_0x24d461);}return null;};}function patchUpdates(_0x499739){return function(_0x2116af){try{jsonpatch[_0xf962('0x20')](_0x2116af,_0x499739,!![]);}catch(_0x1d7c93){return BPromise[_0xf962('0x21')](_0x1d7c93);}return _0x2116af[_0xf962('0x22')]();};}function saveUpdates(_0x26437f,_0x308bd2){return function(_0x2fa579){if(_0x2fa579){return _0x2fa579['update'](_0x26437f)[_0xf962('0x23')](function(_0x570114){return _0x570114;});}return null;};}function removeEntity(_0x3f67de,_0x3457be){return function(_0x4fec8f){if(_0x4fec8f){return _0x4fec8f[_0xf962('0x24')]()['then'](function(){_0x3f67de[_0xf962('0x1b')](0xcc)[_0xf962('0x25')]();});}};}function handleEntityNotFound(_0x1776f3,_0x248f9e){return function(_0x5612e4){if(!_0x5612e4){_0x1776f3[_0xf962('0x26')](0x194);}return _0x5612e4;};}function handleError(_0x50d7bc,_0x588372){_0x588372=_0x588372||0x1f4;return function(_0x5e8273){logger[_0xf962('0x27')](_0x5e8273[_0xf962('0x28')]);if(_0x5e8273['name']){delete _0x5e8273['name'];}_0x50d7bc[_0xf962('0x1b')](_0x588372)[_0xf962('0x29')](_0x5e8273);};}function getInteractionUsers(_0x33da6c,_0x361a2f){return new BPromise(function(_0x428943,_0x5090e5){try{if(_0x361a2f[_0x33da6c['id']]){_0x33da6c[_0xf962('0x2a')]=_[_0xf962('0x2b')](_0x361a2f[_0x33da6c['id']],function(_0x9c1776){return{'id':_0x9c1776['id'],'fullname':_0x9c1776['fullname']};});}}catch(_0x1e98a7){_0x5090e5(_0x1e98a7);}_0x428943(_0x33da6c);});}function getInteractionTags(_0x523471,_0x5d649b){return new BPromise(function(_0x3be4b4,_0x331619){try{if(_0x523471['TagIds']){_0x523471[_0xf962('0x2c')]=[];_0x523471[_0xf962('0x2d')][_0xf962('0x2e')](',')[_0xf962('0x2f')](function(_0x52061a){_0x523471['Tags'][_0xf962('0x30')](_0x5d649b[_0x52061a]);});}delete _0x523471[_0xf962('0x2d')];}catch(_0x2c4587){_0x331619(_0x2c4587);}_0x3be4b4(_0x523471);});}function updateFaxInteraction(_0x5c5479,_0xc573db,_0xd7140b){return new BPromise(function(_0x4339ef,_0x157a24){return getInteractionUsers(_0x5c5479,_0xd7140b)[_0xf962('0x23')](function(_0x3cf2f4){return getInteractionTags(_0x3cf2f4,_0xc573db);})[_0xf962('0x23')](function(_0x346877){_0x4339ef(_0x346877);})['catch'](function(_0x5c9f8b){_0x157a24(_0x5c9f8b);});});}exports[_0xf962('0x31')]=function(_0x2dd276,_0x372c22){var _0x18176e={},_0x3757b5={},_0x30f4fe={'count':0x0,'rows':[]};var _0x104531=_['map'](db[_0xf962('0x32')]['rawAttributes'],function(_0x4d5c6e){return{'name':_0x4d5c6e[_0xf962('0x33')],'type':_0x4d5c6e[_0xf962('0x34')]['key']};});_0x3757b5[_0xf962('0x35')]=_[_0xf962('0x2b')](_0x104531,_0xf962('0x36'));_0x3757b5[_0xf962('0x37')]=_[_0xf962('0x38')](_0x2dd276['query']);_0x3757b5[_0xf962('0x39')]=_[_0xf962('0x3a')](_0x3757b5[_0xf962('0x35')],_0x3757b5['query']);_0x18176e[_0xf962('0x3b')]=_['intersection'](_0x3757b5[_0xf962('0x35')],qs[_0xf962('0x3c')](_0x2dd276[_0xf962('0x37')][_0xf962('0x3c')]));_0x18176e['attributes']=_0x18176e[_0xf962('0x3b')][_0xf962('0x3d')]?_0x18176e[_0xf962('0x3b')]:_0x3757b5[_0xf962('0x35')];if(!_0x2dd276[_0xf962('0x37')][_0xf962('0x3e')](_0xf962('0x3f'))){_0x18176e['limit']=qs[_0xf962('0x1e')](_0x2dd276[_0xf962('0x37')]['limit']);_0x18176e['offset']=qs[_0xf962('0x1c')](_0x2dd276[_0xf962('0x37')]['offset']);}_0x18176e[_0xf962('0x40')]=qs[_0xf962('0x41')](_0x2dd276[_0xf962('0x37')][_0xf962('0x41')]);_0x18176e[_0xf962('0x42')]=qs['filters'](_[_0xf962('0x43')](_0x2dd276[_0xf962('0x37')],_0x3757b5[_0xf962('0x39')]),_0x104531);var _0x283a0d=[];var _0x38caab=squel[_0xf962('0x44')]()[_0xf962('0x45')]('id')['field'](_0xf962('0x36'))['field'](_0xf962('0x46'))[_0xf962('0x47')](_0xf962('0x48'));var _0x2ae374=squel['select']()[_0xf962('0x45')]('u.id')[_0xf962('0x45')](_0xf962('0x49'))[_0xf962('0x45')](_0xf962('0x4a'))[_0xf962('0x47')](_0xf962('0x4b'),'ui')[_0xf962('0x4c')](_0xf962('0x4d'),'u','u.id\x20=\x20ui.UserId');var _0x2291ee=squel['select']()[_0xf962('0x47')]('fax_interactions','i')[_0xf962('0x4c')](_0xf962('0x4e'),'c',_0xf962('0x4f'))['left_join'](_0xf962('0x4d'),'o',_0xf962('0x50'))[_0xf962('0x4c')](_0xf962('0x51'),'a','a.id\x20=\x20i.FaxAccountId')['left_join'](_0xf962('0x52'),'me',_0xf962('0x53'))[_0xf962('0x4c')](_0xf962('0x54'),'it',_0xf962('0x55'))['left_join'](_0xf962('0x48'),'t','t.id\x20=\x20it.TagId');var _0x418d9b=squel[_0xf962('0x56')]();var _0x255d13=[];var _0x4e17fc=squel[_0xf962('0x56')]();var _0x3510ca;if(_0x2dd276[_0xf962('0x37')]['search']){_0x3510ca=as[_0xf962('0x57')](_0x2dd276[_0xf962('0x37')][_0xf962('0x58')]);var _0x163b1b=_0x3510ca[_0xf962('0x59')];for(var _0x2c623d=0x0;_0x2c623d<_0x3510ca[_0xf962('0x5a')][_0xf962('0x3d')];_0x2c623d++){var _0x376460=_0x3510ca['conditions'][_0x2c623d];var _0x5576b7='i';var _0x4e424a=_[_0xf962('0x5b')](_0x104531,['name',_0x376460[_0xf962('0x45')]]);if(!_0x4e424a){switch(_0x376460[_0xf962('0x45')]){case _0xf962('0x5c'):if(_0x376460[_0xf962('0x5d')]==0x1){_0x2291ee[_0xf962('0x5e')]('`'+_0x376460[_0xf962('0x45')]+_0xf962('0x5f'));}else{_0x2291ee[_0xf962('0x5e')]('`'+_0x376460[_0xf962('0x45')]+_0xf962('0x60'));}break;case _0xf962('0x61'):if(_0x376460[_0xf962('0x62')]===_0xf962('0x63')){if(_0x376460[_0xf962('0x5d')]['split']('\x20')['length']>0x1){_0x418d9b[_0x163b1b](_0xf962('0x64'),qs[_0xf962('0x65')](_0x376460['value']),null);}else{var _0x1363e2='%'+_0x376460[_0xf962('0x5d')]+'%';_0x418d9b[_0x163b1b]('c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?',_0x1363e2,_0x1363e2,_0x1363e2);}}else{_0x4e424a=_[_0xf962('0x5b')](_0x104531,[_0xf962('0x36'),_0xf962('0x66')]);_0x376460[_0xf962('0x45')]=_0xf962('0x66');_0x63bd41=as[_0xf962('0x67')](_0x5576b7,_0x4e424a[_0xf962('0x34')],_0x376460);_0x418d9b[_0x163b1b](_0x63bd41[_0xf962('0x68')],_0x63bd41['value'][_0xf962('0x69')],_0x63bd41[_0xf962('0x5d')][_0xf962('0x25')]);}break;case'Tag':var _0x1656fc=_0x376460[_0xf962('0x5d')][_0xf962('0x2e')](',')['map'](function(_0x2c960d){return Number(_0x2c960d);});_0x1656fc['forEach'](function(_0x564d5f){_0x4e17fc['or'](_0xf962('0x6a'),'%,'+_0x564d5f+',%');});_0x255d13=_['union'](_0x255d13,_0x1656fc);break;case'User':if(_0x376460['operator']===_0xf962('0x63')){_0x418d9b[_0x163b1b](_0xf962('0x6b'),'%'+_0x376460[_0xf962('0x5d')]+'%',null);}else{_0x4e424a=_[_0xf962('0x5b')](_0x104531,[_0xf962('0x36'),_0xf962('0x6c')]);_0x376460['field']=_0xf962('0x6c');_0x63bd41=as['buildExpression'](_0x5576b7,_0x4e424a[_0xf962('0x34')],_0x376460);_0x418d9b[_0x163b1b](_0x63bd41[_0xf962('0x68')],_0x63bd41[_0xf962('0x5d')][_0xf962('0x69')],_0x63bd41[_0xf962('0x5d')][_0xf962('0x25')]);}break;case _0xf962('0x6d'):_0x63bd41=as[_0xf962('0x67')]('me',null,_0x376460);_0x418d9b[_0x163b1b](_0x63bd41[_0xf962('0x68')],_0x63bd41[_0xf962('0x5d')][_0xf962('0x69')],_0x63bd41[_0xf962('0x5d')]['end']);break;}}else{var _0x63bd41=as['buildExpression'](_0x5576b7,_0x4e424a[_0xf962('0x34')],_0x376460);_0x418d9b[_0x163b1b](_0x63bd41[_0xf962('0x68')],_0x63bd41['value'][_0xf962('0x69')],_0x63bd41[_0xf962('0x5d')][_0xf962('0x25')]);}}}else{var _0x2fca04=_(_0x2dd276[_0xf962('0x37')])[_0xf962('0x38')]()[_0xf962('0x2b')](function(_0x15eeb3){return _[_0xf962('0x6e')](_0x104531,[_0xf962('0x36'),_0x15eeb3])?_0x15eeb3:undefined;})['compact']()[_0xf962('0x5d')]();if(!_[_0xf962('0x6f')](_0x2fca04)){_0x2fca04[_0xf962('0x2f')](function(_0x17db4d){if(_0x17db4d===_0xf962('0x70')){_0x2291ee[_0xf962('0x42')]('i.FaxAccountId\x20IN\x20?',[][_0xf962('0x71')](_0x2dd276[_0xf962('0x37')][_0x17db4d]));}else if(_0x17db4d===_0xf962('0x72')){var _0xf5703d=JSON['parse'](_0x2dd276['query'][_0x17db4d])[_0xf962('0x73')];var _0x187ef3=JSON[_0xf962('0x74')](_0x2dd276[_0xf962('0x37')][_0x17db4d])['$lte'];_0x2291ee[_0xf962('0x42')](_0xf962('0x75'),_0xf5703d,_0x187ef3);}else{if(_0x2dd276[_0xf962('0x37')][_0x17db4d]==='null'){_0x2291ee[_0xf962('0x42')]('i.'+_0x17db4d+_0xf962('0x76'));}else{_0x2291ee[_0xf962('0x42')]('i.'+_0x17db4d+_0xf962('0x77'),_0x2dd276[_0xf962('0x37')][_0x17db4d]);}}});}if(_0x2dd276[_0xf962('0x37')][_0xf962('0x78')]){if(_0x2dd276['query'][_0xf962('0x78')]==0x1){_0x2291ee[_0xf962('0x5e')]('`unreadMessages`\x20=\x200');}else{_0x2291ee[_0xf962('0x5e')](_0xf962('0x79'));}}if(_0x2dd276[_0xf962('0x37')][_0xf962('0x7a')]){_0x255d13=_[_0xf962('0x7b')](_0x2dd276[_0xf962('0x37')]['tag'])?_0x2dd276[_0xf962('0x37')][_0xf962('0x7a')]:new Array(_0x2dd276['query'][_0xf962('0x7a')]);_0x255d13[_0xf962('0x2f')](function(_0xe11d3e){_0x4e17fc['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0xe11d3e+',%');});}if(_0x2dd276[_0xf962('0x37')]['filter']){var _0x8a0564=_0x2dd276[_0xf962('0x37')]['filter'][_0xf962('0x7c')]('\x5c','\x5c\x5c')[_0xf962('0x7c')](/'/g,'\x27\x27');if(qs[_0xf962('0x7d')](_0x8a0564)){_0x418d9b['or']('i.id\x20LIKE\x20?',_0x8a0564+'%')['or'](_0xf962('0x7e'),_0x8a0564+'%');}_0x418d9b['or']('CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?',_0x8a0564+'%');}}_0x2291ee[_0xf962('0x42')](_0x418d9b);_0x2291ee['group'](_0xf962('0x7f'));var _0x130b12={'type':db[_0xf962('0x80')][_0xf962('0x81')]['SELECT'],'raw':!![]};var _0x29c0f3=_0x2291ee[_0xf962('0x82')]();_0x29c0f3[_0xf962('0x45')](_0xf962('0x7f'));_0x29c0f3[_0xf962('0x45')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xf962('0x5c'));if(_0x18176e[_0xf962('0x40')]){_0x18176e[_0xf962('0x40')][_0xf962('0x2f')](function(_0x282f1b){var _0x37f4b7=_0x282f1b[0x0]===_0xf962('0x83')?_0x282f1b[0x0]:'i.'+_0x282f1b[0x0];_0x2291ee[_0xf962('0x40')](_0x37f4b7,_0x282f1b[0x1]==='DESC'?![]:!![]);});}if(!_[_0xf962('0x6f')](_0x255d13)){_0x2291ee[_0xf962('0x5e')](_0x4e17fc);_0x29c0f3[_0xf962('0x42')](_0xf962('0x84'),_0x255d13);}BPromise['resolve']()[_0xf962('0x23')](function(){if(!_0x3510ca){if(_0x2dd276[_0xf962('0x37')][_0xf962('0x70')])return;_0x29c0f3[_0xf962('0x42')]('i.FaxAccountId\x20IS\x20NOT\x20NULL');_0x2291ee[_0xf962('0x42')](_0xf962('0x85'));return;}if(_0x2dd276[_0xf962('0x86')][_0xf962('0x87')]!==_0xf962('0x88'))return;return _0x2dd276[_0xf962('0x86')][_0xf962('0x89')]({'attributes':['id'],'raw':!![]})['then'](function(_0x535ba9){if(_['isEmpty'](_0x535ba9)){_0x29c0f3['where'](_0xf962('0x8a'));_0x2291ee[_0xf962('0x42')]('i.FaxAccountId\x20IS\x20NULL');}else{_0x29c0f3[_0xf962('0x42')](_0xf962('0x8b'),_[_0xf962('0x2b')](_0x535ba9,'id'));_0x2291ee[_0xf962('0x42')]('i.FaxAccountId\x20IN\x20?',_[_0xf962('0x2b')](_0x535ba9,'id'));}});})[_0xf962('0x23')](function(){if(_0x2dd276[_0xf962('0x86')][_0xf962('0x87')]===_0xf962('0x88')&&!_0x3510ca&&!_0x2dd276[_0xf962('0x37')][_0xf962('0x70')])return[];return db[_0xf962('0x8c')][_0xf962('0x37')](_0x29c0f3[_0xf962('0x8d')](),_0x130b12);})['then'](function(_0x4019ec){_0x30f4fe[_0xf962('0x1f')]=_0x4019ec['length'];if(_0x30f4fe[_0xf962('0x1f')]===0x0)return[];return db[_0xf962('0x8c')][_0xf962('0x37')](_0x38caab[_0xf962('0x8d')](),_0x130b12)[_0xf962('0x23')](function(_0x1cfa6d){_0x283a0d=_[_0xf962('0x8e')](_0x1cfa6d,'id');_0x130b12=_[_0xf962('0x8f')](_0x130b12,{'model':db[_0xf962('0x32')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x2dd276[_0xf962('0x37')]['fields']){_0x18176e['attributes']['forEach'](function(_0x14845e){_0x2291ee[_0xf962('0x45')]('i.'+_0x14845e);});}else{_0x2291ee[_0xf962('0x45')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xf962('0x5c'));_0x2291ee['field'](_0xf962('0x90'),'Account.key');_0x2291ee[_0xf962('0x45')](_0xf962('0x91'),_0xf962('0x92'));_0x2291ee[_0xf962('0x45')](_0xf962('0x93'),_0xf962('0x83'));_0x2291ee[_0xf962('0x45')](_0xf962('0x94'));_0x2291ee[_0xf962('0x45')]('c.firstName',_0xf962('0x95'));_0x2291ee[_0xf962('0x45')](_0xf962('0x96'),_0xf962('0x97'));_0x2291ee[_0xf962('0x45')](_0xf962('0x98'),_0xf962('0x99'));_0x2291ee[_0xf962('0x45')](_0xf962('0x9a'),_0xf962('0x9b'));_0x2291ee[_0xf962('0x45')](_0xf962('0x9c'),_0xf962('0x9d'));_0x2291ee[_0xf962('0x45')](_0xf962('0x9e'),_0xf962('0x9f'));_0x2291ee[_0xf962('0x45')](_0xf962('0xa0'),'Owner.fullname');_0x2291ee[_0xf962('0x45')]('o.internal',_0xf962('0xa1'));_0x2291ee[_0xf962('0x45')](_0xf962('0xa2'),_0xf962('0x2d'));}if(_0x18176e[_0xf962('0x1e')])_0x2291ee[_0xf962('0x1e')](_0x18176e[_0xf962('0x1e')]);if(_0x18176e[_0xf962('0x1c')])_0x2291ee[_0xf962('0x1c')](_0x18176e['offset']);return db[_0xf962('0x8c')][_0xf962('0x37')](_0x2291ee[_0xf962('0x8d')](),_0x130b12);})[_0xf962('0x23')](function(_0x4cbeb5){if(_0x4cbeb5[_0xf962('0x3d')]>0x0)_0x2ae374[_0xf962('0x42')](_0xf962('0xa3'),_[_0xf962('0x2b')](_0x4cbeb5,'id'));return db[_0xf962('0x8c')][_0xf962('0x37')](_0x2ae374['toString'](),_0x130b12)[_0xf962('0x23')](function(_0x171a6a){var _0x397576=_[_0xf962('0xa4')](_0x171a6a,'FaxInteractionId');var _0x4d942e=[];_0x4cbeb5[_0xf962('0x2f')](function(_0xfc146d){_0x4d942e[_0xf962('0x30')](updateFaxInteraction(_0xfc146d,_0x283a0d,_0x397576));});return BPromise[_0xf962('0xa5')](_0x4d942e);});});})[_0xf962('0x23')](function(_0x23c72e){_0x30f4fe['rows']=_0x23c72e;return _0x30f4fe;})[_0xf962('0x23')](respondWithFilteredResult(_0x372c22,_0x18176e))[_0xf962('0xa6')](handleError(_0x372c22,null));};exports[_0xf962('0xa7')]=function(_0x404b6d,_0x4202b6){var _0x2e51ea={'raw':![],'where':{'id':_0x404b6d[_0xf962('0xa8')]['id']}},_0xd8ed15={};_0xd8ed15[_0xf962('0x35')]=_[_0xf962('0x38')](db[_0xf962('0x32')][_0xf962('0xa9')]);_0xd8ed15[_0xf962('0x37')]=_[_0xf962('0x38')](_0x404b6d[_0xf962('0x37')]);_0xd8ed15[_0xf962('0x39')]=_[_0xf962('0x3a')](_0xd8ed15[_0xf962('0x35')],_0xd8ed15[_0xf962('0x37')]);_0x2e51ea[_0xf962('0x3b')]=_[_0xf962('0x3a')](_0xd8ed15['model'],qs[_0xf962('0x3c')](_0x404b6d['query']['fields']));_0x2e51ea[_0xf962('0x3b')]=_0x2e51ea[_0xf962('0x3b')]['length']?_0x2e51ea['attributes']:_0xd8ed15[_0xf962('0x35')];if(_0x404b6d[_0xf962('0x37')]['includeAll']){_0x2e51ea[_0xf962('0xaa')]=[{'all':!![]}];}_0x2e51ea=_[_0xf962('0x8f')]({},_0x2e51ea,_0x404b6d[_0xf962('0xab')]);return db[_0xf962('0x32')]['find'](_0x2e51ea)[_0xf962('0x23')](handleEntityNotFound(_0x4202b6,null))[_0xf962('0x23')](respondWithResult(_0x4202b6,null))[_0xf962('0xa6')](handleError(_0x4202b6,null));};exports[_0xf962('0xac')]=function(_0x1a97f6,_0x1ea6d8){return db[_0xf962('0x32')][_0xf962('0xac')](_0x1a97f6[_0xf962('0x6d')],{})[_0xf962('0x23')](respondWithResult(_0x1ea6d8,0xc9))['catch'](handleError(_0x1ea6d8,null));};exports['update']=function(_0x513316,_0xe67825){if(_0x513316['body']['id']){delete _0x513316[_0xf962('0x6d')]['id'];}return db[_0xf962('0x32')][_0xf962('0x5b')]({'where':{'id':_0x513316[_0xf962('0xa8')]['id']}})[_0xf962('0x23')](handleEntityNotFound(_0xe67825,null))['then'](saveUpdates(_0x513316[_0xf962('0x6d')],null))[_0xf962('0x23')](respondWithResult(_0xe67825,null))[_0xf962('0xa6')](handleError(_0xe67825,null));};exports[_0xf962('0x24')]=function(_0x228a1b,_0x18b9ef){return db['FaxInteraction'][_0xf962('0x5b')]({'where':{'id':_0x228a1b['params']['id']}})['then'](handleEntityNotFound(_0x18b9ef,null))[_0xf962('0x23')](removeEntity(_0x18b9ef,null))[_0xf962('0xa6')](handleError(_0x18b9ef,null));};exports[_0xf962('0xad')]=function(_0xad5ba,_0x2fe753){return db[_0xf962('0x32')]['describe']()['then'](respondWithResult(_0x2fe753,null))[_0xf962('0xa6')](handleError(_0x2fe753,null));};exports[_0xf962('0xae')]=function(_0x1bce43,_0x3fe03e,_0x37a2c1){return db[_0xf962('0xaf')][_0xf962('0x5b')]({'where':{'id':_0x1bce43['params']['id']}})[_0xf962('0x23')](handleEntityNotFound(_0x3fe03e,null))['then'](function(_0x154434){if(_0x154434){return _0x154434[_0xf962('0xae')](_0x1bce43[_0xf962('0x6d')][_0xf962('0xb0')],_[_0xf962('0xb1')](_0x1bce43[_0xf962('0x6d')],['ids','id'])||{});}})['then'](respondWithResult(_0x3fe03e,null))[_0xf962('0xa6')](handleError(_0x3fe03e,null));};exports[_0xf962('0xb2')]=function(_0x1d9f4d,_0x371f4f,_0x556f0c){var _0x374e68={'raw':![],'where':{}};var _0xef8922={};var _0x2ae8d8={'count':0x0,'rows':[]};return db[_0xf962('0x32')][_0xf962('0xb3')]({'where':{'id':_0x1d9f4d[_0xf962('0xa8')]['id']}})[_0xf962('0x23')](handleEntityNotFound(_0x371f4f,null))['then'](function(_0x3bc7ea){if(_0x3bc7ea){_0xef8922['model']=_[_0xf962('0x38')](db['FaxMessage'][_0xf962('0xa9')]);_0xef8922[_0xf962('0x37')]=_['keys'](_0x1d9f4d[_0xf962('0x37')]);_0xef8922[_0xf962('0x39')]=_[_0xf962('0x3a')](_0xef8922[_0xf962('0x35')],_0xef8922['query']);_0x374e68['attributes']=_[_0xf962('0x3a')](_0xef8922[_0xf962('0x35')],qs[_0xf962('0x3c')](_0x1d9f4d[_0xf962('0x37')][_0xf962('0x3c')]));_0x374e68['attributes']=_0x374e68[_0xf962('0x3b')][_0xf962('0x3d')]?_0x374e68[_0xf962('0x3b')]:_0xef8922['model'];if(!_0x1d9f4d[_0xf962('0x37')]['hasOwnProperty']('nolimit')){_0x374e68['limit']=qs['limit'](_0x1d9f4d['query']['limit']);_0x374e68['offset']=qs[_0xf962('0x1c')](_0x1d9f4d[_0xf962('0x37')]['offset']);}_0x374e68[_0xf962('0x40')]=qs[_0xf962('0x41')](_0x1d9f4d[_0xf962('0x37')][_0xf962('0x41')]);_0x374e68[_0xf962('0x42')]=qs[_0xf962('0x39')](_['pick'](_0x1d9f4d[_0xf962('0x37')],_0xef8922[_0xf962('0x39')]));_0x374e68[_0xf962('0x42')]['FaxInteractionId']=_0x3bc7ea['id'];if(_0x1d9f4d['query'][_0xf962('0xb4')]){_0x374e68[_0xf962('0x42')]=_[_0xf962('0x8f')](_0x374e68[_0xf962('0x42')],{'$or':_[_0xf962('0x2b')](_0x374e68[_0xf962('0x3b')],function(_0xfcfc8){var _0x3e2a40={};_0x3e2a40[_0xfcfc8]={'$like':'%'+_0x1d9f4d[_0xf962('0x37')]['filter']+'%'};return _0x3e2a40;})});}if(_0x1d9f4d['query']['$gte']){var _0x122d06=_0x1d9f4d['query'][_0xf962('0x73')][_0xf962('0x2e')](',');var _0x413352={};_0x413352[_0x122d06[0x0]]={'$gte':moment(_0x122d06[0x1])[_0xf962('0xb5')](_0xf962('0xb6'))};_0x374e68[_0xf962('0x42')]=_['merge'](_0x374e68[_0xf962('0x42')],_0x413352);}_0x374e68=_[_0xf962('0x8f')]({},_0x374e68,_0x1d9f4d[_0xf962('0xab')]);return db['FaxMessage']['count']({'where':_0x374e68[_0xf962('0x42')]})['then'](function(_0x379ef3){_0x2ae8d8[_0xf962('0x1f')]=_0x379ef3;if(_0x1d9f4d[_0xf962('0x37')]['includeAll']){_0x374e68[_0xf962('0xaa')]=[{'all':!![]}];}return db[_0xf962('0xaf')]['findAll'](_0x374e68);})['then'](function(_0x5d3fcf){_0x2ae8d8[_0xf962('0xb7')]=_0x5d3fcf;return _0x2ae8d8;});}})['then'](respondWithFilteredResult(_0x371f4f,_0x374e68))[_0xf962('0xa6')](handleError(_0x371f4f,null));};exports['addTags']=function(_0x14be3e,_0x4d221b,_0x5ee300){return db[_0xf962('0x32')][_0xf962('0x5b')]({'where':{'id':_0x14be3e['params']['id']}})['then'](handleEntityNotFound(_0x4d221b,null))[_0xf962('0x23')](function(_0x3b0a31){if(_0x3b0a31){return _0x3b0a31['setTags'](_0x14be3e[_0xf962('0x6d')][_0xf962('0xb0')],_['omit'](_0x14be3e['body'],[_0xf962('0xb0'),'id'])||{})['spread'](function(){return db[_0xf962('0xb8')][_0xf962('0xb9')]({'attributes':['id',_0xf962('0x36'),_0xf962('0x46')],'where':{'id':_0x14be3e[_0xf962('0x6d')]['ids']}});})[_0xf962('0x23')](function(_0x5598c5){socket[_0xf962('0xba')]('faxInteractionTags:save',{'id':Number(_0x14be3e['params']['id']),'tags':_0x5598c5||[]});return{'id':Number(_0x14be3e[_0xf962('0xa8')]['id']),'tags':_0x5598c5||[]};});}})[_0xf962('0x23')](respondWithResult(_0x4d221b,null))[_0xf962('0xa6')](handleError(_0x4d221b,null));};exports['removeTags']=function(_0x1f2ed9,_0x117fdc,_0x4e8640){return db[_0xf962('0x32')][_0xf962('0x5b')]({'where':{'id':_0x1f2ed9['params']['id']}})['then'](handleEntityNotFound(_0x117fdc,null))[_0xf962('0x23')](function(_0x5d3fd4){if(_0x5d3fd4){return _0x5d3fd4[_0xf962('0xbb')](_0x1f2ed9[_0xf962('0x37')][_0xf962('0xb0')]);}})[_0xf962('0x23')](respondWithStatusCode(_0x117fdc,null))[_0xf962('0xa6')](handleError(_0x117fdc,null));};exports['download']=function(_0x12fd63,_0x3bd340){var _0x2fb7ce=moment()[_0xf962('0xbc')]()[_0xf962('0x8d')]();var _0x2b942b=path[_0xf962('0xbd')](config[_0xf962('0xbe')],_0xf962('0xbf'),_0xf962('0xc0'),_0xf962('0xc1'));var _0x44a52a=path['join'](config['root'],_0xf962('0xbf'),_0xf962('0xc0'),'attachments');var _0x1795f7=path[_0xf962('0xbd')](_0x2b942b,_0x2fb7ce);var _0x3f3c67=util['format'](_0xf962('0xc2'),_0x12fd63[_0xf962('0xa8')]['id'],_0x2fb7ce);var _0x59ce8b=path['join'](_0x2b942b,_0x3f3c67);var _0x5b4181=[];_0x5b4181[_0xf962('0x30')]({'model':db['Attachment'],'as':_0xf962('0xc3'),'raw':!![]});var _0x4bac66=[{'model':db['FaxMessage'],'as':_0xf962('0xc4'),'attributes':['id','body','createdAt'],'include':_0x5b4181}];return db[_0xf962('0x32')][_0xf962('0x5b')]({'where':{'id':_0x12fd63[_0xf962('0xa8')]['id']},'include':_0x4bac66})[_0xf962('0x23')](handleEntityNotFound(_0x3bd340,null))[_0xf962('0x23')](function(_0x144d4d){if(_0x144d4d&&_0x144d4d['Messages']){var _0x5a4e0a=_0x144d4d[_0xf962('0xc5')]({'plain':!![]});fs[_0xf962('0xc6')](_0x1795f7);for(var _0x421dfc=0x0;_0x421dfc<_0x5a4e0a[_0xf962('0xc4')][_0xf962('0x3d')];_0x421dfc++){var _0x27be08=_0x5a4e0a['Messages'][_0x421dfc][_0xf962('0xc3')];if(_0x27be08){var _0x2657ff=path[_0xf962('0xbd')](_0x44a52a,_0x27be08[_0xf962('0xc7')]);if(fs[_0xf962('0xc8')](_0x2657ff)){fs[_0xf962('0xc9')](_0x2657ff)['pipe'](fs[_0xf962('0xca')](path[_0xf962('0xbd')](_0x1795f7,_0x27be08[_0xf962('0xc7')])));}}}return BPromise[_0xf962('0xcb')]()[_0xf962('0x23')](function(){return new BPromise(function(_0x37b855,_0x3a2802){zipdir(_0x1795f7,{'saveTo':_0x59ce8b},function(_0x3e077d,_0xbcce93){if(_0x3e077d)return _0x3a2802(_0x3e077d);return _0x37b855(_0xbcce93);});})['then'](function(){return new BPromise(function(_0x323358,_0x5a9d7f){rimraf(_0x1795f7,function(_0xd4482e){if(_0xd4482e)_0x5a9d7f(_0xd4482e);return _0x323358();});});})[_0xf962('0x23')](function(){return _0x3bd340[_0xf962('0xcc')](_0x59ce8b,_0x3f3c67,function(_0x196442){if(_0x196442){console[_0xf962('0xcd')]('err',_0x196442);}else{fs[_0xf962('0xce')](_0x59ce8b);}});});});}else{return _0x3bd340[_0xf962('0x26')](0xc8);}})[_0xf962('0xa6')](handleError(_0x3bd340,null));};
\ No newline at end of file