Built motion from commit 9d1906d1.|2.5.40
[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 _0xe5f9=['and','replace','split','length','slice','forEach','match','filter','indexOf','map','conditions','buildExpression','DATE','operator','$eq','value','$lte','format','YYYY-MM-DD','castTo','CAST(','field','\x20AS\x20','text','includes','$ne','\x20OR\x20','\x20IS\x20NULL)','$in','$notIn','NOT\x20IN\x20?','=\x20?','<>\x20?','$endsWith','$lt','<\x20?','$gt','<=\x20?','$gte','>=\x20?','$between','BETWEEN\x20?\x20AND\x20?','$startsWith','start','shift','pop','utcOffset','add','hours','minutes','seconds','moment','parseSearch'];(function(_0xfae23b,_0x2be4ba){var _0x200640=function(_0x4ae258){while(--_0x4ae258){_0xfae23b['push'](_0xfae23b['shift']());}};_0x200640(++_0x2be4ba);}(_0xe5f9,0x1a6));var _0x9e5f=function(_0x238d10,_0x5cfb70){_0x238d10=_0x238d10-0x0;var _0x57765a=_0xe5f9[_0x238d10];return _0x57765a;};'use strict';var _=require('lodash');var moment=require(_0x9e5f('0x0'));exports[_0x9e5f('0x1')]=function(_0x41ae8c){var _0x15956b={'conditions':[]};_0x15956b['sqlOperator']=_['startsWith'](_0x41ae8c,'[$or]')?'or':_0x9e5f('0x2');var _0x18da5c=_0x41ae8c[_0x9e5f('0x3')]('[$and]','')[_0x9e5f('0x3')]('[$or]','')[_0x9e5f('0x4')]('||');for(var _0xb18a91=0x0;_0xb18a91<_0x18da5c[_0x9e5f('0x5')];_0xb18a91++){var _0x428bd7=_0x18da5c[_0xb18a91][_0x9e5f('0x4')](':=');var _0x471236=_0x428bd7[0x0];var _0x169c75=_0x428bd7[_0x9e5f('0x6')](0x1);_0x169c75[_0x9e5f('0x7')](function(_0x32a267){var _0x74e626=_0x32a267[_0x9e5f('0x4')]('[')['shift']();var _0x4b231d=_0x32a267[_0x9e5f('0x8')](/\[(.*?)\]/g);_0x4b231d['forEach'](function(_0x1a575b){var _0xccd98a=_0x1a575b[_0x9e5f('0x4')]('[')[_0x9e5f('0x9')](function(_0x4fb76d){return _0x4fb76d[_0x9e5f('0xa')](']')>-0x1;})[_0x9e5f('0xb')](function(_0xb5054a){return _0xb5054a[_0x9e5f('0x4')](']')[0x0];})[0x0];_0x15956b[_0x9e5f('0xc')]['push']({'field':_0x471236,'operator':_0x74e626,'value':_0xccd98a});});});}return _0x15956b;};exports[_0x9e5f('0xd')]=function(_0x369f02,_0x229831,_0x57f411){var _0x972a8d={};if(_0x229831===_0x9e5f('0xe')){if(_0x57f411[_0x9e5f('0xf')]===_0x9e5f('0x10')){_0x57f411[_0x9e5f('0xf')]='$between';_0x57f411[_0x9e5f('0x11')]+=','+_0x57f411[_0x9e5f('0x11')];}else if(_['includes'](['$gt',_0x9e5f('0x12')],_0x57f411[_0x9e5f('0xf')])){_0x57f411['value']=moment(_0x57f411[_0x9e5f('0x11')])['add'](0x1,'days')[_0x9e5f('0x13')](_0x9e5f('0x14'));}}if(_0x57f411['castTo']){_0x229831=_0x57f411[_0x9e5f('0x15')];_0x972a8d['text']=_0x9e5f('0x16')+_0x369f02+'.'+_0x57f411[_0x9e5f('0x17')]+_0x9e5f('0x18')+_0x57f411['castTo']+')\x20'+parseOperator(_0x57f411[_0x9e5f('0xf')]);}else{_0x972a8d[_0x9e5f('0x19')]=_0x369f02+'.'+_0x57f411['field']+'\x20'+parseOperator(_0x57f411[_0x9e5f('0xf')]);}if(_[_0x9e5f('0x1a')]([_0x9e5f('0x1b'),'$notIn'],_0x57f411[_0x9e5f('0xf')]))_0x972a8d['text']='('+_0x972a8d[_0x9e5f('0x19')]+_0x9e5f('0x1c')+_0x369f02+'.'+_0x57f411[_0x9e5f('0x17')]+_0x9e5f('0x1d');_0x972a8d[_0x9e5f('0x11')]=parseValue(_0x229831,_0x57f411['operator'],_0x57f411[_0x9e5f('0x11')]);return _0x972a8d;};function parseOperator(_0x1732e7){var _0x545778;switch(_0x1732e7){case _0x9e5f('0x1e'):_0x545778='IN\x20?';break;case _0x9e5f('0x1f'):_0x545778=_0x9e5f('0x20');break;case _0x9e5f('0x10'):_0x545778=_0x9e5f('0x21');break;case _0x9e5f('0x1b'):_0x545778=_0x9e5f('0x22');break;case'$substring':case'$startsWith':case _0x9e5f('0x23'):_0x545778='LIKE\x20?';break;case _0x9e5f('0x24'):_0x545778=_0x9e5f('0x25');break;case _0x9e5f('0x26'):_0x545778='>\x20?';break;case _0x9e5f('0x12'):_0x545778=_0x9e5f('0x27');break;case _0x9e5f('0x28'):_0x545778=_0x9e5f('0x29');break;case _0x9e5f('0x2a'):_0x545778=_0x9e5f('0x2b');break;}return _0x545778;}function parseValue(_0x22b1e9,_0x5ab93c,_0x19cefd){var _0x48b373={'start':undefined,'end':undefined};switch(_0x5ab93c){case _0x9e5f('0x1e'):case _0x9e5f('0x1f'):_0x48b373['start']=_0x19cefd['split'](',');break;case'$substring':_0x48b373['start']='%'+_0x19cefd+'%';break;case _0x9e5f('0x2c'):_0x48b373[_0x9e5f('0x2d')]=_0x19cefd+'%';break;case'$endsWith':_0x48b373[_0x9e5f('0x2d')]='%'+_0x19cefd;break;case _0x9e5f('0x2a'):var _0x8bb513=_0x19cefd[_0x9e5f('0x4')](',');var _0x19cefd=_0x8bb513[_0x9e5f('0x2e')]();var _0x30e00a=_0x8bb513[_0x9e5f('0x2f')]();if(_0x22b1e9===_0x9e5f('0xe')){_0x19cefd=moment(_0x19cefd)[_0x9e5f('0x30')](0x0,!![])[_0x9e5f('0x13')]();_0x30e00a=moment(_0x30e00a)['utcOffset'](0x0,!![])[_0x9e5f('0x31')](0x17,_0x9e5f('0x32'))[_0x9e5f('0x31')](0x3b,_0x9e5f('0x33'))['add'](0x3b,_0x9e5f('0x34'))[_0x9e5f('0x13')]();}_0x48b373={'start':_0x19cefd,'end':_0x30e00a};break;default:_0x48b373[_0x9e5f('0x2d')]=_0x19cefd;break;}return _0x48b373;}