Built motion from commit d1eab355.|2.6.28
[motion2.git] / server / components / interaction / sql-utils.js
index 553c96a..bfcc05e 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x24cd=['\x20=\x20i.id','it.','t.id\x20=\x20it.TagId','expr','getSelectedTags','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','unreadMessages\x20{OPERATOR}\x200','replace','{OPERATOR}','isNumeric','whatsapp','includes','i.phone\x20LIKE\x20?','fax','openchannel','i.from\x20LIKE\x20?','mail','isEmail','c.email\x20LIKE\x20?','MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','parseSearch','conditions','find','name','buildExpression','default','text','start','value','end','read','$substring','contact','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','type','Tag','tags','clause','User','user','UserId','body','keys','some','compact','forEach','concat','$gte','parse','$lte','and','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','resolve','then','tag','filter','get','capitalize','chat','Websites','Accounts','\x20IS\x20NOT\x20NULL','i.secondDisposition','i.disposition','unshift','i.substatus','closed','shift','Sequelize','QueryTypes','SELECT','sequelize','toString','keyBy','merge','fields','attributes','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','a.email','Account.email','CASE\x20WHEN\x20i.to\x20IS\x20NOT\x20NULL\x20AND\x20i.to\x20<>\x20\x27\x27\x20AND\x20i.to\x20NOT\x20LIKE\x20CONCAT(\x27%\x27,\x20a.email,\x20\x27%\x27)\x20THEN\x20TRIM(SUBSTRING_INDEX(i.to,\x20\x27<\x27,\x201))\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.updatedAt','i.closed','i.closedAt','i.lastMsgAt','i.lastMsgDirection','i.subject','i.to','i.ContactId','i.UserId','CASE\x20WHEN\x20i.from\x20IS\x20NOT\x20NULL\x20AND\x20i.from\x20<>\x20\x27\x27\x20THEN\x20i.from\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','CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','i.*','c.firstName','Contact.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.mobile','Contact.mobile','c.fax','Contact.fax','o.fullname','GROUP_CONCAT(DISTINCT\x20t.id)','TagIds','limit','offset','query','findOne','enableEmailPreview','all','clone','COUNT(*)','isEmpty','where','t.id\x20IN\x20?','exports','lodash','squel','../parsers/qs','updateInteraction','./utils','../../mysqldb','getAccountFK','role','agent','search','select','field','color','from','tools_tags','getInteractionFK','_interactions','u.id','u.fullname','ui.','left_join','u.id\x20=\x20ui.UserId','length','\x20IN\x20?','map','interactions','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','users','o.id\x20=\x20i.UserId','accounts','a.id\x20=\x20i.','messages','me.'];(function(_0x956671,_0x10d4b5){var _0x460fcd=function(_0x1ca84e){while(--_0x1ca84e){_0x956671['push'](_0x956671['shift']());}};_0x460fcd(++_0x10d4b5);}(_0x24cd,0x83));var _0xd24c=function(_0x62d78e,_0x1c719a){_0x62d78e=_0x62d78e-0x0;var _0x1f1b5a=_0x24cd[_0x62d78e];return _0x1f1b5a;};'use strict';var _=require(_0xd24c('0x0'));var squel=require(_0xd24c('0x1'));var as=require('../parsers/advancedSearch');var qs=require(_0xd24c('0x2'));var updateInteraction=require('./update-interaction')[_0xd24c('0x3')];var utils=require(_0xd24c('0x4'));var db=require(_0xd24c('0x5'))['db'];function skipInteractionsQuery(_0x4d515c,_0x21a58c,_0x32001a){var _0x47c9ea=![];var _0x1c30fc=utils[_0xd24c('0x6')](_0x4d515c);if(_0x21a58c[_0xd24c('0x7')]===_0xd24c('0x8')&&!_0x32001a[_0xd24c('0x9')]&&!_0x32001a[_0x1c30fc]){_0x47c9ea=!![];}return _0x47c9ea;}function getTagsQuery(){return squel[_0xd24c('0xa')]()[_0xd24c('0xb')]('id')[_0xd24c('0xb')]('name')['field'](_0xd24c('0xc'))[_0xd24c('0xd')](_0xd24c('0xe'));}function getUsersQuery(_0x43ab46,_0x225c20){var _0x1aa701=utils[_0xd24c('0xf')](_0x43ab46);var _0x453907='user_has_'+_0x43ab46+_0xd24c('0x10');var _0x5a7556=squel['select']()[_0xd24c('0xb')](_0xd24c('0x11'))[_0xd24c('0xb')](_0xd24c('0x12'))[_0xd24c('0xb')](_0xd24c('0x13')+_0x1aa701)[_0xd24c('0xd')](_0x453907,'ui')[_0xd24c('0x14')]('users','u',_0xd24c('0x15'));if(_0x225c20[_0xd24c('0x16')]>0x0){_0x5a7556['where'](_0xd24c('0x13')+_0x1aa701+_0xd24c('0x17'),_[_0xd24c('0x18')](_0x225c20,'id'));}return _0x5a7556;}function getInteractionsQuery(_0x3221a8){var _0x509992=utils['getInteractionsTables'](_0x3221a8);var _0xc87bb7=utils[_0xd24c('0x6')](_0x3221a8);var _0x170d59=utils['getInteractionFK'](_0x3221a8);return squel[_0xd24c('0xa')]()[_0xd24c('0xd')](_0x509992[_0xd24c('0x19')],'i')[_0xd24c('0x14')]('cm_contacts','c',_0xd24c('0x1a'))['left_join'](_0xd24c('0x1b'),'o',_0xd24c('0x1c'))[_0xd24c('0x14')](_0x509992[_0xd24c('0x1d')],'a',_0xd24c('0x1e')+_0xc87bb7)[_0xd24c('0x14')](_0x509992[_0xd24c('0x1f')],'me',_0xd24c('0x20')+_0x170d59+_0xd24c('0x21'))[_0xd24c('0x14')](_0x509992['interactionsTags'],'it',_0xd24c('0x22')+_0x170d59+_0xd24c('0x21'))[_0xd24c('0x14')]('tools_tags','t',_0xd24c('0x23'));}function getSqlClauses(){var _0x2c3328={'body':squel[_0xd24c('0x24')](),'contact':squel['expr'](),'default':squel[_0xd24c('0x24')](),'fields':squel[_0xd24c('0x24')](),'filter':squel[_0xd24c('0x24')](),'read':squel[_0xd24c('0x24')](),'tags':{'clause':squel['expr'](),'ids':null},'user':squel['expr']()};return _0x2c3328;}function parseTagParameter(_0x32d310){var _0x4d56f4=squel[_0xd24c('0x24')]();if(_0x32d310){var _0xaf8b16=utils[_0xd24c('0x25')](_0x32d310);_0xaf8b16['forEach'](function(_0x4cb1b3){_0x4d56f4['or'](_0xd24c('0x26'),'%,'+_0x4cb1b3+',%');});}return _0x4d56f4;}function parseReadParameter(_0x14d44a){var _0x1a18b7='';if(_0x14d44a){_0x1a18b7=_0xd24c('0x27');if(_0x14d44a==='1'){_0x1a18b7=_0x1a18b7[_0xd24c('0x28')](_0xd24c('0x29'),'=');}else{_0x1a18b7=_0x1a18b7[_0xd24c('0x28')](_0xd24c('0x29'),'>');}}return _0x1a18b7;}function parseSearchFilter(_0x1c48d6,_0x3b14c7){var _0x2586d7=squel['expr']();if(_0x3b14c7){var _0x4e128b=_0x3b14c7[_0xd24c('0x28')]('\x5c','\x5c\x5c')[_0xd24c('0x28')](/'/g,'\x27\x27');if(qs[_0xd24c('0x2a')](_0x4e128b)){_0x2586d7['or']('i.id\x20LIKE\x20?',_0x4e128b+'%');if(['sms',_0xd24c('0x2b')][_0xd24c('0x2c')](_0x1c48d6)){_0x2586d7['or'](_0xd24c('0x2d'),_0x4e128b+'%');}else if(_0x1c48d6===_0xd24c('0x2e')){_0x2586d7['or']('i.fax\x20LIKE\x20?',_0x4e128b+'%');}else if(_0x1c48d6===_0xd24c('0x2f')){_0x2586d7['or'](_0xd24c('0x30'),_0x4e128b+'%');}}else if(_0x1c48d6===_0xd24c('0x31')&&qs[_0xd24c('0x32')](_0x4e128b)){_0x2586d7['or'](_0xd24c('0x33'),_0x4e128b+'%');}else{if(_0x1c48d6===_0xd24c('0x31')){_0x2586d7['or'](_0xd24c('0x34'),qs[_0xd24c('0x35')](_0x4e128b))['or'](_0xd24c('0x36'),qs['getFullTextValue'](_0x4e128b));}else{if(_0x1c48d6!==_0xd24c('0x2e')){_0x2586d7['or']('MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs['getFullTextValue'](_0x4e128b));}_0x2586d7['or'](_0xd24c('0x37'),_0x4e128b+'%');}}}return _0x2586d7;}function parseAdvancedSearchFilter(_0x44fab7,_0x24f1a9){var _0x1113a6=getSqlClauses();var _0x7d11e5=as[_0xd24c('0x38')](_0x44fab7);var _0x4526e3=_0x7d11e5['sqlOperator'];for(var _0x3a0043=0x0;_0x3a0043<_0x7d11e5[_0xd24c('0x39')][_0xd24c('0x16')];_0x3a0043++){var _0x241102=_0x7d11e5[_0xd24c('0x39')][_0x3a0043];var _0x356557='i';var _0x54cce4=_[_0xd24c('0x3a')](_0x24f1a9,[_0xd24c('0x3b'),_0x241102['field']]);if(_0x54cce4){var _0x100553=as[_0xd24c('0x3c')](_0x356557,_0x54cce4['type'],_0x241102);_0x1113a6[_0xd24c('0x3d')][_0x4526e3](_0x100553[_0xd24c('0x3e')],_0x100553['value'][_0xd24c('0x3f')],_0x100553[_0xd24c('0x40')][_0xd24c('0x41')]);}else{switch(_0x241102[_0xd24c('0xb')]){case'unreadMessages':var _0x11ab7b=parseReadParameter(_0x241102['value']);_0x1113a6[_0xd24c('0x42')]['and'](_0x11ab7b);break;case'Contact':if(_0x241102['operator']===_0xd24c('0x43')){if(_0x241102['value']['split']('\x20')[_0xd24c('0x16')]>0x1){_0x1113a6[_0xd24c('0x44')][_0x4526e3](_0xd24c('0x45'),qs[_0xd24c('0x35')](_0x241102['value']),null);}else{var _0xe5fe3a='%'+_0x241102['value']+'%';_0x1113a6[_0xd24c('0x44')][_0x4526e3](_0xd24c('0x46'),_0xe5fe3a,_0xe5fe3a,_0xe5fe3a);}}else{_0x54cce4=_[_0xd24c('0x3a')](_0x24f1a9,[_0xd24c('0x3b'),_0xd24c('0x47')]);_0x241102[_0xd24c('0xb')]=_0xd24c('0x47');_0x100553=as[_0xd24c('0x3c')](_0x356557,_0x54cce4[_0xd24c('0x48')],_0x241102);_0x1113a6[_0xd24c('0x44')][_0x4526e3](_0x100553['text'],_0x100553[_0xd24c('0x40')][_0xd24c('0x3f')],_0x100553['value'][_0xd24c('0x41')]);}break;case _0xd24c('0x49'):var _0x49053b=_0x241102[_0xd24c('0x40')]['split'](',')[_0xd24c('0x18')](function(_0x2d46b8){return Number(_0x2d46b8);});var _0x969fa0=parseTagParameter(_0x49053b);_0x1113a6[_0xd24c('0x4a')][_0xd24c('0x4b')]['and'](_0x969fa0);_0x1113a6[_0xd24c('0x4a')]['ids']=_0x49053b;break;case _0xd24c('0x4c'):if(_0x241102['operator']===_0xd24c('0x43')){_0x1113a6[_0xd24c('0x4d')][_0x4526e3]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0x241102[_0xd24c('0x40')]+'%',null);}else{_0x54cce4=_[_0xd24c('0x3a')](_0x24f1a9,['name',_0xd24c('0x4e')]);_0x241102['field']='UserId';_0x100553=as['buildExpression'](_0x356557,_0x54cce4[_0xd24c('0x48')],_0x241102);_0x1113a6[_0xd24c('0x4d')][_0x4526e3](_0x100553['text'],_0x100553['value'][_0xd24c('0x3f')],_0x100553[_0xd24c('0x40')][_0xd24c('0x41')]);}break;case _0xd24c('0x4f'):case'plainBody':_0x100553=as[_0xd24c('0x3c')]('me',null,_0x241102);_0x1113a6[_0xd24c('0x4f')][_0x4526e3](_0x100553['text'],_0x100553[_0xd24c('0x40')][_0xd24c('0x3f')],_0x100553[_0xd24c('0x40')]['end']);break;}}}return _0x1113a6;}function parseModelFields(_0x3039aa,_0x4b10c6,_0x26c1d0){var _0x33cb6f=utils[_0xd24c('0x6')](_0x3039aa);var _0x1c594d=squel['expr']();var _0x14684c=_(_0x4b10c6)[_0xd24c('0x50')]()[_0xd24c('0x18')](function(_0x1a4549){return _[_0xd24c('0x51')](_0x26c1d0,[_0xd24c('0x3b'),_0x1a4549])?_0x1a4549:undefined;})[_0xd24c('0x52')]()[_0xd24c('0x40')]();if(_0x14684c[_0xd24c('0x16')]>0x0){_0x14684c[_0xd24c('0x53')](function(_0x131e14){if(_0x131e14===_0x33cb6f){_0x1c594d['and']('i.'+_0x33cb6f+_0xd24c('0x17'),[][_0xd24c('0x54')](_0x4b10c6[_0x131e14]));}else if(_0x131e14==='createdAt'){var _0x5bb14f=JSON['parse'](_0x4b10c6[_0x131e14])[_0xd24c('0x55')];var _0x4273d2=JSON[_0xd24c('0x56')](_0x4b10c6[_0x131e14])[_0xd24c('0x57')];_0x1c594d[_0xd24c('0x58')](_0xd24c('0x59'),_0x5bb14f,_0x4273d2);}else{if(_0x4b10c6[_0x131e14]===_0xd24c('0x5a')){_0x1c594d[_0xd24c('0x58')]('i.'+_0x131e14+_0xd24c('0x5b'));}else{_0x1c594d[_0xd24c('0x58')]('i.'+_0x131e14+_0xd24c('0x5c'),_0x4b10c6[_0x131e14]);}}});}return _0x1c594d;}function parseQueryParameters(_0x4fbb0b,_0x3a8e76,_0x3ac5ca){var _0x49eee7=getSqlClauses();return Promise[_0xd24c('0x5d')]()[_0xd24c('0x5e')](function(){return parseModelFields(_0x4fbb0b,_0x3a8e76,_0x3ac5ca);})[_0xd24c('0x5e')](function(_0x5d525d){_0x49eee7['fields'][_0xd24c('0x58')](_0x5d525d);return parseReadParameter(_0x3a8e76[_0xd24c('0x42')]);})[_0xd24c('0x5e')](function(_0x1be98f){_0x49eee7[_0xd24c('0x42')][_0xd24c('0x58')](_0x1be98f);return parseTagParameter(_0x3a8e76[_0xd24c('0x5f')]);})[_0xd24c('0x5e')](function(_0x5ba7ab){_0x49eee7[_0xd24c('0x4a')]['clause']['and'](_0x5ba7ab);return parseSearchFilter(_0x4fbb0b,_0x3a8e76[_0xd24c('0x60')]);})['then'](function(_0x4f6b11){_0x49eee7[_0xd24c('0x60')]=_0x4f6b11;return _0x49eee7;});}function checkAccountsRestrictions(_0x1b649e,_0x1b1b0e,_0x7e4f1){var _0x4890d6=utils[_0xd24c('0x6')](_0x1b649e);var _0x1e99e7=_0xd24c('0x61')+_[_0xd24c('0x62')](_0x1b649e)+(_0x1b649e===_0xd24c('0x63')?_0xd24c('0x64'):_0xd24c('0x65'));var _0x5f17e3=squel['expr']();return Promise['resolve']()[_0xd24c('0x5e')](function(){if(_0x7e4f1[_0xd24c('0x9')]&&_0x1b1b0e[_0xd24c('0x7')]===_0xd24c('0x8')){return _0x1b1b0e[_0x1e99e7]({'attributes':['id'],'raw':!![]});}})[_0xd24c('0x5e')](function(_0x39f5eb){if(_0x39f5eb){if(_0x39f5eb['length']===0x0){_0x5f17e3[_0xd24c('0x58')]('i.'+_0x4890d6+_0xd24c('0x5b'));}else{_0x5f17e3['and']('i.'+_0x4890d6+_0xd24c('0x17'),_[_0xd24c('0x18')](_0x39f5eb,'id'));}}else if(!_0x7e4f1[_0x4890d6]){_0x5f17e3[_0xd24c('0x58')]('i.'+_0x4890d6+_0xd24c('0x66'));}})[_0xd24c('0x5e')](function(){return _0x5f17e3;});}function getClosedOrderClause(_0x50ef46,_0x59bfe0){var _0x2a6d13='';var _0x22c469=['i.thirdDisposition',_0xd24c('0x67'),_0xd24c('0x68')];if(_0x50ef46==='mail'){_0x22c469[_0xd24c('0x69')](_0xd24c('0x6a'));}if(_0x59bfe0[_0xd24c('0x6b')]==='0'&&_0x50ef46===_0xd24c('0x31')){_0x2a6d13=_0xd24c('0x6a');}else{if(_0x59bfe0[_0xd24c('0x6b')]==='1'){_0x22c469[_0xd24c('0x6c')]();}_0x2a6d13='CONCAT_WS(\x27\x27,\x20'+_0x22c469['join'](',\x20')+')';}return _0x2a6d13;}function getFilteredInteractions(_0x5a45db,_0x1f0b87,_0x492f5c,_0x5293b4){var _0x55fb1d=utils[_0xd24c('0xf')](_0x5a45db);var _0x29ace6=_[_0xd24c('0x62')](_0x5a45db)+'Interaction';var _0x312c4c=[];var _0xef4950=getTagsQuery();var _0x424680={'type':db[_0xd24c('0x6d')][_0xd24c('0x6e')][_0xd24c('0x6f')],'raw':!![]};var _0x52567d=[];var _0x8a7fa8=[];return db[_0xd24c('0x70')]['query'](_0xef4950[_0xd24c('0x71')](),_0x424680)[_0xd24c('0x5e')](function(_0x30ca13){_0x312c4c=_[_0xd24c('0x72')](_0x30ca13,'id');_0x424680=_[_0xd24c('0x73')](_0x424680,{'model':db[_0x29ace6],'mapToModel':!![],'nest':!![]});if(_0x492f5c[_0xd24c('0x74')]){_0x5293b4[_0xd24c('0x75')][_0xd24c('0x53')](function(_0x4628aa){_0x1f0b87[_0xd24c('0xb')]('i.'+_0x4628aa);});}else{_0x1f0b87['field'](_0xd24c('0x76'),_0xd24c('0x77'));_0x1f0b87['field']('a.key',_0xd24c('0x78'));_0x1f0b87['field'](_0xd24c('0x79'),_0xd24c('0x7a'));if(_0x5a45db===_0xd24c('0x31')){_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x7b'),_0xd24c('0x7c'));_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x7d'),_0xd24c('0x7e'));_0x1f0b87[_0xd24c('0xb')]('i.id');_0x1f0b87[_0xd24c('0xb')]('i.createdAt');_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x7f'));_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x80'));_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x81'));_0x1f0b87[_0xd24c('0xb')]('i.attach');_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x82'));_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x83'));_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x84'));_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x68'));_0x1f0b87[_0xd24c('0xb')]('i.secondDisposition');_0x1f0b87[_0xd24c('0xb')]('i.thirdDisposition');_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x6a'));_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x85'));_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x86'));_0x1f0b87[_0xd24c('0xb')]('i.MailAccountId');_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x87'));}else if(_0x5a45db===_0xd24c('0x2f')){_0x1f0b87['field'](_0xd24c('0x88'),_0xd24c('0x7e'));}else{_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x89'),_0xd24c('0x7e'));}if(_0x5a45db!==_0xd24c('0x31')){_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x8a'));}_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x8b'),_0xd24c('0x8c'));_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x8d'),_0xd24c('0x8e'));_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x8f'),_0xd24c('0x90'));_0x1f0b87[_0xd24c('0xb')]('c.phone','Contact.phone');_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x91'),_0xd24c('0x92'));_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x93'),_0xd24c('0x94'));_0x1f0b87[_0xd24c('0xb')](_0xd24c('0x95'),'Owner.fullname');_0x1f0b87[_0xd24c('0xb')]('o.internal','Owner.internal');_0x1f0b87['field'](_0xd24c('0x96'),_0xd24c('0x97'));}if(_0x5293b4['limit']){_0x1f0b87['limit'](_0x5293b4[_0xd24c('0x98')]);}if(_0x5293b4[_0xd24c('0x99')]){_0x1f0b87[_0xd24c('0x99')](_0x5293b4[_0xd24c('0x99')]);}return db['sequelize']['query'](_0x1f0b87[_0xd24c('0x71')](),_0x424680);})['then'](function(_0x3a00a0){_0x52567d=_0x3a00a0;var _0x2cdc42=getUsersQuery(_0x5a45db,_0x52567d);return db[_0xd24c('0x70')][_0xd24c('0x9a')](_0x2cdc42[_0xd24c('0x71')](),_0x424680);})[_0xd24c('0x5e')](function(_0xdee697){_0x8a7fa8=_['groupBy'](_0xdee697,_0x55fb1d);if(_0x5a45db==='mail'){return db['Setting'][_0xd24c('0x9b')]({'attributes':[_0xd24c('0x9c')],'raw':!![]});}})[_0xd24c('0x5e')](function(_0x18cf30){var _0x320a2b=_0x18cf30?_0x18cf30[_0xd24c('0x9c')]:undefined;var _0x4843ed=_0x52567d[_0xd24c('0x18')](function(_0x1d75a9){return updateInteraction(_0x1d75a9,_0x312c4c,_0x8a7fa8,_0x320a2b);});return Promise[_0xd24c('0x9d')](_0x4843ed);});}function countFilteredInteractions(_0x3eae0c,_0x37329f){var _0x39c952=_0x3eae0c[_0xd24c('0x9e')]();_0x39c952[_0xd24c('0xb')](_0xd24c('0x9f'));_0x39c952[_0xd24c('0xb')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xd24c('0x77'));var _0x496929=utils[_0xd24c('0x25')](_0x37329f);if(!_[_0xd24c('0xa0')](_0x496929)){_0x39c952[_0xd24c('0xa1')](_0xd24c('0xa2'),_0x496929);}var _0x52e4a9={'type':db[_0xd24c('0x6d')]['QueryTypes'][_0xd24c('0x6f')],'raw':!![]};return db[_0xd24c('0x70')][_0xd24c('0x9a')](_0x39c952[_0xd24c('0x71')](),_0x52e4a9);}module[_0xd24c('0xa3')]={'checkAccountsRestrictions':checkAccountsRestrictions,'countFilteredInteractions':countFilteredInteractions,'getClosedOrderClause':getClosedOrderClause,'getFilteredInteractions':getFilteredInteractions,'getInteractionsQuery':getInteractionsQuery,'parseAdvancedSearchFilter':parseAdvancedSearchFilter,'parseQueryParameters':parseQueryParameters,'skipInteractionsQuery':skipInteractionsQuery};
\ No newline at end of file
+var _0xe3ef=['CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','user','body','plainBody','some','compact','forEach','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20=\x20?','resolve','fields','read','then','tag','filter','get','capitalize','chat','Accounts','\x20IS\x20NOT\x20NULL','i.thirdDisposition','i.secondDisposition','i.disposition','unshift','i.substatus','closed','CONCAT_WS(\x27\x27,\x20','join','Interaction','Sequelize','QueryTypes','SELECT','sequelize','query','toString','keyBy','merge','attributes','a.key','Account.key','a.mandatoryDisposition','a.email','Account.email','CASE\x20WHEN\x20i.to\x20IS\x20NOT\x20NULL\x20AND\x20i.to\x20<>\x20\x27\x27\x20AND\x20i.to\x20NOT\x20LIKE\x20CONCAT(\x27%\x27,\x20a.email,\x20\x27%\x27)\x20THEN\x20TRIM(SUBSTRING_INDEX(i.to,\x20\x27<\x27,\x201))\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.createdAt','i.updatedAt','i.closed','i.closedAt','i.attach','i.lastMsgAt','i.lastMsgDirection','i.subject','i.to','CASE\x20WHEN\x20i.from\x20IS\x20NOT\x20NULL\x20AND\x20i.from\x20<>\x20\x27\x27\x20THEN\x20i.from\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','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','Contact.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','Contact.phone','c.mobile','Contact.mobile','c.fax','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','TagIds','limit','offset','groupBy','Setting','findOne','enableEmailPreview','clone','COUNT(*)','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','t.id\x20IN\x20?','lodash','../parsers/advancedSearch','../parsers/qs','./update-interaction','updateInteraction','../../mysqldb','role','agent','search','field','name','from','getInteractionFK','user_has_','u.id','u.fullname','left_join','length','where','\x20IN\x20?','map','getInteractionsTables','getAccountFK','interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','users','o.id\x20=\x20i.UserId','accounts','a.id\x20=\x20i.','messages','me.','interactionsTags','\x20=\x20i.id','tools_tags','t.id\x20=\x20it.TagId','expr','getSelectedTags','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','unreadMessages\x20{OPERATOR}\x200','{OPERATOR}','replace','isNumeric','i.id\x20LIKE\x20?','sms','whatsapp','includes','i.phone\x20LIKE\x20?','fax','i.fax\x20LIKE\x20?','openchannel','mail','isEmail','MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','parseSearch','sqlOperator','conditions','find','buildExpression','type','default','value','start','end','unreadMessages','and','Contact','operator','contact','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','text','Tag','split','tags','clause','ids','$substring'];(function(_0x2d7f0e,_0x3e6fbd){var _0x110b07=function(_0x557b00){while(--_0x557b00){_0x2d7f0e['push'](_0x2d7f0e['shift']());}};_0x110b07(++_0x3e6fbd);}(_0xe3ef,0x101));var _0xfe3e=function(_0x11fe17,_0xbf3b3a){_0x11fe17=_0x11fe17-0x0;var _0x11dcf5=_0xe3ef[_0x11fe17];return _0x11dcf5;};'use strict';var _=require(_0xfe3e('0x0'));var squel=require('squel');var as=require(_0xfe3e('0x1'));var qs=require(_0xfe3e('0x2'));var updateInteraction=require(_0xfe3e('0x3'))[_0xfe3e('0x4')];var utils=require('./utils');var db=require(_0xfe3e('0x5'))['db'];function skipInteractionsQuery(_0x51897e,_0x57cd55,_0x5e16b2){var _0x1244a5=![];var _0x119c7f=utils['getAccountFK'](_0x51897e);if(_0x57cd55[_0xfe3e('0x6')]===_0xfe3e('0x7')&&!_0x5e16b2[_0xfe3e('0x8')]&&!_0x5e16b2[_0x119c7f]){_0x1244a5=!![];}return _0x1244a5;}function getTagsQuery(){return squel['select']()['field']('id')[_0xfe3e('0x9')](_0xfe3e('0xa'))[_0xfe3e('0x9')]('color')[_0xfe3e('0xb')]('tools_tags');}function getUsersQuery(_0x15346b,_0x4f9555){var _0x294100=utils[_0xfe3e('0xc')](_0x15346b);var _0x193a2c=_0xfe3e('0xd')+_0x15346b+'_interactions';var _0x382ea3=squel['select']()[_0xfe3e('0x9')](_0xfe3e('0xe'))[_0xfe3e('0x9')](_0xfe3e('0xf'))[_0xfe3e('0x9')]('ui.'+_0x294100)[_0xfe3e('0xb')](_0x193a2c,'ui')[_0xfe3e('0x10')]('users','u','u.id\x20=\x20ui.UserId');if(_0x4f9555[_0xfe3e('0x11')]>0x0){_0x382ea3[_0xfe3e('0x12')]('ui.'+_0x294100+_0xfe3e('0x13'),_[_0xfe3e('0x14')](_0x4f9555,'id'));}return _0x382ea3;}function getInteractionsQuery(_0x5d74f9){var _0x502a13=utils[_0xfe3e('0x15')](_0x5d74f9);var _0x4372b8=utils[_0xfe3e('0x16')](_0x5d74f9);var _0x462639=utils[_0xfe3e('0xc')](_0x5d74f9);return squel['select']()[_0xfe3e('0xb')](_0x502a13[_0xfe3e('0x17')],'i')[_0xfe3e('0x10')](_0xfe3e('0x18'),'c',_0xfe3e('0x19'))[_0xfe3e('0x10')](_0xfe3e('0x1a'),'o',_0xfe3e('0x1b'))[_0xfe3e('0x10')](_0x502a13[_0xfe3e('0x1c')],'a',_0xfe3e('0x1d')+_0x4372b8)[_0xfe3e('0x10')](_0x502a13[_0xfe3e('0x1e')],'me',_0xfe3e('0x1f')+_0x462639+'\x20=\x20i.id')[_0xfe3e('0x10')](_0x502a13[_0xfe3e('0x20')],'it','it.'+_0x462639+_0xfe3e('0x21'))[_0xfe3e('0x10')](_0xfe3e('0x22'),'t',_0xfe3e('0x23'));}function getSqlClauses(){var _0x19cfab={'body':squel['expr'](),'contact':squel[_0xfe3e('0x24')](),'default':squel['expr'](),'fields':squel['expr'](),'filter':squel[_0xfe3e('0x24')](),'read':squel[_0xfe3e('0x24')](),'tags':{'clause':squel[_0xfe3e('0x24')](),'ids':null},'user':squel[_0xfe3e('0x24')]()};return _0x19cfab;}function parseTagParameter(_0x2e26e9){var _0x566612=squel[_0xfe3e('0x24')]();if(_0x2e26e9){var _0xdb95a1=utils[_0xfe3e('0x25')](_0x2e26e9);_0xdb95a1['forEach'](function(_0x2d2eab){_0x566612['or'](_0xfe3e('0x26'),'%,'+_0x2d2eab+',%');});}return _0x566612;}function parseReadParameter(_0x3ddcf5){var _0x39789d='';if(_0x3ddcf5){_0x39789d=_0xfe3e('0x27');if(_0x3ddcf5==='1'){_0x39789d=_0x39789d['replace'](_0xfe3e('0x28'),'=');}else{_0x39789d=_0x39789d[_0xfe3e('0x29')](_0xfe3e('0x28'),'>');}}return _0x39789d;}function parseSearchFilter(_0x4368c2,_0x1eb36e){var _0x426ffc=squel['expr']();if(_0x1eb36e){var _0x2721ca=_0x1eb36e['replace']('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs[_0xfe3e('0x2a')](_0x2721ca)){_0x426ffc['or'](_0xfe3e('0x2b'),_0x2721ca+'%');if([_0xfe3e('0x2c'),_0xfe3e('0x2d')][_0xfe3e('0x2e')](_0x4368c2)){_0x426ffc['or'](_0xfe3e('0x2f'),_0x2721ca+'%');}else if(_0x4368c2===_0xfe3e('0x30')){_0x426ffc['or'](_0xfe3e('0x31'),_0x2721ca+'%');}else if(_0x4368c2===_0xfe3e('0x32')){_0x426ffc['or']('i.from\x20LIKE\x20?',_0x2721ca+'%');}}else if(_0x4368c2===_0xfe3e('0x33')&&qs[_0xfe3e('0x34')](_0x2721ca)){_0x426ffc['or']('c.email\x20LIKE\x20?',_0x2721ca+'%');}else{if(_0x4368c2===_0xfe3e('0x33')){_0x426ffc['or'](_0xfe3e('0x35'),qs[_0xfe3e('0x36')](_0x2721ca,!![]))['or']('MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xfe3e('0x36')](_0x2721ca));}else if(_0x4368c2!==_0xfe3e('0x30')){_0x426ffc['or'](_0xfe3e('0x37'),qs['getFullTextValue'](_0x2721ca));}_0x426ffc['or'](_0xfe3e('0x38'),qs['getFullTextValue'](_0x2721ca,!![]),null);}}return _0x426ffc;}function parseAdvancedSearchFilter(_0x152ddf,_0x53c65f){var _0xefe1f6=getSqlClauses();var _0x1730ac=as[_0xfe3e('0x39')](_0x152ddf);var _0x2360ce=_0x1730ac[_0xfe3e('0x3a')];for(var _0x528e29=0x0;_0x528e29<_0x1730ac[_0xfe3e('0x3b')][_0xfe3e('0x11')];_0x528e29++){var _0x1b891a=_0x1730ac[_0xfe3e('0x3b')][_0x528e29];var _0x7cb9f8='i';var _0x1055c3=_[_0xfe3e('0x3c')](_0x53c65f,[_0xfe3e('0xa'),_0x1b891a[_0xfe3e('0x9')]]);if(_0x1055c3){var _0x511439=as[_0xfe3e('0x3d')](_0x7cb9f8,_0x1055c3[_0xfe3e('0x3e')],_0x1b891a);_0xefe1f6[_0xfe3e('0x3f')][_0x2360ce](_0x511439['text'],_0x511439[_0xfe3e('0x40')][_0xfe3e('0x41')],_0x511439[_0xfe3e('0x40')][_0xfe3e('0x42')]);}else{switch(_0x1b891a['field']){case _0xfe3e('0x43'):var _0x4f4e5c=parseReadParameter(_0x1b891a[_0xfe3e('0x40')]);_0xefe1f6['read'][_0xfe3e('0x44')](_0x4f4e5c);break;case _0xfe3e('0x45'):if(_0x1b891a[_0xfe3e('0x46')]==='$substring'){if(_0x1b891a[_0xfe3e('0x40')]['split']('\x20')[_0xfe3e('0x11')]>0x1){_0xefe1f6[_0xfe3e('0x47')][_0x2360ce]('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xfe3e('0x36')](_0x1b891a['value'],!![]),null);}else{var _0x8dacde='%'+_0x1b891a[_0xfe3e('0x40')]+'%';_0xefe1f6[_0xfe3e('0x47')][_0x2360ce](_0xfe3e('0x48'),_0x8dacde,_0x8dacde,_0x8dacde);}}else{_0x1055c3=_['find'](_0x53c65f,[_0xfe3e('0xa'),_0xfe3e('0x49')]);_0x1b891a[_0xfe3e('0x9')]=_0xfe3e('0x49');_0x511439=as[_0xfe3e('0x3d')](_0x7cb9f8,_0x1055c3['type'],_0x1b891a);_0xefe1f6[_0xfe3e('0x47')][_0x2360ce](_0x511439[_0xfe3e('0x4a')],_0x511439[_0xfe3e('0x40')][_0xfe3e('0x41')],_0x511439[_0xfe3e('0x40')][_0xfe3e('0x42')]);}break;case _0xfe3e('0x4b'):var _0x36716c=_0x1b891a[_0xfe3e('0x40')][_0xfe3e('0x4c')](',')[_0xfe3e('0x14')](function(_0x781ef1){return Number(_0x781ef1);});var _0x2eaa91=parseTagParameter(_0x36716c);_0xefe1f6[_0xfe3e('0x4d')][_0xfe3e('0x4e')][_0xfe3e('0x44')](_0x2eaa91);_0xefe1f6['tags'][_0xfe3e('0x4f')]=_0x36716c;break;case'User':if(_0x1b891a[_0xfe3e('0x46')]===_0xfe3e('0x50')){_0xefe1f6['user'][_0x2360ce](_0xfe3e('0x51'),'%'+_0x1b891a[_0xfe3e('0x40')]+'%',null);}else{_0x1055c3=_[_0xfe3e('0x3c')](_0x53c65f,[_0xfe3e('0xa'),_0xfe3e('0x52')]);_0x1b891a[_0xfe3e('0x9')]=_0xfe3e('0x52');_0x511439=as[_0xfe3e('0x3d')](_0x7cb9f8,_0x1055c3[_0xfe3e('0x3e')],_0x1b891a);_0xefe1f6[_0xfe3e('0x53')][_0x2360ce](_0x511439[_0xfe3e('0x4a')],_0x511439[_0xfe3e('0x40')][_0xfe3e('0x41')],_0x511439[_0xfe3e('0x40')][_0xfe3e('0x42')]);}break;case _0xfe3e('0x54'):case _0xfe3e('0x55'):_0x511439=as[_0xfe3e('0x3d')]('me',null,_0x1b891a);_0xefe1f6[_0xfe3e('0x54')][_0x2360ce](_0x511439['text'],_0x511439[_0xfe3e('0x40')]['start'],_0x511439['value'][_0xfe3e('0x42')]);break;}}}return _0xefe1f6;}function parseModelFields(_0x543781,_0x183f0c,_0x315db4){var _0x543c2d=utils[_0xfe3e('0x16')](_0x543781);var _0x578738=squel['expr']();var _0x193bfe=_(_0x183f0c)['keys']()[_0xfe3e('0x14')](function(_0x57e48c){return _[_0xfe3e('0x56')](_0x315db4,['name',_0x57e48c])?_0x57e48c:undefined;})[_0xfe3e('0x57')]()[_0xfe3e('0x40')]();if(_0x193bfe[_0xfe3e('0x11')]>0x0){_0x193bfe[_0xfe3e('0x58')](function(_0x3eb3ef){if(_0x3eb3ef===_0x543c2d){_0x578738[_0xfe3e('0x44')]('i.'+_0x543c2d+_0xfe3e('0x13'),[]['concat'](_0x183f0c[_0x3eb3ef]));}else if(_0x3eb3ef===_0xfe3e('0x59')){var _0x4719e9=JSON[_0xfe3e('0x5a')](_0x183f0c[_0x3eb3ef])[_0xfe3e('0x5b')];var _0x6ff20d=JSON['parse'](_0x183f0c[_0x3eb3ef])[_0xfe3e('0x5c')];_0x578738[_0xfe3e('0x44')](_0xfe3e('0x5d'),_0x4719e9,_0x6ff20d);}else{if(_0x183f0c[_0x3eb3ef]===_0xfe3e('0x5e')){_0x578738[_0xfe3e('0x44')]('i.'+_0x3eb3ef+'\x20IS\x20NULL');}else{_0x578738[_0xfe3e('0x44')]('i.'+_0x3eb3ef+_0xfe3e('0x5f'),_0x183f0c[_0x3eb3ef]);}}});}return _0x578738;}function parseQueryParameters(_0x313ede,_0x3e8a8b,_0x431da8){var _0x12f2a8=getSqlClauses();return Promise[_0xfe3e('0x60')]()['then'](function(){return parseModelFields(_0x313ede,_0x3e8a8b,_0x431da8);})['then'](function(_0x2a4d9b){_0x12f2a8[_0xfe3e('0x61')]['and'](_0x2a4d9b);return parseReadParameter(_0x3e8a8b[_0xfe3e('0x62')]);})[_0xfe3e('0x63')](function(_0x52f847){_0x12f2a8['read'][_0xfe3e('0x44')](_0x52f847);return parseTagParameter(_0x3e8a8b[_0xfe3e('0x64')]);})[_0xfe3e('0x63')](function(_0x34f720){_0x12f2a8[_0xfe3e('0x4d')][_0xfe3e('0x4e')][_0xfe3e('0x44')](_0x34f720);return parseSearchFilter(_0x313ede,_0x3e8a8b[_0xfe3e('0x65')]);})[_0xfe3e('0x63')](function(_0x4d59c6){_0x12f2a8[_0xfe3e('0x65')]=_0x4d59c6;return _0x12f2a8;});}function checkAccountsRestrictions(_0x41bc8b,_0x37b17e,_0x5336cc){var _0x5db34e=utils['getAccountFK'](_0x41bc8b);var _0x17695a=_0xfe3e('0x66')+_[_0xfe3e('0x67')](_0x41bc8b)+(_0x41bc8b===_0xfe3e('0x68')?'Websites':_0xfe3e('0x69'));var _0x4c4fa8=squel[_0xfe3e('0x24')]();return Promise['resolve']()[_0xfe3e('0x63')](function(){if(_0x5336cc[_0xfe3e('0x8')]&&_0x37b17e[_0xfe3e('0x6')]===_0xfe3e('0x7')){return _0x37b17e[_0x17695a]({'attributes':['id'],'raw':!![]});}})['then'](function(_0xf916f3){if(_0xf916f3){if(_0xf916f3[_0xfe3e('0x11')]===0x0){_0x4c4fa8[_0xfe3e('0x44')]('i.'+_0x5db34e+'\x20IS\x20NULL');}else{_0x4c4fa8['and']('i.'+_0x5db34e+'\x20IN\x20?',_[_0xfe3e('0x14')](_0xf916f3,'id'));}}else if(!_0x5336cc[_0x5db34e]){_0x4c4fa8[_0xfe3e('0x44')]('i.'+_0x5db34e+_0xfe3e('0x6a'));}})['then'](function(){return _0x4c4fa8;});}function getClosedOrderClause(_0x4c2bc4,_0x30b9e0){var _0x1796f6='';var _0x110617=[_0xfe3e('0x6b'),_0xfe3e('0x6c'),_0xfe3e('0x6d')];if(_0x4c2bc4===_0xfe3e('0x33')){_0x110617[_0xfe3e('0x6e')](_0xfe3e('0x6f'));}if(_0x30b9e0[_0xfe3e('0x70')]==='0'&&_0x4c2bc4===_0xfe3e('0x33')){_0x1796f6='i.substatus';}else{if(_0x30b9e0['closed']==='1'){_0x110617['shift']();}_0x1796f6=_0xfe3e('0x71')+_0x110617[_0xfe3e('0x72')](',\x20')+')';}return _0x1796f6;}function getFilteredInteractions(_0x499240,_0x522ada,_0x4a5535,_0x548814){var _0x4fddf6=utils[_0xfe3e('0xc')](_0x499240);var _0xdfd456=_[_0xfe3e('0x67')](_0x499240)+_0xfe3e('0x73');var _0x32be98=[];var _0x57445e=getTagsQuery();var _0x266078={'type':db[_0xfe3e('0x74')][_0xfe3e('0x75')][_0xfe3e('0x76')],'raw':!![]};var _0x23948c=[];var _0x35daa6=[];return db[_0xfe3e('0x77')][_0xfe3e('0x78')](_0x57445e[_0xfe3e('0x79')](),_0x266078)[_0xfe3e('0x63')](function(_0x5db59f){_0x32be98=_[_0xfe3e('0x7a')](_0x5db59f,'id');_0x266078=_[_0xfe3e('0x7b')](_0x266078,{'model':db[_0xdfd456],'mapToModel':!![],'nest':!![]});if(_0x4a5535['fields']){_0x548814[_0xfe3e('0x7c')]['forEach'](function(_0x5b79b4){_0x522ada[_0xfe3e('0x9')]('i.'+_0x5b79b4);});}else{_0x522ada[_0xfe3e('0x9')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages');_0x522ada['field'](_0xfe3e('0x7d'),_0xfe3e('0x7e'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x7f'),'Account.mandatoryDisposition');if(_0x499240==='mail'){_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x80'),_0xfe3e('0x81'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x82'),'contactName');_0x522ada[_0xfe3e('0x9')]('i.id');_0x522ada['field'](_0xfe3e('0x83'));_0x522ada['field'](_0xfe3e('0x84'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x85'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x86'));_0x522ada['field'](_0xfe3e('0x87'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x88'));_0x522ada['field'](_0xfe3e('0x89'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x8a'));_0x522ada['field'](_0xfe3e('0x6d'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x6c'));_0x522ada[_0xfe3e('0x9')]('i.thirdDisposition');_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x6f'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x8b'));_0x522ada[_0xfe3e('0x9')]('i.ContactId');_0x522ada[_0xfe3e('0x9')]('i.MailAccountId');_0x522ada['field']('i.UserId');}else if(_0x499240===_0xfe3e('0x32')){_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x8c'),'contactName');}else{_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x8d'),_0xfe3e('0x8e'));}if(_0x499240!=='mail'){_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x8f'));}_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x90'),_0xfe3e('0x91'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x92'),_0xfe3e('0x93'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x94'),_0xfe3e('0x95'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x96'),_0xfe3e('0x97'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x98'),_0xfe3e('0x99'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x9a'),'Contact.fax');_0x522ada['field']('o.fullname','Owner.fullname');_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x9b'),_0xfe3e('0x9c'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x9d'),_0xfe3e('0x9e'));}if(_0x548814[_0xfe3e('0x9f')]){_0x522ada[_0xfe3e('0x9f')](_0x548814['limit']);}if(_0x548814['offset']){_0x522ada[_0xfe3e('0xa0')](_0x548814['offset']);}return db['sequelize'][_0xfe3e('0x78')](_0x522ada['toString'](),_0x266078);})[_0xfe3e('0x63')](function(_0x2a549f){_0x23948c=_0x2a549f;var _0x4a0492=getUsersQuery(_0x499240,_0x23948c);return db[_0xfe3e('0x77')][_0xfe3e('0x78')](_0x4a0492[_0xfe3e('0x79')](),_0x266078);})[_0xfe3e('0x63')](function(_0xc38b97){_0x35daa6=_[_0xfe3e('0xa1')](_0xc38b97,_0x4fddf6);if(_0x499240===_0xfe3e('0x33')){return db[_0xfe3e('0xa2')][_0xfe3e('0xa3')]({'attributes':[_0xfe3e('0xa4')],'raw':!![]});}})['then'](function(_0x5c5753){var _0x3f5c53=_0x5c5753?_0x5c5753['enableEmailPreview']:undefined;var _0x187267=_0x23948c[_0xfe3e('0x14')](function(_0x3b9488){return updateInteraction(_0x3b9488,_0x32be98,_0x35daa6,_0x3f5c53);});return Promise['all'](_0x187267);});}function countFilteredInteractions(_0x5298ff,_0x39dfeb){var _0x1d9ca7=_0x5298ff[_0xfe3e('0xa5')]();_0x1d9ca7[_0xfe3e('0x9')](_0xfe3e('0xa6'));_0x1d9ca7[_0xfe3e('0x9')](_0xfe3e('0xa7'),'unreadMessages');var _0x420963=utils['getSelectedTags'](_0x39dfeb);if(!_['isEmpty'](_0x420963)){_0x1d9ca7[_0xfe3e('0x12')](_0xfe3e('0xa8'),_0x420963);}var _0x409239={'type':db[_0xfe3e('0x74')][_0xfe3e('0x75')][_0xfe3e('0x76')],'raw':!![]};return db[_0xfe3e('0x77')][_0xfe3e('0x78')](_0x1d9ca7[_0xfe3e('0x79')](),_0x409239);}module['exports']={'checkAccountsRestrictions':checkAccountsRestrictions,'countFilteredInteractions':countFilteredInteractions,'getClosedOrderClause':getClosedOrderClause,'getFilteredInteractions':getFilteredInteractions,'getInteractionsQuery':getInteractionsQuery,'parseAdvancedSearchFilter':parseAdvancedSearchFilter,'parseQueryParameters':parseQueryParameters,'skipInteractionsQuery':skipInteractionsQuery};
\ No newline at end of file