bde980620edadb8ffc8c705b0622dd32fe8d7370
[motion2.git] / server / components / parsers / advancedSearch.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 _0xb4f6=['LIKE\x20?','<\x20?','>\x20?','<=\x20?','$gte','>=\x20?','$in','start','utcOffset','format','hours','seconds','moment','parseSearch','[$or]','and','replace','split','length','slice','forEach','shift','match','filter','map','conditions','push','buildExpression','DATE','$eq','operator','$between','value','includes','$gt','$lte','add','YYYY-MM-DD','castTo','text','field','$notIn','\x20OR\x20','IN\x20?','NOT\x20IN\x20?','=\x20?','$ne','<>\x20?','$substring','$endsWith'];(function(_0x2be757,_0x32b312){var _0x195cff=function(_0x3a3e33){while(--_0x3a3e33){_0x2be757['push'](_0x2be757['shift']());}};_0x195cff(++_0x32b312);}(_0xb4f6,0x1ce));var _0x6b4f=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0xb4f6[_0x321bb2];return _0x9c12ed;};'use strict';var _=require('lodash');var moment=require(_0x6b4f('0x0'));exports[_0x6b4f('0x1')]=function(_0xb2fbc4){var _0x12f5cd={'conditions':[]};_0x12f5cd['sqlOperator']=_['startsWith'](_0xb2fbc4,_0x6b4f('0x2'))?'or':_0x6b4f('0x3');var _0x379038=_0xb2fbc4[_0x6b4f('0x4')]('[$and]','')[_0x6b4f('0x4')]('[$or]','')[_0x6b4f('0x5')]('||');for(var _0x36f0ec=0x0;_0x36f0ec<_0x379038[_0x6b4f('0x6')];_0x36f0ec++){var _0x465f68=_0x379038[_0x36f0ec][_0x6b4f('0x5')](':=');var _0x3407de=_0x465f68[0x0];var _0x297f72=_0x465f68[_0x6b4f('0x7')](0x1);_0x297f72[_0x6b4f('0x8')](function(_0x186eff){var _0x220772=_0x186eff['split']('[')[_0x6b4f('0x9')]();var _0x22854d=_0x186eff[_0x6b4f('0xa')](/\[(.*?)\]/g);_0x22854d[_0x6b4f('0x8')](function(_0x31a09f){var _0x30ed79=_0x31a09f[_0x6b4f('0x5')]('[')[_0x6b4f('0xb')](function(_0x5e1ffa){return _0x5e1ffa['indexOf'](']')>-0x1;})[_0x6b4f('0xc')](function(_0x52a494){return _0x52a494[_0x6b4f('0x5')](']')[0x0];})[0x0];_0x12f5cd[_0x6b4f('0xd')][_0x6b4f('0xe')]({'field':_0x3407de,'operator':_0x220772,'value':_0x30ed79});});});}return _0x12f5cd;};exports[_0x6b4f('0xf')]=function(_0x1b4fcf,_0x566cbc,_0xd893ad){var _0x4529f6={};if(_0x566cbc===_0x6b4f('0x10')){if(_0xd893ad['operator']===_0x6b4f('0x11')){_0xd893ad[_0x6b4f('0x12')]=_0x6b4f('0x13');_0xd893ad[_0x6b4f('0x14')]+=','+_0xd893ad[_0x6b4f('0x14')];}else if(_[_0x6b4f('0x15')]([_0x6b4f('0x16'),_0x6b4f('0x17')],_0xd893ad[_0x6b4f('0x12')])){_0xd893ad[_0x6b4f('0x14')]=moment(_0xd893ad[_0x6b4f('0x14')])[_0x6b4f('0x18')](0x1,'days')['format'](_0x6b4f('0x19'));}}if(_0xd893ad[_0x6b4f('0x1a')]){_0x566cbc=_0xd893ad[_0x6b4f('0x1a')];_0x4529f6[_0x6b4f('0x1b')]='CAST('+_0x1b4fcf+'.'+_0xd893ad[_0x6b4f('0x1c')]+'\x20AS\x20'+_0xd893ad[_0x6b4f('0x1a')]+')\x20'+parseOperator(_0xd893ad[_0x6b4f('0x12')]);}else{_0x4529f6[_0x6b4f('0x1b')]=_0x1b4fcf+'.'+_0xd893ad[_0x6b4f('0x1c')]+'\x20'+parseOperator(_0xd893ad[_0x6b4f('0x12')]);}if(_[_0x6b4f('0x15')](['$ne',_0x6b4f('0x1d')],_0xd893ad[_0x6b4f('0x12')]))_0x4529f6[_0x6b4f('0x1b')]='('+_0x4529f6[_0x6b4f('0x1b')]+_0x6b4f('0x1e')+_0x1b4fcf+'.'+_0xd893ad[_0x6b4f('0x1c')]+'\x20IS\x20NULL)';_0x4529f6[_0x6b4f('0x14')]=parseValue(_0x566cbc,_0xd893ad['operator'],_0xd893ad[_0x6b4f('0x14')]);return _0x4529f6;};function parseOperator(_0x264116){var _0x2ba09f;switch(_0x264116){case'$in':_0x2ba09f=_0x6b4f('0x1f');break;case _0x6b4f('0x1d'):_0x2ba09f=_0x6b4f('0x20');break;case _0x6b4f('0x11'):_0x2ba09f=_0x6b4f('0x21');break;case _0x6b4f('0x22'):_0x2ba09f=_0x6b4f('0x23');break;case _0x6b4f('0x24'):case'$startsWith':case _0x6b4f('0x25'):_0x2ba09f=_0x6b4f('0x26');break;case'$lt':_0x2ba09f=_0x6b4f('0x27');break;case _0x6b4f('0x16'):_0x2ba09f=_0x6b4f('0x28');break;case _0x6b4f('0x17'):_0x2ba09f=_0x6b4f('0x29');break;case _0x6b4f('0x2a'):_0x2ba09f=_0x6b4f('0x2b');break;case _0x6b4f('0x13'):_0x2ba09f='BETWEEN\x20?\x20AND\x20?';break;}return _0x2ba09f;}function parseValue(_0x202fc2,_0x49891c,_0x552804){var _0x3058b1={'start':undefined,'end':undefined};switch(_0x49891c){case _0x6b4f('0x2c'):case _0x6b4f('0x1d'):_0x3058b1['start']=_0x552804[_0x6b4f('0x5')](',');break;case _0x6b4f('0x24'):_0x3058b1['start']='%'+_0x552804+'%';break;case'$startsWith':_0x3058b1[_0x6b4f('0x2d')]=_0x552804+'%';break;case'$endsWith':_0x3058b1[_0x6b4f('0x2d')]='%'+_0x552804;break;case _0x6b4f('0x13'):var _0x532058=_0x552804[_0x6b4f('0x5')](',');var _0x552804=_0x532058[_0x6b4f('0x9')]();var _0x44897f=_0x532058['pop']();if(_0x202fc2==='DATE'){_0x552804=moment(_0x552804)[_0x6b4f('0x2e')](0x0,!![])[_0x6b4f('0x2f')]();_0x44897f=moment(_0x44897f)[_0x6b4f('0x2e')](0x0,!![])[_0x6b4f('0x18')](0x17,_0x6b4f('0x30'))[_0x6b4f('0x18')](0x3b,'minutes')[_0x6b4f('0x18')](0x3b,_0x6b4f('0x31'))[_0x6b4f('0x2f')]();}_0x3058b1={'start':_0x552804,'end':_0x44897f};break;default:_0x3058b1[_0x6b4f('0x2d')]=_0x552804;break;}return _0x3058b1;}