a5c7bb71171127384f9df292d6025b048404e568
[motion2.git] / server / components / interaction / sql-utils.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xcea2=['Setting','findOne','enableEmailPreview','all','isEmpty','t.id\x20IN\x20?','SELECT','exports','lodash','../parsers/advancedSearch','./update-interaction','updateInteraction','./utils','role','agent','search','select','field','color','from','tools_tags','getInteractionFK','_interactions','u.id','u.fullname','ui.','u.id\x20=\x20ui.UserId','where','\x20IN\x20?','map','getInteractionsTables','interactions','left_join','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','users','o.id\x20=\x20i.UserId','a.id\x20=\x20i.','messages','me.','\x20=\x20i.id','interactionsTags','expr','getSelectedTags','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','unreadMessages\x20{OPERATOR}\x200','replace','{OPERATOR}','isNumeric','i.id\x20LIKE\x20?','sms','whatsapp','includes','i.phone\x20LIKE\x20?','fax','i.fax\x20LIKE\x20?','openchannel','i.from\x20LIKE\x20?','isEmail','c.email\x20LIKE\x20?','mail','MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','parseSearch','conditions','find','default','end','value','read','Contact','operator','$substring','split','length','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?','name','ContactId','buildExpression','text','start','Tag','tags','and','ids','user','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','type','body','plainBody','getAccountFK','keys','some','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','then','tag','clause','filter','capitalize','chat','Websites','Accounts','resolve','i.secondDisposition','i.disposition','unshift','i.substatus','closed','shift','CONCAT_WS(\x27\x27,\x20','join','Interaction','Sequelize','sequelize','keyBy','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.id','i.createdAt','i.updatedAt','i.closed','i.closedAt','i.attach','i.lastMsgAt','i.lastMsgDirection','i.subject','i.thirdDisposition','i.to','i.ContactId','i.MailAccountId','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','c.firstName','Contact.firstName','c.lastName','c.phone','Contact.phone','c.mobile','Contact.mobile','c.fax','o.fullname','o.internal','Owner.internal','TagIds','limit','offset','query','toString','groupBy'];(function(_0x2f5ac5,_0x1ee939){var _0x37c9a8=function(_0x15031f){while(--_0x15031f){_0x2f5ac5['push'](_0x2f5ac5['shift']());}};_0x37c9a8(++_0x1ee939);}(_0xcea2,0x15a));var _0x2cea=function(_0xc4001c,_0x1bf8f0){_0xc4001c=_0xc4001c-0x0;var _0x49f7bc=_0xcea2[_0xc4001c];return _0x49f7bc;};'use strict';var _=require(_0x2cea('0x0'));var squel=require('squel');var as=require(_0x2cea('0x1'));var qs=require('../parsers/qs');var updateInteraction=require(_0x2cea('0x2'))[_0x2cea('0x3')];var utils=require(_0x2cea('0x4'));var db=require('../../mysqldb')['db'];function skipInteractionsQuery(_0x3ff73f,_0x46060b,_0x11596e){var _0x496c21=![];var _0x34f0f2=utils['getAccountFK'](_0x3ff73f);if(_0x46060b[_0x2cea('0x5')]===_0x2cea('0x6')&&!_0x11596e[_0x2cea('0x7')]&&!_0x11596e[_0x34f0f2]){_0x496c21=!![];}return _0x496c21;}function getTagsQuery(){return squel[_0x2cea('0x8')]()[_0x2cea('0x9')]('id')[_0x2cea('0x9')]('name')[_0x2cea('0x9')](_0x2cea('0xa'))[_0x2cea('0xb')](_0x2cea('0xc'));}function getUsersQuery(_0x306cf7,_0x439c4d){var _0x4298a4=utils[_0x2cea('0xd')](_0x306cf7);var _0x58a102='user_has_'+_0x306cf7+_0x2cea('0xe');var _0x2db0ff=squel['select']()['field'](_0x2cea('0xf'))['field'](_0x2cea('0x10'))[_0x2cea('0x9')](_0x2cea('0x11')+_0x4298a4)['from'](_0x58a102,'ui')['left_join']('users','u',_0x2cea('0x12'));if(_0x439c4d['length']>0x0){_0x2db0ff[_0x2cea('0x13')](_0x2cea('0x11')+_0x4298a4+_0x2cea('0x14'),_[_0x2cea('0x15')](_0x439c4d,'id'));}return _0x2db0ff;}function getInteractionsQuery(_0x232dad){var _0x1bbfdb=utils[_0x2cea('0x16')](_0x232dad);var _0x1ead4c=utils['getAccountFK'](_0x232dad);var _0x19927a=utils[_0x2cea('0xd')](_0x232dad);return squel[_0x2cea('0x8')]()[_0x2cea('0xb')](_0x1bbfdb[_0x2cea('0x17')],'i')[_0x2cea('0x18')]('cm_contacts','c',_0x2cea('0x19'))['left_join'](_0x2cea('0x1a'),'o',_0x2cea('0x1b'))[_0x2cea('0x18')](_0x1bbfdb['accounts'],'a',_0x2cea('0x1c')+_0x1ead4c)[_0x2cea('0x18')](_0x1bbfdb[_0x2cea('0x1d')],'me',_0x2cea('0x1e')+_0x19927a+_0x2cea('0x1f'))[_0x2cea('0x18')](_0x1bbfdb[_0x2cea('0x20')],'it','it.'+_0x19927a+_0x2cea('0x1f'))['left_join'](_0x2cea('0xc'),'t','t.id\x20=\x20it.TagId');}function getSqlClauses(){var _0x3966d5={'body':squel[_0x2cea('0x21')](),'contact':squel['expr'](),'default':squel[_0x2cea('0x21')](),'fields':squel[_0x2cea('0x21')](),'filter':squel[_0x2cea('0x21')](),'read':squel[_0x2cea('0x21')](),'tags':{'clause':squel[_0x2cea('0x21')](),'ids':null},'user':squel[_0x2cea('0x21')]()};return _0x3966d5;}function parseTagParameter(_0x5d032f){var _0x4ec9b3=squel[_0x2cea('0x21')]();if(_0x5d032f){var _0x2bbe9b=utils[_0x2cea('0x22')](_0x5d032f);_0x2bbe9b[_0x2cea('0x23')](function(_0x3ea40c){_0x4ec9b3['or'](_0x2cea('0x24'),'%,'+_0x3ea40c+',%');});}return _0x4ec9b3;}function parseReadParameter(_0x2741cb){var _0x4e9cab='';if(_0x2741cb){_0x4e9cab=_0x2cea('0x25');if(_0x2741cb==='1'){_0x4e9cab=_0x4e9cab[_0x2cea('0x26')]('{OPERATOR}','=');}else{_0x4e9cab=_0x4e9cab[_0x2cea('0x26')](_0x2cea('0x27'),'>');}}return _0x4e9cab;}function parseSearchFilter(_0x271b2f,_0x16cf9f){var _0x5e0519=squel[_0x2cea('0x21')]();if(_0x16cf9f){var _0x128934=_0x16cf9f['replace']('\x5c','\x5c\x5c')[_0x2cea('0x26')](/'/g,'\x27\x27');if(qs[_0x2cea('0x28')](_0x128934)){_0x5e0519['or'](_0x2cea('0x29'),_0x128934+'%');if([_0x2cea('0x2a'),_0x2cea('0x2b')][_0x2cea('0x2c')](_0x271b2f)){_0x5e0519['or'](_0x2cea('0x2d'),_0x128934+'%');}else if(_0x271b2f===_0x2cea('0x2e')){_0x5e0519['or'](_0x2cea('0x2f'),_0x128934+'%');}else if(_0x271b2f===_0x2cea('0x30')){_0x5e0519['or'](_0x2cea('0x31'),_0x128934+'%');}}else if(_0x271b2f==='mail'&&qs[_0x2cea('0x32')](_0x128934)){_0x5e0519['or'](_0x2cea('0x33'),_0x128934+'%');}else{if(_0x271b2f===_0x2cea('0x34')){_0x5e0519['or'](_0x2cea('0x35'),qs['getFullTextValue'](_0x128934))['or']('MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x2cea('0x36')](_0x128934));}else{if(_0x271b2f!==_0x2cea('0x2e')){_0x5e0519['or']('MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x2cea('0x36')](_0x128934));}_0x5e0519['or']('CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?',_0x128934+'%');}}}return _0x5e0519;}function parseAdvancedSearchFilter(_0x3332db,_0x48a5d4){var _0x510d66=getSqlClauses();var _0x5bd36b=as[_0x2cea('0x37')](_0x3332db);var _0x4518eb=_0x5bd36b['sqlOperator'];for(var _0x389a2c=0x0;_0x389a2c<_0x5bd36b[_0x2cea('0x38')]['length'];_0x389a2c++){var _0x24b67d=_0x5bd36b[_0x2cea('0x38')][_0x389a2c];var _0x40c96f='i';var _0x3c9f6e=_[_0x2cea('0x39')](_0x48a5d4,['name',_0x24b67d[_0x2cea('0x9')]]);if(_0x3c9f6e){var _0x69e6e8=as['buildExpression'](_0x40c96f,_0x3c9f6e['type'],_0x24b67d);_0x510d66[_0x2cea('0x3a')][_0x4518eb](_0x69e6e8['text'],_0x69e6e8['value']['start'],_0x69e6e8['value'][_0x2cea('0x3b')]);}else{switch(_0x24b67d[_0x2cea('0x9')]){case'unreadMessages':var _0x219560=parseReadParameter(_0x24b67d[_0x2cea('0x3c')]);_0x510d66[_0x2cea('0x3d')]['and'](_0x219560);break;case _0x2cea('0x3e'):if(_0x24b67d[_0x2cea('0x3f')]===_0x2cea('0x40')){if(_0x24b67d[_0x2cea('0x3c')][_0x2cea('0x41')]('\x20')[_0x2cea('0x42')]>0x1){_0x510d66[_0x2cea('0x43')][_0x4518eb](_0x2cea('0x44'),qs[_0x2cea('0x36')](_0x24b67d[_0x2cea('0x3c')]),null);}else{var _0x3c0b91='%'+_0x24b67d[_0x2cea('0x3c')]+'%';_0x510d66[_0x2cea('0x43')][_0x4518eb](_0x2cea('0x45'),_0x3c0b91,_0x3c0b91,_0x3c0b91);}}else{_0x3c9f6e=_[_0x2cea('0x39')](_0x48a5d4,[_0x2cea('0x46'),_0x2cea('0x47')]);_0x24b67d[_0x2cea('0x9')]='ContactId';_0x69e6e8=as[_0x2cea('0x48')](_0x40c96f,_0x3c9f6e['type'],_0x24b67d);_0x510d66[_0x2cea('0x43')][_0x4518eb](_0x69e6e8[_0x2cea('0x49')],_0x69e6e8[_0x2cea('0x3c')][_0x2cea('0x4a')],_0x69e6e8[_0x2cea('0x3c')][_0x2cea('0x3b')]);}break;case _0x2cea('0x4b'):var _0x352621=_0x24b67d[_0x2cea('0x3c')][_0x2cea('0x41')](',')['map'](function(_0x515494){return Number(_0x515494);});var _0x1be683=parseTagParameter(_0x352621);_0x510d66[_0x2cea('0x4c')]['clause'][_0x2cea('0x4d')](_0x1be683);_0x510d66['tags'][_0x2cea('0x4e')]=_0x352621;break;case'User':if(_0x24b67d[_0x2cea('0x3f')]===_0x2cea('0x40')){_0x510d66[_0x2cea('0x4f')][_0x4518eb](_0x2cea('0x50'),'%'+_0x24b67d[_0x2cea('0x3c')]+'%',null);}else{_0x3c9f6e=_[_0x2cea('0x39')](_0x48a5d4,[_0x2cea('0x46'),_0x2cea('0x51')]);_0x24b67d[_0x2cea('0x9')]=_0x2cea('0x51');_0x69e6e8=as['buildExpression'](_0x40c96f,_0x3c9f6e[_0x2cea('0x52')],_0x24b67d);_0x510d66[_0x2cea('0x4f')][_0x4518eb](_0x69e6e8[_0x2cea('0x49')],_0x69e6e8[_0x2cea('0x3c')]['start'],_0x69e6e8['value'][_0x2cea('0x3b')]);}break;case _0x2cea('0x53'):case _0x2cea('0x54'):_0x69e6e8=as['buildExpression']('me',null,_0x24b67d);_0x510d66[_0x2cea('0x53')][_0x4518eb](_0x69e6e8[_0x2cea('0x49')],_0x69e6e8[_0x2cea('0x3c')][_0x2cea('0x4a')],_0x69e6e8['value'][_0x2cea('0x3b')]);break;}}}return _0x510d66;}function parseModelFields(_0x526e92,_0x4d1b77,_0x42379a){var _0x8a8cae=utils[_0x2cea('0x55')](_0x526e92);var _0x3af41f=squel['expr']();var _0x492fcf=_(_0x4d1b77)[_0x2cea('0x56')]()[_0x2cea('0x15')](function(_0x464b89){return _[_0x2cea('0x57')](_0x42379a,['name',_0x464b89])?_0x464b89:undefined;})['compact']()['value']();if(_0x492fcf[_0x2cea('0x42')]>0x0){_0x492fcf[_0x2cea('0x23')](function(_0x127069){if(_0x127069===_0x8a8cae){_0x3af41f[_0x2cea('0x4d')]('i.'+_0x8a8cae+_0x2cea('0x14'),[][_0x2cea('0x58')](_0x4d1b77[_0x127069]));}else if(_0x127069===_0x2cea('0x59')){var _0x4d31dc=JSON[_0x2cea('0x5a')](_0x4d1b77[_0x127069])[_0x2cea('0x5b')];var _0x3ccb9f=JSON['parse'](_0x4d1b77[_0x127069])[_0x2cea('0x5c')];_0x3af41f['and'](_0x2cea('0x5d'),_0x4d31dc,_0x3ccb9f);}else{if(_0x4d1b77[_0x127069]===_0x2cea('0x5e')){_0x3af41f[_0x2cea('0x4d')]('i.'+_0x127069+_0x2cea('0x5f'));}else{_0x3af41f[_0x2cea('0x4d')]('i.'+_0x127069+_0x2cea('0x60'),_0x4d1b77[_0x127069]);}}});}return _0x3af41f;}function parseQueryParameters(_0x33f411,_0x326fb2,_0x5b6baf){var _0x2a4148=getSqlClauses();return Promise['resolve']()[_0x2cea('0x61')](function(){return parseModelFields(_0x33f411,_0x326fb2,_0x5b6baf);})[_0x2cea('0x61')](function(_0x400a80){_0x2a4148['fields'][_0x2cea('0x4d')](_0x400a80);return parseReadParameter(_0x326fb2['read']);})['then'](function(_0x264aa5){_0x2a4148[_0x2cea('0x3d')][_0x2cea('0x4d')](_0x264aa5);return parseTagParameter(_0x326fb2[_0x2cea('0x62')]);})[_0x2cea('0x61')](function(_0x581b18){_0x2a4148['tags'][_0x2cea('0x63')][_0x2cea('0x4d')](_0x581b18);return parseSearchFilter(_0x33f411,_0x326fb2[_0x2cea('0x64')]);})[_0x2cea('0x61')](function(_0x526269){_0x2a4148[_0x2cea('0x64')]=_0x526269;return _0x2a4148;});}function checkAccountsRestrictions(_0x5ae31b,_0x372921,_0x3a7daf){var _0x35d64b=utils[_0x2cea('0x55')](_0x5ae31b);var _0x221c16='get'+_[_0x2cea('0x65')](_0x5ae31b)+(_0x5ae31b===_0x2cea('0x66')?_0x2cea('0x67'):_0x2cea('0x68'));var _0x43922e=squel['expr']();return Promise[_0x2cea('0x69')]()[_0x2cea('0x61')](function(){if(_0x3a7daf['search']&&_0x372921[_0x2cea('0x5')]===_0x2cea('0x6')){return _0x372921[_0x221c16]({'attributes':['id'],'raw':!![]});}})[_0x2cea('0x61')](function(_0xd51dd5){if(_0xd51dd5){if(_0xd51dd5['length']===0x0){_0x43922e['and']('i.'+_0x35d64b+_0x2cea('0x5f'));}else{_0x43922e[_0x2cea('0x4d')]('i.'+_0x35d64b+'\x20IN\x20?',_[_0x2cea('0x15')](_0xd51dd5,'id'));}}else if(!_0x3a7daf[_0x35d64b]){_0x43922e[_0x2cea('0x4d')]('i.'+_0x35d64b+'\x20IS\x20NOT\x20NULL');}})[_0x2cea('0x61')](function(){return _0x43922e;});}function getClosedOrderClause(_0x34a4e1,_0x82198){var _0x42881c='';var _0x14daae=['i.thirdDisposition',_0x2cea('0x6a'),_0x2cea('0x6b')];if(_0x34a4e1==='mail'){_0x14daae[_0x2cea('0x6c')](_0x2cea('0x6d'));}if(_0x82198[_0x2cea('0x6e')]==='0'&&_0x34a4e1===_0x2cea('0x34')){_0x42881c=_0x2cea('0x6d');}else{if(_0x82198[_0x2cea('0x6e')]==='1'){_0x14daae[_0x2cea('0x6f')]();}_0x42881c=_0x2cea('0x70')+_0x14daae[_0x2cea('0x71')](',\x20')+')';}return _0x42881c;}function getFilteredInteractions(_0x225d1b,_0x45e266,_0x175d9a,_0x400459){var _0x54abde=utils['getInteractionFK'](_0x225d1b);var _0x1364c3=_[_0x2cea('0x65')](_0x225d1b)+_0x2cea('0x72');var _0x104051=[];var _0x3c51e8=getTagsQuery();var _0x3bb026={'type':db[_0x2cea('0x73')]['QueryTypes']['SELECT'],'raw':!![]};var _0x1dfeaf=[];var _0x1875d4=[];return db[_0x2cea('0x74')]['query'](_0x3c51e8['toString'](),_0x3bb026)['then'](function(_0x3e2c5c){_0x104051=_[_0x2cea('0x75')](_0x3e2c5c,'id');_0x3bb026=_['merge'](_0x3bb026,{'model':db[_0x1364c3],'mapToModel':!![],'nest':!![]});if(_0x175d9a['fields']){_0x400459[_0x2cea('0x76')][_0x2cea('0x23')](function(_0x77f341){_0x45e266[_0x2cea('0x9')]('i.'+_0x77f341);});}else{_0x45e266[_0x2cea('0x9')](_0x2cea('0x77'),_0x2cea('0x78'));_0x45e266[_0x2cea('0x9')]('a.key',_0x2cea('0x79'));_0x45e266[_0x2cea('0x9')](_0x2cea('0x7a'),_0x2cea('0x7b'));if(_0x225d1b===_0x2cea('0x34')){_0x45e266['field'](_0x2cea('0x7c'),_0x2cea('0x7d'));_0x45e266['field'](_0x2cea('0x7e'),_0x2cea('0x7f'));_0x45e266[_0x2cea('0x9')](_0x2cea('0x80'));_0x45e266['field'](_0x2cea('0x81'));_0x45e266[_0x2cea('0x9')](_0x2cea('0x82'));_0x45e266['field'](_0x2cea('0x83'));_0x45e266[_0x2cea('0x9')](_0x2cea('0x84'));_0x45e266[_0x2cea('0x9')](_0x2cea('0x85'));_0x45e266[_0x2cea('0x9')](_0x2cea('0x86'));_0x45e266[_0x2cea('0x9')](_0x2cea('0x87'));_0x45e266['field'](_0x2cea('0x88'));_0x45e266[_0x2cea('0x9')](_0x2cea('0x6b'));_0x45e266[_0x2cea('0x9')]('i.secondDisposition');_0x45e266[_0x2cea('0x9')](_0x2cea('0x89'));_0x45e266[_0x2cea('0x9')](_0x2cea('0x6d'));_0x45e266['field'](_0x2cea('0x8a'));_0x45e266[_0x2cea('0x9')](_0x2cea('0x8b'));_0x45e266[_0x2cea('0x9')](_0x2cea('0x8c'));_0x45e266[_0x2cea('0x9')](_0x2cea('0x8d'));}else if(_0x225d1b===_0x2cea('0x30')){_0x45e266[_0x2cea('0x9')](_0x2cea('0x8e'),_0x2cea('0x7f'));}else{_0x45e266[_0x2cea('0x9')](_0x2cea('0x8f'),_0x2cea('0x7f'));}if(_0x225d1b!=='mail'){_0x45e266[_0x2cea('0x9')]('i.*');}_0x45e266[_0x2cea('0x9')](_0x2cea('0x90'),_0x2cea('0x91'));_0x45e266[_0x2cea('0x9')](_0x2cea('0x92'),'Contact.lastName');_0x45e266[_0x2cea('0x9')]('c.email','Contact.email');_0x45e266[_0x2cea('0x9')](_0x2cea('0x93'),_0x2cea('0x94'));_0x45e266['field'](_0x2cea('0x95'),_0x2cea('0x96'));_0x45e266[_0x2cea('0x9')](_0x2cea('0x97'),'Contact.fax');_0x45e266[_0x2cea('0x9')](_0x2cea('0x98'),'Owner.fullname');_0x45e266[_0x2cea('0x9')](_0x2cea('0x99'),_0x2cea('0x9a'));_0x45e266[_0x2cea('0x9')]('GROUP_CONCAT(DISTINCT\x20t.id)',_0x2cea('0x9b'));}if(_0x400459['limit']){_0x45e266[_0x2cea('0x9c')](_0x400459[_0x2cea('0x9c')]);}if(_0x400459[_0x2cea('0x9d')]){_0x45e266[_0x2cea('0x9d')](_0x400459[_0x2cea('0x9d')]);}return db[_0x2cea('0x74')][_0x2cea('0x9e')](_0x45e266[_0x2cea('0x9f')](),_0x3bb026);})[_0x2cea('0x61')](function(_0x287ebf){_0x1dfeaf=_0x287ebf;var _0x75a462=getUsersQuery(_0x225d1b,_0x1dfeaf);return db[_0x2cea('0x74')][_0x2cea('0x9e')](_0x75a462[_0x2cea('0x9f')](),_0x3bb026);})[_0x2cea('0x61')](function(_0x1a2f79){_0x1875d4=_[_0x2cea('0xa0')](_0x1a2f79,_0x54abde);if(_0x225d1b===_0x2cea('0x34')){return db[_0x2cea('0xa1')][_0x2cea('0xa2')]({'attributes':[_0x2cea('0xa3')],'raw':!![]});}})['then'](function(_0x3d94e2){var _0x270a07=_0x3d94e2?_0x3d94e2[_0x2cea('0xa3')]:undefined;var _0x5aec87=_0x1dfeaf[_0x2cea('0x15')](function(_0x437c21){return updateInteraction(_0x437c21,_0x104051,_0x1875d4,_0x270a07);});return Promise[_0x2cea('0xa4')](_0x5aec87);});}function countFilteredInteractions(_0x89acb6,_0x1e2b88){var _0x52f796=_0x89acb6['clone']();_0x52f796['field']('COUNT(*)');_0x52f796[_0x2cea('0x9')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x2cea('0x78'));var _0x52db25=utils[_0x2cea('0x22')](_0x1e2b88);if(!_[_0x2cea('0xa5')](_0x52db25)){_0x52f796[_0x2cea('0x13')](_0x2cea('0xa6'),_0x52db25);}var _0x5e9c7e={'type':db[_0x2cea('0x73')]['QueryTypes'][_0x2cea('0xa7')],'raw':!![]};return db[_0x2cea('0x74')][_0x2cea('0x9e')](_0x52f796[_0x2cea('0x9f')](),_0x5e9c7e);}module[_0x2cea('0xa8')]={'checkAccountsRestrictions':checkAccountsRestrictions,'countFilteredInteractions':countFilteredInteractions,'getClosedOrderClause':getClosedOrderClause,'getFilteredInteractions':getFilteredInteractions,'getInteractionsQuery':getInteractionsQuery,'parseAdvancedSearchFilter':parseAdvancedSearchFilter,'parseQueryParameters':parseQueryParameters,'skipInteractionsQuery':skipInteractionsQuery};