Built motion from commit e1760111.|2.6.18
[motion2.git] / server / api / faxInteraction / faxInteraction.controller.js
index a4c2694..4e5665d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x8e42=['faxInteractionTags:save','removeTags','download','unix','join','server','files','attachments','format','transcript-%d-%s.zip','createdAt','Messages','get','mkdirSync','existsSync','createReadStream','pipe','createWriteStream','basename','log','err','unlinkSync','html-pdf','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','redis','defaults','localhost','socket.io-emitter','sendStatus','end','status','json','count','offset','limit','set','Content-Range','apply','save','update','destroy','then','stack','name','Users','map','TagIds','Tags','forEach','catch','index','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','nolimit','order','sort','pick','select','field','color','from','tools_tags','u.id','u.fullname','ui.FaxInteractionId','user_has_fax_interactions','u.id\x20=\x20ui.UserId','fax_interactions','left_join','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','users','fax_accounts','a.id\x20=\x20i.FaxAccountId','me.FaxInteractionId\x20=\x20i.id','fax_interaction_has_tags','it.FaxInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch','find','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','operator','$substring','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','text','start','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','UserId','body','some','compact','isEmpty','FaxAccountId','where','concat','parse','$gte','null','\x20IS\x20NULL','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','isArray','filter','replace','isNumeric','i.id\x20LIKE\x20?','i.fax\x20LIKE\x20?','group','QueryTypes','SELECT','i.id','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','DESC','t.id\x20IN\x20?','resolve','journey','user','getFaxAccounts','i.FaxAccountId\x20IS\x20NULL','i.FaxAccountId\x20IN\x20?','sequelize','toString','keyBy','FaxInteraction','a.key','Account.key','c.firstName','c.lastName','Contact.lastName','c.email','c.phone','Contact.phone','Contact.mobile','c.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.FaxInteractionId\x20IN\x20?','FaxInteractionId','push','all','rows','params','includeAll','include','merge','create','describe','addMessage','FaxMessage','ids','omit','getMessages','findOne','rawAttributes','split','YYYY-MM-DD\x20HH:mm:ss','options','findAll','setTags','spread','emit'];(function(_0x938275,_0x544a3e){var _0x2f8be1=function(_0xcfa0bd){while(--_0xcfa0bd){_0x938275['push'](_0x938275['shift']());}};_0x2f8be1(++_0x544a3e);}(_0x8e42,0x1b8));var _0x28e4=function(_0x53e787,_0x4298e6){_0x53e787=_0x53e787-0x0;var _0x2781a0=_0x8e42[_0x53e787];return _0x2781a0;};'use strict';var pdf=require(_0x28e4('0x0'));var emlformat=require(_0x28e4('0x1'));var rimraf=require(_0x28e4('0x2'));var zipdir=require(_0x28e4('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0x28e4('0x4'));var moment=require(_0x28e4('0x5'));var BPromise=require(_0x28e4('0x6'));var Mustache=require(_0x28e4('0x7'));var util=require(_0x28e4('0x8'));var path=require(_0x28e4('0x9'));var sox=require(_0x28e4('0xa'));var csv=require(_0x28e4('0xb'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x28e4('0xc'));var squel=require(_0x28e4('0xd'));var crypto=require(_0x28e4('0xe'));var jsforce=require(_0x28e4('0xf'));var deskjs=require(_0x28e4('0x10'));var toCsv=require('to-csv');var querystring=require(_0x28e4('0x11'));var Papa=require(_0x28e4('0x12'));var Redis=require(_0x28e4('0x13'));var authService=require(_0x28e4('0x14'));var qs=require(_0x28e4('0x15'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x28e4('0x16'));var logger=require('../../config/logger')(_0x28e4('0x17'));var utils=require(_0x28e4('0x18'));var config=require(_0x28e4('0x19'));var db=require('../../mysqldb')['db'];config[_0x28e4('0x1a')]=_[_0x28e4('0x1b')](config[_0x28e4('0x1a')],{'host':_0x28e4('0x1c'),'port':0x18eb});var socket=require(_0x28e4('0x1d'))(new Redis(config['redis']));require('./faxInteraction.socket')['register'](socket);function respondWithStatusCode(_0x42670e,_0x2c7b2b){_0x2c7b2b=_0x2c7b2b||0xcc;return function(_0x417f24){if(_0x417f24){return _0x42670e[_0x28e4('0x1e')](_0x2c7b2b);}return _0x42670e['status'](_0x2c7b2b)[_0x28e4('0x1f')]();};}function respondWithResult(_0x583d34,_0x2c8901){_0x2c8901=_0x2c8901||0xc8;return function(_0x502e6c){if(_0x502e6c){return _0x583d34[_0x28e4('0x20')](_0x2c8901)[_0x28e4('0x21')](_0x502e6c);}};}function respondWithFilteredResult(_0x30070c,_0x11b77f){return function(_0x11434c){if(_0x11434c){var _0x10d635=_0x11434c[_0x28e4('0x22')],_0x53037a=_0x11b77f[_0x28e4('0x23')],_0x2f93b0=_0x11b77f[_0x28e4('0x23')]+_0x11b77f[_0x28e4('0x24')],_0x36040b;if(_0x2f93b0>=_0x10d635){_0x2f93b0=_0x10d635;_0x36040b=0xc8;}else{_0x36040b=0xce;}_0x30070c[_0x28e4('0x20')](_0x36040b);return _0x30070c[_0x28e4('0x25')](_0x28e4('0x26'),_0x53037a+'-'+_0x2f93b0+'/'+_0x10d635)[_0x28e4('0x21')](_0x11434c);}return null;};}function patchUpdates(_0x5980de){return function(_0x2252ee){try{jsonpatch[_0x28e4('0x27')](_0x2252ee,_0x5980de,!![]);}catch(_0x1249c8){return BPromise['reject'](_0x1249c8);}return _0x2252ee[_0x28e4('0x28')]();};}function saveUpdates(_0x46be2c,_0x448312){return function(_0x24dd78){if(_0x24dd78){return _0x24dd78[_0x28e4('0x29')](_0x46be2c)['then'](function(_0x38a41f){return _0x38a41f;});}return null;};}function removeEntity(_0x454b24,_0x446a4d){return function(_0x3a579b){if(_0x3a579b){return _0x3a579b[_0x28e4('0x2a')]()[_0x28e4('0x2b')](function(){_0x454b24['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x81b2fe,_0x27b94f){return function(_0x22451a){if(!_0x22451a){_0x81b2fe[_0x28e4('0x1e')](0x194);}return _0x22451a;};}function handleError(_0x170194,_0x2c8534){_0x2c8534=_0x2c8534||0x1f4;return function(_0x70a709){logger['error'](_0x70a709[_0x28e4('0x2c')]);if(_0x70a709[_0x28e4('0x2d')]){delete _0x70a709[_0x28e4('0x2d')];}_0x170194[_0x28e4('0x20')](_0x2c8534)['send'](_0x70a709);};}function getInteractionUsers(_0x123f2b,_0x3d879e){return new BPromise(function(_0xca35bc,_0x409895){try{if(_0x3d879e[_0x123f2b['id']]){_0x123f2b[_0x28e4('0x2e')]=_[_0x28e4('0x2f')](_0x3d879e[_0x123f2b['id']],function(_0x5ecd4b){return{'id':_0x5ecd4b['id'],'fullname':_0x5ecd4b['fullname']};});}}catch(_0x15755d){_0x409895(_0x15755d);}_0xca35bc(_0x123f2b);});}function getInteractionTags(_0x4b342a,_0x169690){return new BPromise(function(_0x2b7750,_0xe5917c){try{if(_0x4b342a[_0x28e4('0x30')]){_0x4b342a[_0x28e4('0x31')]=[];_0x4b342a[_0x28e4('0x30')]['split'](',')[_0x28e4('0x32')](function(_0x330a92){_0x4b342a['Tags']['push'](_0x169690[_0x330a92]);});}delete _0x4b342a['TagIds'];}catch(_0x1d5fde){_0xe5917c(_0x1d5fde);}_0x2b7750(_0x4b342a);});}function updateFaxInteraction(_0x5c2281,_0x5763e8,_0x237bb7){return new BPromise(function(_0x1a7c31,_0x594c95){return getInteractionUsers(_0x5c2281,_0x237bb7)['then'](function(_0x7f6b93){return getInteractionTags(_0x7f6b93,_0x5763e8);})[_0x28e4('0x2b')](function(_0x245d39){_0x1a7c31(_0x245d39);})[_0x28e4('0x33')](function(_0x120b8e){_0x594c95(_0x120b8e);});});}exports[_0x28e4('0x34')]=function(_0x3c958a,_0x5f34b5){var _0x43c54c={},_0x39f988={},_0x44bbb6={'count':0x0,'rows':[]};var _0x558972=_[_0x28e4('0x2f')](db['FaxInteraction']['rawAttributes'],function(_0x150147){return{'name':_0x150147[_0x28e4('0x35')],'type':_0x150147[_0x28e4('0x36')][_0x28e4('0x37')]};});_0x39f988[_0x28e4('0x38')]=_[_0x28e4('0x2f')](_0x558972,_0x28e4('0x2d'));_0x39f988[_0x28e4('0x39')]=_[_0x28e4('0x3a')](_0x3c958a['query']);_0x39f988[_0x28e4('0x3b')]=_[_0x28e4('0x3c')](_0x39f988['model'],_0x39f988[_0x28e4('0x39')]);_0x43c54c[_0x28e4('0x3d')]=_[_0x28e4('0x3c')](_0x39f988[_0x28e4('0x38')],qs[_0x28e4('0x3e')](_0x3c958a[_0x28e4('0x39')][_0x28e4('0x3e')]));_0x43c54c[_0x28e4('0x3d')]=_0x43c54c['attributes'][_0x28e4('0x3f')]?_0x43c54c[_0x28e4('0x3d')]:_0x39f988[_0x28e4('0x38')];if(!_0x3c958a[_0x28e4('0x39')]['hasOwnProperty'](_0x28e4('0x40'))){_0x43c54c[_0x28e4('0x24')]=qs[_0x28e4('0x24')](_0x3c958a['query'][_0x28e4('0x24')]);_0x43c54c[_0x28e4('0x23')]=qs[_0x28e4('0x23')](_0x3c958a[_0x28e4('0x39')]['offset']);}_0x43c54c[_0x28e4('0x41')]=qs['sort'](_0x3c958a[_0x28e4('0x39')][_0x28e4('0x42')]);_0x43c54c['where']=qs['filters'](_[_0x28e4('0x43')](_0x3c958a[_0x28e4('0x39')],_0x39f988[_0x28e4('0x3b')]));var _0x5cdcb4=[];var _0x862dbc=squel[_0x28e4('0x44')]()[_0x28e4('0x45')]('id')['field']('name')[_0x28e4('0x45')](_0x28e4('0x46'))[_0x28e4('0x47')](_0x28e4('0x48'));var _0x266238=squel[_0x28e4('0x44')]()[_0x28e4('0x45')](_0x28e4('0x49'))[_0x28e4('0x45')](_0x28e4('0x4a'))[_0x28e4('0x45')](_0x28e4('0x4b'))[_0x28e4('0x47')](_0x28e4('0x4c'),'ui')['left_join']('users','u',_0x28e4('0x4d'));var _0x6db1cd=squel[_0x28e4('0x44')]()['from'](_0x28e4('0x4e'),'i')[_0x28e4('0x4f')](_0x28e4('0x50'),'c',_0x28e4('0x51'))[_0x28e4('0x4f')](_0x28e4('0x52'),'o','o.id\x20=\x20i.UserId')[_0x28e4('0x4f')](_0x28e4('0x53'),'a',_0x28e4('0x54'))[_0x28e4('0x4f')]('fax_messages','me',_0x28e4('0x55'))['left_join'](_0x28e4('0x56'),'it',_0x28e4('0x57'))[_0x28e4('0x4f')](_0x28e4('0x48'),'t',_0x28e4('0x58'));var _0x2b5c71=squel[_0x28e4('0x59')]();var _0x251bf2=[];var _0x3cbb7f=squel[_0x28e4('0x59')]();var _0x1dd4d0;if(_0x3c958a[_0x28e4('0x39')][_0x28e4('0x5a')]){_0x1dd4d0=as[_0x28e4('0x5b')](_0x3c958a[_0x28e4('0x39')]['search']);var _0x3c7532=_0x1dd4d0['sqlOperator'];for(var _0x1e1c5e=0x0;_0x1e1c5e<_0x1dd4d0['conditions'][_0x28e4('0x3f')];_0x1e1c5e++){var _0x3338bf=_0x1dd4d0['conditions'][_0x1e1c5e];var _0x1b81f5='i';var _0x496a5b=_[_0x28e4('0x5c')](_0x558972,[_0x28e4('0x2d'),_0x3338bf[_0x28e4('0x45')]]);if(!_0x496a5b){switch(_0x3338bf[_0x28e4('0x45')]){case _0x28e4('0x5d'):if(_0x3338bf[_0x28e4('0x5e')]==0x1){_0x6db1cd[_0x28e4('0x5f')]('`'+_0x3338bf[_0x28e4('0x45')]+_0x28e4('0x60'));}else{_0x6db1cd['having']('`'+_0x3338bf[_0x28e4('0x45')]+_0x28e4('0x61'));}break;case'Contact':if(_0x3338bf[_0x28e4('0x62')]===_0x28e4('0x63')){if(_0x3338bf['value']['split']('\x20')[_0x28e4('0x3f')]>0x1){_0x2b5c71[_0x3c7532](_0x28e4('0x64'),qs[_0x28e4('0x65')](_0x3338bf[_0x28e4('0x5e')]),null);}else{var _0x367dfb='%'+_0x3338bf['value']+'%';_0x2b5c71[_0x3c7532](_0x28e4('0x66'),_0x367dfb,_0x367dfb,_0x367dfb);}}else{_0x496a5b=_[_0x28e4('0x5c')](_0x558972,[_0x28e4('0x2d'),_0x28e4('0x67')]);_0x3338bf['field']=_0x28e4('0x67');_0x4e39a8=as[_0x28e4('0x68')](_0x1b81f5,_0x496a5b['type'],_0x3338bf);_0x2b5c71[_0x3c7532](_0x4e39a8[_0x28e4('0x69')],_0x4e39a8[_0x28e4('0x5e')][_0x28e4('0x6a')],_0x4e39a8[_0x28e4('0x5e')][_0x28e4('0x1f')]);}break;case'Tag':var _0x4fbc23=_0x3338bf[_0x28e4('0x5e')]['split'](',')[_0x28e4('0x2f')](function(_0x40bbe0){return Number(_0x40bbe0);});_0x4fbc23['forEach'](function(_0x4bf5e8){_0x3cbb7f['or'](_0x28e4('0x6b'),'%,'+_0x4bf5e8+',%');});_0x251bf2=_[_0x28e4('0x6c')](_0x251bf2,_0x4fbc23);break;case'User':if(_0x3338bf['operator']===_0x28e4('0x63')){_0x2b5c71[_0x3c7532]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0x3338bf[_0x28e4('0x5e')]+'%',null);}else{_0x496a5b=_['find'](_0x558972,[_0x28e4('0x2d'),_0x28e4('0x6d')]);_0x3338bf[_0x28e4('0x45')]=_0x28e4('0x6d');_0x4e39a8=as[_0x28e4('0x68')](_0x1b81f5,_0x496a5b[_0x28e4('0x36')],_0x3338bf);_0x2b5c71[_0x3c7532](_0x4e39a8[_0x28e4('0x69')],_0x4e39a8[_0x28e4('0x5e')][_0x28e4('0x6a')],_0x4e39a8[_0x28e4('0x5e')][_0x28e4('0x1f')]);}break;case _0x28e4('0x6e'):_0x4e39a8=as[_0x28e4('0x68')]('me',null,_0x3338bf);_0x2b5c71[_0x3c7532](_0x4e39a8[_0x28e4('0x69')],_0x4e39a8[_0x28e4('0x5e')][_0x28e4('0x6a')],_0x4e39a8[_0x28e4('0x5e')][_0x28e4('0x1f')]);break;}}else{var _0x4e39a8=as[_0x28e4('0x68')](_0x1b81f5,_0x496a5b[_0x28e4('0x36')],_0x3338bf);_0x2b5c71[_0x3c7532](_0x4e39a8['text'],_0x4e39a8['value'][_0x28e4('0x6a')],_0x4e39a8[_0x28e4('0x5e')][_0x28e4('0x1f')]);}}}else{var _0x18b752=_(_0x3c958a[_0x28e4('0x39')])[_0x28e4('0x3a')]()[_0x28e4('0x2f')](function(_0xf8c3e7){return _[_0x28e4('0x6f')](_0x558972,['name',_0xf8c3e7])?_0xf8c3e7:undefined;})[_0x28e4('0x70')]()[_0x28e4('0x5e')]();if(!_[_0x28e4('0x71')](_0x18b752)){_0x18b752[_0x28e4('0x32')](function(_0x34696f){if(_0x34696f===_0x28e4('0x72')){_0x6db1cd[_0x28e4('0x73')]('i.FaxAccountId\x20IN\x20?',[][_0x28e4('0x74')](_0x3c958a[_0x28e4('0x39')][_0x34696f]));}else if(_0x34696f==='createdAt'){var _0x5f544b=JSON[_0x28e4('0x75')](_0x3c958a[_0x28e4('0x39')][_0x34696f])[_0x28e4('0x76')];var _0x3dd167=JSON[_0x28e4('0x75')](_0x3c958a['query'][_0x34696f])['$lte'];_0x6db1cd[_0x28e4('0x73')]('i.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x5f544b,_0x3dd167);}else{if(_0x3c958a[_0x28e4('0x39')][_0x34696f]===_0x28e4('0x77')){_0x6db1cd[_0x28e4('0x73')]('i.'+_0x34696f+_0x28e4('0x78'));}else{_0x6db1cd[_0x28e4('0x73')]('i.'+_0x34696f+'\x20=\x20?',_0x3c958a[_0x28e4('0x39')][_0x34696f]);}}});}if(_0x3c958a[_0x28e4('0x39')][_0x28e4('0x79')]){if(_0x3c958a[_0x28e4('0x39')][_0x28e4('0x79')]==0x1){_0x6db1cd['having'](_0x28e4('0x7a'));}else{_0x6db1cd[_0x28e4('0x5f')](_0x28e4('0x7b'));}}if(_0x3c958a['query']['tag']){_0x251bf2=_[_0x28e4('0x7c')](_0x3c958a['query']['tag'])?_0x3c958a[_0x28e4('0x39')]['tag']:new Array(_0x3c958a[_0x28e4('0x39')]['tag']);_0x251bf2[_0x28e4('0x32')](function(_0x541b64){_0x3cbb7f['or'](_0x28e4('0x6b'),'%,'+_0x541b64+',%');});}if(_0x3c958a[_0x28e4('0x39')]['filter']){var _0x3432c0=_0x3c958a['query'][_0x28e4('0x7d')][_0x28e4('0x7e')]('\x5c','\x5c\x5c')[_0x28e4('0x7e')]('\x27\x27','\x27\x27\x27\x27');if(qs[_0x28e4('0x7f')](_0x3432c0)){_0x2b5c71['or'](_0x28e4('0x80'),_0x3432c0+'%')['or'](_0x28e4('0x81'),_0x3432c0+'%');}_0x2b5c71['or']('CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?',_0x3432c0+'%');}}_0x6db1cd[_0x28e4('0x73')](_0x2b5c71);_0x6db1cd[_0x28e4('0x82')]('i.id');var _0x26f168={'type':db['Sequelize'][_0x28e4('0x83')][_0x28e4('0x84')],'raw':!![]};var _0x3018ce=_0x6db1cd['clone']();_0x3018ce['field'](_0x28e4('0x85'));_0x3018ce[_0x28e4('0x45')](_0x28e4('0x86'),_0x28e4('0x5d'));if(_0x43c54c[_0x28e4('0x41')]){_0x43c54c['order'][_0x28e4('0x32')](function(_0x9d8f0f){_0x6db1cd[_0x28e4('0x41')]('i.'+_0x9d8f0f[0x0],_0x9d8f0f[0x1]===_0x28e4('0x87')?![]:!![]);});}if(!_[_0x28e4('0x71')](_0x251bf2)){_0x6db1cd[_0x28e4('0x5f')](_0x3cbb7f);_0x3018ce[_0x28e4('0x73')](_0x28e4('0x88'),_0x251bf2);}BPromise[_0x28e4('0x89')]()[_0x28e4('0x2b')](function(){if(!_0x1dd4d0){if(_0x3c958a['query'][_0x28e4('0x72')]||_0x3c958a[_0x28e4('0x39')][_0x28e4('0x8a')])return;_0x3018ce[_0x28e4('0x73')]('i.FaxAccountId\x20IS\x20NOT\x20NULL');_0x6db1cd['where']('i.FaxAccountId\x20IS\x20NOT\x20NULL');return;}return _0x3c958a[_0x28e4('0x8b')][_0x28e4('0x8c')]({'attributes':['id'],'raw':!![]})['then'](function(_0x1d9b06){if(_[_0x28e4('0x71')](_0x1d9b06)){_0x3018ce[_0x28e4('0x73')](_0x28e4('0x8d'));_0x6db1cd[_0x28e4('0x73')]('i.FaxAccountId\x20IS\x20NULL');}else{_0x3018ce[_0x28e4('0x73')](_0x28e4('0x8e'),_[_0x28e4('0x2f')](_0x1d9b06,'id'));_0x6db1cd[_0x28e4('0x73')](_0x28e4('0x8e'),_['map'](_0x1d9b06,'id'));}});})[_0x28e4('0x2b')](function(){db[_0x28e4('0x8f')][_0x28e4('0x39')](_0x3018ce[_0x28e4('0x90')](),_0x26f168)[_0x28e4('0x2b')](function(_0x5c170e){_0x44bbb6['count']=_0x5c170e[_0x28e4('0x3f')];if(_0x44bbb6[_0x28e4('0x22')]===0x0)return[];return db[_0x28e4('0x8f')]['query'](_0x862dbc[_0x28e4('0x90')](),_0x26f168)[_0x28e4('0x2b')](function(_0x5b126c){_0x5cdcb4=_[_0x28e4('0x91')](_0x5b126c,'id');_0x26f168=_['merge'](_0x26f168,{'model':db[_0x28e4('0x92')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x3c958a[_0x28e4('0x39')][_0x28e4('0x3e')]){_0x43c54c[_0x28e4('0x3d')][_0x28e4('0x32')](function(_0x527016){_0x6db1cd[_0x28e4('0x45')]('i.'+_0x527016);});}else{_0x6db1cd['field']('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x28e4('0x5d'));_0x6db1cd['field'](_0x28e4('0x93'),_0x28e4('0x94'));_0x6db1cd[_0x28e4('0x45')]('a.mandatoryDisposition','Account.mandatoryDisposition');_0x6db1cd['field']('i.*');_0x6db1cd[_0x28e4('0x45')](_0x28e4('0x95'),'Contact.firstName');_0x6db1cd[_0x28e4('0x45')](_0x28e4('0x96'),_0x28e4('0x97'));_0x6db1cd[_0x28e4('0x45')](_0x28e4('0x98'),'Contact.email');_0x6db1cd['field'](_0x28e4('0x99'),_0x28e4('0x9a'));_0x6db1cd[_0x28e4('0x45')]('c.mobile',_0x28e4('0x9b'));_0x6db1cd['field'](_0x28e4('0x9c'),'Contact.fax');_0x6db1cd[_0x28e4('0x45')](_0x28e4('0x9d'),_0x28e4('0x9e'));_0x6db1cd[_0x28e4('0x45')](_0x28e4('0x9f'),_0x28e4('0xa0'));_0x6db1cd['field'](_0x28e4('0xa1'),'TagIds');}_0x6db1cd[_0x28e4('0x24')](_0x43c54c[_0x28e4('0x24')]);_0x6db1cd[_0x28e4('0x23')](_0x43c54c[_0x28e4('0x23')]);return db[_0x28e4('0x8f')][_0x28e4('0x39')](_0x6db1cd['toString'](),_0x26f168);})[_0x28e4('0x2b')](function(_0x3bc6f0){_0x266238['where'](_0x28e4('0xa2'),_[_0x28e4('0x2f')](_0x3bc6f0,'id'));return db['sequelize'][_0x28e4('0x39')](_0x266238['toString'](),_0x26f168)[_0x28e4('0x2b')](function(_0x1b468c){var _0x10997a=_['groupBy'](_0x1b468c,_0x28e4('0xa3'));var _0x16a2bc=[];_0x3bc6f0[_0x28e4('0x32')](function(_0x252b37){_0x16a2bc[_0x28e4('0xa4')](updateFaxInteraction(_0x252b37,_0x5cdcb4,_0x10997a));});return BPromise[_0x28e4('0xa5')](_0x16a2bc);});});})['then'](function(_0x301abd){_0x44bbb6[_0x28e4('0xa6')]=_0x301abd;return _0x44bbb6;})[_0x28e4('0x2b')](respondWithFilteredResult(_0x5f34b5,_0x43c54c));})[_0x28e4('0x33')](handleError(_0x5f34b5,null));};exports['show']=function(_0x27888a,_0x134e1a){var _0x46986c={'raw':![],'where':{'id':_0x27888a[_0x28e4('0xa7')]['id']}},_0x2bd6c7={};_0x2bd6c7[_0x28e4('0x38')]=_[_0x28e4('0x3a')](db['FaxInteraction']['rawAttributes']);_0x2bd6c7['query']=_['keys'](_0x27888a[_0x28e4('0x39')]);_0x2bd6c7['filters']=_[_0x28e4('0x3c')](_0x2bd6c7[_0x28e4('0x38')],_0x2bd6c7[_0x28e4('0x39')]);_0x46986c[_0x28e4('0x3d')]=_['intersection'](_0x2bd6c7[_0x28e4('0x38')],qs[_0x28e4('0x3e')](_0x27888a['query'][_0x28e4('0x3e')]));_0x46986c['attributes']=_0x46986c[_0x28e4('0x3d')][_0x28e4('0x3f')]?_0x46986c[_0x28e4('0x3d')]:_0x2bd6c7[_0x28e4('0x38')];if(_0x27888a[_0x28e4('0x39')][_0x28e4('0xa8')]){_0x46986c[_0x28e4('0xa9')]=[{'all':!![]}];}_0x46986c=_[_0x28e4('0xaa')]({},_0x46986c,_0x27888a['options']);return db[_0x28e4('0x92')][_0x28e4('0x5c')](_0x46986c)[_0x28e4('0x2b')](handleEntityNotFound(_0x134e1a,null))[_0x28e4('0x2b')](respondWithResult(_0x134e1a,null))[_0x28e4('0x33')](handleError(_0x134e1a,null));};exports[_0x28e4('0xab')]=function(_0x3b3f91,_0x30a531){return db[_0x28e4('0x92')]['create'](_0x3b3f91[_0x28e4('0x6e')],{})[_0x28e4('0x2b')](respondWithResult(_0x30a531,0xc9))['catch'](handleError(_0x30a531,null));};exports[_0x28e4('0x29')]=function(_0x3f7d0c,_0x2a6a21){if(_0x3f7d0c['body']['id']){delete _0x3f7d0c[_0x28e4('0x6e')]['id'];}return db[_0x28e4('0x92')][_0x28e4('0x5c')]({'where':{'id':_0x3f7d0c[_0x28e4('0xa7')]['id']}})[_0x28e4('0x2b')](handleEntityNotFound(_0x2a6a21,null))[_0x28e4('0x2b')](saveUpdates(_0x3f7d0c[_0x28e4('0x6e')],null))[_0x28e4('0x2b')](respondWithResult(_0x2a6a21,null))[_0x28e4('0x33')](handleError(_0x2a6a21,null));};exports[_0x28e4('0x2a')]=function(_0x4ffb15,_0xe7b92d){return db[_0x28e4('0x92')][_0x28e4('0x5c')]({'where':{'id':_0x4ffb15[_0x28e4('0xa7')]['id']}})['then'](handleEntityNotFound(_0xe7b92d,null))[_0x28e4('0x2b')](removeEntity(_0xe7b92d,null))[_0x28e4('0x33')](handleError(_0xe7b92d,null));};exports[_0x28e4('0xac')]=function(_0x7389c0,_0x3d54da){return db[_0x28e4('0x92')][_0x28e4('0xac')]()[_0x28e4('0x2b')](respondWithResult(_0x3d54da,null))['catch'](handleError(_0x3d54da,null));};exports[_0x28e4('0xad')]=function(_0x575a09,_0x26bd82,_0xb9d4bd){return db[_0x28e4('0xae')][_0x28e4('0x5c')]({'where':{'id':_0x575a09[_0x28e4('0xa7')]['id']}})['then'](handleEntityNotFound(_0x26bd82,null))['then'](function(_0x291ff7){if(_0x291ff7){return _0x291ff7[_0x28e4('0xad')](_0x575a09[_0x28e4('0x6e')][_0x28e4('0xaf')],_[_0x28e4('0xb0')](_0x575a09['body'],[_0x28e4('0xaf'),'id'])||{});}})['then'](respondWithResult(_0x26bd82,null))['catch'](handleError(_0x26bd82,null));};exports[_0x28e4('0xb1')]=function(_0x4edd67,_0x319703,_0x1be9ab){var _0x41c325={'raw':![],'where':{}};var _0x1b5f8f={};var _0x5afe43={'count':0x0,'rows':[]};return db[_0x28e4('0x92')][_0x28e4('0xb2')]({'where':{'id':_0x4edd67[_0x28e4('0xa7')]['id']}})['then'](handleEntityNotFound(_0x319703,null))['then'](function(_0x41a176){if(_0x41a176){_0x1b5f8f['model']=_[_0x28e4('0x3a')](db[_0x28e4('0xae')][_0x28e4('0xb3')]);_0x1b5f8f['query']=_[_0x28e4('0x3a')](_0x4edd67[_0x28e4('0x39')]);_0x1b5f8f['filters']=_[_0x28e4('0x3c')](_0x1b5f8f[_0x28e4('0x38')],_0x1b5f8f[_0x28e4('0x39')]);_0x41c325[_0x28e4('0x3d')]=_['intersection'](_0x1b5f8f[_0x28e4('0x38')],qs[_0x28e4('0x3e')](_0x4edd67[_0x28e4('0x39')][_0x28e4('0x3e')]));_0x41c325[_0x28e4('0x3d')]=_0x41c325[_0x28e4('0x3d')]['length']?_0x41c325[_0x28e4('0x3d')]:_0x1b5f8f[_0x28e4('0x38')];if(!_0x4edd67[_0x28e4('0x39')]['hasOwnProperty'](_0x28e4('0x40'))){_0x41c325[_0x28e4('0x24')]=qs['limit'](_0x4edd67['query'][_0x28e4('0x24')]);_0x41c325[_0x28e4('0x23')]=qs['offset'](_0x4edd67[_0x28e4('0x39')][_0x28e4('0x23')]);}_0x41c325['order']=qs['sort'](_0x4edd67[_0x28e4('0x39')][_0x28e4('0x42')]);_0x41c325[_0x28e4('0x73')]=qs[_0x28e4('0x3b')](_['pick'](_0x4edd67['query'],_0x1b5f8f[_0x28e4('0x3b')]));_0x41c325[_0x28e4('0x73')][_0x28e4('0xa3')]=_0x41a176['id'];if(_0x4edd67[_0x28e4('0x39')][_0x28e4('0x7d')]){_0x41c325[_0x28e4('0x73')]=_[_0x28e4('0xaa')](_0x41c325['where'],{'$or':_['map'](_0x41c325[_0x28e4('0x3d')],function(_0x5c7d0b){var _0x2a8274={};_0x2a8274[_0x5c7d0b]={'$like':'%'+_0x4edd67[_0x28e4('0x39')]['filter']+'%'};return _0x2a8274;})});}if(_0x4edd67['query']['$gte']){var _0x38a2fc=_0x4edd67['query'][_0x28e4('0x76')][_0x28e4('0xb4')](',');var _0x324fcc={};_0x324fcc[_0x38a2fc[0x0]]={'$gte':moment(_0x38a2fc[0x1])['format'](_0x28e4('0xb5'))};_0x41c325[_0x28e4('0x73')]=_[_0x28e4('0xaa')](_0x41c325['where'],_0x324fcc);}_0x41c325=_[_0x28e4('0xaa')]({},_0x41c325,_0x4edd67[_0x28e4('0xb6')]);return db['FaxMessage'][_0x28e4('0x22')]({'where':_0x41c325[_0x28e4('0x73')]})[_0x28e4('0x2b')](function(_0x319526){_0x5afe43[_0x28e4('0x22')]=_0x319526;if(_0x4edd67[_0x28e4('0x39')][_0x28e4('0xa8')]){_0x41c325['include']=[{'all':!![]}];}return db['FaxMessage'][_0x28e4('0xb7')](_0x41c325);})[_0x28e4('0x2b')](function(_0x2b949d){_0x5afe43[_0x28e4('0xa6')]=_0x2b949d;return _0x5afe43;});}})['then'](respondWithFilteredResult(_0x319703,_0x41c325))[_0x28e4('0x33')](handleError(_0x319703,null));};exports['addTags']=function(_0x1825bd,_0x2395c7,_0x5b968b){return db['FaxInteraction']['find']({'where':{'id':_0x1825bd[_0x28e4('0xa7')]['id']}})['then'](handleEntityNotFound(_0x2395c7,null))[_0x28e4('0x2b')](function(_0x316792){if(_0x316792){return _0x316792[_0x28e4('0xb8')](_0x1825bd['body'][_0x28e4('0xaf')],_[_0x28e4('0xb0')](_0x1825bd[_0x28e4('0x6e')],[_0x28e4('0xaf'),'id'])||{})[_0x28e4('0xb9')](function(){return db['Tag'][_0x28e4('0xb7')]({'attributes':['id','name','color'],'where':{'id':_0x1825bd[_0x28e4('0x6e')]['ids']}});})[_0x28e4('0x2b')](function(_0x244d90){socket[_0x28e4('0xba')](_0x28e4('0xbb'),{'id':Number(_0x1825bd[_0x28e4('0xa7')]['id']),'tags':_0x244d90||[]});return{'id':Number(_0x1825bd['params']['id']),'tags':_0x244d90||[]};});}})[_0x28e4('0x2b')](respondWithResult(_0x2395c7,null))[_0x28e4('0x33')](handleError(_0x2395c7,null));};exports[_0x28e4('0xbc')]=function(_0xd7a7b8,_0x2def10,_0x334ab6){return db['FaxInteraction'][_0x28e4('0x5c')]({'where':{'id':_0xd7a7b8[_0x28e4('0xa7')]['id']}})['then'](handleEntityNotFound(_0x2def10,null))['then'](function(_0x29ec8f){if(_0x29ec8f){return _0x29ec8f[_0x28e4('0xbc')](_0xd7a7b8[_0x28e4('0x39')][_0x28e4('0xaf')]);}})['then'](respondWithStatusCode(_0x2def10,null))[_0x28e4('0x33')](handleError(_0x2def10,null));};exports[_0x28e4('0xbd')]=function(_0x345c59,_0x1a9c94){var _0x1c24ee=moment()[_0x28e4('0xbe')]()[_0x28e4('0x90')]();var _0x37b4c2=path[_0x28e4('0xbf')](config['root'],_0x28e4('0xc0'),_0x28e4('0xc1'),'tmp');var _0x481aaf=path['join'](config['root'],_0x28e4('0xc0'),_0x28e4('0xc1'),_0x28e4('0xc2'));var _0x273fb7=path['join'](_0x37b4c2,_0x1c24ee);var _0x3eae49=util[_0x28e4('0xc3')](_0x28e4('0xc4'),_0x345c59['params']['id'],_0x1c24ee);var _0x37acab=path[_0x28e4('0xbf')](_0x37b4c2,_0x3eae49);var _0x447bb0=[];_0x447bb0[_0x28e4('0xa4')]({'model':db['Attachment'],'as':'Attachment','raw':!![]});var _0x2bf058=[{'model':db[_0x28e4('0xae')],'as':'Messages','attributes':['id',_0x28e4('0x6e'),_0x28e4('0xc5')],'include':_0x447bb0}];return db[_0x28e4('0x92')]['find']({'where':{'id':_0x345c59[_0x28e4('0xa7')]['id']},'include':_0x2bf058})[_0x28e4('0x2b')](handleEntityNotFound(_0x1a9c94,null))['then'](function(_0x53bbfa){if(_0x53bbfa&&_0x53bbfa[_0x28e4('0xc6')]){var _0x43cb21=_0x53bbfa[_0x28e4('0xc7')]({'plain':!![]});fs[_0x28e4('0xc8')](_0x273fb7);for(var _0x358375=0x0;_0x358375<_0x43cb21['Messages']['length'];_0x358375++){var _0x5df7fe=_0x43cb21[_0x28e4('0xc6')][_0x358375]['Attachment'];if(_0x5df7fe){var _0x38d33d=path[_0x28e4('0xbf')](_0x481aaf,_0x5df7fe['basename']);if(fs[_0x28e4('0xc9')](_0x38d33d)){fs[_0x28e4('0xca')](_0x38d33d)[_0x28e4('0xcb')](fs[_0x28e4('0xcc')](path['join'](_0x273fb7,_0x5df7fe[_0x28e4('0xcd')])));}}}return BPromise['resolve']()[_0x28e4('0x2b')](function(){return new BPromise(function(_0x3cbe1a,_0x562cdd){zipdir(_0x273fb7,{'saveTo':_0x37acab},function(_0x366d4b,_0x40b8f3){if(_0x366d4b)return _0x562cdd(_0x366d4b);return _0x3cbe1a(_0x40b8f3);});})[_0x28e4('0x2b')](function(){return new BPromise(function(_0x54f829,_0xeceb75){rimraf(_0x273fb7,function(_0x47a754){if(_0x47a754)_0xeceb75(_0x47a754);return _0x54f829();});});})[_0x28e4('0x2b')](function(){return _0x1a9c94[_0x28e4('0xbd')](_0x37acab,_0x3eae49,function(_0x429af9){if(_0x429af9){console[_0x28e4('0xce')](_0x28e4('0xcf'),_0x429af9);}else{fs[_0x28e4('0xd0')](_0x37acab);}});});});}else{return _0x1a9c94[_0x28e4('0x1e')](0xc8);}})[_0x28e4('0x33')](handleError(_0x1a9c94,null));};
\ No newline at end of file
+var _0x6de9=['json','offset','undefined','limit','count','Content-Range','update','then','end','error','stack','name','send','index','map','FaxInteraction','rawAttributes','fieldName','type','key','getOptions','findAll','query','user','show','params','model','keys','filters','intersection','attributes','fields','length','include','merge','options','find','catch','create','body','destroy','describe','FaxMessage','addMessage','ids','omit','getMessages','findOne','nolimit','order','sort','where','FaxInteractionId','filter','$gte','format','YYYY-MM-DD\x20HH:mm:ss','includeAll','rows','addTags','Tag','emit','faxInteractionTags:save','removeTags','download','unix','toString','join','root','server','files','tmp','transcript-%d-%s.zip','push','Attachment','Messages','createdAt','get','mkdirSync','basename','existsSync','pipe','createWriteStream','log','err','unlinkSync','rimraf','zip-dir','bluebird','util','path','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../config/logger','api','../../config/environment','redis','defaults','localhost','socket.io-emitter','./faxInteraction.socket','sendStatus','status'];(function(_0x22e679,_0x39a6c5){var _0x3b793b=function(_0x25f580){while(--_0x25f580){_0x22e679['push'](_0x22e679['shift']());}};_0x3b793b(++_0x39a6c5);}(_0x6de9,0x191));var _0x96de=function(_0x618414,_0x1a7a60){_0x618414=_0x618414-0x0;var _0x21c19a=_0x6de9[_0x618414];return _0x21c19a;};'use strict';var rimraf=require(_0x96de('0x0'));var zipdir=require(_0x96de('0x1'));var moment=require('moment');var BPromise=require(_0x96de('0x2'));var util=require(_0x96de('0x3'));var path=require(_0x96de('0x4'));var fs=require('fs');var _=require(_0x96de('0x5'));var Redis=require(_0x96de('0x6'));var interaction=require(_0x96de('0x7'));var qs=require(_0x96de('0x8'));var logger=require(_0x96de('0x9'))(_0x96de('0xa'));var config=require(_0x96de('0xb'));var db=require('../../mysqldb')['db'];config[_0x96de('0xc')]=_[_0x96de('0xd')](config['redis'],{'host':_0x96de('0xe'),'port':0x18eb});var socket=require(_0x96de('0xf'))(new Redis(config[_0x96de('0xc')]));require(_0x96de('0x10'))['register'](socket);function respondWithStatusCode(_0x219079,_0x2f048d){_0x2f048d=_0x2f048d||0xcc;return function(_0x5191b8){if(_0x5191b8){return _0x219079[_0x96de('0x11')](_0x2f048d);}return _0x219079[_0x96de('0x12')](_0x2f048d)['end']();};}function respondWithResult(_0xab73f3,_0x3de513){_0x3de513=_0x3de513||0xc8;return function(_0x5dc791){if(_0x5dc791){return _0xab73f3['status'](_0x3de513)[_0x96de('0x13')](_0x5dc791);}};}function respondWithFilteredResult(_0x4dccde,_0x52454f){return function(_0x18a49f){if(_0x18a49f){var _0xf21fb4=typeof _0x52454f[_0x96de('0x14')]===_0x96de('0x15')&&typeof _0x52454f[_0x96de('0x16')]===_0x96de('0x15');var _0x47980f=_0x18a49f[_0x96de('0x17')];var _0x13efc5=_0xf21fb4?0x0:_0x52454f[_0x96de('0x14')];var _0x3042d1=_0xf21fb4?_0x18a49f[_0x96de('0x17')]:_0x52454f[_0x96de('0x14')]+_0x52454f[_0x96de('0x16')];var _0x84390a;if(_0x3042d1>=_0x47980f){_0x3042d1=_0x47980f;_0x84390a=0xc8;}else{_0x84390a=0xce;}_0x4dccde['status'](_0x84390a);return _0x4dccde['set'](_0x96de('0x18'),_0x13efc5+'-'+_0x3042d1+'/'+_0x47980f)[_0x96de('0x13')](_0x18a49f);}return null;};}function saveUpdates(_0x47966c){return function(_0x48de62){if(_0x48de62){return _0x48de62[_0x96de('0x19')](_0x47966c)[_0x96de('0x1a')](function(_0x22cc47){return _0x22cc47;});}return null;};}function removeEntity(_0x2a3d13){return function(_0x10465a){if(_0x10465a){return _0x10465a['destroy']()['then'](function(){_0x2a3d13[_0x96de('0x12')](0xcc)[_0x96de('0x1b')]();});}};}function handleEntityNotFound(_0x443265){return function(_0x3674a2){if(!_0x3674a2){_0x443265['sendStatus'](0x194);}return _0x3674a2;};}function handleError(_0x420f85,_0x520fe4){_0x520fe4=_0x520fe4||0x1f4;return function(_0x36a7c6){logger[_0x96de('0x1c')](_0x36a7c6[_0x96de('0x1d')]);if(_0x36a7c6['name']){delete _0x36a7c6[_0x96de('0x1e')];}_0x420f85[_0x96de('0x12')](_0x520fe4)[_0x96de('0x1f')](_0x36a7c6);};}exports[_0x96de('0x20')]=function(_0x2da196,_0x4e9b9d){var _0x4b8eb9={};var _0xf0074=_[_0x96de('0x21')](db[_0x96de('0x22')][_0x96de('0x23')],function(_0x1ead38){return{'name':_0x1ead38[_0x96de('0x24')],'type':_0x1ead38[_0x96de('0x25')][_0x96de('0x26')]};});_0x4b8eb9=qs[_0x96de('0x27')](_0xf0074,_0x2da196);return interaction[_0x96de('0x28')]('fax',_0x2da196[_0x96de('0x29')],_0x2da196[_0x96de('0x2a')],_0x4b8eb9,_0xf0074)[_0x96de('0x1a')](respondWithFilteredResult(_0x4e9b9d,_0x4b8eb9))['catch'](handleError(_0x4e9b9d,null));};exports[_0x96de('0x2b')]=function(_0x2b4eac,_0x279d53){var _0x257859={'raw':![],'where':{'id':_0x2b4eac[_0x96de('0x2c')]['id']}},_0xc3f37f={};_0xc3f37f[_0x96de('0x2d')]=_[_0x96de('0x2e')](db['FaxInteraction'][_0x96de('0x23')]);_0xc3f37f[_0x96de('0x29')]=_[_0x96de('0x2e')](_0x2b4eac['query']);_0xc3f37f[_0x96de('0x2f')]=_[_0x96de('0x30')](_0xc3f37f[_0x96de('0x2d')],_0xc3f37f['query']);_0x257859[_0x96de('0x31')]=_[_0x96de('0x30')](_0xc3f37f[_0x96de('0x2d')],qs[_0x96de('0x32')](_0x2b4eac[_0x96de('0x29')][_0x96de('0x32')]));_0x257859[_0x96de('0x31')]=_0x257859[_0x96de('0x31')][_0x96de('0x33')]?_0x257859[_0x96de('0x31')]:_0xc3f37f[_0x96de('0x2d')];if(_0x2b4eac[_0x96de('0x29')]['includeAll']){_0x257859[_0x96de('0x34')]=[{'all':!![]}];}_0x257859=_[_0x96de('0x35')]({},_0x257859,_0x2b4eac[_0x96de('0x36')]);return db[_0x96de('0x22')][_0x96de('0x37')](_0x257859)['then'](handleEntityNotFound(_0x279d53,null))[_0x96de('0x1a')](respondWithResult(_0x279d53,null))[_0x96de('0x38')](handleError(_0x279d53,null));};exports['create']=function(_0x29ac66,_0x33ee3a){return db[_0x96de('0x22')][_0x96de('0x39')](_0x29ac66[_0x96de('0x3a')],{})['then'](respondWithResult(_0x33ee3a,0xc9))[_0x96de('0x38')](handleError(_0x33ee3a,null));};exports[_0x96de('0x19')]=function(_0x3e3cfd,_0x304198){if(_0x3e3cfd['body']['id']){delete _0x3e3cfd[_0x96de('0x3a')]['id'];}return db[_0x96de('0x22')][_0x96de('0x37')]({'where':{'id':_0x3e3cfd[_0x96de('0x2c')]['id']}})[_0x96de('0x1a')](handleEntityNotFound(_0x304198,null))['then'](saveUpdates(_0x3e3cfd[_0x96de('0x3a')],null))[_0x96de('0x1a')](respondWithResult(_0x304198,null))['catch'](handleError(_0x304198,null));};exports[_0x96de('0x3b')]=function(_0x35a2f4,_0xb02711){return db[_0x96de('0x22')][_0x96de('0x37')]({'where':{'id':_0x35a2f4[_0x96de('0x2c')]['id']}})['then'](handleEntityNotFound(_0xb02711,null))[_0x96de('0x1a')](removeEntity(_0xb02711,null))[_0x96de('0x38')](handleError(_0xb02711,null));};exports['describe']=function(_0x3b5ac5,_0x472988){return db[_0x96de('0x22')][_0x96de('0x3c')]()[_0x96de('0x1a')](respondWithResult(_0x472988,null))[_0x96de('0x38')](handleError(_0x472988,null));};exports['addMessage']=function(_0x24963b,_0x53c85c){return db[_0x96de('0x3d')][_0x96de('0x37')]({'where':{'id':_0x24963b[_0x96de('0x2c')]['id']}})['then'](handleEntityNotFound(_0x53c85c,null))[_0x96de('0x1a')](function(_0x5124dd){if(_0x5124dd){return _0x5124dd[_0x96de('0x3e')](_0x24963b[_0x96de('0x3a')][_0x96de('0x3f')],_[_0x96de('0x40')](_0x24963b[_0x96de('0x3a')],[_0x96de('0x3f'),'id'])||{});}})[_0x96de('0x1a')](respondWithResult(_0x53c85c,null))['catch'](handleError(_0x53c85c,null));};exports[_0x96de('0x41')]=function(_0x485bc6,_0xf871fc){var _0x3e2f6b={'raw':![],'where':{}};var _0x4a5c12={};var _0x1cfda3={'count':0x0,'rows':[]};return db['FaxInteraction'][_0x96de('0x42')]({'where':{'id':_0x485bc6['params']['id']}})[_0x96de('0x1a')](handleEntityNotFound(_0xf871fc,null))['then'](function(_0x2c4b2a){if(_0x2c4b2a){_0x4a5c12[_0x96de('0x2d')]=_[_0x96de('0x2e')](db[_0x96de('0x3d')][_0x96de('0x23')]);_0x4a5c12[_0x96de('0x29')]=_[_0x96de('0x2e')](_0x485bc6[_0x96de('0x29')]);_0x4a5c12[_0x96de('0x2f')]=_[_0x96de('0x30')](_0x4a5c12[_0x96de('0x2d')],_0x4a5c12[_0x96de('0x29')]);_0x3e2f6b[_0x96de('0x31')]=_[_0x96de('0x30')](_0x4a5c12[_0x96de('0x2d')],qs['fields'](_0x485bc6[_0x96de('0x29')]['fields']));_0x3e2f6b['attributes']=_0x3e2f6b['attributes'][_0x96de('0x33')]?_0x3e2f6b[_0x96de('0x31')]:_0x4a5c12[_0x96de('0x2d')];if(!_0x485bc6[_0x96de('0x29')]['hasOwnProperty'](_0x96de('0x43'))){_0x3e2f6b[_0x96de('0x16')]=qs[_0x96de('0x16')](_0x485bc6[_0x96de('0x29')]['limit']);_0x3e2f6b['offset']=qs[_0x96de('0x14')](_0x485bc6[_0x96de('0x29')][_0x96de('0x14')]);}_0x3e2f6b[_0x96de('0x44')]=qs['sort'](_0x485bc6[_0x96de('0x29')][_0x96de('0x45')]);_0x3e2f6b['where']=qs[_0x96de('0x2f')](_['pick'](_0x485bc6[_0x96de('0x29')],_0x4a5c12[_0x96de('0x2f')]));_0x3e2f6b[_0x96de('0x46')][_0x96de('0x47')]=_0x2c4b2a['id'];if(_0x485bc6[_0x96de('0x29')][_0x96de('0x48')]){_0x3e2f6b[_0x96de('0x46')]=_[_0x96de('0x35')](_0x3e2f6b[_0x96de('0x46')],{'$or':_[_0x96de('0x21')](_0x3e2f6b[_0x96de('0x31')],function(_0x8120e1){var _0x2c1ea6={};_0x2c1ea6[_0x8120e1]={'$like':'%'+_0x485bc6[_0x96de('0x29')][_0x96de('0x48')]+'%'};return _0x2c1ea6;})});}if(_0x485bc6[_0x96de('0x29')][_0x96de('0x49')]){var _0x53ec75=_0x485bc6['query'][_0x96de('0x49')]['split'](',');var _0x1b76eb={};_0x1b76eb[_0x53ec75[0x0]]={'$gte':moment(_0x53ec75[0x1])[_0x96de('0x4a')](_0x96de('0x4b'))};_0x3e2f6b['where']=_[_0x96de('0x35')](_0x3e2f6b[_0x96de('0x46')],_0x1b76eb);}_0x3e2f6b=_[_0x96de('0x35')]({},_0x3e2f6b,_0x485bc6[_0x96de('0x36')]);return db['FaxMessage'][_0x96de('0x17')]({'where':_0x3e2f6b[_0x96de('0x46')]})[_0x96de('0x1a')](function(_0x144d79){_0x1cfda3['count']=_0x144d79;if(_0x485bc6['query'][_0x96de('0x4c')]){_0x3e2f6b['include']=[{'all':!![]}];}return db[_0x96de('0x3d')][_0x96de('0x28')](_0x3e2f6b);})[_0x96de('0x1a')](function(_0x5068f2){_0x1cfda3[_0x96de('0x4d')]=_0x5068f2;return _0x1cfda3;});}})['then'](respondWithFilteredResult(_0xf871fc,_0x3e2f6b))['catch'](handleError(_0xf871fc,null));};exports[_0x96de('0x4e')]=function(_0x4e584d,_0x49b650){return db[_0x96de('0x22')]['find']({'where':{'id':_0x4e584d[_0x96de('0x2c')]['id']}})[_0x96de('0x1a')](handleEntityNotFound(_0x49b650,null))[_0x96de('0x1a')](function(_0x1a59c1){if(_0x1a59c1){return _0x1a59c1['setTags'](_0x4e584d[_0x96de('0x3a')][_0x96de('0x3f')],_[_0x96de('0x40')](_0x4e584d[_0x96de('0x3a')],['ids','id'])||{})['spread'](function(){return db[_0x96de('0x4f')][_0x96de('0x28')]({'attributes':['id',_0x96de('0x1e'),'color'],'where':{'id':_0x4e584d[_0x96de('0x3a')][_0x96de('0x3f')]}});})[_0x96de('0x1a')](function(_0x5bc07a){socket[_0x96de('0x50')](_0x96de('0x51'),{'id':Number(_0x4e584d[_0x96de('0x2c')]['id']),'tags':_0x5bc07a||[]});return{'id':Number(_0x4e584d[_0x96de('0x2c')]['id']),'tags':_0x5bc07a||[]};});}})['then'](respondWithResult(_0x49b650,null))[_0x96de('0x38')](handleError(_0x49b650,null));};exports[_0x96de('0x52')]=function(_0x8f260f,_0x57f675){return db['FaxInteraction'][_0x96de('0x37')]({'where':{'id':_0x8f260f['params']['id']}})[_0x96de('0x1a')](handleEntityNotFound(_0x57f675,null))['then'](function(_0x5602a3){if(_0x5602a3){return _0x5602a3[_0x96de('0x52')](_0x8f260f[_0x96de('0x29')][_0x96de('0x3f')]);}})[_0x96de('0x1a')](respondWithStatusCode(_0x57f675,null))['catch'](handleError(_0x57f675,null));};exports[_0x96de('0x53')]=function(_0x4ca14a,_0x27a81a){var _0x2b7a07=moment()[_0x96de('0x54')]()[_0x96de('0x55')]();var _0x3724fc=path[_0x96de('0x56')](config[_0x96de('0x57')],_0x96de('0x58'),_0x96de('0x59'),_0x96de('0x5a'));var _0xf2690d=path[_0x96de('0x56')](config['root'],'server',_0x96de('0x59'),'attachments');var _0x1fd7b8=path[_0x96de('0x56')](_0x3724fc,_0x2b7a07);var _0x60dc6b=util[_0x96de('0x4a')](_0x96de('0x5b'),_0x4ca14a[_0x96de('0x2c')]['id'],_0x2b7a07);var _0x3ceb48=path[_0x96de('0x56')](_0x3724fc,_0x60dc6b);var _0x505ffe=[];_0x505ffe[_0x96de('0x5c')]({'model':db[_0x96de('0x5d')],'as':_0x96de('0x5d'),'raw':!![]});var _0x3cff7b=[{'model':db[_0x96de('0x3d')],'as':_0x96de('0x5e'),'attributes':['id',_0x96de('0x3a'),_0x96de('0x5f')],'include':_0x505ffe}];return db['FaxInteraction'][_0x96de('0x37')]({'where':{'id':_0x4ca14a['params']['id']},'include':_0x3cff7b})[_0x96de('0x1a')](handleEntityNotFound(_0x27a81a,null))[_0x96de('0x1a')](function(_0x3d4983){if(_0x3d4983&&_0x3d4983['Messages']){var _0x4742e2=_0x3d4983[_0x96de('0x60')]({'plain':!![]});fs[_0x96de('0x61')](_0x1fd7b8);for(var _0x5bca7c=0x0;_0x5bca7c<_0x4742e2[_0x96de('0x5e')][_0x96de('0x33')];_0x5bca7c++){var _0x2d38f8=_0x4742e2[_0x96de('0x5e')][_0x5bca7c]['Attachment'];if(_0x2d38f8){var _0x2e76dc=path[_0x96de('0x56')](_0xf2690d,_0x2d38f8[_0x96de('0x62')]);if(fs[_0x96de('0x63')](_0x2e76dc)){fs['createReadStream'](_0x2e76dc)[_0x96de('0x64')](fs[_0x96de('0x65')](path[_0x96de('0x56')](_0x1fd7b8,_0x2d38f8[_0x96de('0x62')])));}}}return BPromise['resolve']()[_0x96de('0x1a')](function(){return new BPromise(function(_0x54c447,_0x5daa10){zipdir(_0x1fd7b8,{'saveTo':_0x3ceb48},function(_0x22d208,_0x4f0b47){if(_0x22d208)return _0x5daa10(_0x22d208);return _0x54c447(_0x4f0b47);});})[_0x96de('0x1a')](function(){return new BPromise(function(_0x4ffba6,_0x4d3521){rimraf(_0x1fd7b8,function(_0x240b9f){if(_0x240b9f)_0x4d3521(_0x240b9f);return _0x4ffba6();});});})['then'](function(){return _0x27a81a['download'](_0x3ceb48,_0x60dc6b,function(_0x2ceb19){if(_0x2ceb19){console[_0x96de('0x66')](_0x96de('0x67'),_0x2ceb19);}else{fs[_0x96de('0x68')](_0x3ceb48);}});});});}else{return _0x27a81a[_0x96de('0x11')](0xc8);}})['catch'](handleError(_0x27a81a,null));};
\ No newline at end of file