Built motion from commit (unavailable).|2.5.4
[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 _0xf30f=['YYYY-MM-DD','castTo','text','CAST(','field','\x20AS\x20','includes','$ne','$notIn','\x20IS\x20NULL)','$in','IN\x20?','NOT\x20IN\x20?','<>\x20?','$substring','$startsWith','$endsWith','LIKE\x20?','$lt','<\x20?','>\x20?','$lte','<=\x20?','$gte','>=\x20?','BETWEEN\x20?\x20AND\x20?','start','pop','utcOffset','format','hours','minutes','lodash','moment','sqlOperator','startsWith','[$or]','and','replace','length','slice','split','shift','match','forEach','filter','indexOf','map','conditions','buildExpression','DATE','$eq','$between','value','$gt','operator','add','days'];(function(_0x487578,_0x540a0b){var _0x548568=function(_0x3b61cb){while(--_0x3b61cb){_0x487578['push'](_0x487578['shift']());}};_0x548568(++_0x540a0b);}(_0xf30f,0x1b6));var _0xff30=function(_0x18ab2a,_0x4debcd){_0x18ab2a=_0x18ab2a-0x0;var _0x16dcee=_0xf30f[_0x18ab2a];return _0x16dcee;};'use strict';var _=require(_0xff30('0x0'));var moment=require(_0xff30('0x1'));exports['parseSearch']=function(_0x195ce4){var _0x18be59={'conditions':[]};_0x18be59[_0xff30('0x2')]=_[_0xff30('0x3')](_0x195ce4,_0xff30('0x4'))?'or':_0xff30('0x5');var _0x1c042d=_0x195ce4['replace']('[$and]','')[_0xff30('0x6')](_0xff30('0x4'),'')['split']('||');for(var _0x1acf55=0x0;_0x1acf55<_0x1c042d[_0xff30('0x7')];_0x1acf55++){var _0x48eb83=_0x1c042d[_0x1acf55]['split'](':=');var _0xe457d=_0x48eb83[0x0];var _0x49ff46=_0x48eb83[_0xff30('0x8')](0x1);_0x49ff46['forEach'](function(_0x3cfcfc){var _0x38e50e=_0x3cfcfc[_0xff30('0x9')]('[')[_0xff30('0xa')]();var _0x8247a1=_0x3cfcfc[_0xff30('0xb')](/\[(.*?)\]/g);_0x8247a1[_0xff30('0xc')](function(_0xd572a5){var _0xa926f1=_0xd572a5[_0xff30('0x9')]('[')[_0xff30('0xd')](function(_0x166309){return _0x166309[_0xff30('0xe')](']')>-0x1;})[_0xff30('0xf')](function(_0x14e27d){return _0x14e27d[_0xff30('0x9')](']')[0x0];})[0x0];_0x18be59[_0xff30('0x10')]['push']({'field':_0xe457d,'operator':_0x38e50e,'value':_0xa926f1});});});}return _0x18be59;};exports[_0xff30('0x11')]=function(_0xbb8138,_0x58d974,_0x315c2d){var _0x40a7d8={};if(_0x58d974===_0xff30('0x12')){if(_0x315c2d['operator']===_0xff30('0x13')){_0x315c2d['operator']=_0xff30('0x14');_0x315c2d[_0xff30('0x15')]+=','+_0x315c2d[_0xff30('0x15')];}else if(_['includes']([_0xff30('0x16'),'$lte'],_0x315c2d[_0xff30('0x17')])){_0x315c2d['value']=moment(_0x315c2d['value'])[_0xff30('0x18')](0x1,_0xff30('0x19'))['format'](_0xff30('0x1a'));}}if(_0x315c2d[_0xff30('0x1b')]){_0x58d974=_0x315c2d[_0xff30('0x1b')];_0x40a7d8[_0xff30('0x1c')]=_0xff30('0x1d')+_0xbb8138+'.'+_0x315c2d[_0xff30('0x1e')]+_0xff30('0x1f')+_0x315c2d['castTo']+')\x20'+parseOperator(_0x315c2d[_0xff30('0x17')]);}else{_0x40a7d8[_0xff30('0x1c')]=_0xbb8138+'.'+_0x315c2d['field']+'\x20'+parseOperator(_0x315c2d[_0xff30('0x17')]);}if(_[_0xff30('0x20')]([_0xff30('0x21'),_0xff30('0x22')],_0x315c2d['operator']))_0x40a7d8['text']='('+_0x40a7d8['text']+'\x20OR\x20'+_0xbb8138+'.'+_0x315c2d[_0xff30('0x1e')]+_0xff30('0x23');_0x40a7d8[_0xff30('0x15')]=parseValue(_0x58d974,_0x315c2d['operator'],_0x315c2d['value']);return _0x40a7d8;};function parseOperator(_0x43a3a1){var _0x42a057;switch(_0x43a3a1){case _0xff30('0x24'):_0x42a057=_0xff30('0x25');break;case _0xff30('0x22'):_0x42a057=_0xff30('0x26');break;case'$eq':_0x42a057='=\x20?';break;case _0xff30('0x21'):_0x42a057=_0xff30('0x27');break;case _0xff30('0x28'):case _0xff30('0x29'):case _0xff30('0x2a'):_0x42a057=_0xff30('0x2b');break;case _0xff30('0x2c'):_0x42a057=_0xff30('0x2d');break;case _0xff30('0x16'):_0x42a057=_0xff30('0x2e');break;case _0xff30('0x2f'):_0x42a057=_0xff30('0x30');break;case _0xff30('0x31'):_0x42a057=_0xff30('0x32');break;case _0xff30('0x14'):_0x42a057=_0xff30('0x33');break;}return _0x42a057;}function parseValue(_0x49bb11,_0x58dce8,_0x49aeb7){var _0x4eb644={'start':undefined,'end':undefined};switch(_0x58dce8){case _0xff30('0x24'):case _0xff30('0x22'):_0x4eb644[_0xff30('0x34')]=_0x49aeb7[_0xff30('0x9')](',');break;case'$substring':_0x4eb644[_0xff30('0x34')]='%'+_0x49aeb7+'%';break;case _0xff30('0x29'):_0x4eb644['start']=_0x49aeb7+'%';break;case _0xff30('0x2a'):_0x4eb644[_0xff30('0x34')]='%'+_0x49aeb7;break;case _0xff30('0x14'):var _0x51b91b=_0x49aeb7['split'](',');var _0x49aeb7=_0x51b91b[_0xff30('0xa')]();var _0x3e674e=_0x51b91b[_0xff30('0x35')]();if(_0x49bb11===_0xff30('0x12')){_0x49aeb7=moment(_0x49aeb7)[_0xff30('0x36')](0x0,!![])[_0xff30('0x37')]();_0x3e674e=moment(_0x3e674e)[_0xff30('0x36')](0x0,!![])[_0xff30('0x18')](0x17,_0xff30('0x38'))[_0xff30('0x18')](0x3b,_0xff30('0x39'))[_0xff30('0x18')](0x3b,'seconds')[_0xff30('0x37')]();}_0x4eb644={'start':_0x49aeb7,'end':_0x3e674e};break;default:_0x4eb644[_0xff30('0x34')]=_0x49aeb7;break;}return _0x4eb644;}