Built motion from commit 14588770.|2.5.38
[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 _0x693f=['start','$endsWith','shift','utcOffset','add','hours','minutes','seconds','moment','parseSearch','sqlOperator','startsWith','[$or]','and','replace','[$and]','split','slice','forEach','filter','indexOf','map','conditions','push','buildExpression','DATE','operator','$eq','value','$gt','$lte','days','format','YYYY-MM-DD','castTo','text','CAST(','field','\x20AS\x20','includes','$notIn','\x20OR\x20','\x20IS\x20NULL)','IN\x20?','NOT\x20IN\x20?','=\x20?','$ne','<>\x20?','$substring','$startsWith','LIKE\x20?','<\x20?','>\x20?','<=\x20?','$gte','>=\x20?','$between','BETWEEN\x20?\x20AND\x20?','$in'];(function(_0x52ac28,_0x4b92b5){var _0x1dfa82=function(_0x1cd4ce){while(--_0x1cd4ce){_0x52ac28['push'](_0x52ac28['shift']());}};_0x1dfa82(++_0x4b92b5);}(_0x693f,0xf4));var _0xf693=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0x693f[_0x20a584];return _0x4b41a8;};'use strict';var _=require('lodash');var moment=require(_0xf693('0x0'));exports[_0xf693('0x1')]=function(_0x9ee1ee){var _0x35542c={'conditions':[]};_0x35542c[_0xf693('0x2')]=_[_0xf693('0x3')](_0x9ee1ee,_0xf693('0x4'))?'or':_0xf693('0x5');var _0x2164b5=_0x9ee1ee[_0xf693('0x6')](_0xf693('0x7'),'')['replace']('[$or]','')[_0xf693('0x8')]('||');for(var _0x5be26e=0x0;_0x5be26e<_0x2164b5['length'];_0x5be26e++){var _0x90879=_0x2164b5[_0x5be26e][_0xf693('0x8')](':=');var _0x577fa7=_0x90879[0x0];var _0x5df73b=_0x90879[_0xf693('0x9')](0x1);_0x5df73b['forEach'](function(_0x1682e9){var _0x2ffc94=_0x1682e9[_0xf693('0x8')]('[')['shift']();var _0x1e0c69=_0x1682e9['match'](/\[(.*?)\]/g);_0x1e0c69[_0xf693('0xa')](function(_0x2f9f78){var _0x3f7476=_0x2f9f78[_0xf693('0x8')]('[')[_0xf693('0xb')](function(_0xcb4731){return _0xcb4731[_0xf693('0xc')](']')>-0x1;})[_0xf693('0xd')](function(_0x4b5c4e){return _0x4b5c4e[_0xf693('0x8')](']')[0x0];})[0x0];_0x35542c[_0xf693('0xe')][_0xf693('0xf')]({'field':_0x577fa7,'operator':_0x2ffc94,'value':_0x3f7476});});});}return _0x35542c;};exports[_0xf693('0x10')]=function(_0x4724ff,_0x3779d3,_0x38adeb){var _0x28d1f5={};if(_0x3779d3===_0xf693('0x11')){if(_0x38adeb[_0xf693('0x12')]===_0xf693('0x13')){_0x38adeb['operator']='$between';_0x38adeb[_0xf693('0x14')]+=','+_0x38adeb['value'];}else if(_['includes']([_0xf693('0x15'),_0xf693('0x16')],_0x38adeb[_0xf693('0x12')])){_0x38adeb[_0xf693('0x14')]=moment(_0x38adeb['value'])['add'](0x1,_0xf693('0x17'))[_0xf693('0x18')](_0xf693('0x19'));}}if(_0x38adeb[_0xf693('0x1a')]){_0x3779d3=_0x38adeb[_0xf693('0x1a')];_0x28d1f5[_0xf693('0x1b')]=_0xf693('0x1c')+_0x4724ff+'.'+_0x38adeb[_0xf693('0x1d')]+_0xf693('0x1e')+_0x38adeb[_0xf693('0x1a')]+')\x20'+parseOperator(_0x38adeb[_0xf693('0x12')]);}else{_0x28d1f5['text']=_0x4724ff+'.'+_0x38adeb[_0xf693('0x1d')]+'\x20'+parseOperator(_0x38adeb[_0xf693('0x12')]);}if(_[_0xf693('0x1f')](['$ne',_0xf693('0x20')],_0x38adeb['operator']))_0x28d1f5['text']='('+_0x28d1f5['text']+_0xf693('0x21')+_0x4724ff+'.'+_0x38adeb['field']+_0xf693('0x22');_0x28d1f5[_0xf693('0x14')]=parseValue(_0x3779d3,_0x38adeb[_0xf693('0x12')],_0x38adeb[_0xf693('0x14')]);return _0x28d1f5;};function parseOperator(_0x1452ac){var _0x47c60f;switch(_0x1452ac){case'$in':_0x47c60f=_0xf693('0x23');break;case _0xf693('0x20'):_0x47c60f=_0xf693('0x24');break;case'$eq':_0x47c60f=_0xf693('0x25');break;case _0xf693('0x26'):_0x47c60f=_0xf693('0x27');break;case _0xf693('0x28'):case _0xf693('0x29'):case'$endsWith':_0x47c60f=_0xf693('0x2a');break;case'$lt':_0x47c60f=_0xf693('0x2b');break;case _0xf693('0x15'):_0x47c60f=_0xf693('0x2c');break;case _0xf693('0x16'):_0x47c60f=_0xf693('0x2d');break;case _0xf693('0x2e'):_0x47c60f=_0xf693('0x2f');break;case _0xf693('0x30'):_0x47c60f=_0xf693('0x31');break;}return _0x47c60f;}function parseValue(_0x158d15,_0x202632,_0x5d917f){var _0x143e16={'start':undefined,'end':undefined};switch(_0x202632){case _0xf693('0x32'):case _0xf693('0x20'):_0x143e16[_0xf693('0x33')]=_0x5d917f['split'](',');break;case _0xf693('0x28'):_0x143e16['start']='%'+_0x5d917f+'%';break;case _0xf693('0x29'):_0x143e16[_0xf693('0x33')]=_0x5d917f+'%';break;case _0xf693('0x34'):_0x143e16['start']='%'+_0x5d917f;break;case _0xf693('0x30'):var _0x3a2417=_0x5d917f[_0xf693('0x8')](',');var _0x5d917f=_0x3a2417[_0xf693('0x35')]();var _0x332a43=_0x3a2417['pop']();if(_0x158d15===_0xf693('0x11')){_0x5d917f=moment(_0x5d917f)['utcOffset'](0x0,!![])[_0xf693('0x18')]();_0x332a43=moment(_0x332a43)[_0xf693('0x36')](0x0,!![])[_0xf693('0x37')](0x17,_0xf693('0x38'))[_0xf693('0x37')](0x3b,_0xf693('0x39'))[_0xf693('0x37')](0x3b,_0xf693('0x3a'))[_0xf693('0x18')]();}_0x143e16={'start':_0x5d917f,'end':_0x332a43};break;default:_0x143e16[_0xf693('0x33')]=_0x5d917f;break;}return _0x143e16;}