Built motion from commit 9d7072cc.|2.5.39
[motion2.git] / server / api / faxInteraction / faxInteraction.controller.js
index 7663a15..87642ce 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-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
+var _0x19dd=['querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./faxInteraction.socket','register','sendStatus','status','end','json','undefined','limit','count','offset','apply','then','destroy','error','stack','name','send','Users','map','TagIds','split','forEach','Tags','push','catch','waiting','talking','answered','unmanaged','total','closed','UserId','index','FaxInteraction','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','field','color','from','tools_tags','u.fullname','ui.FaxInteractionId','user_has_fax_interactions','users','u.id\x20=\x20ui.UserId','select','left_join','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','fax_accounts','a.id\x20=\x20i.FaxAccountId','fax_messages','me.FaxInteractionId\x20=\x20i.id','it.FaxInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch','conditions','length','find','unreadMessages','value','`\x20=\x200','having','`\x20>\x200','Contact','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','text','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','buildExpression','body','start','keys','some','compact','FaxAccountId','i.FaxAccountId\x20IN\x20?','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','filter','replace','isNumeric','i.fax\x20LIKE\x20?','group','Sequelize','QueryTypes','clone','i.id','order','DESC','isEmpty','t.id\x20IN\x20?','resolve','i.FaxAccountId\x20IS\x20NOT\x20NULL','user','agent','getFaxAccounts','i.FaxAccountId\x20IS\x20NULL','role','sequelize','toString','keyBy','merge','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','a.key','Account.key','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','contactName','i.*','c.firstName','c.lastName','Contact.lastName','Contact.email','c.mobile','Contact.mobile','c.fax','Owner.fullname','o.internal','ui.FaxInteractionId\x20IN\x20?','groupBy','FaxInteractionId','all','rows','params','include','options','create','describe','addMessage','FaxMessage','ids','omit','getMessages','findOne','pick','YYYY-MM-DD\x20HH:mm:ss','includeAll','addTags','setTags','spread','emit','faxInteractionTags:save','removeTags','download','unix','join','root','server','files','attachments','format','transcript-%d-%s.zip','Attachment','mkdirSync','Messages','basename','existsSync','createReadStream','pipe','createWriteStream','log','err','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','squel','crypto','jsforce','desk.js'];(function(_0xb19ed3,_0x3c4efb){var _0x4bc52c=function(_0x42aa64){while(--_0x42aa64){_0xb19ed3['push'](_0xb19ed3['shift']());}};_0x4bc52c(++_0x3c4efb);}(_0x19dd,0x1b2));var _0xd19d=function(_0x488fc8,_0x37db11){_0x488fc8=_0x488fc8-0x0;var _0x5994dd=_0x19dd[_0x488fc8];return _0x5994dd;};'use strict';var emlformat=require(_0xd19d('0x0'));var rimraf=require(_0xd19d('0x1'));var zipdir=require(_0xd19d('0x2'));var jsonpatch=require(_0xd19d('0x3'));var rp=require(_0xd19d('0x4'));var moment=require(_0xd19d('0x5'));var BPromise=require(_0xd19d('0x6'));var Mustache=require(_0xd19d('0x7'));var util=require(_0xd19d('0x8'));var path=require(_0xd19d('0x9'));var sox=require(_0xd19d('0xa'));var csv=require('to-csv');var ejs=require(_0xd19d('0xb'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0xd19d('0xc'));var crypto=require(_0xd19d('0xd'));var jsforce=require(_0xd19d('0xe'));var deskjs=require(_0xd19d('0xf'));var toCsv=require('to-csv');var querystring=require(_0xd19d('0x10'));var Papa=require(_0xd19d('0x11'));var Redis=require(_0xd19d('0x12'));var authService=require('../../components/auth/service');var qs=require(_0xd19d('0x13'));var as=require(_0xd19d('0x14'));var hardwareService=require(_0xd19d('0x15'));var logger=require(_0xd19d('0x16'))(_0xd19d('0x17'));var utils=require(_0xd19d('0x18'));var config=require(_0xd19d('0x19'));var licenseUtil=require(_0xd19d('0x1a'));var db=require(_0xd19d('0x1b'))['db'];config[_0xd19d('0x1c')]=_['defaults'](config[_0xd19d('0x1c')],{'host':_0xd19d('0x1d'),'port':0x18eb});var socket=require(_0xd19d('0x1e'))(new Redis(config[_0xd19d('0x1c')]));require(_0xd19d('0x1f'))[_0xd19d('0x20')](socket);function respondWithStatusCode(_0x29342a,_0x17da91){_0x17da91=_0x17da91||0xcc;return function(_0x46d576){if(_0x46d576){return _0x29342a[_0xd19d('0x21')](_0x17da91);}return _0x29342a[_0xd19d('0x22')](_0x17da91)[_0xd19d('0x23')]();};}function respondWithResult(_0x3e1135,_0x21076e){_0x21076e=_0x21076e||0xc8;return function(_0x407b21){if(_0x407b21){return _0x3e1135['status'](_0x21076e)[_0xd19d('0x24')](_0x407b21);}};}function respondWithFilteredResult(_0xd3fe43,_0x8211ca){return function(_0x4a055b){if(_0x4a055b){var _0x5a2b49=typeof _0x8211ca['offset']===_0xd19d('0x25')&&typeof _0x8211ca[_0xd19d('0x26')]===_0xd19d('0x25');var _0x535df8=_0x4a055b[_0xd19d('0x27')];var _0x683fbb=_0x5a2b49?0x0:_0x8211ca[_0xd19d('0x28')];var _0x41d790=_0x5a2b49?_0x4a055b[_0xd19d('0x27')]:_0x8211ca[_0xd19d('0x28')]+_0x8211ca['limit'];var _0x193928;if(_0x41d790>=_0x535df8){_0x41d790=_0x535df8;_0x193928=0xc8;}else{_0x193928=0xce;}_0xd3fe43[_0xd19d('0x22')](_0x193928);return _0xd3fe43['set']('Content-Range',_0x683fbb+'-'+_0x41d790+'/'+_0x535df8)[_0xd19d('0x24')](_0x4a055b);}return null;};}function patchUpdates(_0x5eb466){return function(_0xbc04f8){try{jsonpatch[_0xd19d('0x29')](_0xbc04f8,_0x5eb466,!![]);}catch(_0x11436f){return BPromise['reject'](_0x11436f);}return _0xbc04f8['save']();};}function saveUpdates(_0x42d7bf,_0x15d7ab){return function(_0x5a4345){if(_0x5a4345){return _0x5a4345['update'](_0x42d7bf)[_0xd19d('0x2a')](function(_0x4f75fd){return _0x4f75fd;});}return null;};}function removeEntity(_0x8d2c84,_0x5bb466){return function(_0x2183af){if(_0x2183af){return _0x2183af[_0xd19d('0x2b')]()[_0xd19d('0x2a')](function(){_0x8d2c84[_0xd19d('0x22')](0xcc)[_0xd19d('0x23')]();});}};}function handleEntityNotFound(_0x235eb8,_0x3e25df){return function(_0x2b06fe){if(!_0x2b06fe){_0x235eb8[_0xd19d('0x21')](0x194);}return _0x2b06fe;};}function handleError(_0x46cfdf,_0x231698){_0x231698=_0x231698||0x1f4;return function(_0x97e338){logger[_0xd19d('0x2c')](_0x97e338[_0xd19d('0x2d')]);if(_0x97e338[_0xd19d('0x2e')]){delete _0x97e338['name'];}_0x46cfdf[_0xd19d('0x22')](_0x231698)[_0xd19d('0x2f')](_0x97e338);};}function getInteractionUsers(_0x358ae6,_0x3ba5d6){return new BPromise(function(_0x3d3461,_0x567f87){try{if(_0x3ba5d6[_0x358ae6['id']]){_0x358ae6[_0xd19d('0x30')]=_[_0xd19d('0x31')](_0x3ba5d6[_0x358ae6['id']],function(_0x378fd4){return{'id':_0x378fd4['id'],'fullname':_0x378fd4['fullname']};});}}catch(_0x4703b3){_0x567f87(_0x4703b3);}_0x3d3461(_0x358ae6);});}function getInteractionTags(_0x5163e7,_0x2de134){return new BPromise(function(_0x20baad,_0x5a6c4d){try{if(_0x5163e7[_0xd19d('0x32')]){_0x5163e7['Tags']=[];_0x5163e7[_0xd19d('0x32')][_0xd19d('0x33')](',')[_0xd19d('0x34')](function(_0x45caac){_0x5163e7[_0xd19d('0x35')][_0xd19d('0x36')](_0x2de134[_0x45caac]);});}delete _0x5163e7[_0xd19d('0x32')];}catch(_0x52041c){_0x5a6c4d(_0x52041c);}_0x20baad(_0x5163e7);});}function updateFaxInteraction(_0x2ecf74,_0x4ad02f,_0x7dcb57){return new BPromise(function(_0x5238e2,_0x152a12){return getInteractionUsers(_0x2ecf74,_0x7dcb57)[_0xd19d('0x2a')](function(_0x113383){return getInteractionTags(_0x113383,_0x4ad02f);})[_0xd19d('0x2a')](function(_0xcdf438){return getStateInteraction(_0xcdf438);})[_0xd19d('0x2a')](function(_0x4453eb){_0x5238e2(_0x4453eb);})[_0xd19d('0x37')](function(_0x4d497e){_0x152a12(_0x4d497e);});});}function getStateInteraction(_0x931166){return new BPromise(function(_0x29bd3a){_0x931166[_0xd19d('0x38')]=0x0;_0x931166[_0xd19d('0x39')]=0x0;_0x931166[_0xd19d('0x3a')]=0x0;_0x931166[_0xd19d('0x3b')]=0x0;_0x931166[_0xd19d('0x3c')]=0x0;if(!_0x931166[_0xd19d('0x3d')]&&!_0x931166[_0xd19d('0x3e')]){_0x931166[_0xd19d('0x38')]+=0x1;}if(!_0x931166[_0xd19d('0x3d')]&&_0x931166[_0xd19d('0x3e')]){_0x931166[_0xd19d('0x39')]+=0x1;if(_0x931166[_0xd19d('0x38')]){_0x931166[_0xd19d('0x38')]-=0x1;}}if(_0x931166['closed']&&_0x931166['UserId']){_0x931166[_0xd19d('0x3a')]+=0x1;if(_0x931166[_0xd19d('0x39')]){_0x931166[_0xd19d('0x39')]-=0x1;}}if(_0x931166['closed']&&!_0x931166[_0xd19d('0x3e')]){_0x931166[_0xd19d('0x3b')]+=0x1;if(_0x931166[_0xd19d('0x38')]){_0x931166[_0xd19d('0x38')]-=0x1;}}_0x931166['total']+=0x1;_0x29bd3a(_0x931166);});}exports[_0xd19d('0x3f')]=function(_0x49089e,_0x186847){var _0x322d7d={},_0x28d085={},_0x2ef444={'count':0x0,'rows':[]};var _0xe8c452=_[_0xd19d('0x31')](db[_0xd19d('0x40')][_0xd19d('0x41')],function(_0x351411){return{'name':_0x351411[_0xd19d('0x42')],'type':_0x351411[_0xd19d('0x43')][_0xd19d('0x44')]};});_0x28d085[_0xd19d('0x45')]=_[_0xd19d('0x31')](_0xe8c452,'name');_0x28d085['query']=_['keys'](_0x49089e[_0xd19d('0x46')]);_0x28d085[_0xd19d('0x47')]=_[_0xd19d('0x48')](_0x28d085[_0xd19d('0x45')],_0x28d085[_0xd19d('0x46')]);_0x322d7d[_0xd19d('0x49')]=_[_0xd19d('0x48')](_0x28d085[_0xd19d('0x45')],qs[_0xd19d('0x4a')](_0x49089e[_0xd19d('0x46')][_0xd19d('0x4a')]));_0x322d7d[_0xd19d('0x49')]=_0x322d7d[_0xd19d('0x49')]['length']?_0x322d7d['attributes']:_0x28d085['model'];if(!_0x49089e[_0xd19d('0x46')][_0xd19d('0x4b')](_0xd19d('0x4c'))){_0x322d7d['limit']=qs[_0xd19d('0x26')](_0x49089e[_0xd19d('0x46')][_0xd19d('0x26')]);_0x322d7d[_0xd19d('0x28')]=qs[_0xd19d('0x28')](_0x49089e[_0xd19d('0x46')][_0xd19d('0x28')]);}_0x322d7d['order']=qs['sort'](_0x49089e[_0xd19d('0x46')][_0xd19d('0x4d')]);_0x322d7d[_0xd19d('0x4e')]=qs[_0xd19d('0x47')](_['pick'](_0x49089e[_0xd19d('0x46')],_0x28d085[_0xd19d('0x47')]),_0xe8c452);var _0x1ce91d=[];var _0x250b7a=squel['select']()['field']('id')[_0xd19d('0x4f')](_0xd19d('0x2e'))[_0xd19d('0x4f')](_0xd19d('0x50'))[_0xd19d('0x51')](_0xd19d('0x52'));var _0x4b205d=squel['select']()[_0xd19d('0x4f')]('u.id')[_0xd19d('0x4f')](_0xd19d('0x53'))[_0xd19d('0x4f')](_0xd19d('0x54'))[_0xd19d('0x51')](_0xd19d('0x55'),'ui')['left_join'](_0xd19d('0x56'),'u',_0xd19d('0x57'));var _0x2c4a04=squel[_0xd19d('0x58')]()['from']('fax_interactions','i')[_0xd19d('0x59')]('cm_contacts','c',_0xd19d('0x5a'))['left_join']('users','o',_0xd19d('0x5b'))[_0xd19d('0x59')](_0xd19d('0x5c'),'a',_0xd19d('0x5d'))['left_join'](_0xd19d('0x5e'),'me',_0xd19d('0x5f'))[_0xd19d('0x59')]('fax_interaction_has_tags','it',_0xd19d('0x60'))[_0xd19d('0x59')]('tools_tags','t',_0xd19d('0x61'));var _0x2ba2e9=squel[_0xd19d('0x62')]();var _0x3bfa27=[];var _0x5cd31b=squel[_0xd19d('0x62')]();var _0x3f4528;if(_0x49089e[_0xd19d('0x46')][_0xd19d('0x63')]){_0x3f4528=as[_0xd19d('0x64')](_0x49089e['query'][_0xd19d('0x63')]);var _0x55b961=_0x3f4528['sqlOperator'];for(var _0x21ff42=0x0;_0x21ff42<_0x3f4528[_0xd19d('0x65')][_0xd19d('0x66')];_0x21ff42++){var _0x151b84=_0x3f4528[_0xd19d('0x65')][_0x21ff42];var _0x5372a1='i';var _0x389faf=_[_0xd19d('0x67')](_0xe8c452,[_0xd19d('0x2e'),_0x151b84[_0xd19d('0x4f')]]);if(!_0x389faf){switch(_0x151b84[_0xd19d('0x4f')]){case _0xd19d('0x68'):if(_0x151b84[_0xd19d('0x69')]==0x1){_0x2c4a04['having']('`'+_0x151b84['field']+_0xd19d('0x6a'));}else{_0x2c4a04[_0xd19d('0x6b')]('`'+_0x151b84[_0xd19d('0x4f')]+_0xd19d('0x6c'));}break;case _0xd19d('0x6d'):if(_0x151b84[_0xd19d('0x6e')]===_0xd19d('0x6f')){if(_0x151b84['value']['split']('\x20')[_0xd19d('0x66')]>0x1){_0x2ba2e9[_0x55b961](_0xd19d('0x70'),qs['getFullTextValue'](_0x151b84[_0xd19d('0x69')]),null);}else{var _0x5a65fd='%'+_0x151b84['value']+'%';_0x2ba2e9[_0x55b961](_0xd19d('0x71'),_0x5a65fd,_0x5a65fd,_0x5a65fd);}}else{_0x389faf=_[_0xd19d('0x67')](_0xe8c452,[_0xd19d('0x2e'),'ContactId']);_0x151b84[_0xd19d('0x4f')]=_0xd19d('0x72');_0xbeb638=as['buildExpression'](_0x5372a1,_0x389faf[_0xd19d('0x43')],_0x151b84);_0x2ba2e9[_0x55b961](_0xbeb638[_0xd19d('0x73')],_0xbeb638[_0xd19d('0x69')]['start'],_0xbeb638[_0xd19d('0x69')][_0xd19d('0x23')]);}break;case _0xd19d('0x74'):var _0x405c8c=_0x151b84[_0xd19d('0x69')][_0xd19d('0x33')](',')[_0xd19d('0x31')](function(_0x1a2dd6){return Number(_0x1a2dd6);});_0x405c8c[_0xd19d('0x34')](function(_0x8b985e){_0x5cd31b['or'](_0xd19d('0x75'),'%,'+_0x8b985e+',%');});_0x3bfa27=_[_0xd19d('0x76')](_0x3bfa27,_0x405c8c);break;case'User':if(_0x151b84['operator']===_0xd19d('0x6f')){_0x2ba2e9[_0x55b961](_0xd19d('0x77'),'%'+_0x151b84[_0xd19d('0x69')]+'%',null);}else{_0x389faf=_[_0xd19d('0x67')](_0xe8c452,['name',_0xd19d('0x3e')]);_0x151b84['field']=_0xd19d('0x3e');_0xbeb638=as[_0xd19d('0x78')](_0x5372a1,_0x389faf[_0xd19d('0x43')],_0x151b84);_0x2ba2e9[_0x55b961](_0xbeb638[_0xd19d('0x73')],_0xbeb638[_0xd19d('0x69')]['start'],_0xbeb638[_0xd19d('0x69')]['end']);}break;case _0xd19d('0x79'):_0xbeb638=as[_0xd19d('0x78')]('me',null,_0x151b84);_0x2ba2e9[_0x55b961](_0xbeb638[_0xd19d('0x73')],_0xbeb638['value'][_0xd19d('0x7a')],_0xbeb638['value'][_0xd19d('0x23')]);break;}}else{var _0xbeb638=as[_0xd19d('0x78')](_0x5372a1,_0x389faf['type'],_0x151b84);_0x2ba2e9[_0x55b961](_0xbeb638['text'],_0xbeb638[_0xd19d('0x69')]['start'],_0xbeb638['value'][_0xd19d('0x23')]);}}}else{var _0x157524=_(_0x49089e[_0xd19d('0x46')])[_0xd19d('0x7b')]()[_0xd19d('0x31')](function(_0x4d734f){return _[_0xd19d('0x7c')](_0xe8c452,[_0xd19d('0x2e'),_0x4d734f])?_0x4d734f:undefined;})[_0xd19d('0x7d')]()[_0xd19d('0x69')]();if(!_['isEmpty'](_0x157524)){_0x157524[_0xd19d('0x34')](function(_0xce0aaf){if(_0xce0aaf===_0xd19d('0x7e')){_0x2c4a04[_0xd19d('0x4e')](_0xd19d('0x7f'),[][_0xd19d('0x80')](_0x49089e[_0xd19d('0x46')][_0xce0aaf]));}else if(_0xce0aaf===_0xd19d('0x81')){var _0x5d61d8=JSON[_0xd19d('0x82')](_0x49089e[_0xd19d('0x46')][_0xce0aaf])[_0xd19d('0x83')];var _0x4a5999=JSON[_0xd19d('0x82')](_0x49089e[_0xd19d('0x46')][_0xce0aaf])[_0xd19d('0x84')];_0x2c4a04[_0xd19d('0x4e')](_0xd19d('0x85'),_0x5d61d8,_0x4a5999);}else{if(_0x49089e[_0xd19d('0x46')][_0xce0aaf]===_0xd19d('0x86')){_0x2c4a04[_0xd19d('0x4e')]('i.'+_0xce0aaf+_0xd19d('0x87'));}else{_0x2c4a04[_0xd19d('0x4e')]('i.'+_0xce0aaf+_0xd19d('0x88'),_0x49089e[_0xd19d('0x46')][_0xce0aaf]);}}});}if(_0x49089e[_0xd19d('0x46')]['read']){if(_0x49089e[_0xd19d('0x46')]['read']==0x1){_0x2c4a04['having'](_0xd19d('0x89'));}else{_0x2c4a04[_0xd19d('0x6b')](_0xd19d('0x8a'));}}if(_0x49089e[_0xd19d('0x46')][_0xd19d('0x8b')]){_0x3bfa27=_['isArray'](_0x49089e[_0xd19d('0x46')]['tag'])?_0x49089e[_0xd19d('0x46')][_0xd19d('0x8b')]:new Array(_0x49089e[_0xd19d('0x46')][_0xd19d('0x8b')]);_0x3bfa27[_0xd19d('0x34')](function(_0x524f8f){_0x5cd31b['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x524f8f+',%');});}if(_0x49089e['query'][_0xd19d('0x8c')]){var _0x15b383=_0x49089e[_0xd19d('0x46')][_0xd19d('0x8c')][_0xd19d('0x8d')]('\x5c','\x5c\x5c')[_0xd19d('0x8d')](/'/g,'\x27\x27');if(qs[_0xd19d('0x8e')](_0x15b383)){_0x2ba2e9['or']('i.id\x20LIKE\x20?',_0x15b383+'%')['or'](_0xd19d('0x8f'),_0x15b383+'%');}_0x2ba2e9['or']('CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?',_0x15b383+'%');}}_0x2c4a04[_0xd19d('0x4e')](_0x2ba2e9);_0x2c4a04[_0xd19d('0x90')]('i.id');var _0xaeded4={'type':db[_0xd19d('0x91')][_0xd19d('0x92')]['SELECT'],'raw':!![]};var _0x5643ce=_0x2c4a04[_0xd19d('0x93')]();_0x5643ce[_0xd19d('0x4f')](_0xd19d('0x94'));_0x5643ce['field']('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xd19d('0x68'));if(_0x322d7d[_0xd19d('0x95')]){_0x322d7d[_0xd19d('0x95')][_0xd19d('0x34')](function(_0x211e79){var _0x418c86=_0x211e79[0x0]==='contactName'?_0x211e79[0x0]:'i.'+_0x211e79[0x0];_0x2c4a04[_0xd19d('0x95')](_0x418c86,_0x211e79[0x1]===_0xd19d('0x96')?![]:!![]);});}if(!_[_0xd19d('0x97')](_0x3bfa27)){_0x2c4a04['having'](_0x5cd31b);_0x5643ce['where'](_0xd19d('0x98'),_0x3bfa27);}BPromise[_0xd19d('0x99')]()['then'](function(){if(!_0x3f4528){if(_0x49089e[_0xd19d('0x46')][_0xd19d('0x7e')])return;_0x5643ce[_0xd19d('0x4e')](_0xd19d('0x9a'));_0x2c4a04[_0xd19d('0x4e')](_0xd19d('0x9a'));return;}if(_0x49089e[_0xd19d('0x9b')]['role']!==_0xd19d('0x9c'))return;return _0x49089e[_0xd19d('0x9b')][_0xd19d('0x9d')]({'attributes':['id'],'raw':!![]})[_0xd19d('0x2a')](function(_0xb80cb7){if(_['isEmpty'](_0xb80cb7)){_0x5643ce[_0xd19d('0x4e')](_0xd19d('0x9e'));_0x2c4a04['where'](_0xd19d('0x9e'));}else{_0x5643ce[_0xd19d('0x4e')](_0xd19d('0x7f'),_['map'](_0xb80cb7,'id'));_0x2c4a04['where']('i.FaxAccountId\x20IN\x20?',_['map'](_0xb80cb7,'id'));}});})[_0xd19d('0x2a')](function(){if(_0x49089e[_0xd19d('0x9b')][_0xd19d('0x9f')]===_0xd19d('0x9c')&&!_0x3f4528&&!_0x49089e[_0xd19d('0x46')][_0xd19d('0x7e')])return[];return db[_0xd19d('0xa0')][_0xd19d('0x46')](_0x5643ce[_0xd19d('0xa1')](),_0xaeded4);})[_0xd19d('0x2a')](function(_0x2bcb15){_0x2ef444[_0xd19d('0x27')]=_0x2bcb15[_0xd19d('0x66')];if(_0x2ef444[_0xd19d('0x27')]===0x0)return[];return db[_0xd19d('0xa0')]['query'](_0x250b7a[_0xd19d('0xa1')](),_0xaeded4)[_0xd19d('0x2a')](function(_0x428b22){_0x1ce91d=_[_0xd19d('0xa2')](_0x428b22,'id');_0xaeded4=_[_0xd19d('0xa3')](_0xaeded4,{'model':db['FaxInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x49089e[_0xd19d('0x46')][_0xd19d('0x4a')]){_0x322d7d[_0xd19d('0x49')][_0xd19d('0x34')](function(_0x157b32){_0x2c4a04['field']('i.'+_0x157b32);});}else{_0x2c4a04[_0xd19d('0x4f')](_0xd19d('0xa4'),'unreadMessages');_0x2c4a04[_0xd19d('0x4f')](_0xd19d('0xa5'),_0xd19d('0xa6'));_0x2c4a04[_0xd19d('0x4f')]('a.mandatoryDisposition',_0xd19d('0xa7'));_0x2c4a04['field'](_0xd19d('0xa8'),_0xd19d('0xa9'));_0x2c4a04[_0xd19d('0x4f')](_0xd19d('0xaa'));_0x2c4a04['field'](_0xd19d('0xab'),'Contact.firstName');_0x2c4a04[_0xd19d('0x4f')](_0xd19d('0xac'),_0xd19d('0xad'));_0x2c4a04[_0xd19d('0x4f')]('c.email',_0xd19d('0xae'));_0x2c4a04['field']('c.phone','Contact.phone');_0x2c4a04[_0xd19d('0x4f')](_0xd19d('0xaf'),_0xd19d('0xb0'));_0x2c4a04['field'](_0xd19d('0xb1'),'Contact.fax');_0x2c4a04['field']('o.fullname',_0xd19d('0xb2'));_0x2c4a04['field'](_0xd19d('0xb3'),'Owner.internal');_0x2c4a04[_0xd19d('0x4f')]('GROUP_CONCAT(DISTINCT\x20t.id)',_0xd19d('0x32'));}if(_0x322d7d['limit'])_0x2c4a04[_0xd19d('0x26')](_0x322d7d[_0xd19d('0x26')]);if(_0x322d7d['offset'])_0x2c4a04['offset'](_0x322d7d[_0xd19d('0x28')]);return db[_0xd19d('0xa0')][_0xd19d('0x46')](_0x2c4a04[_0xd19d('0xa1')](),_0xaeded4);})[_0xd19d('0x2a')](function(_0x22407d){if(_0x22407d[_0xd19d('0x66')]>0x0)_0x4b205d[_0xd19d('0x4e')](_0xd19d('0xb4'),_[_0xd19d('0x31')](_0x22407d,'id'));return db[_0xd19d('0xa0')]['query'](_0x4b205d[_0xd19d('0xa1')](),_0xaeded4)['then'](function(_0x41399f){var _0x316f2e=_[_0xd19d('0xb5')](_0x41399f,_0xd19d('0xb6'));var _0x3c17ca=[];_0x22407d[_0xd19d('0x34')](function(_0x488061){_0x3c17ca['push'](updateFaxInteraction(_0x488061,_0x1ce91d,_0x316f2e));});return BPromise[_0xd19d('0xb7')](_0x3c17ca);});});})['then'](function(_0x13eab2){_0x2ef444[_0xd19d('0xb8')]=_0x13eab2;return _0x2ef444;})['then'](respondWithFilteredResult(_0x186847,_0x322d7d))[_0xd19d('0x37')](handleError(_0x186847,null));};exports['show']=function(_0x24b9d7,_0x1a54c1){var _0x169b7b={'raw':![],'where':{'id':_0x24b9d7[_0xd19d('0xb9')]['id']}},_0x56dabe={};_0x56dabe['model']=_[_0xd19d('0x7b')](db['FaxInteraction'][_0xd19d('0x41')]);_0x56dabe['query']=_[_0xd19d('0x7b')](_0x24b9d7[_0xd19d('0x46')]);_0x56dabe[_0xd19d('0x47')]=_['intersection'](_0x56dabe[_0xd19d('0x45')],_0x56dabe[_0xd19d('0x46')]);_0x169b7b[_0xd19d('0x49')]=_[_0xd19d('0x48')](_0x56dabe[_0xd19d('0x45')],qs[_0xd19d('0x4a')](_0x24b9d7['query'][_0xd19d('0x4a')]));_0x169b7b[_0xd19d('0x49')]=_0x169b7b[_0xd19d('0x49')][_0xd19d('0x66')]?_0x169b7b[_0xd19d('0x49')]:_0x56dabe[_0xd19d('0x45')];if(_0x24b9d7[_0xd19d('0x46')]['includeAll']){_0x169b7b[_0xd19d('0xba')]=[{'all':!![]}];}_0x169b7b=_[_0xd19d('0xa3')]({},_0x169b7b,_0x24b9d7[_0xd19d('0xbb')]);return db[_0xd19d('0x40')]['find'](_0x169b7b)[_0xd19d('0x2a')](handleEntityNotFound(_0x1a54c1,null))[_0xd19d('0x2a')](respondWithResult(_0x1a54c1,null))['catch'](handleError(_0x1a54c1,null));};exports[_0xd19d('0xbc')]=function(_0x1ebc38,_0x4ee644){return db[_0xd19d('0x40')][_0xd19d('0xbc')](_0x1ebc38[_0xd19d('0x79')],{})['then'](respondWithResult(_0x4ee644,0xc9))[_0xd19d('0x37')](handleError(_0x4ee644,null));};exports['update']=function(_0x4dc814,_0x22c702){if(_0x4dc814['body']['id']){delete _0x4dc814[_0xd19d('0x79')]['id'];}return db[_0xd19d('0x40')][_0xd19d('0x67')]({'where':{'id':_0x4dc814[_0xd19d('0xb9')]['id']}})[_0xd19d('0x2a')](handleEntityNotFound(_0x22c702,null))[_0xd19d('0x2a')](saveUpdates(_0x4dc814['body'],null))[_0xd19d('0x2a')](respondWithResult(_0x22c702,null))[_0xd19d('0x37')](handleError(_0x22c702,null));};exports['destroy']=function(_0x4dc2f2,_0x22eccd){return db[_0xd19d('0x40')][_0xd19d('0x67')]({'where':{'id':_0x4dc2f2[_0xd19d('0xb9')]['id']}})[_0xd19d('0x2a')](handleEntityNotFound(_0x22eccd,null))[_0xd19d('0x2a')](removeEntity(_0x22eccd,null))[_0xd19d('0x37')](handleError(_0x22eccd,null));};exports[_0xd19d('0xbd')]=function(_0x250828,_0x39854){return db[_0xd19d('0x40')]['describe']()[_0xd19d('0x2a')](respondWithResult(_0x39854,null))[_0xd19d('0x37')](handleError(_0x39854,null));};exports[_0xd19d('0xbe')]=function(_0x3934f1,_0x4b76d2,_0xb3999e){return db[_0xd19d('0xbf')][_0xd19d('0x67')]({'where':{'id':_0x3934f1[_0xd19d('0xb9')]['id']}})[_0xd19d('0x2a')](handleEntityNotFound(_0x4b76d2,null))['then'](function(_0x1cc1ef){if(_0x1cc1ef){return _0x1cc1ef['addMessage'](_0x3934f1[_0xd19d('0x79')][_0xd19d('0xc0')],_[_0xd19d('0xc1')](_0x3934f1[_0xd19d('0x79')],['ids','id'])||{});}})['then'](respondWithResult(_0x4b76d2,null))['catch'](handleError(_0x4b76d2,null));};exports[_0xd19d('0xc2')]=function(_0x460e21,_0x16ed35,_0x27a168){var _0x25a790={'raw':![],'where':{}};var _0x3e0f12={};var _0x3839ff={'count':0x0,'rows':[]};return db[_0xd19d('0x40')][_0xd19d('0xc3')]({'where':{'id':_0x460e21['params']['id']}})[_0xd19d('0x2a')](handleEntityNotFound(_0x16ed35,null))['then'](function(_0x576c0f){if(_0x576c0f){_0x3e0f12[_0xd19d('0x45')]=_['keys'](db['FaxMessage']['rawAttributes']);_0x3e0f12[_0xd19d('0x46')]=_[_0xd19d('0x7b')](_0x460e21[_0xd19d('0x46')]);_0x3e0f12[_0xd19d('0x47')]=_[_0xd19d('0x48')](_0x3e0f12[_0xd19d('0x45')],_0x3e0f12[_0xd19d('0x46')]);_0x25a790[_0xd19d('0x49')]=_['intersection'](_0x3e0f12['model'],qs[_0xd19d('0x4a')](_0x460e21['query'][_0xd19d('0x4a')]));_0x25a790['attributes']=_0x25a790[_0xd19d('0x49')][_0xd19d('0x66')]?_0x25a790[_0xd19d('0x49')]:_0x3e0f12[_0xd19d('0x45')];if(!_0x460e21[_0xd19d('0x46')]['hasOwnProperty']('nolimit')){_0x25a790[_0xd19d('0x26')]=qs['limit'](_0x460e21[_0xd19d('0x46')][_0xd19d('0x26')]);_0x25a790[_0xd19d('0x28')]=qs[_0xd19d('0x28')](_0x460e21[_0xd19d('0x46')][_0xd19d('0x28')]);}_0x25a790[_0xd19d('0x95')]=qs['sort'](_0x460e21[_0xd19d('0x46')][_0xd19d('0x4d')]);_0x25a790[_0xd19d('0x4e')]=qs[_0xd19d('0x47')](_[_0xd19d('0xc4')](_0x460e21[_0xd19d('0x46')],_0x3e0f12['filters']));_0x25a790['where'][_0xd19d('0xb6')]=_0x576c0f['id'];if(_0x460e21[_0xd19d('0x46')]['filter']){_0x25a790[_0xd19d('0x4e')]=_['merge'](_0x25a790[_0xd19d('0x4e')],{'$or':_['map'](_0x25a790[_0xd19d('0x49')],function(_0x17c2fb){var _0xbb8743={};_0xbb8743[_0x17c2fb]={'$like':'%'+_0x460e21[_0xd19d('0x46')]['filter']+'%'};return _0xbb8743;})});}if(_0x460e21[_0xd19d('0x46')][_0xd19d('0x83')]){var _0x3cb50a=_0x460e21[_0xd19d('0x46')][_0xd19d('0x83')]['split'](',');var _0x4daaa2={};_0x4daaa2[_0x3cb50a[0x0]]={'$gte':moment(_0x3cb50a[0x1])['format'](_0xd19d('0xc5'))};_0x25a790[_0xd19d('0x4e')]=_[_0xd19d('0xa3')](_0x25a790[_0xd19d('0x4e')],_0x4daaa2);}_0x25a790=_[_0xd19d('0xa3')]({},_0x25a790,_0x460e21[_0xd19d('0xbb')]);return db[_0xd19d('0xbf')][_0xd19d('0x27')]({'where':_0x25a790[_0xd19d('0x4e')]})[_0xd19d('0x2a')](function(_0x2bef3d){_0x3839ff['count']=_0x2bef3d;if(_0x460e21['query'][_0xd19d('0xc6')]){_0x25a790[_0xd19d('0xba')]=[{'all':!![]}];}return db[_0xd19d('0xbf')]['findAll'](_0x25a790);})[_0xd19d('0x2a')](function(_0x5c1cf2){_0x3839ff['rows']=_0x5c1cf2;return _0x3839ff;});}})[_0xd19d('0x2a')](respondWithFilteredResult(_0x16ed35,_0x25a790))['catch'](handleError(_0x16ed35,null));};exports[_0xd19d('0xc7')]=function(_0xa907f7,_0x59352c,_0x58442f){return db[_0xd19d('0x40')][_0xd19d('0x67')]({'where':{'id':_0xa907f7['params']['id']}})['then'](handleEntityNotFound(_0x59352c,null))['then'](function(_0x3cf382){if(_0x3cf382){return _0x3cf382[_0xd19d('0xc8')](_0xa907f7['body'][_0xd19d('0xc0')],_['omit'](_0xa907f7[_0xd19d('0x79')],[_0xd19d('0xc0'),'id'])||{})[_0xd19d('0xc9')](function(){return db[_0xd19d('0x74')]['findAll']({'attributes':['id',_0xd19d('0x2e'),_0xd19d('0x50')],'where':{'id':_0xa907f7[_0xd19d('0x79')][_0xd19d('0xc0')]}});})[_0xd19d('0x2a')](function(_0x37ec48){socket[_0xd19d('0xca')](_0xd19d('0xcb'),{'id':Number(_0xa907f7['params']['id']),'tags':_0x37ec48||[]});return{'id':Number(_0xa907f7['params']['id']),'tags':_0x37ec48||[]};});}})['then'](respondWithResult(_0x59352c,null))[_0xd19d('0x37')](handleError(_0x59352c,null));};exports['removeTags']=function(_0x32a71d,_0x4e5dd0,_0x509e16){return db[_0xd19d('0x40')][_0xd19d('0x67')]({'where':{'id':_0x32a71d['params']['id']}})['then'](handleEntityNotFound(_0x4e5dd0,null))[_0xd19d('0x2a')](function(_0x1dd821){if(_0x1dd821){return _0x1dd821[_0xd19d('0xcc')](_0x32a71d[_0xd19d('0x46')][_0xd19d('0xc0')]);}})[_0xd19d('0x2a')](respondWithStatusCode(_0x4e5dd0,null))[_0xd19d('0x37')](handleError(_0x4e5dd0,null));};exports[_0xd19d('0xcd')]=function(_0x229a44,_0x136f18){var _0x179845=moment()[_0xd19d('0xce')]()[_0xd19d('0xa1')]();var _0x21290b=path[_0xd19d('0xcf')](config[_0xd19d('0xd0')],_0xd19d('0xd1'),'files','tmp');var _0x5c1b74=path['join'](config[_0xd19d('0xd0')],'server',_0xd19d('0xd2'),_0xd19d('0xd3'));var _0x172860=path[_0xd19d('0xcf')](_0x21290b,_0x179845);var _0x4c6c5b=util[_0xd19d('0xd4')](_0xd19d('0xd5'),_0x229a44[_0xd19d('0xb9')]['id'],_0x179845);var _0x7dbbd9=path['join'](_0x21290b,_0x4c6c5b);var _0x47884a=[];_0x47884a['push']({'model':db[_0xd19d('0xd6')],'as':'Attachment','raw':!![]});var _0x4685ad=[{'model':db[_0xd19d('0xbf')],'as':'Messages','attributes':['id',_0xd19d('0x79'),_0xd19d('0x81')],'include':_0x47884a}];return db[_0xd19d('0x40')][_0xd19d('0x67')]({'where':{'id':_0x229a44[_0xd19d('0xb9')]['id']},'include':_0x4685ad})[_0xd19d('0x2a')](handleEntityNotFound(_0x136f18,null))['then'](function(_0x4b2a90){if(_0x4b2a90&&_0x4b2a90['Messages']){var _0x3dcdff=_0x4b2a90['get']({'plain':!![]});fs[_0xd19d('0xd7')](_0x172860);for(var _0xf28388=0x0;_0xf28388<_0x3dcdff[_0xd19d('0xd8')][_0xd19d('0x66')];_0xf28388++){var _0x2afd20=_0x3dcdff[_0xd19d('0xd8')][_0xf28388][_0xd19d('0xd6')];if(_0x2afd20){var _0x58497e=path['join'](_0x5c1b74,_0x2afd20[_0xd19d('0xd9')]);if(fs[_0xd19d('0xda')](_0x58497e)){fs[_0xd19d('0xdb')](_0x58497e)[_0xd19d('0xdc')](fs[_0xd19d('0xdd')](path['join'](_0x172860,_0x2afd20[_0xd19d('0xd9')])));}}}return BPromise[_0xd19d('0x99')]()[_0xd19d('0x2a')](function(){return new BPromise(function(_0x23f48d,_0x167506){zipdir(_0x172860,{'saveTo':_0x7dbbd9},function(_0x52ca2d,_0x484745){if(_0x52ca2d)return _0x167506(_0x52ca2d);return _0x23f48d(_0x484745);});})[_0xd19d('0x2a')](function(){return new BPromise(function(_0x3e3151,_0x3b04e4){rimraf(_0x172860,function(_0x16afc8){if(_0x16afc8)_0x3b04e4(_0x16afc8);return _0x3e3151();});});})[_0xd19d('0x2a')](function(){return _0x136f18[_0xd19d('0xcd')](_0x7dbbd9,_0x4c6c5b,function(_0x4467de){if(_0x4467de){console[_0xd19d('0xde')](_0xd19d('0xdf'),_0x4467de);}else{fs[_0xd19d('0xe0')](_0x7dbbd9);}});});});}else{return _0x136f18[_0xd19d('0x21')](0xc8);}})[_0xd19d('0x37')](handleError(_0x136f18,null));};
\ No newline at end of file