Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / api / faxInteraction / faxInteraction.controller.js
index c50701c..f55d740 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5f83=['user','agent','sequelize','toString','keyBy','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','a.key','Account.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.*','c.firstName','Contact.firstName','c.lastName','c.email','c.phone','Contact.phone','c.mobile','c.fax','o.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.FaxInteractionId\x20IN\x20?','groupBy','FaxInteractionId','rows','show','includeAll','merge','options','create','params','describe','addMessage','FaxMessage','omit','findOne','rawAttributes','nolimit','filter','$gte','format','include','findAll','addTags','setTags','ids','spread','faxInteractionTags:save','removeTags','download','unix','join','server','files','root','attachments','transcript-%d-%s.zip','Attachment','Messages','mkdirSync','basename','existsSync','createReadStream','pipe','createWriteStream','log','err','unlinkSync','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','register','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','end','stack','name','Users','map','fullname','Tags','TagIds','split','forEach','push','catch','index','FaxInteraction','fieldName','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','pick','select','field','color','from','u.id','left_join','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','fax_accounts','a.id\x20=\x20i.FaxAccountId','me.FaxInteractionId\x20=\x20i.id','it.FaxInteractionId\x20=\x20i.id','tools_tags','t.id\x20=\x20it.TagId','expr','parseSearch','search','sqlOperator','conditions','find','unreadMessages','having','`\x20=\x200','`\x20>\x200','Contact','$substring','value','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','type','text','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','User','operator','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','body','isEmpty','FaxAccountId','where','i.FaxAccountId\x20IN\x20?','concat','createdAt','parse','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','isArray','tag','replace','isNumeric','i.id\x20LIKE\x20?','i.fax\x20LIKE\x20?','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','Sequelize','QueryTypes','SELECT','i.id','contactName','DESC','resolve','i.FaxAccountId\x20IS\x20NOT\x20NULL','role','getFaxAccounts','i.FaxAccountId\x20IS\x20NULL'];(function(_0x4168b0,_0x566b80){var _0x5d488e=function(_0x506861){while(--_0x506861){_0x4168b0['push'](_0x4168b0['shift']());}};_0x5d488e(++_0x566b80);}(_0x5f83,0x120));var _0x35f8=function(_0x5a86b0,_0x5d7b16){_0x5a86b0=_0x5a86b0-0x0;var _0x32bd12=_0x5f83[_0x5a86b0];return _0x32bd12;};'use strict';var pdf=require(_0x35f8('0x0'));var emlformat=require(_0x35f8('0x1'));var rimraf=require(_0x35f8('0x2'));var zipdir=require(_0x35f8('0x3'));var jsonpatch=require(_0x35f8('0x4'));var rp=require('request-promise');var moment=require(_0x35f8('0x5'));var BPromise=require(_0x35f8('0x6'));var Mustache=require(_0x35f8('0x7'));var util=require(_0x35f8('0x8'));var path=require('path');var sox=require(_0x35f8('0x9'));var csv=require(_0x35f8('0xa'));var ejs=require(_0x35f8('0xb'));var fs=require('fs');var _=require(_0x35f8('0xc'));var squel=require(_0x35f8('0xd'));var crypto=require('crypto');var jsforce=require(_0x35f8('0xe'));var deskjs=require(_0x35f8('0xf'));var toCsv=require(_0x35f8('0xa'));var querystring=require(_0x35f8('0x10'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x35f8('0x11'));var as=require(_0x35f8('0x12'));var hardwareService=require(_0x35f8('0x13'));var logger=require('../../config/logger')(_0x35f8('0x14'));var utils=require(_0x35f8('0x15'));var config=require(_0x35f8('0x16'));var licenseUtil=require(_0x35f8('0x17'));var db=require(_0x35f8('0x18'))['db'];config[_0x35f8('0x19')]=_['defaults'](config['redis'],{'host':_0x35f8('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x35f8('0x19')]));require('./faxInteraction.socket')[_0x35f8('0x1b')](socket);function respondWithStatusCode(_0x437dce,_0x16eced){_0x16eced=_0x16eced||0xcc;return function(_0x487e65){if(_0x487e65){return _0x437dce[_0x35f8('0x1c')](_0x16eced);}return _0x437dce[_0x35f8('0x1d')](_0x16eced)['end']();};}function respondWithResult(_0x46c849,_0x4c77c0){_0x4c77c0=_0x4c77c0||0xc8;return function(_0x42fdc9){if(_0x42fdc9){return _0x46c849[_0x35f8('0x1d')](_0x4c77c0)[_0x35f8('0x1e')](_0x42fdc9);}};}function respondWithFilteredResult(_0x58f583,_0x2bef4b){return function(_0x3bf745){if(_0x3bf745){var _0x3b49f2=_0x3bf745[_0x35f8('0x1f')],_0x5d9948=_0x2bef4b['offset'],_0x28e529=_0x2bef4b[_0x35f8('0x20')]+_0x2bef4b[_0x35f8('0x21')],_0x361a38;if(_0x28e529>=_0x3b49f2){_0x28e529=_0x3b49f2;_0x361a38=0xc8;}else{_0x361a38=0xce;}_0x58f583['status'](_0x361a38);return _0x58f583[_0x35f8('0x22')](_0x35f8('0x23'),_0x5d9948+'-'+_0x28e529+'/'+_0x3b49f2)[_0x35f8('0x1e')](_0x3bf745);}return null;};}function patchUpdates(_0x368f70){return function(_0x43e52d){try{jsonpatch[_0x35f8('0x24')](_0x43e52d,_0x368f70,!![]);}catch(_0x2a0fe0){return BPromise[_0x35f8('0x25')](_0x2a0fe0);}return _0x43e52d[_0x35f8('0x26')]();};}function saveUpdates(_0x2d2d47,_0x56d5c9){return function(_0x3c915a){if(_0x3c915a){return _0x3c915a[_0x35f8('0x27')](_0x2d2d47)[_0x35f8('0x28')](function(_0x2374ee){return _0x2374ee;});}return null;};}function removeEntity(_0x5e5acd,_0x65bf2a){return function(_0x4ab70c){if(_0x4ab70c){return _0x4ab70c[_0x35f8('0x29')]()[_0x35f8('0x28')](function(){_0x5e5acd[_0x35f8('0x1d')](0xcc)[_0x35f8('0x2a')]();});}};}function handleEntityNotFound(_0x5d77f9,_0x1c59f4){return function(_0x20277e){if(!_0x20277e){_0x5d77f9[_0x35f8('0x1c')](0x194);}return _0x20277e;};}function handleError(_0x1daa54,_0x25434c){_0x25434c=_0x25434c||0x1f4;return function(_0x3defc4){logger['error'](_0x3defc4[_0x35f8('0x2b')]);if(_0x3defc4[_0x35f8('0x2c')]){delete _0x3defc4['name'];}_0x1daa54[_0x35f8('0x1d')](_0x25434c)['send'](_0x3defc4);};}function getInteractionUsers(_0x5bed8c,_0x616970){return new BPromise(function(_0x3c305e,_0x4630a9){try{if(_0x616970[_0x5bed8c['id']]){_0x5bed8c[_0x35f8('0x2d')]=_[_0x35f8('0x2e')](_0x616970[_0x5bed8c['id']],function(_0x47ad75){return{'id':_0x47ad75['id'],'fullname':_0x47ad75[_0x35f8('0x2f')]};});}}catch(_0x2afe07){_0x4630a9(_0x2afe07);}_0x3c305e(_0x5bed8c);});}function getInteractionTags(_0x161d39,_0x2deb0b){return new BPromise(function(_0x297e36,_0x19e08a){try{if(_0x161d39['TagIds']){_0x161d39[_0x35f8('0x30')]=[];_0x161d39[_0x35f8('0x31')][_0x35f8('0x32')](',')[_0x35f8('0x33')](function(_0x178506){_0x161d39[_0x35f8('0x30')][_0x35f8('0x34')](_0x2deb0b[_0x178506]);});}delete _0x161d39[_0x35f8('0x31')];}catch(_0x471970){_0x19e08a(_0x471970);}_0x297e36(_0x161d39);});}function updateFaxInteraction(_0x380d6e,_0x18ed29,_0x97e4d5){return new BPromise(function(_0x5cd4d6,_0x2172aa){return getInteractionUsers(_0x380d6e,_0x97e4d5)[_0x35f8('0x28')](function(_0x371787){return getInteractionTags(_0x371787,_0x18ed29);})[_0x35f8('0x28')](function(_0x1ff471){_0x5cd4d6(_0x1ff471);})[_0x35f8('0x35')](function(_0x4d15bd){_0x2172aa(_0x4d15bd);});});}exports[_0x35f8('0x36')]=function(_0x495057,_0xb13e03){var _0x1e7cc4={},_0x53ee75={},_0x15c21a={'count':0x0,'rows':[]};var _0x53dce3=_[_0x35f8('0x2e')](db[_0x35f8('0x37')]['rawAttributes'],function(_0x298ac3){return{'name':_0x298ac3[_0x35f8('0x38')],'type':_0x298ac3['type']['key']};});_0x53ee75[_0x35f8('0x39')]=_['map'](_0x53dce3,'name');_0x53ee75[_0x35f8('0x3a')]=_[_0x35f8('0x3b')](_0x495057[_0x35f8('0x3a')]);_0x53ee75[_0x35f8('0x3c')]=_[_0x35f8('0x3d')](_0x53ee75[_0x35f8('0x39')],_0x53ee75[_0x35f8('0x3a')]);_0x1e7cc4[_0x35f8('0x3e')]=_[_0x35f8('0x3d')](_0x53ee75['model'],qs[_0x35f8('0x3f')](_0x495057['query'][_0x35f8('0x3f')]));_0x1e7cc4['attributes']=_0x1e7cc4['attributes'][_0x35f8('0x40')]?_0x1e7cc4[_0x35f8('0x3e')]:_0x53ee75[_0x35f8('0x39')];if(!_0x495057[_0x35f8('0x3a')][_0x35f8('0x41')]('nolimit')){_0x1e7cc4[_0x35f8('0x21')]=qs[_0x35f8('0x21')](_0x495057[_0x35f8('0x3a')]['limit']);_0x1e7cc4[_0x35f8('0x20')]=qs['offset'](_0x495057[_0x35f8('0x3a')]['offset']);}_0x1e7cc4[_0x35f8('0x42')]=qs['sort'](_0x495057[_0x35f8('0x3a')][_0x35f8('0x43')]);_0x1e7cc4['where']=qs['filters'](_[_0x35f8('0x44')](_0x495057['query'],_0x53ee75[_0x35f8('0x3c')]),_0x53dce3);var _0x508e1a=[];var _0x246ed4=squel[_0x35f8('0x45')]()[_0x35f8('0x46')]('id')[_0x35f8('0x46')](_0x35f8('0x2c'))['field'](_0x35f8('0x47'))[_0x35f8('0x48')]('tools_tags');var _0x34213f=squel[_0x35f8('0x45')]()['field'](_0x35f8('0x49'))[_0x35f8('0x46')]('u.fullname')[_0x35f8('0x46')]('ui.FaxInteractionId')[_0x35f8('0x48')]('user_has_fax_interactions','ui')[_0x35f8('0x4a')](_0x35f8('0x4b'),'u',_0x35f8('0x4c'));var _0x40a2af=squel[_0x35f8('0x45')]()[_0x35f8('0x48')](_0x35f8('0x4d'),'i')['left_join'](_0x35f8('0x4e'),'c',_0x35f8('0x4f'))[_0x35f8('0x4a')](_0x35f8('0x4b'),'o',_0x35f8('0x50'))[_0x35f8('0x4a')](_0x35f8('0x51'),'a',_0x35f8('0x52'))[_0x35f8('0x4a')]('fax_messages','me',_0x35f8('0x53'))['left_join']('fax_interaction_has_tags','it',_0x35f8('0x54'))[_0x35f8('0x4a')](_0x35f8('0x55'),'t',_0x35f8('0x56'));var _0xf886e8=squel[_0x35f8('0x57')]();var _0x1da6cf=[];var _0x17869b=squel[_0x35f8('0x57')]();var _0x4f20ae;if(_0x495057[_0x35f8('0x3a')]['search']){_0x4f20ae=as[_0x35f8('0x58')](_0x495057[_0x35f8('0x3a')][_0x35f8('0x59')]);var _0x3debd2=_0x4f20ae[_0x35f8('0x5a')];for(var _0x238153=0x0;_0x238153<_0x4f20ae[_0x35f8('0x5b')][_0x35f8('0x40')];_0x238153++){var _0x3a69ee=_0x4f20ae['conditions'][_0x238153];var _0x2914bc='i';var _0x300d6c=_[_0x35f8('0x5c')](_0x53dce3,['name',_0x3a69ee[_0x35f8('0x46')]]);if(!_0x300d6c){switch(_0x3a69ee['field']){case _0x35f8('0x5d'):if(_0x3a69ee['value']==0x1){_0x40a2af[_0x35f8('0x5e')]('`'+_0x3a69ee[_0x35f8('0x46')]+_0x35f8('0x5f'));}else{_0x40a2af['having']('`'+_0x3a69ee[_0x35f8('0x46')]+_0x35f8('0x60'));}break;case _0x35f8('0x61'):if(_0x3a69ee['operator']===_0x35f8('0x62')){if(_0x3a69ee[_0x35f8('0x63')][_0x35f8('0x32')]('\x20')['length']>0x1){_0xf886e8[_0x3debd2](_0x35f8('0x64'),qs[_0x35f8('0x65')](_0x3a69ee[_0x35f8('0x63')]),null);}else{var _0x7bdbd0='%'+_0x3a69ee[_0x35f8('0x63')]+'%';_0xf886e8[_0x3debd2](_0x35f8('0x66'),_0x7bdbd0,_0x7bdbd0,_0x7bdbd0);}}else{_0x300d6c=_[_0x35f8('0x5c')](_0x53dce3,[_0x35f8('0x2c'),_0x35f8('0x67')]);_0x3a69ee[_0x35f8('0x46')]='ContactId';_0x41009c=as[_0x35f8('0x68')](_0x2914bc,_0x300d6c[_0x35f8('0x69')],_0x3a69ee);_0xf886e8[_0x3debd2](_0x41009c[_0x35f8('0x6a')],_0x41009c[_0x35f8('0x63')][_0x35f8('0x6b')],_0x41009c[_0x35f8('0x63')]['end']);}break;case _0x35f8('0x6c'):var _0x1dd15d=_0x3a69ee[_0x35f8('0x63')][_0x35f8('0x32')](',')[_0x35f8('0x2e')](function(_0x187683){return Number(_0x187683);});_0x1dd15d[_0x35f8('0x33')](function(_0x439f3d){_0x17869b['or'](_0x35f8('0x6d'),'%,'+_0x439f3d+',%');});_0x1da6cf=_['union'](_0x1da6cf,_0x1dd15d);break;case _0x35f8('0x6e'):if(_0x3a69ee[_0x35f8('0x6f')]==='$substring'){_0xf886e8[_0x3debd2](_0x35f8('0x70'),'%'+_0x3a69ee[_0x35f8('0x63')]+'%',null);}else{_0x300d6c=_['find'](_0x53dce3,['name','UserId']);_0x3a69ee[_0x35f8('0x46')]='UserId';_0x41009c=as[_0x35f8('0x68')](_0x2914bc,_0x300d6c[_0x35f8('0x69')],_0x3a69ee);_0xf886e8[_0x3debd2](_0x41009c[_0x35f8('0x6a')],_0x41009c[_0x35f8('0x63')][_0x35f8('0x6b')],_0x41009c[_0x35f8('0x63')][_0x35f8('0x2a')]);}break;case _0x35f8('0x71'):_0x41009c=as[_0x35f8('0x68')]('me',null,_0x3a69ee);_0xf886e8[_0x3debd2](_0x41009c[_0x35f8('0x6a')],_0x41009c['value'][_0x35f8('0x6b')],_0x41009c[_0x35f8('0x63')][_0x35f8('0x2a')]);break;}}else{var _0x41009c=as[_0x35f8('0x68')](_0x2914bc,_0x300d6c[_0x35f8('0x69')],_0x3a69ee);_0xf886e8[_0x3debd2](_0x41009c[_0x35f8('0x6a')],_0x41009c[_0x35f8('0x63')]['start'],_0x41009c[_0x35f8('0x63')][_0x35f8('0x2a')]);}}}else{var _0x57def4=_(_0x495057['query'])['keys']()[_0x35f8('0x2e')](function(_0x2a2133){return _['some'](_0x53dce3,[_0x35f8('0x2c'),_0x2a2133])?_0x2a2133:undefined;})['compact']()[_0x35f8('0x63')]();if(!_[_0x35f8('0x72')](_0x57def4)){_0x57def4['forEach'](function(_0x31910f){if(_0x31910f===_0x35f8('0x73')){_0x40a2af[_0x35f8('0x74')](_0x35f8('0x75'),[][_0x35f8('0x76')](_0x495057['query'][_0x31910f]));}else if(_0x31910f===_0x35f8('0x77')){var _0x3156a1=JSON[_0x35f8('0x78')](_0x495057['query'][_0x31910f])['$gte'];var _0x29fc89=JSON['parse'](_0x495057[_0x35f8('0x3a')][_0x31910f])[_0x35f8('0x79')];_0x40a2af[_0x35f8('0x74')](_0x35f8('0x7a'),_0x3156a1,_0x29fc89);}else{if(_0x495057[_0x35f8('0x3a')][_0x31910f]===_0x35f8('0x7b')){_0x40a2af[_0x35f8('0x74')]('i.'+_0x31910f+_0x35f8('0x7c'));}else{_0x40a2af['where']('i.'+_0x31910f+_0x35f8('0x7d'),_0x495057['query'][_0x31910f]);}}});}if(_0x495057[_0x35f8('0x3a')]['read']){if(_0x495057[_0x35f8('0x3a')][_0x35f8('0x7e')]==0x1){_0x40a2af[_0x35f8('0x5e')]('`unreadMessages`\x20=\x200');}else{_0x40a2af[_0x35f8('0x5e')]('`unreadMessages`\x20>\x200');}}if(_0x495057[_0x35f8('0x3a')]['tag']){_0x1da6cf=_[_0x35f8('0x7f')](_0x495057[_0x35f8('0x3a')]['tag'])?_0x495057[_0x35f8('0x3a')]['tag']:new Array(_0x495057[_0x35f8('0x3a')][_0x35f8('0x80')]);_0x1da6cf[_0x35f8('0x33')](function(_0x55a8af){_0x17869b['or'](_0x35f8('0x6d'),'%,'+_0x55a8af+',%');});}if(_0x495057[_0x35f8('0x3a')]['filter']){var _0x394051=_0x495057[_0x35f8('0x3a')]['filter'][_0x35f8('0x81')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs[_0x35f8('0x82')](_0x394051)){_0xf886e8['or'](_0x35f8('0x83'),_0x394051+'%')['or'](_0x35f8('0x84'),_0x394051+'%');}_0xf886e8['or'](_0x35f8('0x85'),_0x394051+'%');}}_0x40a2af[_0x35f8('0x74')](_0xf886e8);_0x40a2af[_0x35f8('0x86')]('i.id');var _0x147141={'type':db[_0x35f8('0x87')][_0x35f8('0x88')][_0x35f8('0x89')],'raw':!![]};var _0x8b565a=_0x40a2af['clone']();_0x8b565a['field'](_0x35f8('0x8a'));_0x8b565a[_0x35f8('0x46')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x35f8('0x5d'));if(_0x1e7cc4[_0x35f8('0x42')]){_0x1e7cc4[_0x35f8('0x42')][_0x35f8('0x33')](function(_0x5ab3cd){var _0x373af7=_0x5ab3cd[0x0]===_0x35f8('0x8b')?_0x5ab3cd[0x0]:'i.'+_0x5ab3cd[0x0];_0x40a2af[_0x35f8('0x42')](_0x373af7,_0x5ab3cd[0x1]===_0x35f8('0x8c')?![]:!![]);});}if(!_[_0x35f8('0x72')](_0x1da6cf)){_0x40a2af[_0x35f8('0x5e')](_0x17869b);_0x8b565a[_0x35f8('0x74')]('t.id\x20IN\x20?',_0x1da6cf);}BPromise[_0x35f8('0x8d')]()[_0x35f8('0x28')](function(){if(!_0x4f20ae){if(_0x495057[_0x35f8('0x3a')][_0x35f8('0x73')])return;_0x8b565a[_0x35f8('0x74')](_0x35f8('0x8e'));_0x40a2af[_0x35f8('0x74')](_0x35f8('0x8e'));return;}if(_0x495057['user'][_0x35f8('0x8f')]!=='agent')return;return _0x495057['user'][_0x35f8('0x90')]({'attributes':['id'],'raw':!![]})['then'](function(_0x2b0223){if(_[_0x35f8('0x72')](_0x2b0223)){_0x8b565a['where'](_0x35f8('0x91'));_0x40a2af[_0x35f8('0x74')](_0x35f8('0x91'));}else{_0x8b565a['where']('i.FaxAccountId\x20IN\x20?',_[_0x35f8('0x2e')](_0x2b0223,'id'));_0x40a2af['where']('i.FaxAccountId\x20IN\x20?',_[_0x35f8('0x2e')](_0x2b0223,'id'));}});})[_0x35f8('0x28')](function(){if(_0x495057[_0x35f8('0x92')]['role']===_0x35f8('0x93')&&!_0x4f20ae&&!_0x495057[_0x35f8('0x3a')][_0x35f8('0x73')])return[];return db[_0x35f8('0x94')][_0x35f8('0x3a')](_0x8b565a[_0x35f8('0x95')](),_0x147141);})[_0x35f8('0x28')](function(_0x3c45a2){_0x15c21a['count']=_0x3c45a2[_0x35f8('0x40')];if(_0x15c21a[_0x35f8('0x1f')]===0x0)return[];return db[_0x35f8('0x94')][_0x35f8('0x3a')](_0x246ed4[_0x35f8('0x95')](),_0x147141)[_0x35f8('0x28')](function(_0x10da5f){_0x508e1a=_[_0x35f8('0x96')](_0x10da5f,'id');_0x147141=_['merge'](_0x147141,{'model':db[_0x35f8('0x37')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x495057[_0x35f8('0x3a')][_0x35f8('0x3f')]){_0x1e7cc4[_0x35f8('0x3e')]['forEach'](function(_0x6125f){_0x40a2af[_0x35f8('0x46')]('i.'+_0x6125f);});}else{_0x40a2af[_0x35f8('0x46')](_0x35f8('0x97'),_0x35f8('0x5d'));_0x40a2af[_0x35f8('0x46')](_0x35f8('0x98'),_0x35f8('0x99'));_0x40a2af['field'](_0x35f8('0x9a'),_0x35f8('0x9b'));_0x40a2af[_0x35f8('0x46')](_0x35f8('0x9c'),_0x35f8('0x8b'));_0x40a2af['field'](_0x35f8('0x9d'));_0x40a2af[_0x35f8('0x46')](_0x35f8('0x9e'),_0x35f8('0x9f'));_0x40a2af[_0x35f8('0x46')](_0x35f8('0xa0'),'Contact.lastName');_0x40a2af[_0x35f8('0x46')](_0x35f8('0xa1'),'Contact.email');_0x40a2af[_0x35f8('0x46')](_0x35f8('0xa2'),_0x35f8('0xa3'));_0x40a2af[_0x35f8('0x46')](_0x35f8('0xa4'),'Contact.mobile');_0x40a2af[_0x35f8('0x46')](_0x35f8('0xa5'),'Contact.fax');_0x40a2af['field'](_0x35f8('0xa6'),'Owner.fullname');_0x40a2af[_0x35f8('0x46')](_0x35f8('0xa7'),_0x35f8('0xa8'));_0x40a2af['field'](_0x35f8('0xa9'),_0x35f8('0x31'));}if(_0x1e7cc4[_0x35f8('0x21')])_0x40a2af[_0x35f8('0x21')](_0x1e7cc4[_0x35f8('0x21')]);if(_0x1e7cc4[_0x35f8('0x20')])_0x40a2af[_0x35f8('0x20')](_0x1e7cc4[_0x35f8('0x20')]);return db[_0x35f8('0x94')][_0x35f8('0x3a')](_0x40a2af[_0x35f8('0x95')](),_0x147141);})[_0x35f8('0x28')](function(_0x42d11b){_0x34213f['where'](_0x35f8('0xaa'),_[_0x35f8('0x2e')](_0x42d11b,'id'));return db['sequelize'][_0x35f8('0x3a')](_0x34213f[_0x35f8('0x95')](),_0x147141)[_0x35f8('0x28')](function(_0x139334){var _0x1b7437=_[_0x35f8('0xab')](_0x139334,_0x35f8('0xac'));var _0x2f5560=[];_0x42d11b[_0x35f8('0x33')](function(_0x4eb1d8){_0x2f5560[_0x35f8('0x34')](updateFaxInteraction(_0x4eb1d8,_0x508e1a,_0x1b7437));});return BPromise['all'](_0x2f5560);});});})[_0x35f8('0x28')](function(_0x114c8b){_0x15c21a[_0x35f8('0xad')]=_0x114c8b;return _0x15c21a;})['then'](respondWithFilteredResult(_0xb13e03,_0x1e7cc4))[_0x35f8('0x35')](handleError(_0xb13e03,null));};exports[_0x35f8('0xae')]=function(_0x5c824f,_0x58a1a3){var _0x313506={'raw':![],'where':{'id':_0x5c824f['params']['id']}},_0xfc44f6={};_0xfc44f6[_0x35f8('0x39')]=_[_0x35f8('0x3b')](db[_0x35f8('0x37')]['rawAttributes']);_0xfc44f6['query']=_[_0x35f8('0x3b')](_0x5c824f[_0x35f8('0x3a')]);_0xfc44f6[_0x35f8('0x3c')]=_[_0x35f8('0x3d')](_0xfc44f6[_0x35f8('0x39')],_0xfc44f6[_0x35f8('0x3a')]);_0x313506[_0x35f8('0x3e')]=_['intersection'](_0xfc44f6['model'],qs[_0x35f8('0x3f')](_0x5c824f[_0x35f8('0x3a')]['fields']));_0x313506['attributes']=_0x313506[_0x35f8('0x3e')][_0x35f8('0x40')]?_0x313506[_0x35f8('0x3e')]:_0xfc44f6[_0x35f8('0x39')];if(_0x5c824f[_0x35f8('0x3a')][_0x35f8('0xaf')]){_0x313506['include']=[{'all':!![]}];}_0x313506=_[_0x35f8('0xb0')]({},_0x313506,_0x5c824f[_0x35f8('0xb1')]);return db[_0x35f8('0x37')]['find'](_0x313506)['then'](handleEntityNotFound(_0x58a1a3,null))[_0x35f8('0x28')](respondWithResult(_0x58a1a3,null))['catch'](handleError(_0x58a1a3,null));};exports[_0x35f8('0xb2')]=function(_0x4a6cda,_0x416a35){return db['FaxInteraction'][_0x35f8('0xb2')](_0x4a6cda[_0x35f8('0x71')],{})[_0x35f8('0x28')](respondWithResult(_0x416a35,0xc9))[_0x35f8('0x35')](handleError(_0x416a35,null));};exports[_0x35f8('0x27')]=function(_0x286cd8,_0x23c061){if(_0x286cd8[_0x35f8('0x71')]['id']){delete _0x286cd8['body']['id'];}return db[_0x35f8('0x37')][_0x35f8('0x5c')]({'where':{'id':_0x286cd8[_0x35f8('0xb3')]['id']}})[_0x35f8('0x28')](handleEntityNotFound(_0x23c061,null))[_0x35f8('0x28')](saveUpdates(_0x286cd8[_0x35f8('0x71')],null))[_0x35f8('0x28')](respondWithResult(_0x23c061,null))['catch'](handleError(_0x23c061,null));};exports[_0x35f8('0x29')]=function(_0x30fd2f,_0x1241e2){return db[_0x35f8('0x37')][_0x35f8('0x5c')]({'where':{'id':_0x30fd2f[_0x35f8('0xb3')]['id']}})['then'](handleEntityNotFound(_0x1241e2,null))[_0x35f8('0x28')](removeEntity(_0x1241e2,null))[_0x35f8('0x35')](handleError(_0x1241e2,null));};exports[_0x35f8('0xb4')]=function(_0xd1c5be,_0x49ce6f){return db['FaxInteraction']['describe']()[_0x35f8('0x28')](respondWithResult(_0x49ce6f,null))['catch'](handleError(_0x49ce6f,null));};exports[_0x35f8('0xb5')]=function(_0x50bf7f,_0x11fe71,_0x46f5cd){return db[_0x35f8('0xb6')][_0x35f8('0x5c')]({'where':{'id':_0x50bf7f[_0x35f8('0xb3')]['id']}})[_0x35f8('0x28')](handleEntityNotFound(_0x11fe71,null))['then'](function(_0x486937){if(_0x486937){return _0x486937['addMessage'](_0x50bf7f[_0x35f8('0x71')]['ids'],_[_0x35f8('0xb7')](_0x50bf7f['body'],['ids','id'])||{});}})[_0x35f8('0x28')](respondWithResult(_0x11fe71,null))[_0x35f8('0x35')](handleError(_0x11fe71,null));};exports['getMessages']=function(_0x295f21,_0x636936,_0x737641){var _0x46c492={'raw':![],'where':{}};var _0x84b5f6={};var _0x13db3b={'count':0x0,'rows':[]};return db['FaxInteraction'][_0x35f8('0xb8')]({'where':{'id':_0x295f21[_0x35f8('0xb3')]['id']}})[_0x35f8('0x28')](handleEntityNotFound(_0x636936,null))[_0x35f8('0x28')](function(_0x480903){if(_0x480903){_0x84b5f6[_0x35f8('0x39')]=_[_0x35f8('0x3b')](db[_0x35f8('0xb6')][_0x35f8('0xb9')]);_0x84b5f6[_0x35f8('0x3a')]=_[_0x35f8('0x3b')](_0x295f21[_0x35f8('0x3a')]);_0x84b5f6[_0x35f8('0x3c')]=_[_0x35f8('0x3d')](_0x84b5f6['model'],_0x84b5f6['query']);_0x46c492[_0x35f8('0x3e')]=_['intersection'](_0x84b5f6['model'],qs['fields'](_0x295f21[_0x35f8('0x3a')][_0x35f8('0x3f')]));_0x46c492[_0x35f8('0x3e')]=_0x46c492[_0x35f8('0x3e')][_0x35f8('0x40')]?_0x46c492[_0x35f8('0x3e')]:_0x84b5f6[_0x35f8('0x39')];if(!_0x295f21[_0x35f8('0x3a')]['hasOwnProperty'](_0x35f8('0xba'))){_0x46c492[_0x35f8('0x21')]=qs[_0x35f8('0x21')](_0x295f21[_0x35f8('0x3a')][_0x35f8('0x21')]);_0x46c492[_0x35f8('0x20')]=qs['offset'](_0x295f21[_0x35f8('0x3a')][_0x35f8('0x20')]);}_0x46c492[_0x35f8('0x42')]=qs[_0x35f8('0x43')](_0x295f21[_0x35f8('0x3a')][_0x35f8('0x43')]);_0x46c492[_0x35f8('0x74')]=qs[_0x35f8('0x3c')](_[_0x35f8('0x44')](_0x295f21[_0x35f8('0x3a')],_0x84b5f6[_0x35f8('0x3c')]));_0x46c492[_0x35f8('0x74')][_0x35f8('0xac')]=_0x480903['id'];if(_0x295f21['query'][_0x35f8('0xbb')]){_0x46c492[_0x35f8('0x74')]=_[_0x35f8('0xb0')](_0x46c492[_0x35f8('0x74')],{'$or':_[_0x35f8('0x2e')](_0x46c492[_0x35f8('0x3e')],function(_0x385e9b){var _0xa81435={};_0xa81435[_0x385e9b]={'$like':'%'+_0x295f21['query'][_0x35f8('0xbb')]+'%'};return _0xa81435;})});}if(_0x295f21['query'][_0x35f8('0xbc')]){var _0x231020=_0x295f21[_0x35f8('0x3a')][_0x35f8('0xbc')]['split'](',');var _0x58b797={};_0x58b797[_0x231020[0x0]]={'$gte':moment(_0x231020[0x1])[_0x35f8('0xbd')]('YYYY-MM-DD\x20HH:mm:ss')};_0x46c492[_0x35f8('0x74')]=_[_0x35f8('0xb0')](_0x46c492['where'],_0x58b797);}_0x46c492=_[_0x35f8('0xb0')]({},_0x46c492,_0x295f21['options']);return db['FaxMessage']['count']({'where':_0x46c492[_0x35f8('0x74')]})[_0x35f8('0x28')](function(_0x920d56){_0x13db3b[_0x35f8('0x1f')]=_0x920d56;if(_0x295f21[_0x35f8('0x3a')]['includeAll']){_0x46c492[_0x35f8('0xbe')]=[{'all':!![]}];}return db[_0x35f8('0xb6')][_0x35f8('0xbf')](_0x46c492);})[_0x35f8('0x28')](function(_0x269c8b){_0x13db3b[_0x35f8('0xad')]=_0x269c8b;return _0x13db3b;});}})['then'](respondWithFilteredResult(_0x636936,_0x46c492))[_0x35f8('0x35')](handleError(_0x636936,null));};exports[_0x35f8('0xc0')]=function(_0x24b1f5,_0x2594f3,_0x473ff5){return db[_0x35f8('0x37')][_0x35f8('0x5c')]({'where':{'id':_0x24b1f5[_0x35f8('0xb3')]['id']}})[_0x35f8('0x28')](handleEntityNotFound(_0x2594f3,null))[_0x35f8('0x28')](function(_0x2864c6){if(_0x2864c6){return _0x2864c6[_0x35f8('0xc1')](_0x24b1f5['body']['ids'],_[_0x35f8('0xb7')](_0x24b1f5['body'],[_0x35f8('0xc2'),'id'])||{})[_0x35f8('0xc3')](function(){return db[_0x35f8('0x6c')]['findAll']({'attributes':['id',_0x35f8('0x2c'),_0x35f8('0x47')],'where':{'id':_0x24b1f5[_0x35f8('0x71')][_0x35f8('0xc2')]}});})[_0x35f8('0x28')](function(_0x120c8a){socket['emit'](_0x35f8('0xc4'),{'id':Number(_0x24b1f5[_0x35f8('0xb3')]['id']),'tags':_0x120c8a||[]});return{'id':Number(_0x24b1f5[_0x35f8('0xb3')]['id']),'tags':_0x120c8a||[]};});}})['then'](respondWithResult(_0x2594f3,null))[_0x35f8('0x35')](handleError(_0x2594f3,null));};exports['removeTags']=function(_0x3c1a4f,_0x49847d,_0xec54cf){return db[_0x35f8('0x37')][_0x35f8('0x5c')]({'where':{'id':_0x3c1a4f[_0x35f8('0xb3')]['id']}})[_0x35f8('0x28')](handleEntityNotFound(_0x49847d,null))[_0x35f8('0x28')](function(_0xe77921){if(_0xe77921){return _0xe77921[_0x35f8('0xc5')](_0x3c1a4f[_0x35f8('0x3a')][_0x35f8('0xc2')]);}})[_0x35f8('0x28')](respondWithStatusCode(_0x49847d,null))[_0x35f8('0x35')](handleError(_0x49847d,null));};exports[_0x35f8('0xc6')]=function(_0x38dab9,_0x43d0df){var _0x6f36a9=moment()[_0x35f8('0xc7')]()[_0x35f8('0x95')]();var _0xcb575c=path[_0x35f8('0xc8')](config['root'],_0x35f8('0xc9'),_0x35f8('0xca'),'tmp');var _0x592560=path[_0x35f8('0xc8')](config[_0x35f8('0xcb')],_0x35f8('0xc9'),_0x35f8('0xca'),_0x35f8('0xcc'));var _0x2f0e36=path[_0x35f8('0xc8')](_0xcb575c,_0x6f36a9);var _0x50251e=util[_0x35f8('0xbd')](_0x35f8('0xcd'),_0x38dab9[_0x35f8('0xb3')]['id'],_0x6f36a9);var _0x5eca53=path[_0x35f8('0xc8')](_0xcb575c,_0x50251e);var _0x25e36a=[];_0x25e36a[_0x35f8('0x34')]({'model':db[_0x35f8('0xce')],'as':_0x35f8('0xce'),'raw':!![]});var _0x33e89c=[{'model':db[_0x35f8('0xb6')],'as':_0x35f8('0xcf'),'attributes':['id',_0x35f8('0x71'),_0x35f8('0x77')],'include':_0x25e36a}];return db[_0x35f8('0x37')][_0x35f8('0x5c')]({'where':{'id':_0x38dab9[_0x35f8('0xb3')]['id']},'include':_0x33e89c})['then'](handleEntityNotFound(_0x43d0df,null))['then'](function(_0x4c00a3){if(_0x4c00a3&&_0x4c00a3['Messages']){var _0x18cc64=_0x4c00a3['get']({'plain':!![]});fs[_0x35f8('0xd0')](_0x2f0e36);for(var _0x18de3d=0x0;_0x18de3d<_0x18cc64[_0x35f8('0xcf')]['length'];_0x18de3d++){var _0x2e580d=_0x18cc64[_0x35f8('0xcf')][_0x18de3d]['Attachment'];if(_0x2e580d){var _0x588f4e=path[_0x35f8('0xc8')](_0x592560,_0x2e580d[_0x35f8('0xd1')]);if(fs[_0x35f8('0xd2')](_0x588f4e)){fs[_0x35f8('0xd3')](_0x588f4e)[_0x35f8('0xd4')](fs[_0x35f8('0xd5')](path[_0x35f8('0xc8')](_0x2f0e36,_0x2e580d['basename'])));}}}return BPromise[_0x35f8('0x8d')]()[_0x35f8('0x28')](function(){return new BPromise(function(_0x15ca6d,_0x46caa3){zipdir(_0x2f0e36,{'saveTo':_0x5eca53},function(_0x2f96fb,_0x386580){if(_0x2f96fb)return _0x46caa3(_0x2f96fb);return _0x15ca6d(_0x386580);});})[_0x35f8('0x28')](function(){return new BPromise(function(_0x49e51b,_0x178d26){rimraf(_0x2f0e36,function(_0x264ba4){if(_0x264ba4)_0x178d26(_0x264ba4);return _0x49e51b();});});})[_0x35f8('0x28')](function(){return _0x43d0df[_0x35f8('0xc6')](_0x5eca53,_0x50251e,function(_0x2c150e){if(_0x2c150e){console[_0x35f8('0xd6')](_0x35f8('0xd7'),_0x2c150e);}else{fs[_0x35f8('0xd8')](_0x5eca53);}});});});}else{return _0x43d0df[_0x35f8('0x1c')](0xc8);}})[_0x35f8('0x35')](handleError(_0x43d0df,null));};
\ No newline at end of file
+var _0xc2c1=['c.lastName','Contact.lastName','c.email','Contact.email','c.phone','Contact.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','Owner.internal','groupBy','all','show','params','includeAll','include','merge','options','create','update','destroy','describe','addMessage','omit','ids','getMessages','FaxMessage','nolimit','FaxInteractionId','filter','format','YYYY-MM-DD\x20HH:mm:ss','findAll','rows','addTags','setTags','spread','faxInteractionTags:save','removeTags','unix','files','join','root','server','attachments','transcript-%d-%s.zip','Attachment','Messages','basename','existsSync','createReadStream','log','err','unlinkSync','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','status','undefined','count','offset','json','reject','then','sendStatus','stack','name','Users','fullname','TagIds','split','forEach','Tags','push','catch','waiting','answered','total','closed','UserId','talking','unmanaged','map','FaxInteraction','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','limit','order','sort','where','pick','select','field','color','from','tools_tags','u.id','u.fullname','left_join','users','u.id\x20=\x20ui.UserId','fax_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','a.id\x20=\x20i.FaxAccountId','fax_messages','me.FaxInteractionId\x20=\x20i.id','fax_interaction_has_tags','it.FaxInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch','sqlOperator','conditions','find','value','having','`\x20>\x200','operator','$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','start','end','Tag','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','text','body','isEmpty','FaxAccountId','concat','createdAt','parse','$gte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','replace','isNumeric','i.id\x20LIKE\x20?','i.fax\x20LIKE\x20?','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','i.id','Sequelize','QueryTypes','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages','contactName','t.id\x20IN\x20?','resolve','i.FaxAccountId\x20IS\x20NOT\x20NULL','user','role','agent','getFaxAccounts','i.FaxAccountId\x20IN\x20?','sequelize','toString','keyBy','a.key','a.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.*','c.firstName','Contact.firstName'];(function(_0xe1a964,_0x5ec09d){var _0x3de37b=function(_0x406ffc){while(--_0x406ffc){_0xe1a964['push'](_0xe1a964['shift']());}};_0x3de37b(++_0x5ec09d);}(_0xc2c1,0x1ed));var _0x1c2c=function(_0x24f022,_0x138a49){_0x24f022=_0x24f022-0x0;var _0x5a19f5=_0xc2c1[_0x24f022];return _0x5a19f5;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x1c2c('0x0'));var zipdir=require(_0x1c2c('0x1'));var jsonpatch=require(_0x1c2c('0x2'));var rp=require(_0x1c2c('0x3'));var moment=require(_0x1c2c('0x4'));var BPromise=require(_0x1c2c('0x5'));var Mustache=require('mustache');var util=require(_0x1c2c('0x6'));var path=require(_0x1c2c('0x7'));var sox=require(_0x1c2c('0x8'));var csv=require('to-csv');var ejs=require(_0x1c2c('0x9'));var fs=require('fs');var fs_extra=require(_0x1c2c('0xa'));var _=require(_0x1c2c('0xb'));var squel=require(_0x1c2c('0xc'));var crypto=require(_0x1c2c('0xd'));var jsforce=require(_0x1c2c('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x1c2c('0xf'));var querystring=require(_0x1c2c('0x10'));var Papa=require(_0x1c2c('0x11'));var Redis=require(_0x1c2c('0x12'));var authService=require(_0x1c2c('0x13'));var qs=require(_0x1c2c('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x1c2c('0x15'));var logger=require(_0x1c2c('0x16'))(_0x1c2c('0x17'));var utils=require(_0x1c2c('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0x1c2c('0x19'));var db=require(_0x1c2c('0x1a'))['db'];config[_0x1c2c('0x1b')]=_[_0x1c2c('0x1c')](config[_0x1c2c('0x1b')],{'host':_0x1c2c('0x1d'),'port':0x18eb});var socket=require(_0x1c2c('0x1e'))(new Redis(config[_0x1c2c('0x1b')]));require('./faxInteraction.socket')['register'](socket);function respondWithStatusCode(_0x5b19f8,_0x3b67cb){_0x3b67cb=_0x3b67cb||0xcc;return function(_0x48d62a){if(_0x48d62a){return _0x5b19f8['sendStatus'](_0x3b67cb);}return _0x5b19f8[_0x1c2c('0x1f')](_0x3b67cb)['end']();};}function respondWithResult(_0x39f87,_0x3fe214){_0x3fe214=_0x3fe214||0xc8;return function(_0x589ffc){if(_0x589ffc){return _0x39f87[_0x1c2c('0x1f')](_0x3fe214)['json'](_0x589ffc);}};}function respondWithFilteredResult(_0x410e7b,_0x525beb){return function(_0x134235){if(_0x134235){var _0x4a979c=typeof _0x525beb['offset']===_0x1c2c('0x20')&&typeof _0x525beb['limit']==='undefined';var _0x551885=_0x134235[_0x1c2c('0x21')];var _0x31b226=_0x4a979c?0x0:_0x525beb['offset'];var _0x573415=_0x4a979c?_0x134235[_0x1c2c('0x21')]:_0x525beb[_0x1c2c('0x22')]+_0x525beb['limit'];var _0x1c28d6;if(_0x573415>=_0x551885){_0x573415=_0x551885;_0x1c28d6=0xc8;}else{_0x1c28d6=0xce;}_0x410e7b['status'](_0x1c28d6);return _0x410e7b['set']('Content-Range',_0x31b226+'-'+_0x573415+'/'+_0x551885)[_0x1c2c('0x23')](_0x134235);}return null;};}function patchUpdates(_0x17580c){return function(_0x26aa1b){try{jsonpatch['apply'](_0x26aa1b,_0x17580c,!![]);}catch(_0x1e28a5){return BPromise[_0x1c2c('0x24')](_0x1e28a5);}return _0x26aa1b['save']();};}function saveUpdates(_0x3d1a7d,_0x2a3c0f){return function(_0x244fe6){if(_0x244fe6){return _0x244fe6['update'](_0x3d1a7d)[_0x1c2c('0x25')](function(_0x32ffca){return _0x32ffca;});}return null;};}function removeEntity(_0x319c0b,_0x2829bb){return function(_0x3ae0a9){if(_0x3ae0a9){return _0x3ae0a9['destroy']()[_0x1c2c('0x25')](function(){_0x319c0b[_0x1c2c('0x1f')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1f16e5,_0x5893be){return function(_0x19e466){if(!_0x19e466){_0x1f16e5[_0x1c2c('0x26')](0x194);}return _0x19e466;};}function handleError(_0x348fbc,_0x4846d4){_0x4846d4=_0x4846d4||0x1f4;return function(_0x419ad5){logger['error'](_0x419ad5[_0x1c2c('0x27')]);if(_0x419ad5[_0x1c2c('0x28')]){delete _0x419ad5[_0x1c2c('0x28')];}_0x348fbc['status'](_0x4846d4)['send'](_0x419ad5);};}function getInteractionUsers(_0x56bdb8,_0x57f940){return new BPromise(function(_0x2c536a,_0x28bca1){try{if(_0x57f940[_0x56bdb8['id']]){_0x56bdb8[_0x1c2c('0x29')]=_['map'](_0x57f940[_0x56bdb8['id']],function(_0x160a80){return{'id':_0x160a80['id'],'fullname':_0x160a80[_0x1c2c('0x2a')]};});}}catch(_0x257327){_0x28bca1(_0x257327);}_0x2c536a(_0x56bdb8);});}function getInteractionTags(_0x4dbae5,_0x4b2998){return new BPromise(function(_0x4b9fad,_0x19d729){try{if(_0x4dbae5['TagIds']){_0x4dbae5['Tags']=[];_0x4dbae5[_0x1c2c('0x2b')][_0x1c2c('0x2c')](',')[_0x1c2c('0x2d')](function(_0x48b8fd){_0x4dbae5[_0x1c2c('0x2e')][_0x1c2c('0x2f')](_0x4b2998[_0x48b8fd]);});}delete _0x4dbae5[_0x1c2c('0x2b')];}catch(_0x5a9b0b){_0x19d729(_0x5a9b0b);}_0x4b9fad(_0x4dbae5);});}function updateFaxInteraction(_0x20de2e,_0xcbda94,_0x3f6b5d){return new BPromise(function(_0x598141,_0x3c3fa5){return getInteractionUsers(_0x20de2e,_0x3f6b5d)[_0x1c2c('0x25')](function(_0x443c4e){return getInteractionTags(_0x443c4e,_0xcbda94);})[_0x1c2c('0x25')](function(_0x8b5fc8){return getStateInteraction(_0x8b5fc8);})[_0x1c2c('0x25')](function(_0x317979){_0x598141(_0x317979);})[_0x1c2c('0x30')](function(_0x21e5a){_0x3c3fa5(_0x21e5a);});});}function getStateInteraction(_0x2a53f1){return new BPromise(function(_0x8e144e){_0x2a53f1[_0x1c2c('0x31')]=0x0;_0x2a53f1['talking']=0x0;_0x2a53f1[_0x1c2c('0x32')]=0x0;_0x2a53f1['unmanaged']=0x0;_0x2a53f1[_0x1c2c('0x33')]=0x0;if(!_0x2a53f1[_0x1c2c('0x34')]&&!_0x2a53f1['UserId']){_0x2a53f1[_0x1c2c('0x31')]+=0x1;}if(!_0x2a53f1['closed']&&_0x2a53f1[_0x1c2c('0x35')]){_0x2a53f1[_0x1c2c('0x36')]+=0x1;if(_0x2a53f1[_0x1c2c('0x31')]){_0x2a53f1[_0x1c2c('0x31')]-=0x1;}}if(_0x2a53f1['closed']&&_0x2a53f1[_0x1c2c('0x35')]){_0x2a53f1[_0x1c2c('0x32')]+=0x1;if(_0x2a53f1[_0x1c2c('0x36')]){_0x2a53f1[_0x1c2c('0x36')]-=0x1;}}if(_0x2a53f1['closed']&&!_0x2a53f1['UserId']){_0x2a53f1[_0x1c2c('0x37')]+=0x1;if(_0x2a53f1['waiting']){_0x2a53f1[_0x1c2c('0x31')]-=0x1;}}_0x2a53f1[_0x1c2c('0x33')]+=0x1;_0x8e144e(_0x2a53f1);});}exports['index']=function(_0x4272ad,_0x4797b4){var _0x3044d7={},_0xa80ec1={},_0x251071={'count':0x0,'rows':[]};var _0x200367=_[_0x1c2c('0x38')](db[_0x1c2c('0x39')][_0x1c2c('0x3a')],function(_0x1e132b){return{'name':_0x1e132b[_0x1c2c('0x3b')],'type':_0x1e132b[_0x1c2c('0x3c')][_0x1c2c('0x3d')]};});_0xa80ec1[_0x1c2c('0x3e')]=_[_0x1c2c('0x38')](_0x200367,_0x1c2c('0x28'));_0xa80ec1[_0x1c2c('0x3f')]=_[_0x1c2c('0x40')](_0x4272ad[_0x1c2c('0x3f')]);_0xa80ec1[_0x1c2c('0x41')]=_[_0x1c2c('0x42')](_0xa80ec1[_0x1c2c('0x3e')],_0xa80ec1[_0x1c2c('0x3f')]);_0x3044d7[_0x1c2c('0x43')]=_[_0x1c2c('0x42')](_0xa80ec1[_0x1c2c('0x3e')],qs['fields'](_0x4272ad[_0x1c2c('0x3f')][_0x1c2c('0x44')]));_0x3044d7['attributes']=_0x3044d7[_0x1c2c('0x43')][_0x1c2c('0x45')]?_0x3044d7[_0x1c2c('0x43')]:_0xa80ec1[_0x1c2c('0x3e')];if(!_0x4272ad['query'][_0x1c2c('0x46')]('nolimit')){_0x3044d7['limit']=qs[_0x1c2c('0x47')](_0x4272ad[_0x1c2c('0x3f')][_0x1c2c('0x47')]);_0x3044d7[_0x1c2c('0x22')]=qs['offset'](_0x4272ad[_0x1c2c('0x3f')]['offset']);}_0x3044d7[_0x1c2c('0x48')]=qs[_0x1c2c('0x49')](_0x4272ad[_0x1c2c('0x3f')][_0x1c2c('0x49')]);_0x3044d7[_0x1c2c('0x4a')]=qs[_0x1c2c('0x41')](_[_0x1c2c('0x4b')](_0x4272ad[_0x1c2c('0x3f')],_0xa80ec1[_0x1c2c('0x41')]),_0x200367);var _0x4eefae=[];var _0x51e104=squel[_0x1c2c('0x4c')]()[_0x1c2c('0x4d')]('id')[_0x1c2c('0x4d')](_0x1c2c('0x28'))['field'](_0x1c2c('0x4e'))[_0x1c2c('0x4f')](_0x1c2c('0x50'));var _0x4057fc=squel['select']()[_0x1c2c('0x4d')](_0x1c2c('0x51'))[_0x1c2c('0x4d')](_0x1c2c('0x52'))[_0x1c2c('0x4d')]('ui.FaxInteractionId')[_0x1c2c('0x4f')]('user_has_fax_interactions','ui')[_0x1c2c('0x53')](_0x1c2c('0x54'),'u',_0x1c2c('0x55'));var _0x58826f=squel[_0x1c2c('0x4c')]()[_0x1c2c('0x4f')](_0x1c2c('0x56'),'i')[_0x1c2c('0x53')](_0x1c2c('0x57'),'c',_0x1c2c('0x58'))[_0x1c2c('0x53')](_0x1c2c('0x54'),'o','o.id\x20=\x20i.UserId')[_0x1c2c('0x53')]('fax_accounts','a',_0x1c2c('0x59'))['left_join'](_0x1c2c('0x5a'),'me',_0x1c2c('0x5b'))['left_join'](_0x1c2c('0x5c'),'it',_0x1c2c('0x5d'))['left_join']('tools_tags','t',_0x1c2c('0x5e'));var _0x47c9d5=squel['expr']();var _0x2bee86=[];var _0x673d7f=squel[_0x1c2c('0x5f')]();var _0x345406;if(_0x4272ad[_0x1c2c('0x3f')][_0x1c2c('0x60')]){_0x345406=as[_0x1c2c('0x61')](_0x4272ad[_0x1c2c('0x3f')][_0x1c2c('0x60')]);var _0x16a207=_0x345406[_0x1c2c('0x62')];for(var _0x40f9da=0x0;_0x40f9da<_0x345406[_0x1c2c('0x63')][_0x1c2c('0x45')];_0x40f9da++){var _0x1aac27=_0x345406[_0x1c2c('0x63')][_0x40f9da];var _0x43605c='i';var _0x36e71b=_[_0x1c2c('0x64')](_0x200367,[_0x1c2c('0x28'),_0x1aac27[_0x1c2c('0x4d')]]);if(!_0x36e71b){switch(_0x1aac27[_0x1c2c('0x4d')]){case'unreadMessages':if(_0x1aac27[_0x1c2c('0x65')]==0x1){_0x58826f[_0x1c2c('0x66')]('`'+_0x1aac27[_0x1c2c('0x4d')]+'`\x20=\x200');}else{_0x58826f['having']('`'+_0x1aac27['field']+_0x1c2c('0x67'));}break;case'Contact':if(_0x1aac27[_0x1c2c('0x68')]===_0x1c2c('0x69')){if(_0x1aac27[_0x1c2c('0x65')][_0x1c2c('0x2c')]('\x20')[_0x1c2c('0x45')]>0x1){_0x47c9d5[_0x16a207](_0x1c2c('0x6a'),qs['getFullTextValue'](_0x1aac27[_0x1c2c('0x65')]),null);}else{var _0x5a1075='%'+_0x1aac27[_0x1c2c('0x65')]+'%';_0x47c9d5[_0x16a207](_0x1c2c('0x6b'),_0x5a1075,_0x5a1075,_0x5a1075);}}else{_0x36e71b=_['find'](_0x200367,[_0x1c2c('0x28'),_0x1c2c('0x6c')]);_0x1aac27[_0x1c2c('0x4d')]=_0x1c2c('0x6c');_0x599a2b=as[_0x1c2c('0x6d')](_0x43605c,_0x36e71b['type'],_0x1aac27);_0x47c9d5[_0x16a207](_0x599a2b['text'],_0x599a2b[_0x1c2c('0x65')][_0x1c2c('0x6e')],_0x599a2b[_0x1c2c('0x65')][_0x1c2c('0x6f')]);}break;case _0x1c2c('0x70'):var _0x2121d1=_0x1aac27[_0x1c2c('0x65')]['split'](',')[_0x1c2c('0x38')](function(_0x690816){return Number(_0x690816);});_0x2121d1[_0x1c2c('0x2d')](function(_0x476060){_0x673d7f['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x476060+',%');});_0x2bee86=_[_0x1c2c('0x71')](_0x2bee86,_0x2121d1);break;case _0x1c2c('0x72'):if(_0x1aac27['operator']===_0x1c2c('0x69')){_0x47c9d5[_0x16a207](_0x1c2c('0x73'),'%'+_0x1aac27[_0x1c2c('0x65')]+'%',null);}else{_0x36e71b=_[_0x1c2c('0x64')](_0x200367,[_0x1c2c('0x28'),_0x1c2c('0x35')]);_0x1aac27[_0x1c2c('0x4d')]=_0x1c2c('0x35');_0x599a2b=as[_0x1c2c('0x6d')](_0x43605c,_0x36e71b['type'],_0x1aac27);_0x47c9d5[_0x16a207](_0x599a2b[_0x1c2c('0x74')],_0x599a2b['value'][_0x1c2c('0x6e')],_0x599a2b[_0x1c2c('0x65')][_0x1c2c('0x6f')]);}break;case _0x1c2c('0x75'):_0x599a2b=as['buildExpression']('me',null,_0x1aac27);_0x47c9d5[_0x16a207](_0x599a2b[_0x1c2c('0x74')],_0x599a2b[_0x1c2c('0x65')]['start'],_0x599a2b['value'][_0x1c2c('0x6f')]);break;}}else{var _0x599a2b=as['buildExpression'](_0x43605c,_0x36e71b[_0x1c2c('0x3c')],_0x1aac27);_0x47c9d5[_0x16a207](_0x599a2b['text'],_0x599a2b[_0x1c2c('0x65')]['start'],_0x599a2b[_0x1c2c('0x65')]['end']);}}}else{var _0x5e4808=_(_0x4272ad['query'])[_0x1c2c('0x40')]()['map'](function(_0x44c638){return _['some'](_0x200367,[_0x1c2c('0x28'),_0x44c638])?_0x44c638:undefined;})['compact']()[_0x1c2c('0x65')]();if(!_[_0x1c2c('0x76')](_0x5e4808)){_0x5e4808[_0x1c2c('0x2d')](function(_0x81a585){if(_0x81a585===_0x1c2c('0x77')){_0x58826f[_0x1c2c('0x4a')]('i.FaxAccountId\x20IN\x20?',[][_0x1c2c('0x78')](_0x4272ad[_0x1c2c('0x3f')][_0x81a585]));}else if(_0x81a585===_0x1c2c('0x79')){var _0x5bf5ce=JSON[_0x1c2c('0x7a')](_0x4272ad[_0x1c2c('0x3f')][_0x81a585])[_0x1c2c('0x7b')];var _0x34f03b=JSON[_0x1c2c('0x7a')](_0x4272ad[_0x1c2c('0x3f')][_0x81a585])['$lte'];_0x58826f[_0x1c2c('0x4a')](_0x1c2c('0x7c'),_0x5bf5ce,_0x34f03b);}else{if(_0x4272ad[_0x1c2c('0x3f')][_0x81a585]==='null'){_0x58826f[_0x1c2c('0x4a')]('i.'+_0x81a585+_0x1c2c('0x7d'));}else{_0x58826f[_0x1c2c('0x4a')]('i.'+_0x81a585+_0x1c2c('0x7e'),_0x4272ad[_0x1c2c('0x3f')][_0x81a585]);}}});}if(_0x4272ad[_0x1c2c('0x3f')][_0x1c2c('0x7f')]){if(_0x4272ad[_0x1c2c('0x3f')][_0x1c2c('0x7f')]==0x1){_0x58826f[_0x1c2c('0x66')](_0x1c2c('0x80'));}else{_0x58826f[_0x1c2c('0x66')](_0x1c2c('0x81'));}}if(_0x4272ad[_0x1c2c('0x3f')][_0x1c2c('0x82')]){_0x2bee86=_['isArray'](_0x4272ad[_0x1c2c('0x3f')][_0x1c2c('0x82')])?_0x4272ad[_0x1c2c('0x3f')][_0x1c2c('0x82')]:new Array(_0x4272ad['query'][_0x1c2c('0x82')]);_0x2bee86[_0x1c2c('0x2d')](function(_0xed1bb5){_0x673d7f['or'](_0x1c2c('0x83'),'%,'+_0xed1bb5+',%');});}if(_0x4272ad[_0x1c2c('0x3f')]['filter']){var _0x2f059e=_0x4272ad[_0x1c2c('0x3f')]['filter'][_0x1c2c('0x84')]('\x5c','\x5c\x5c')[_0x1c2c('0x84')](/'/g,'\x27\x27');if(qs[_0x1c2c('0x85')](_0x2f059e)){_0x47c9d5['or'](_0x1c2c('0x86'),_0x2f059e+'%')['or'](_0x1c2c('0x87'),_0x2f059e+'%');}_0x47c9d5['or'](_0x1c2c('0x88'),_0x2f059e+'%');}}_0x58826f[_0x1c2c('0x4a')](_0x47c9d5);_0x58826f['group'](_0x1c2c('0x89'));var _0x37b5d1={'type':db[_0x1c2c('0x8a')][_0x1c2c('0x8b')]['SELECT'],'raw':!![]};var _0x4077e5=_0x58826f[_0x1c2c('0x8c')]();_0x4077e5[_0x1c2c('0x4d')](_0x1c2c('0x89'));_0x4077e5[_0x1c2c('0x4d')](_0x1c2c('0x8d'),_0x1c2c('0x8e'));if(_0x3044d7[_0x1c2c('0x48')]){_0x3044d7[_0x1c2c('0x48')]['forEach'](function(_0x2657fa){var _0x108f0e=_0x2657fa[0x0]===_0x1c2c('0x8f')?_0x2657fa[0x0]:'i.'+_0x2657fa[0x0];_0x58826f[_0x1c2c('0x48')](_0x108f0e,_0x2657fa[0x1]==='DESC'?![]:!![]);});}if(!_['isEmpty'](_0x2bee86)){_0x58826f['having'](_0x673d7f);_0x4077e5[_0x1c2c('0x4a')](_0x1c2c('0x90'),_0x2bee86);}BPromise[_0x1c2c('0x91')]()[_0x1c2c('0x25')](function(){if(!_0x345406){if(_0x4272ad[_0x1c2c('0x3f')][_0x1c2c('0x77')])return;_0x4077e5[_0x1c2c('0x4a')]('i.FaxAccountId\x20IS\x20NOT\x20NULL');_0x58826f[_0x1c2c('0x4a')](_0x1c2c('0x92'));return;}if(_0x4272ad[_0x1c2c('0x93')][_0x1c2c('0x94')]!==_0x1c2c('0x95'))return;return _0x4272ad[_0x1c2c('0x93')][_0x1c2c('0x96')]({'attributes':['id'],'raw':!![]})[_0x1c2c('0x25')](function(_0xa420d9){if(_[_0x1c2c('0x76')](_0xa420d9)){_0x4077e5['where']('i.FaxAccountId\x20IS\x20NULL');_0x58826f['where']('i.FaxAccountId\x20IS\x20NULL');}else{_0x4077e5[_0x1c2c('0x4a')](_0x1c2c('0x97'),_[_0x1c2c('0x38')](_0xa420d9,'id'));_0x58826f[_0x1c2c('0x4a')](_0x1c2c('0x97'),_[_0x1c2c('0x38')](_0xa420d9,'id'));}});})[_0x1c2c('0x25')](function(){if(_0x4272ad[_0x1c2c('0x93')][_0x1c2c('0x94')]==='agent'&&!_0x345406&&!_0x4272ad[_0x1c2c('0x3f')][_0x1c2c('0x77')])return[];return db[_0x1c2c('0x98')][_0x1c2c('0x3f')](_0x4077e5[_0x1c2c('0x99')](),_0x37b5d1);})[_0x1c2c('0x25')](function(_0x1c3367){_0x251071[_0x1c2c('0x21')]=_0x1c3367[_0x1c2c('0x45')];if(_0x251071[_0x1c2c('0x21')]===0x0)return[];return db['sequelize'][_0x1c2c('0x3f')](_0x51e104[_0x1c2c('0x99')](),_0x37b5d1)[_0x1c2c('0x25')](function(_0x2f0bcc){_0x4eefae=_[_0x1c2c('0x9a')](_0x2f0bcc,'id');_0x37b5d1=_['merge'](_0x37b5d1,{'model':db[_0x1c2c('0x39')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x4272ad[_0x1c2c('0x3f')][_0x1c2c('0x44')]){_0x3044d7[_0x1c2c('0x43')][_0x1c2c('0x2d')](function(_0x1d49df){_0x58826f['field']('i.'+_0x1d49df);});}else{_0x58826f['field'](_0x1c2c('0x8d'),_0x1c2c('0x8e'));_0x58826f[_0x1c2c('0x4d')](_0x1c2c('0x9b'),'Account.key');_0x58826f[_0x1c2c('0x4d')](_0x1c2c('0x9c'),'Account.mandatoryDisposition');_0x58826f[_0x1c2c('0x4d')](_0x1c2c('0x9d'),'contactName');_0x58826f[_0x1c2c('0x4d')](_0x1c2c('0x9e'));_0x58826f['field'](_0x1c2c('0x9f'),_0x1c2c('0xa0'));_0x58826f['field'](_0x1c2c('0xa1'),_0x1c2c('0xa2'));_0x58826f[_0x1c2c('0x4d')](_0x1c2c('0xa3'),_0x1c2c('0xa4'));_0x58826f[_0x1c2c('0x4d')](_0x1c2c('0xa5'),_0x1c2c('0xa6'));_0x58826f[_0x1c2c('0x4d')](_0x1c2c('0xa7'),_0x1c2c('0xa8'));_0x58826f[_0x1c2c('0x4d')](_0x1c2c('0xa9'),_0x1c2c('0xaa'));_0x58826f[_0x1c2c('0x4d')](_0x1c2c('0xab'),_0x1c2c('0xac'));_0x58826f[_0x1c2c('0x4d')]('o.internal',_0x1c2c('0xad'));_0x58826f[_0x1c2c('0x4d')]('GROUP_CONCAT(DISTINCT\x20t.id)','TagIds');}if(_0x3044d7[_0x1c2c('0x47')])_0x58826f[_0x1c2c('0x47')](_0x3044d7[_0x1c2c('0x47')]);if(_0x3044d7['offset'])_0x58826f[_0x1c2c('0x22')](_0x3044d7['offset']);return db[_0x1c2c('0x98')]['query'](_0x58826f[_0x1c2c('0x99')](),_0x37b5d1);})[_0x1c2c('0x25')](function(_0x215804){if(_0x215804[_0x1c2c('0x45')]>0x0)_0x4057fc[_0x1c2c('0x4a')]('ui.FaxInteractionId\x20IN\x20?',_[_0x1c2c('0x38')](_0x215804,'id'));return db['sequelize'][_0x1c2c('0x3f')](_0x4057fc[_0x1c2c('0x99')](),_0x37b5d1)[_0x1c2c('0x25')](function(_0x4252da){var _0xff38ba=_[_0x1c2c('0xae')](_0x4252da,'FaxInteractionId');var _0x49d767=[];_0x215804[_0x1c2c('0x2d')](function(_0x447cd6){_0x49d767[_0x1c2c('0x2f')](updateFaxInteraction(_0x447cd6,_0x4eefae,_0xff38ba));});return BPromise[_0x1c2c('0xaf')](_0x49d767);});});})['then'](function(_0x438251){_0x251071['rows']=_0x438251;return _0x251071;})[_0x1c2c('0x25')](respondWithFilteredResult(_0x4797b4,_0x3044d7))[_0x1c2c('0x30')](handleError(_0x4797b4,null));};exports[_0x1c2c('0xb0')]=function(_0x2556a7,_0x451f62){var _0xe9009e={'raw':![],'where':{'id':_0x2556a7[_0x1c2c('0xb1')]['id']}},_0x1d08ce={};_0x1d08ce[_0x1c2c('0x3e')]=_['keys'](db[_0x1c2c('0x39')][_0x1c2c('0x3a')]);_0x1d08ce['query']=_['keys'](_0x2556a7['query']);_0x1d08ce[_0x1c2c('0x41')]=_[_0x1c2c('0x42')](_0x1d08ce['model'],_0x1d08ce['query']);_0xe9009e[_0x1c2c('0x43')]=_[_0x1c2c('0x42')](_0x1d08ce[_0x1c2c('0x3e')],qs[_0x1c2c('0x44')](_0x2556a7['query'][_0x1c2c('0x44')]));_0xe9009e[_0x1c2c('0x43')]=_0xe9009e[_0x1c2c('0x43')][_0x1c2c('0x45')]?_0xe9009e[_0x1c2c('0x43')]:_0x1d08ce[_0x1c2c('0x3e')];if(_0x2556a7[_0x1c2c('0x3f')][_0x1c2c('0xb2')]){_0xe9009e[_0x1c2c('0xb3')]=[{'all':!![]}];}_0xe9009e=_[_0x1c2c('0xb4')]({},_0xe9009e,_0x2556a7[_0x1c2c('0xb5')]);return db['FaxInteraction'][_0x1c2c('0x64')](_0xe9009e)[_0x1c2c('0x25')](handleEntityNotFound(_0x451f62,null))[_0x1c2c('0x25')](respondWithResult(_0x451f62,null))['catch'](handleError(_0x451f62,null));};exports[_0x1c2c('0xb6')]=function(_0x7de7c3,_0x627a32){return db['FaxInteraction'][_0x1c2c('0xb6')](_0x7de7c3[_0x1c2c('0x75')],{})[_0x1c2c('0x25')](respondWithResult(_0x627a32,0xc9))[_0x1c2c('0x30')](handleError(_0x627a32,null));};exports[_0x1c2c('0xb7')]=function(_0x3b7bd5,_0xb6a7b0){if(_0x3b7bd5[_0x1c2c('0x75')]['id']){delete _0x3b7bd5[_0x1c2c('0x75')]['id'];}return db[_0x1c2c('0x39')]['find']({'where':{'id':_0x3b7bd5[_0x1c2c('0xb1')]['id']}})[_0x1c2c('0x25')](handleEntityNotFound(_0xb6a7b0,null))['then'](saveUpdates(_0x3b7bd5['body'],null))['then'](respondWithResult(_0xb6a7b0,null))['catch'](handleError(_0xb6a7b0,null));};exports[_0x1c2c('0xb8')]=function(_0x6a0257,_0x5f5661){return db[_0x1c2c('0x39')]['find']({'where':{'id':_0x6a0257[_0x1c2c('0xb1')]['id']}})[_0x1c2c('0x25')](handleEntityNotFound(_0x5f5661,null))[_0x1c2c('0x25')](removeEntity(_0x5f5661,null))[_0x1c2c('0x30')](handleError(_0x5f5661,null));};exports[_0x1c2c('0xb9')]=function(_0x2ec06b,_0x301e48){return db[_0x1c2c('0x39')][_0x1c2c('0xb9')]()['then'](respondWithResult(_0x301e48,null))['catch'](handleError(_0x301e48,null));};exports[_0x1c2c('0xba')]=function(_0x48eac8,_0x473262,_0x1326ac){return db['FaxMessage'][_0x1c2c('0x64')]({'where':{'id':_0x48eac8[_0x1c2c('0xb1')]['id']}})[_0x1c2c('0x25')](handleEntityNotFound(_0x473262,null))['then'](function(_0x2c2bf7){if(_0x2c2bf7){return _0x2c2bf7[_0x1c2c('0xba')](_0x48eac8[_0x1c2c('0x75')]['ids'],_[_0x1c2c('0xbb')](_0x48eac8[_0x1c2c('0x75')],[_0x1c2c('0xbc'),'id'])||{});}})[_0x1c2c('0x25')](respondWithResult(_0x473262,null))[_0x1c2c('0x30')](handleError(_0x473262,null));};exports[_0x1c2c('0xbd')]=function(_0x497c70,_0x40c8f1,_0x29dded){var _0x4ed1e9={'raw':![],'where':{}};var _0x78a98c={};var _0x46fbe5={'count':0x0,'rows':[]};return db[_0x1c2c('0x39')]['findOne']({'where':{'id':_0x497c70[_0x1c2c('0xb1')]['id']}})['then'](handleEntityNotFound(_0x40c8f1,null))['then'](function(_0x55c21d){if(_0x55c21d){_0x78a98c[_0x1c2c('0x3e')]=_[_0x1c2c('0x40')](db[_0x1c2c('0xbe')][_0x1c2c('0x3a')]);_0x78a98c[_0x1c2c('0x3f')]=_[_0x1c2c('0x40')](_0x497c70[_0x1c2c('0x3f')]);_0x78a98c[_0x1c2c('0x41')]=_[_0x1c2c('0x42')](_0x78a98c[_0x1c2c('0x3e')],_0x78a98c[_0x1c2c('0x3f')]);_0x4ed1e9['attributes']=_['intersection'](_0x78a98c[_0x1c2c('0x3e')],qs[_0x1c2c('0x44')](_0x497c70[_0x1c2c('0x3f')][_0x1c2c('0x44')]));_0x4ed1e9[_0x1c2c('0x43')]=_0x4ed1e9[_0x1c2c('0x43')][_0x1c2c('0x45')]?_0x4ed1e9['attributes']:_0x78a98c['model'];if(!_0x497c70[_0x1c2c('0x3f')][_0x1c2c('0x46')](_0x1c2c('0xbf'))){_0x4ed1e9[_0x1c2c('0x47')]=qs['limit'](_0x497c70[_0x1c2c('0x3f')][_0x1c2c('0x47')]);_0x4ed1e9[_0x1c2c('0x22')]=qs['offset'](_0x497c70[_0x1c2c('0x3f')][_0x1c2c('0x22')]);}_0x4ed1e9[_0x1c2c('0x48')]=qs['sort'](_0x497c70['query'][_0x1c2c('0x49')]);_0x4ed1e9[_0x1c2c('0x4a')]=qs[_0x1c2c('0x41')](_[_0x1c2c('0x4b')](_0x497c70['query'],_0x78a98c[_0x1c2c('0x41')]));_0x4ed1e9['where'][_0x1c2c('0xc0')]=_0x55c21d['id'];if(_0x497c70[_0x1c2c('0x3f')][_0x1c2c('0xc1')]){_0x4ed1e9[_0x1c2c('0x4a')]=_['merge'](_0x4ed1e9[_0x1c2c('0x4a')],{'$or':_[_0x1c2c('0x38')](_0x4ed1e9['attributes'],function(_0x1a74b2){var _0x2bd2aa={};_0x2bd2aa[_0x1a74b2]={'$like':'%'+_0x497c70[_0x1c2c('0x3f')]['filter']+'%'};return _0x2bd2aa;})});}if(_0x497c70[_0x1c2c('0x3f')]['$gte']){var _0x287cac=_0x497c70[_0x1c2c('0x3f')]['$gte'][_0x1c2c('0x2c')](',');var _0x2b3721={};_0x2b3721[_0x287cac[0x0]]={'$gte':moment(_0x287cac[0x1])[_0x1c2c('0xc2')](_0x1c2c('0xc3'))};_0x4ed1e9[_0x1c2c('0x4a')]=_['merge'](_0x4ed1e9[_0x1c2c('0x4a')],_0x2b3721);}_0x4ed1e9=_['merge']({},_0x4ed1e9,_0x497c70['options']);return db[_0x1c2c('0xbe')][_0x1c2c('0x21')]({'where':_0x4ed1e9[_0x1c2c('0x4a')]})[_0x1c2c('0x25')](function(_0x29541b){_0x46fbe5[_0x1c2c('0x21')]=_0x29541b;if(_0x497c70[_0x1c2c('0x3f')][_0x1c2c('0xb2')]){_0x4ed1e9['include']=[{'all':!![]}];}return db[_0x1c2c('0xbe')][_0x1c2c('0xc4')](_0x4ed1e9);})[_0x1c2c('0x25')](function(_0x58b9fc){_0x46fbe5[_0x1c2c('0xc5')]=_0x58b9fc;return _0x46fbe5;});}})[_0x1c2c('0x25')](respondWithFilteredResult(_0x40c8f1,_0x4ed1e9))[_0x1c2c('0x30')](handleError(_0x40c8f1,null));};exports[_0x1c2c('0xc6')]=function(_0x213bad,_0x2be4c1,_0xe44055){return db['FaxInteraction'][_0x1c2c('0x64')]({'where':{'id':_0x213bad[_0x1c2c('0xb1')]['id']}})[_0x1c2c('0x25')](handleEntityNotFound(_0x2be4c1,null))[_0x1c2c('0x25')](function(_0xcf7edf){if(_0xcf7edf){return _0xcf7edf[_0x1c2c('0xc7')](_0x213bad[_0x1c2c('0x75')][_0x1c2c('0xbc')],_[_0x1c2c('0xbb')](_0x213bad[_0x1c2c('0x75')],[_0x1c2c('0xbc'),'id'])||{})[_0x1c2c('0xc8')](function(){return db['Tag'][_0x1c2c('0xc4')]({'attributes':['id','name',_0x1c2c('0x4e')],'where':{'id':_0x213bad['body'][_0x1c2c('0xbc')]}});})[_0x1c2c('0x25')](function(_0x137320){socket['emit'](_0x1c2c('0xc9'),{'id':Number(_0x213bad['params']['id']),'tags':_0x137320||[]});return{'id':Number(_0x213bad[_0x1c2c('0xb1')]['id']),'tags':_0x137320||[]};});}})['then'](respondWithResult(_0x2be4c1,null))['catch'](handleError(_0x2be4c1,null));};exports[_0x1c2c('0xca')]=function(_0x2a5717,_0x355a52,_0x48a810){return db[_0x1c2c('0x39')]['find']({'where':{'id':_0x2a5717[_0x1c2c('0xb1')]['id']}})['then'](handleEntityNotFound(_0x355a52,null))['then'](function(_0x293674){if(_0x293674){return _0x293674['removeTags'](_0x2a5717[_0x1c2c('0x3f')]['ids']);}})['then'](respondWithStatusCode(_0x355a52,null))[_0x1c2c('0x30')](handleError(_0x355a52,null));};exports['download']=function(_0x326dc0,_0x21b066){var _0x928cf7=moment()[_0x1c2c('0xcb')]()[_0x1c2c('0x99')]();var _0x3030ca=path['join'](config['root'],'server',_0x1c2c('0xcc'),'tmp');var _0x1cd09c=path[_0x1c2c('0xcd')](config[_0x1c2c('0xce')],_0x1c2c('0xcf'),_0x1c2c('0xcc'),_0x1c2c('0xd0'));var _0x4663a6=path['join'](_0x3030ca,_0x928cf7);var _0x555412=util[_0x1c2c('0xc2')](_0x1c2c('0xd1'),_0x326dc0['params']['id'],_0x928cf7);var _0x3f40b0=path['join'](_0x3030ca,_0x555412);var _0x3c110f=[];_0x3c110f[_0x1c2c('0x2f')]({'model':db['Attachment'],'as':_0x1c2c('0xd2'),'raw':!![]});var _0x2a7c37=[{'model':db['FaxMessage'],'as':_0x1c2c('0xd3'),'attributes':['id',_0x1c2c('0x75'),_0x1c2c('0x79')],'include':_0x3c110f}];return db['FaxInteraction'][_0x1c2c('0x64')]({'where':{'id':_0x326dc0[_0x1c2c('0xb1')]['id']},'include':_0x2a7c37})[_0x1c2c('0x25')](handleEntityNotFound(_0x21b066,null))['then'](function(_0x564427){if(_0x564427&&_0x564427[_0x1c2c('0xd3')]){var _0x3458cb=_0x564427['get']({'plain':!![]});fs['mkdirSync'](_0x4663a6);for(var _0x2f4461=0x0;_0x2f4461<_0x3458cb[_0x1c2c('0xd3')][_0x1c2c('0x45')];_0x2f4461++){var _0x113f7d=_0x3458cb[_0x1c2c('0xd3')][_0x2f4461]['Attachment'];if(_0x113f7d){var _0x523785=path['join'](_0x1cd09c,_0x113f7d[_0x1c2c('0xd4')]);if(fs[_0x1c2c('0xd5')](_0x523785)){fs[_0x1c2c('0xd6')](_0x523785)['pipe'](fs['createWriteStream'](path['join'](_0x4663a6,_0x113f7d[_0x1c2c('0xd4')])));}}}return BPromise[_0x1c2c('0x91')]()[_0x1c2c('0x25')](function(){return new BPromise(function(_0x1e7d82,_0x177fb8){zipdir(_0x4663a6,{'saveTo':_0x3f40b0},function(_0x349599,_0x53487b){if(_0x349599)return _0x177fb8(_0x349599);return _0x1e7d82(_0x53487b);});})[_0x1c2c('0x25')](function(){return new BPromise(function(_0x278064,_0x76299){rimraf(_0x4663a6,function(_0x1fdbe3){if(_0x1fdbe3)_0x76299(_0x1fdbe3);return _0x278064();});});})[_0x1c2c('0x25')](function(){return _0x21b066['download'](_0x3f40b0,_0x555412,function(_0x203ede){if(_0x203ede){console[_0x1c2c('0xd7')](_0x1c2c('0xd8'),_0x203ede);}else{fs[_0x1c2c('0xd9')](_0x3f40b0);}});});});}else{return _0x21b066[_0x1c2c('0x26')](0xc8);}})[_0x1c2c('0x30')](handleError(_0x21b066,null));};
\ No newline at end of file