Built motion from commit (unavailable).|2.5.30
[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 _0xce2c=['includes','$ne','$notIn','\x20OR\x20','\x20IS\x20NULL)','$in','IN\x20?','NOT\x20IN\x20?','=\x20?','<>\x20?','$startsWith','$endsWith','LIKE\x20?','$lt','>\x20?','$gte','start','$substring','utcOffset','minutes','seconds','lodash','moment','parseSearch','startsWith','[$or]','and','replace','[$and]','split','length','slice','forEach','match','filter','indexOf','map','conditions','buildExpression','DATE','$eq','operator','$between','value','$gt','$lte','add','format','YYYY-MM-DD','castTo','text','field','\x20AS\x20'];(function(_0x222c59,_0x40783f){var _0x1b9ee3=function(_0x3d7100){while(--_0x3d7100){_0x222c59['push'](_0x222c59['shift']());}};_0x1b9ee3(++_0x40783f);}(_0xce2c,0x1bd));var _0xcce2=function(_0x365a5b,_0xeb35ed){_0x365a5b=_0x365a5b-0x0;var _0x437fe1=_0xce2c[_0x365a5b];return _0x437fe1;};'use strict';var _=require(_0xcce2('0x0'));var moment=require(_0xcce2('0x1'));exports[_0xcce2('0x2')]=function(_0x5b8c02){var _0x4f5d19={'conditions':[]};_0x4f5d19['sqlOperator']=_[_0xcce2('0x3')](_0x5b8c02,_0xcce2('0x4'))?'or':_0xcce2('0x5');var _0x47d49b=_0x5b8c02[_0xcce2('0x6')](_0xcce2('0x7'),'')[_0xcce2('0x6')](_0xcce2('0x4'),'')[_0xcce2('0x8')]('||');for(var _0x1da264=0x0;_0x1da264<_0x47d49b[_0xcce2('0x9')];_0x1da264++){var _0x133aca=_0x47d49b[_0x1da264][_0xcce2('0x8')](':=');var _0x2fbc43=_0x133aca[0x0];var _0x421bef=_0x133aca[_0xcce2('0xa')](0x1);_0x421bef[_0xcce2('0xb')](function(_0x361325){var _0x252966=_0x361325[_0xcce2('0x8')]('[')['shift']();var _0x9e0ef3=_0x361325[_0xcce2('0xc')](/\[(.*?)\]/g);_0x9e0ef3[_0xcce2('0xb')](function(_0x556d63){var _0x522c44=_0x556d63[_0xcce2('0x8')]('[')[_0xcce2('0xd')](function(_0x1aeace){return _0x1aeace[_0xcce2('0xe')](']')>-0x1;})[_0xcce2('0xf')](function(_0x2f1356){return _0x2f1356['split'](']')[0x0];})[0x0];_0x4f5d19[_0xcce2('0x10')]['push']({'field':_0x2fbc43,'operator':_0x252966,'value':_0x522c44});});});}return _0x4f5d19;};exports[_0xcce2('0x11')]=function(_0x56e011,_0x32b55a,_0x5e2ccc){var _0x585cda={};if(_0x32b55a===_0xcce2('0x12')){if(_0x5e2ccc['operator']===_0xcce2('0x13')){_0x5e2ccc[_0xcce2('0x14')]=_0xcce2('0x15');_0x5e2ccc[_0xcce2('0x16')]+=','+_0x5e2ccc[_0xcce2('0x16')];}else if(_['includes']([_0xcce2('0x17'),_0xcce2('0x18')],_0x5e2ccc[_0xcce2('0x14')])){_0x5e2ccc[_0xcce2('0x16')]=moment(_0x5e2ccc[_0xcce2('0x16')])[_0xcce2('0x19')](0x1,'days')[_0xcce2('0x1a')](_0xcce2('0x1b'));}}if(_0x5e2ccc[_0xcce2('0x1c')]){_0x32b55a=_0x5e2ccc['castTo'];_0x585cda[_0xcce2('0x1d')]='CAST('+_0x56e011+'.'+_0x5e2ccc[_0xcce2('0x1e')]+_0xcce2('0x1f')+_0x5e2ccc['castTo']+')\x20'+parseOperator(_0x5e2ccc[_0xcce2('0x14')]);}else{_0x585cda[_0xcce2('0x1d')]=_0x56e011+'.'+_0x5e2ccc[_0xcce2('0x1e')]+'\x20'+parseOperator(_0x5e2ccc['operator']);}if(_[_0xcce2('0x20')]([_0xcce2('0x21'),_0xcce2('0x22')],_0x5e2ccc[_0xcce2('0x14')]))_0x585cda[_0xcce2('0x1d')]='('+_0x585cda[_0xcce2('0x1d')]+_0xcce2('0x23')+_0x56e011+'.'+_0x5e2ccc[_0xcce2('0x1e')]+_0xcce2('0x24');_0x585cda['value']=parseValue(_0x32b55a,_0x5e2ccc[_0xcce2('0x14')],_0x5e2ccc[_0xcce2('0x16')]);return _0x585cda;};function parseOperator(_0x545900){var _0xffa48a;switch(_0x545900){case _0xcce2('0x25'):_0xffa48a=_0xcce2('0x26');break;case'$notIn':_0xffa48a=_0xcce2('0x27');break;case _0xcce2('0x13'):_0xffa48a=_0xcce2('0x28');break;case _0xcce2('0x21'):_0xffa48a=_0xcce2('0x29');break;case'$substring':case _0xcce2('0x2a'):case _0xcce2('0x2b'):_0xffa48a=_0xcce2('0x2c');break;case _0xcce2('0x2d'):_0xffa48a='<\x20?';break;case _0xcce2('0x17'):_0xffa48a=_0xcce2('0x2e');break;case _0xcce2('0x18'):_0xffa48a='<=\x20?';break;case _0xcce2('0x2f'):_0xffa48a='>=\x20?';break;case _0xcce2('0x15'):_0xffa48a='BETWEEN\x20?\x20AND\x20?';break;}return _0xffa48a;}function parseValue(_0x285706,_0xfffdf7,_0x84ab04){var _0x5bc547={'start':undefined,'end':undefined};switch(_0xfffdf7){case _0xcce2('0x25'):case'$notIn':_0x5bc547[_0xcce2('0x30')]=_0x84ab04[_0xcce2('0x8')](',');break;case _0xcce2('0x31'):_0x5bc547[_0xcce2('0x30')]='%'+_0x84ab04+'%';break;case _0xcce2('0x2a'):_0x5bc547['start']=_0x84ab04+'%';break;case _0xcce2('0x2b'):_0x5bc547[_0xcce2('0x30')]='%'+_0x84ab04;break;case _0xcce2('0x15'):var _0x1ec344=_0x84ab04['split'](',');var _0x84ab04=_0x1ec344['shift']();var _0x153597=_0x1ec344['pop']();if(_0x285706==='DATE'){_0x84ab04=moment(_0x84ab04)[_0xcce2('0x32')](0x0,!![])[_0xcce2('0x1a')]();_0x153597=moment(_0x153597)[_0xcce2('0x32')](0x0,!![])[_0xcce2('0x19')](0x17,'hours')[_0xcce2('0x19')](0x3b,_0xcce2('0x33'))[_0xcce2('0x19')](0x3b,_0xcce2('0x34'))[_0xcce2('0x1a')]();}_0x5bc547={'start':_0x84ab04,'end':_0x153597};break;default:_0x5bc547[_0xcce2('0x30')]=_0x84ab04;break;}return _0x5bc547;}