Built motion from commit 753c950e.|2.5.42
[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 _0x606e=['DATE','operator','$eq','value','$gt','$lte','format','castTo','\x20AS\x20','field','includes','$ne','$notIn','text','\x20OR\x20','\x20IS\x20NULL)','IN\x20?','NOT\x20IN\x20?','=\x20?','$substring','$startsWith','$endsWith','$lt','<\x20?','>\x20?','$gte','>=\x20?','BETWEEN\x20?\x20AND\x20?','$in','start','$between','pop','utcOffset','add','hours','minutes','seconds','parseSearch','sqlOperator','startsWith','[$or]','and','replace','split','length','shift','forEach','filter','map','conditions'];(function(_0x3c0993,_0x523490){var _0x5c090d=function(_0x208f6a){while(--_0x208f6a){_0x3c0993['push'](_0x3c0993['shift']());}};_0x5c090d(++_0x523490);}(_0x606e,0xbb));var _0xe606=function(_0x233716,_0x346676){_0x233716=_0x233716-0x0;var _0x302298=_0x606e[_0x233716];return _0x302298;};'use strict';var _=require('lodash');var moment=require('moment');exports[_0xe606('0x0')]=function(_0x5834f0){var _0x4c99f4={'conditions':[]};_0x4c99f4[_0xe606('0x1')]=_[_0xe606('0x2')](_0x5834f0,_0xe606('0x3'))?'or':_0xe606('0x4');var _0x452de0=_0x5834f0[_0xe606('0x5')]('[$and]','')['replace'](_0xe606('0x3'),'')[_0xe606('0x6')]('||');for(var _0x345e0c=0x0;_0x345e0c<_0x452de0[_0xe606('0x7')];_0x345e0c++){var _0x1d40b5=_0x452de0[_0x345e0c]['split'](':=');var _0x506e5d=_0x1d40b5[0x0];var _0x4408b4=_0x1d40b5['slice'](0x1);_0x4408b4['forEach'](function(_0x23f7a2){var _0x380e5f=_0x23f7a2[_0xe606('0x6')]('[')[_0xe606('0x8')]();var _0xf3ace8=_0x23f7a2['match'](/\[(.*?)\]/g);_0xf3ace8[_0xe606('0x9')](function(_0x3498a9){var _0x14e43d=_0x3498a9[_0xe606('0x6')]('[')[_0xe606('0xa')](function(_0x4e085d){return _0x4e085d['indexOf'](']')>-0x1;})[_0xe606('0xb')](function(_0x4842be){return _0x4842be[_0xe606('0x6')](']')[0x0];})[0x0];_0x4c99f4[_0xe606('0xc')]['push']({'field':_0x506e5d,'operator':_0x380e5f,'value':_0x14e43d});});});}return _0x4c99f4;};exports['buildExpression']=function(_0x581c86,_0x304c26,_0x1e8019){var _0x5113d6={};if(_0x304c26===_0xe606('0xd')){if(_0x1e8019[_0xe606('0xe')]===_0xe606('0xf')){_0x1e8019[_0xe606('0xe')]='$between';_0x1e8019[_0xe606('0x10')]+=','+_0x1e8019[_0xe606('0x10')];}else if(_['includes']([_0xe606('0x11'),_0xe606('0x12')],_0x1e8019[_0xe606('0xe')])){_0x1e8019['value']=moment(_0x1e8019['value'])['add'](0x1,'days')[_0xe606('0x13')]('YYYY-MM-DD');}}if(_0x1e8019[_0xe606('0x14')]){_0x304c26=_0x1e8019[_0xe606('0x14')];_0x5113d6['text']='CAST('+_0x581c86+'.'+_0x1e8019['field']+_0xe606('0x15')+_0x1e8019['castTo']+')\x20'+parseOperator(_0x1e8019['operator']);}else{_0x5113d6['text']=_0x581c86+'.'+_0x1e8019[_0xe606('0x16')]+'\x20'+parseOperator(_0x1e8019[_0xe606('0xe')]);}if(_[_0xe606('0x17')]([_0xe606('0x18'),_0xe606('0x19')],_0x1e8019[_0xe606('0xe')]))_0x5113d6[_0xe606('0x1a')]='('+_0x5113d6[_0xe606('0x1a')]+_0xe606('0x1b')+_0x581c86+'.'+_0x1e8019[_0xe606('0x16')]+_0xe606('0x1c');_0x5113d6[_0xe606('0x10')]=parseValue(_0x304c26,_0x1e8019[_0xe606('0xe')],_0x1e8019[_0xe606('0x10')]);return _0x5113d6;};function parseOperator(_0x19df0a){var _0x336f25;switch(_0x19df0a){case'$in':_0x336f25=_0xe606('0x1d');break;case _0xe606('0x19'):_0x336f25=_0xe606('0x1e');break;case _0xe606('0xf'):_0x336f25=_0xe606('0x1f');break;case _0xe606('0x18'):_0x336f25='<>\x20?';break;case _0xe606('0x20'):case _0xe606('0x21'):case _0xe606('0x22'):_0x336f25='LIKE\x20?';break;case _0xe606('0x23'):_0x336f25=_0xe606('0x24');break;case _0xe606('0x11'):_0x336f25=_0xe606('0x25');break;case _0xe606('0x12'):_0x336f25='<=\x20?';break;case _0xe606('0x26'):_0x336f25=_0xe606('0x27');break;case'$between':_0x336f25=_0xe606('0x28');break;}return _0x336f25;}function parseValue(_0x45629f,_0x3bdc47,_0x3503d6){var _0xdd1809={'start':undefined,'end':undefined};switch(_0x3bdc47){case _0xe606('0x29'):case _0xe606('0x19'):_0xdd1809[_0xe606('0x2a')]=_0x3503d6[_0xe606('0x6')](',');break;case'$substring':_0xdd1809['start']='%'+_0x3503d6+'%';break;case _0xe606('0x21'):_0xdd1809[_0xe606('0x2a')]=_0x3503d6+'%';break;case _0xe606('0x22'):_0xdd1809[_0xe606('0x2a')]='%'+_0x3503d6;break;case _0xe606('0x2b'):var _0x2f0ddc=_0x3503d6[_0xe606('0x6')](',');var _0x3503d6=_0x2f0ddc[_0xe606('0x8')]();var _0x4520a4=_0x2f0ddc[_0xe606('0x2c')]();if(_0x45629f==='DATE'){_0x3503d6=moment(_0x3503d6)[_0xe606('0x2d')](0x0,!![])['format']();_0x4520a4=moment(_0x4520a4)['utcOffset'](0x0,!![])[_0xe606('0x2e')](0x17,_0xe606('0x2f'))[_0xe606('0x2e')](0x3b,_0xe606('0x30'))[_0xe606('0x2e')](0x3b,_0xe606('0x31'))[_0xe606('0x13')]();}_0xdd1809={'start':_0x3503d6,'end':_0x4520a4};break;default:_0xdd1809[_0xe606('0x2a')]=_0x3503d6;break;}return _0xdd1809;}