d6905fa68a71def3bcf1ba3fe060e80e4a995f88
[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 _0x77f8=['parseSearch','sqlOperator','[$or]','and','replace','[$and]','split','length','shift','match','forEach','filter','indexOf','map','conditions','push','DATE','operator','$eq','$between','includes','$gt','$lte','value','add','format','YYYY-MM-DD','castTo','text','CAST(','field','$ne','$notIn','\x20IS\x20NULL)','$in','IN\x20?','NOT\x20IN\x20?','=\x20?','<>\x20?','$substring','$endsWith','LIKE\x20?','$lt','<\x20?','>\x20?','<=\x20?','>=\x20?','BETWEEN\x20?\x20AND\x20?','start','$startsWith','pop','utcOffset','hours','minutes','lodash','moment'];(function(_0x2ae9ab,_0x54da0a){var _0x5579e1=function(_0x488c5a){while(--_0x488c5a){_0x2ae9ab['push'](_0x2ae9ab['shift']());}};_0x5579e1(++_0x54da0a);}(_0x77f8,0x186));var _0x877f=function(_0x4a747d,_0x3b747f){_0x4a747d=_0x4a747d-0x0;var _0x3a5b5c=_0x77f8[_0x4a747d];return _0x3a5b5c;};'use strict';var _=require(_0x877f('0x0'));var moment=require(_0x877f('0x1'));exports[_0x877f('0x2')]=function(_0x101796){var _0x23fb07={'conditions':[]};_0x23fb07[_0x877f('0x3')]=_['startsWith'](_0x101796,_0x877f('0x4'))?'or':_0x877f('0x5');var _0x5df9c1=_0x101796[_0x877f('0x6')](_0x877f('0x7'),'')[_0x877f('0x6')]('[$or]','')[_0x877f('0x8')]('||');for(var _0xc34230=0x0;_0xc34230<_0x5df9c1[_0x877f('0x9')];_0xc34230++){var _0x1d5620=_0x5df9c1[_0xc34230][_0x877f('0x8')](':=');var _0x1ddf88=_0x1d5620[0x0];var _0x1852e9=_0x1d5620['slice'](0x1);_0x1852e9['forEach'](function(_0x26ee70){var _0x564b48=_0x26ee70[_0x877f('0x8')]('[')[_0x877f('0xa')]();var _0x54787d=_0x26ee70[_0x877f('0xb')](/\[(.*?)\]/g);_0x54787d[_0x877f('0xc')](function(_0x17eab2){var _0x316d8b=_0x17eab2[_0x877f('0x8')]('[')[_0x877f('0xd')](function(_0xa77660){return _0xa77660[_0x877f('0xe')](']')>-0x1;})[_0x877f('0xf')](function(_0x28125b){return _0x28125b['split'](']')[0x0];})[0x0];_0x23fb07[_0x877f('0x10')][_0x877f('0x11')]({'field':_0x1ddf88,'operator':_0x564b48,'value':_0x316d8b});});});}return _0x23fb07;};exports['buildExpression']=function(_0x641dc3,_0x5986a4,_0x10864a){var _0x4b08aa={};if(_0x5986a4===_0x877f('0x12')){if(_0x10864a[_0x877f('0x13')]===_0x877f('0x14')){_0x10864a['operator']=_0x877f('0x15');_0x10864a['value']+=','+_0x10864a['value'];}else if(_[_0x877f('0x16')]([_0x877f('0x17'),_0x877f('0x18')],_0x10864a[_0x877f('0x13')])){_0x10864a[_0x877f('0x19')]=moment(_0x10864a[_0x877f('0x19')])[_0x877f('0x1a')](0x1,'days')[_0x877f('0x1b')](_0x877f('0x1c'));}}if(_0x10864a[_0x877f('0x1d')]){_0x5986a4=_0x10864a[_0x877f('0x1d')];_0x4b08aa[_0x877f('0x1e')]=_0x877f('0x1f')+_0x641dc3+'.'+_0x10864a['field']+'\x20AS\x20'+_0x10864a[_0x877f('0x1d')]+')\x20'+parseOperator(_0x10864a[_0x877f('0x13')]);}else{_0x4b08aa[_0x877f('0x1e')]=_0x641dc3+'.'+_0x10864a[_0x877f('0x20')]+'\x20'+parseOperator(_0x10864a[_0x877f('0x13')]);}if(_[_0x877f('0x16')]([_0x877f('0x21'),_0x877f('0x22')],_0x10864a['operator']))_0x4b08aa[_0x877f('0x1e')]='('+_0x4b08aa[_0x877f('0x1e')]+'\x20OR\x20'+_0x641dc3+'.'+_0x10864a['field']+_0x877f('0x23');_0x4b08aa[_0x877f('0x19')]=parseValue(_0x5986a4,_0x10864a[_0x877f('0x13')],_0x10864a[_0x877f('0x19')]);return _0x4b08aa;};function parseOperator(_0x36e9c4){var _0x23edce;switch(_0x36e9c4){case _0x877f('0x24'):_0x23edce=_0x877f('0x25');break;case _0x877f('0x22'):_0x23edce=_0x877f('0x26');break;case _0x877f('0x14'):_0x23edce=_0x877f('0x27');break;case _0x877f('0x21'):_0x23edce=_0x877f('0x28');break;case _0x877f('0x29'):case'$startsWith':case _0x877f('0x2a'):_0x23edce=_0x877f('0x2b');break;case _0x877f('0x2c'):_0x23edce=_0x877f('0x2d');break;case'$gt':_0x23edce=_0x877f('0x2e');break;case _0x877f('0x18'):_0x23edce=_0x877f('0x2f');break;case'$gte':_0x23edce=_0x877f('0x30');break;case _0x877f('0x15'):_0x23edce=_0x877f('0x31');break;}return _0x23edce;}function parseValue(_0x98cff6,_0x38c3bf,_0x569888){var _0x1b8eef={'start':undefined,'end':undefined};switch(_0x38c3bf){case _0x877f('0x24'):case'$notIn':_0x1b8eef[_0x877f('0x32')]=_0x569888[_0x877f('0x8')](',');break;case _0x877f('0x29'):_0x1b8eef[_0x877f('0x32')]='%'+_0x569888+'%';break;case _0x877f('0x33'):_0x1b8eef[_0x877f('0x32')]=_0x569888+'%';break;case _0x877f('0x2a'):_0x1b8eef['start']='%'+_0x569888;break;case'$between':var _0x25e456=_0x569888[_0x877f('0x8')](',');var _0x569888=_0x25e456[_0x877f('0xa')]();var _0x44b948=_0x25e456[_0x877f('0x34')]();if(_0x98cff6===_0x877f('0x12')){_0x569888=moment(_0x569888)[_0x877f('0x35')](0x0,!![])[_0x877f('0x1b')]();_0x44b948=moment(_0x44b948)[_0x877f('0x35')](0x0,!![])[_0x877f('0x1a')](0x17,_0x877f('0x36'))[_0x877f('0x1a')](0x3b,_0x877f('0x37'))[_0x877f('0x1a')](0x3b,'seconds')[_0x877f('0x1b')]();}_0x1b8eef={'start':_0x569888,'end':_0x44b948};break;default:_0x1b8eef['start']=_0x569888;break;}return _0x1b8eef;}