Built motion from commit 52c8a02d.|2.6.29
[motion2.git] / server / components / contacts / sql-utils.js
index 3449a0e..eb7628b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf5d1=['user','skip','keys','name','Contact','c.ListId\x20IN\x20?','concat','CONCAT_WS(\x27\x20\x27,\x20c.firstName,\x20c.lastName,\x20c.email)\x20LIKE\x20?','\x20=\x20?','resolve','then','fields','tag','filter','getLists','c.ListId\x20IS\x20NULL','limit','offset','group','subqry.id','having','order','subqry.','DESC','findAll','color','keyBy','SELECT','CmContact','sequelize','toString','Tags','clone','COUNT(*)','c.id','getSelectedTags','isEmpty','t.id\x20IN\x20?','Sequelize','QueryTypes','query','exports','squel','../parsers/advancedSearch','../parsers/qs','../interaction/utils','../../mysqldb','role','agent','search','autocomplete','true','select','from','cm_contacts','where','c.deletedAt\x20IS\x20NULL','subqry','left_join','cm_user_has_contacts','uc.CmContactId\x20=\x20','.id','cm_contact_has_tags','ct.CmContactId\x20=\x20','tools_tags','t.id\x20=\x20ct.TagId','lastName','phone','mobile','fax','email','ListId','createdAt','updatedAt','deletedAt','TagIds','includes','push','forEach','field','GROUP_CONCAT(DISTINCT\x20t.id)','expr','CONCAT(\x27,\x27,\x20subqry.TagIds,\x20\x27,\x27)\x20LIKE\x20?','replace','split','length','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','isNumeric','c.phone\x20LIKE\x20?','c.mobile\x20LIKE\x20?','c.fax\x20LIKE\x20?','c.lastName\x20LIKE\x20?','c.email\x20LIKE\x20?','parseSearch','sqlOperator','conditions','find','dateOfBirth','fieldType','datetime','castTo','DATE','type','text','value','end','Tag','map','tags','clause','and','ids','User','uc.UserId\x20=\x20?'];(function(_0x3947c9,_0x4d6c97){var _0x2e7871=function(_0x1236cc){while(--_0x1236cc){_0x3947c9['push'](_0x3947c9['shift']());}};_0x2e7871(++_0x4d6c97);}(_0xf5d1,0x183));var _0x1f5d=function(_0x3c22e0,_0x1dc6ea){_0x3c22e0=_0x3c22e0-0x0;var _0x215811=_0xf5d1[_0x3c22e0];return _0x215811;};'use strict';var _=require('lodash');var squel=require(_0x1f5d('0x0'));var as=require(_0x1f5d('0x1'));var qs=require(_0x1f5d('0x2'));var utils=require(_0x1f5d('0x3'));var db=require(_0x1f5d('0x4'))['db'];function skipContactsQuery(_0x38c568,_0x162cfa){var _0x135140=![];if(_0x38c568[_0x1f5d('0x5')]===_0x1f5d('0x6')&&!_0x162cfa[_0x1f5d('0x7')]&&!_0x162cfa['ListId']&&_0x162cfa[_0x1f5d('0x8')]!==_0x1f5d('0x9')){_0x135140=!![];}return _0x135140;}function getContactsSubquery(){return squel[_0x1f5d('0xa')]()[_0x1f5d('0xb')](_0x1f5d('0xc'),'c')[_0x1f5d('0xd')](_0x1f5d('0xe'));}function applyJoinClauses(_0x93cf0b,_0x1a5822){var _0x32101b=_0x1a5822?'c':_0x1f5d('0xf');_0x93cf0b[_0x1f5d('0x10')](_0x1f5d('0x11'),'uc',_0x1f5d('0x12')+_0x32101b+_0x1f5d('0x13'))[_0x1f5d('0x10')](_0x1f5d('0x14'),'ct',_0x1f5d('0x15')+_0x32101b+_0x1f5d('0x13'))[_0x1f5d('0x10')](_0x1f5d('0x16'),'t',_0x1f5d('0x17'));return _0x93cf0b;}function addFieldsToQuery(_0x28ebc8,_0x1b1aaa,_0x15fd1a,_0x49dc9d,_0x35e990){var _0x3a8ce5=_0x35e990?'c':'subqry';if(!_0x1b1aaa){_0x1b1aaa=['id','firstName',_0x1f5d('0x18'),_0x1f5d('0x19'),_0x1f5d('0x1a'),_0x1f5d('0x1b'),_0x1f5d('0x1c'),_0x1f5d('0x1d'),'CompanyId',_0x1f5d('0x1e'),_0x1f5d('0x1f'),_0x1f5d('0x20'),_0x1f5d('0x21')];}else if(!_0x1b1aaa[_0x1f5d('0x22')]('id')){_0x1b1aaa[_0x1f5d('0x23')]('id');}var _0x161781=_0x15fd1a&&_0x35e990||!_0x15fd1a&&!_0x35e990;if(_0x49dc9d){_0x161781=_0x49dc9d&&_0x35e990||!_0x49dc9d&&!_0x35e990;}_0x1b1aaa[_0x1f5d('0x24')](function(_0x193006){if(_0x193006===_0x1f5d('0x21')){if(_0x161781){_0x28ebc8[_0x1f5d('0x25')](_0x1f5d('0x26'),_0x193006);}else if(_0x15fd1a||_0x49dc9d){_0x28ebc8[_0x1f5d('0x25')](_0x3a8ce5+'.'+_0x193006);}}else{_0x28ebc8[_0x1f5d('0x25')](_0x3a8ce5+'.'+_0x193006);}});return _0x28ebc8;}function getSqlClauses(){var _0x3d475d={'default':squel[_0x1f5d('0x27')](),'fields':squel[_0x1f5d('0x27')](),'filter':squel['expr'](),'tags':{'clause':squel[_0x1f5d('0x27')](),'ids':null},'user':{'clause':squel[_0x1f5d('0x27')](),'skip':![]}};return _0x3d475d;}function parseTagParameter(_0x2bab3c){var _0x1197d8=squel[_0x1f5d('0x27')]();if(_0x2bab3c){var _0x25fb53=utils['getSelectedTags'](_0x2bab3c);_0x25fb53[_0x1f5d('0x24')](function(_0x616a2f){_0x1197d8['or'](_0x1f5d('0x28'),'%,'+_0x616a2f+',%');});}return _0x1197d8;}function parseSearchFilter(_0xc22af2){var _0x195485=squel[_0x1f5d('0x27')]();if(_0xc22af2){var _0x22e4ae=_0xc22af2[_0x1f5d('0x29')]('\x5c','\x5c\x5c')[_0x1f5d('0x29')](/'/g,'\x27\x27');if(_0x22e4ae[_0x1f5d('0x2a')]('\x20')[_0x1f5d('0x2b')]>0x1){_0x195485['or'](_0x1f5d('0x2c'),qs[_0x1f5d('0x2d')](_0x22e4ae,!![]),null);}else{if(qs[_0x1f5d('0x2e')](_0x22e4ae)){_0x195485['or']('c.id\x20LIKE\x20?',_0x22e4ae+'%');_0x195485['or'](_0x1f5d('0x2f'),_0x22e4ae+'%');_0x195485['or'](_0x1f5d('0x30'),_0x22e4ae+'%');_0x195485['or'](_0x1f5d('0x31'),_0x22e4ae+'%');}else if(qs['isEmail'](_0x22e4ae)){_0x195485['or']('c.email\x20LIKE\x20?',_0x22e4ae+'%');}else{_0x195485['or']('c.firstName\x20LIKE\x20?','%'+_0x22e4ae+'%');_0x195485['or'](_0x1f5d('0x32'),'%'+_0x22e4ae+'%');_0x195485['or'](_0x1f5d('0x33'),'%'+_0x22e4ae+'%');}}}return _0x195485;}function parseAdvancedSearchFilter(_0x53bf98,_0x3ad18e){var _0x13e86f=getSqlClauses();var _0x542824=as[_0x1f5d('0x34')](_0x53bf98);var _0x230742=_0x542824[_0x1f5d('0x35')];for(var _0x1e7a15=0x0;_0x1e7a15<_0x542824[_0x1f5d('0x36')][_0x1f5d('0x2b')];_0x1e7a15++){var _0x46a438=_0x542824[_0x1f5d('0x36')][_0x1e7a15];var _0x5c3dde='c';var _0x53f364=_[_0x1f5d('0x37')](_0x3ad18e,['name',_0x46a438['field']]);if(_0x53f364){if(_0x46a438[_0x1f5d('0x25')]===_0x1f5d('0x38')||_0x53f364[_0x1f5d('0x39')]===_0x1f5d('0x3a')){_0x46a438[_0x1f5d('0x3b')]=_0x1f5d('0x3c');}var _0x4a73fd=as['buildExpression'](_0x5c3dde,_0x53f364[_0x1f5d('0x3d')],_0x46a438);_0x13e86f['default'][_0x230742](_0x4a73fd[_0x1f5d('0x3e')],_0x4a73fd[_0x1f5d('0x3f')]['start'],_0x4a73fd[_0x1f5d('0x3f')][_0x1f5d('0x40')]);}else{if(_0x46a438[_0x1f5d('0x25')]===_0x1f5d('0x41')){var _0x56c4bc=_0x46a438[_0x1f5d('0x3f')][_0x1f5d('0x2a')](',')[_0x1f5d('0x42')](function(_0x34cf6b){return Number(_0x34cf6b);});var _0x37f34a=parseTagParameter(_0x56c4bc);_0x13e86f[_0x1f5d('0x43')][_0x1f5d('0x44')][_0x1f5d('0x45')](_0x37f34a);_0x13e86f[_0x1f5d('0x43')][_0x1f5d('0x46')]=_0x56c4bc;}else if(_0x46a438[_0x1f5d('0x25')]===_0x1f5d('0x47')){_0x13e86f['user'][_0x1f5d('0x44')][_0x1f5d('0x45')](_0x1f5d('0x48'),_0x46a438[_0x1f5d('0x3f')]);_0x13e86f[_0x1f5d('0x49')][_0x1f5d('0x4a')]=!![];}}}return _0x13e86f;}function parseModelFields(_0x440c0a,_0x506a26){var _0x6eaef6=squel[_0x1f5d('0x27')]();var _0x1a27f9=_(_0x440c0a)[_0x1f5d('0x4b')]()['map'](function(_0x1d5f1d){return _['some'](_0x506a26,[_0x1f5d('0x4c'),_0x1d5f1d])?_0x1d5f1d:undefined;})['compact']()[_0x1f5d('0x3f')]();if(_0x440c0a[_0x1f5d('0x4d')]){_0x1a27f9['push'](_0x1f5d('0x4d'));}if(_0x440c0a[_0x1f5d('0x47')]){_0x1a27f9[_0x1f5d('0x23')]('User');}if(_0x1a27f9[_0x1f5d('0x2b')]>0x0){_0x1a27f9[_0x1f5d('0x24')](function(_0x3464bc){if(_0x3464bc===_0x1f5d('0x1d')){_0x6eaef6[_0x1f5d('0x45')](_0x1f5d('0x4e'),[][_0x1f5d('0x4f')](_0x440c0a[_0x3464bc]));}else if(_0x3464bc==='Contact'){var _0x3c70cf='%'+_0x440c0a[_0x3464bc]+'%';_0x6eaef6[_0x1f5d('0x45')](_0x1f5d('0x50'),_0x3c70cf);}else if(_0x3464bc==='User'){_0x6eaef6[_0x1f5d('0x45')](_0x1f5d('0x48'),_0x440c0a[_0x3464bc]);}else{_0x6eaef6['and']('c.'+_0x3464bc+_0x1f5d('0x51'),_0x440c0a[_0x3464bc]);}});}return _0x6eaef6;}function parseQueryParameters(_0x19adfc,_0x5ab730){var _0x18d418=getSqlClauses();return Promise[_0x1f5d('0x52')]()[_0x1f5d('0x53')](function(){return parseModelFields(_0x19adfc,_0x5ab730);})[_0x1f5d('0x53')](function(_0x597e3f){_0x18d418[_0x1f5d('0x54')][_0x1f5d('0x45')](_0x597e3f);return parseTagParameter(_0x19adfc[_0x1f5d('0x55')]);})[_0x1f5d('0x53')](function(_0x2886b8){_0x18d418[_0x1f5d('0x43')][_0x1f5d('0x44')][_0x1f5d('0x45')](_0x2886b8);return parseSearchFilter(_0x19adfc[_0x1f5d('0x56')]);})[_0x1f5d('0x53')](function(_0x450483){_0x18d418[_0x1f5d('0x56')]=_0x450483;return _0x18d418;});}function checkListsRestrictions(_0x5d8889,_0x2b34db,_0x368a71){var _0x4866e5=squel[_0x1f5d('0x27')]();return Promise[_0x1f5d('0x52')]()[_0x1f5d('0x53')](function(){if(_0x2b34db[_0x1f5d('0x7')]&&_0x5d8889[_0x1f5d('0x5')]==='agent'&&!_0x368a71){return _0x5d8889[_0x1f5d('0x57')]({'attributes':['id'],'raw':!![]});}})[_0x1f5d('0x53')](function(_0x4284e6){if(_0x4284e6){if(_0x4284e6[_0x1f5d('0x2b')]===0x0){_0x4866e5[_0x1f5d('0x45')](_0x1f5d('0x58'));}else{_0x4866e5['and']('c.ListId\x20IN\x20?',_[_0x1f5d('0x42')](_0x4284e6,'id'));}}})['then'](function(){return _0x4866e5;});}function buildContactsQuery(_0x483169,_0xccc876,_0x401324,_0x3152b3,_0x3ff896,_0x5381b8){if(_0xccc876){_0xccc876=_0x401324['attributes'];}_0x483169=addFieldsToQuery(_0x483169,_0xccc876,_0x3152b3,_0x5381b8,!![]);var _0x5b07f8=squel[_0x1f5d('0xa')]();_0x5b07f8=addFieldsToQuery(_0x5b07f8,_0xccc876,_0x3152b3,_0x5381b8,![]);if(_0x3152b3||_0x5381b8){_0x483169=applyJoinClauses(_0x483169,!![]);_0x483169['group']('c.id');if(_0x401324['limit']){_0x5b07f8[_0x1f5d('0x59')](_0x401324[_0x1f5d('0x59')]);}if(_0x401324[_0x1f5d('0x5a')]){_0x5b07f8[_0x1f5d('0x5a')](_0x401324['offset']);}}else{_0x5b07f8=applyJoinClauses(_0x5b07f8,![]);_0x5b07f8[_0x1f5d('0x5b')](_0x1f5d('0x5c'));if(_0x401324[_0x1f5d('0x59')]){_0x483169['limit'](_0x401324[_0x1f5d('0x59')]);}if(_0x401324[_0x1f5d('0x5a')]){_0x483169[_0x1f5d('0x5a')](_0x401324[_0x1f5d('0x5a')]);}}_0x5b07f8[_0x1f5d('0x5d')](_0x3ff896);if(_0x401324[_0x1f5d('0x5e')]){_0x401324[_0x1f5d('0x5e')]['forEach'](function(_0x6f82c6){_0x483169[_0x1f5d('0x5e')]('c.'+_0x6f82c6[0x0],_0x6f82c6[0x1]==='DESC'?![]:!![]);_0x5b07f8[_0x1f5d('0x5e')](_0x1f5d('0x5f')+_0x6f82c6[0x0],_0x6f82c6[0x1]===_0x1f5d('0x60')?![]:!![]);});}_0x5b07f8[_0x1f5d('0xb')](_0x483169,_0x1f5d('0xf'));return _0x5b07f8;}function getFilteredContacts(_0x17b332){var _0x517b50=[];return db['Tag'][_0x1f5d('0x61')]({'attributes':['id',_0x1f5d('0x4c'),_0x1f5d('0x62')],'raw':!![]})[_0x1f5d('0x53')](function(_0x529432){_0x517b50=_[_0x1f5d('0x63')](_0x529432,'id');var _0x2af24d={'type':db['Sequelize']['QueryTypes'][_0x1f5d('0x64')],'model':db[_0x1f5d('0x65')],'mapToModel':!![],'nest':!![],'raw':!![]};return db[_0x1f5d('0x66')]['query'](_0x17b332[_0x1f5d('0x67')](),_0x2af24d);})[_0x1f5d('0x53')](function(_0x3ba624){_0x3ba624[_0x1f5d('0x24')](function(_0x370e40){if(_0x370e40['TagIds']){_0x370e40[_0x1f5d('0x68')]=[];_0x370e40['TagIds'][_0x1f5d('0x2a')](',')[_0x1f5d('0x24')](function(_0x36830e){_0x370e40[_0x1f5d('0x68')]['push'](_0x517b50[_0x36830e]);});}delete _0x370e40[_0x1f5d('0x21')];});return _0x3ba624;});}function countFilteredContacts(_0x4e2180,_0x51305f){var _0x4a5899=_0x4e2180[_0x1f5d('0x69')]();_0x4a5899[_0x1f5d('0x25')](_0x1f5d('0x6a'));_0x4a5899=applyJoinClauses(_0x4a5899,!![]);_0x4e2180[_0x1f5d('0x5b')](_0x1f5d('0x6b'));var _0x2603e2=utils[_0x1f5d('0x6c')](_0x51305f);if(!_[_0x1f5d('0x6d')](_0x2603e2)){_0x4a5899['where'](_0x1f5d('0x6e'),_0x2603e2);}var _0x20b43d={'type':db[_0x1f5d('0x6f')][_0x1f5d('0x70')][_0x1f5d('0x64')],'raw':!![]};return db[_0x1f5d('0x66')][_0x1f5d('0x71')](_0x4a5899[_0x1f5d('0x67')](),_0x20b43d)['then'](function(_0x1cf3fc){return _0x1cf3fc[0x0][_0x1f5d('0x6a')];});}module[_0x1f5d('0x72')]={'buildContactsQuery':buildContactsQuery,'checkListsRestrictions':checkListsRestrictions,'countFilteredContacts':countFilteredContacts,'getContactsSubquery':getContactsSubquery,'getFilteredContacts':getFilteredContacts,'parseAdvancedSearchFilter':parseAdvancedSearchFilter,'parseQueryParameters':parseQueryParameters,'skipContactsQuery':skipContactsQuery};
\ No newline at end of file
+var _0x3c5d=['TagIds','includes','forEach','field','GROUP_CONCAT(DISTINCT\x20t.id)','expr','getSelectedTags','CONCAT(\x27,\x27,\x20subqry.TagIds,\x20\x27,\x27)\x20LIKE\x20?','replace','split','length','getFullTextValue','isNumeric','c.id\x20LIKE\x20?','c.phone\x20LIKE\x20?','c.mobile\x20LIKE\x20?','isEmail','c.firstName\x20LIKE\x20?','c.email\x20LIKE\x20?','parseSearch','sqlOperator','conditions','find','fieldType','datetime','castTo','buildExpression','type','default','text','value','tags','clause','and','User','user','uc.UserId\x20=\x20?','skip','keys','some','name','compact','Contact','push','c.ListId\x20IN\x20?','concat','CONCAT_WS(\x27\x20\x27,\x20c.firstName,\x20c.lastName,\x20c.email)\x20LIKE\x20?','resolve','then','fields','filter','getLists','c.ListId\x20IS\x20NULL','map','group','c.id','limit','offset','having','order','DESC','subqry.','from','Tag','findAll','color','keyBy','Sequelize','QueryTypes','SELECT','CmContact','query','Tags','clone','COUNT(*)','isEmpty','t.id\x20IN\x20?','toString','lodash','squel','../parsers/advancedSearch','../parsers/qs','../interaction/utils','../../mysqldb','agent','ListId','autocomplete','true','select','cm_contacts','where','c.deletedAt\x20IS\x20NULL','subqry','left_join','uc.CmContactId\x20=\x20','.id','cm_contact_has_tags','ct.CmContactId\x20=\x20','t.id\x20=\x20ct.TagId','lastName','phone','mobile','email','CompanyId','updatedAt','deletedAt'];(function(_0x46c1fe,_0x50e5f5){var _0x42fd53=function(_0x1b30af){while(--_0x1b30af){_0x46c1fe['push'](_0x46c1fe['shift']());}};_0x42fd53(++_0x50e5f5);}(_0x3c5d,0x122));var _0xd3c5=function(_0x58c9f4,_0x57b328){_0x58c9f4=_0x58c9f4-0x0;var _0x2dca0e=_0x3c5d[_0x58c9f4];return _0x2dca0e;};'use strict';var _=require(_0xd3c5('0x0'));var squel=require(_0xd3c5('0x1'));var as=require(_0xd3c5('0x2'));var qs=require(_0xd3c5('0x3'));var utils=require(_0xd3c5('0x4'));var db=require(_0xd3c5('0x5'))['db'];function skipContactsQuery(_0x9bf18e,_0x55dc59){var _0x992eab=![];if(_0x9bf18e['role']===_0xd3c5('0x6')&&!_0x55dc59['search']&&!_0x55dc59[_0xd3c5('0x7')]&&_0x55dc59[_0xd3c5('0x8')]!==_0xd3c5('0x9')){_0x992eab=!![];}return _0x992eab;}function getContactsSubquery(){return squel[_0xd3c5('0xa')]()['from'](_0xd3c5('0xb'),'c')[_0xd3c5('0xc')](_0xd3c5('0xd'));}function applyJoinClauses(_0x2dfde8,_0x5d16bf){var _0x53da0a=_0x5d16bf?'c':_0xd3c5('0xe');_0x2dfde8[_0xd3c5('0xf')]('cm_user_has_contacts','uc',_0xd3c5('0x10')+_0x53da0a+_0xd3c5('0x11'))['left_join'](_0xd3c5('0x12'),'ct',_0xd3c5('0x13')+_0x53da0a+_0xd3c5('0x11'))['left_join']('tools_tags','t',_0xd3c5('0x14'));return _0x2dfde8;}function addFieldsToQuery(_0x517ff2,_0x531f00,_0x3b0085,_0x3b8bf2,_0x5b9d43){var _0x50bc3b=_0x5b9d43?'c':_0xd3c5('0xe');if(!_0x531f00){_0x531f00=['id','firstName',_0xd3c5('0x15'),_0xd3c5('0x16'),_0xd3c5('0x17'),'fax',_0xd3c5('0x18'),_0xd3c5('0x7'),_0xd3c5('0x19'),'createdAt',_0xd3c5('0x1a'),_0xd3c5('0x1b'),_0xd3c5('0x1c')];}else if(!_0x531f00[_0xd3c5('0x1d')]('id')){_0x531f00['push']('id');}var _0x49e30b=_0x3b0085&&_0x5b9d43||!_0x3b0085&&!_0x5b9d43;if(_0x3b8bf2){_0x49e30b=_0x3b8bf2&&_0x5b9d43||!_0x3b8bf2&&!_0x5b9d43;}_0x531f00[_0xd3c5('0x1e')](function(_0x5d1667){if(_0x5d1667==='TagIds'){if(_0x49e30b){_0x517ff2[_0xd3c5('0x1f')](_0xd3c5('0x20'),_0x5d1667);}else if(_0x3b0085||_0x3b8bf2){_0x517ff2['field'](_0x50bc3b+'.'+_0x5d1667);}}else{_0x517ff2[_0xd3c5('0x1f')](_0x50bc3b+'.'+_0x5d1667);}});return _0x517ff2;}function getSqlClauses(){var _0x15ae0f={'default':squel[_0xd3c5('0x21')](),'fields':squel['expr'](),'filter':squel[_0xd3c5('0x21')](),'tags':{'clause':squel[_0xd3c5('0x21')](),'ids':null},'user':{'clause':squel['expr'](),'skip':![]}};return _0x15ae0f;}function parseTagParameter(_0x11c10a){var _0x14f8e6=squel[_0xd3c5('0x21')]();if(_0x11c10a){var _0x2a4df5=utils[_0xd3c5('0x22')](_0x11c10a);_0x2a4df5['forEach'](function(_0x1cb880){_0x14f8e6['or'](_0xd3c5('0x23'),'%,'+_0x1cb880+',%');});}return _0x14f8e6;}function parseSearchFilter(_0x1855d8){var _0x45c95d=squel[_0xd3c5('0x21')]();if(_0x1855d8){var _0x1944e2=_0x1855d8[_0xd3c5('0x24')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(_0x1944e2[_0xd3c5('0x25')]('\x20')[_0xd3c5('0x26')]>0x1){_0x45c95d['or']('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xd3c5('0x27')](_0x1944e2,!![]),null);}else{if(qs[_0xd3c5('0x28')](_0x1944e2)){_0x45c95d['or'](_0xd3c5('0x29'),_0x1944e2+'%');_0x45c95d['or'](_0xd3c5('0x2a'),_0x1944e2+'%');_0x45c95d['or'](_0xd3c5('0x2b'),_0x1944e2+'%');_0x45c95d['or']('c.fax\x20LIKE\x20?',_0x1944e2+'%');}else if(qs[_0xd3c5('0x2c')](_0x1944e2)){_0x45c95d['or']('c.email\x20LIKE\x20?',_0x1944e2+'%');}else{_0x45c95d['or'](_0xd3c5('0x2d'),'%'+_0x1944e2+'%');_0x45c95d['or']('c.lastName\x20LIKE\x20?','%'+_0x1944e2+'%');_0x45c95d['or'](_0xd3c5('0x2e'),'%'+_0x1944e2+'%');}}}return _0x45c95d;}function parseAdvancedSearchFilter(_0x223f9e,_0x555f7d){var _0x42cf3f=getSqlClauses();var _0x2ed105=as[_0xd3c5('0x2f')](_0x223f9e);var _0x43a66b=_0x2ed105[_0xd3c5('0x30')];for(var _0x40e7c8=0x0;_0x40e7c8<_0x2ed105[_0xd3c5('0x31')][_0xd3c5('0x26')];_0x40e7c8++){var _0x5b6775=_0x2ed105['conditions'][_0x40e7c8];var _0x302545='c';var _0x5ce86f=_[_0xd3c5('0x32')](_0x555f7d,['name',_0x5b6775[_0xd3c5('0x1f')]]);if(_0x5ce86f){if(_0x5b6775[_0xd3c5('0x1f')]==='dateOfBirth'||_0x5ce86f[_0xd3c5('0x33')]===_0xd3c5('0x34')){_0x5b6775[_0xd3c5('0x35')]='DATE';}var _0x22c336=as[_0xd3c5('0x36')](_0x302545,_0x5ce86f[_0xd3c5('0x37')],_0x5b6775);_0x42cf3f[_0xd3c5('0x38')][_0x43a66b](_0x22c336[_0xd3c5('0x39')],_0x22c336[_0xd3c5('0x3a')]['start'],_0x22c336[_0xd3c5('0x3a')]['end']);}else{if(_0x5b6775[_0xd3c5('0x1f')]==='Tag'){var _0x43cdc4=_0x5b6775[_0xd3c5('0x3a')][_0xd3c5('0x25')](',')['map'](function(_0x4bbe29){return Number(_0x4bbe29);});var _0x3a76f6=parseTagParameter(_0x43cdc4);_0x42cf3f[_0xd3c5('0x3b')][_0xd3c5('0x3c')][_0xd3c5('0x3d')](_0x3a76f6);_0x42cf3f[_0xd3c5('0x3b')]['ids']=_0x43cdc4;}else if(_0x5b6775['field']===_0xd3c5('0x3e')){_0x42cf3f[_0xd3c5('0x3f')][_0xd3c5('0x3c')][_0xd3c5('0x3d')](_0xd3c5('0x40'),_0x5b6775[_0xd3c5('0x3a')]);_0x42cf3f[_0xd3c5('0x3f')][_0xd3c5('0x41')]=!![];}}}return _0x42cf3f;}function parseModelFields(_0x2488aa,_0x58610f){var _0x222345=squel[_0xd3c5('0x21')]();var _0x590c6d=_(_0x2488aa)[_0xd3c5('0x42')]()['map'](function(_0x4cb2d6){return _[_0xd3c5('0x43')](_0x58610f,[_0xd3c5('0x44'),_0x4cb2d6])?_0x4cb2d6:undefined;})[_0xd3c5('0x45')]()[_0xd3c5('0x3a')]();if(_0x2488aa[_0xd3c5('0x46')]){_0x590c6d['push'](_0xd3c5('0x46'));}if(_0x2488aa[_0xd3c5('0x3e')]){_0x590c6d[_0xd3c5('0x47')](_0xd3c5('0x3e'));}if(_0x590c6d['length']>0x0){_0x590c6d[_0xd3c5('0x1e')](function(_0x484f36){if(_0x484f36===_0xd3c5('0x7')){_0x222345[_0xd3c5('0x3d')](_0xd3c5('0x48'),[][_0xd3c5('0x49')](_0x2488aa[_0x484f36]));}else if(_0x484f36===_0xd3c5('0x46')){var _0x191c8f='%'+_0x2488aa[_0x484f36]+'%';_0x222345[_0xd3c5('0x3d')](_0xd3c5('0x4a'),_0x191c8f);}else if(_0x484f36===_0xd3c5('0x3e')){_0x222345[_0xd3c5('0x3d')](_0xd3c5('0x40'),_0x2488aa[_0x484f36]);}else{_0x222345[_0xd3c5('0x3d')]('c.'+_0x484f36+'\x20=\x20?',_0x2488aa[_0x484f36]);}});}return _0x222345;}function parseQueryParameters(_0x403f1c,_0x1d8e80){var _0xa90e43=getSqlClauses();return Promise[_0xd3c5('0x4b')]()[_0xd3c5('0x4c')](function(){return parseModelFields(_0x403f1c,_0x1d8e80);})[_0xd3c5('0x4c')](function(_0x1c196e){_0xa90e43[_0xd3c5('0x4d')][_0xd3c5('0x3d')](_0x1c196e);return parseTagParameter(_0x403f1c['tag']);})[_0xd3c5('0x4c')](function(_0x360fb9){_0xa90e43[_0xd3c5('0x3b')][_0xd3c5('0x3c')]['and'](_0x360fb9);return parseSearchFilter(_0x403f1c[_0xd3c5('0x4e')]);})[_0xd3c5('0x4c')](function(_0x35ac45){_0xa90e43['filter']=_0x35ac45;return _0xa90e43;});}function checkListsRestrictions(_0x3ed2a8,_0x2d0d39,_0x3b2c41){var _0x1857f0=squel['expr']();return Promise[_0xd3c5('0x4b')]()[_0xd3c5('0x4c')](function(){if(_0x2d0d39['search']&&_0x3ed2a8['role']===_0xd3c5('0x6')&&!_0x3b2c41){return _0x3ed2a8[_0xd3c5('0x4f')]({'attributes':['id'],'raw':!![]});}})['then'](function(_0x2a0ac5){if(_0x2a0ac5){if(_0x2a0ac5[_0xd3c5('0x26')]===0x0){_0x1857f0[_0xd3c5('0x3d')](_0xd3c5('0x50'));}else{_0x1857f0[_0xd3c5('0x3d')](_0xd3c5('0x48'),_[_0xd3c5('0x51')](_0x2a0ac5,'id'));}}})[_0xd3c5('0x4c')](function(){return _0x1857f0;});}function buildContactsQuery(_0x187358,_0x58576a,_0x421e2a,_0x569644,_0x45eb3a,_0x5bbdf1){if(_0x58576a){_0x58576a=_0x421e2a['attributes'];}_0x187358=addFieldsToQuery(_0x187358,_0x58576a,_0x569644,_0x5bbdf1,!![]);var _0x1a4420=squel[_0xd3c5('0xa')]();_0x1a4420=addFieldsToQuery(_0x1a4420,_0x58576a,_0x569644,_0x5bbdf1,![]);if(_0x569644||_0x5bbdf1){_0x187358=applyJoinClauses(_0x187358,!![]);_0x187358[_0xd3c5('0x52')](_0xd3c5('0x53'));if(_0x421e2a[_0xd3c5('0x54')]){_0x1a4420[_0xd3c5('0x54')](_0x421e2a[_0xd3c5('0x54')]);}if(_0x421e2a[_0xd3c5('0x55')]){_0x1a4420['offset'](_0x421e2a['offset']);}}else{_0x1a4420=applyJoinClauses(_0x1a4420,![]);_0x1a4420[_0xd3c5('0x52')]('subqry.id');if(_0x421e2a[_0xd3c5('0x54')]){_0x187358['limit'](_0x421e2a['limit']);}if(_0x421e2a['offset']){_0x187358[_0xd3c5('0x55')](_0x421e2a[_0xd3c5('0x55')]);}}_0x1a4420[_0xd3c5('0x56')](_0x45eb3a);if(_0x421e2a['order']){_0x421e2a[_0xd3c5('0x57')]['forEach'](function(_0x3a99e2){_0x187358[_0xd3c5('0x57')]('c.'+_0x3a99e2[0x0],_0x3a99e2[0x1]===_0xd3c5('0x58')?![]:!![]);_0x1a4420[_0xd3c5('0x57')](_0xd3c5('0x59')+_0x3a99e2[0x0],_0x3a99e2[0x1]==='DESC'?![]:!![]);});}_0x1a4420[_0xd3c5('0x5a')](_0x187358,_0xd3c5('0xe'));return _0x1a4420;}function getFilteredContacts(_0x3b0d73){var _0x290ba6=[];return db[_0xd3c5('0x5b')][_0xd3c5('0x5c')]({'attributes':['id',_0xd3c5('0x44'),_0xd3c5('0x5d')],'raw':!![]})[_0xd3c5('0x4c')](function(_0x3ac8b0){_0x290ba6=_[_0xd3c5('0x5e')](_0x3ac8b0,'id');var _0x5e3fa0={'type':db[_0xd3c5('0x5f')][_0xd3c5('0x60')][_0xd3c5('0x61')],'model':db[_0xd3c5('0x62')],'mapToModel':!![],'nest':!![],'raw':!![]};return db['sequelize'][_0xd3c5('0x63')](_0x3b0d73['toString'](),_0x5e3fa0);})[_0xd3c5('0x4c')](function(_0x515273){_0x515273[_0xd3c5('0x1e')](function(_0xa47567){if(_0xa47567[_0xd3c5('0x1c')]){_0xa47567['Tags']=[];_0xa47567[_0xd3c5('0x1c')]['split'](',')[_0xd3c5('0x1e')](function(_0x2fb037){_0xa47567[_0xd3c5('0x64')][_0xd3c5('0x47')](_0x290ba6[_0x2fb037]);});}delete _0xa47567['TagIds'];});return _0x515273;});}function countFilteredContacts(_0x538dea,_0x2cd0bb){var _0x50662b=_0x538dea[_0xd3c5('0x65')]();_0x50662b['field'](_0xd3c5('0x66'));_0x50662b=applyJoinClauses(_0x50662b,!![]);_0x538dea['group']('c.id');var _0x50ff30=utils[_0xd3c5('0x22')](_0x2cd0bb);if(!_[_0xd3c5('0x67')](_0x50ff30)){_0x50662b['where'](_0xd3c5('0x68'),_0x50ff30);}var _0x2d338f={'type':db['Sequelize'][_0xd3c5('0x60')][_0xd3c5('0x61')],'raw':!![]};return db['sequelize'][_0xd3c5('0x63')](_0x50662b[_0xd3c5('0x69')](),_0x2d338f)[_0xd3c5('0x4c')](function(_0x1d7102){return _0x1d7102[0x0]['COUNT(*)'];});}module['exports']={'buildContactsQuery':buildContactsQuery,'checkListsRestrictions':checkListsRestrictions,'countFilteredContacts':countFilteredContacts,'getContactsSubquery':getContactsSubquery,'getFilteredContacts':getFilteredContacts,'parseAdvancedSearchFilter':parseAdvancedSearchFilter,'parseQueryParameters':parseQueryParameters,'skipContactsQuery':skipContactsQuery};
\ No newline at end of file