Built motion from commit (unavailable).|2.5.10
[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 _0xf506=['$in','IN\x20?','NOT\x20IN\x20?','<>\x20?','$substring','$startsWith','$endsWith','LIKE\x20?','$lt','>\x20?','$lte','<=\x20?','>=\x20?','$between','start','pop','utcOffset','minutes','seconds','lodash','parseSearch','sqlOperator','startsWith','and','[$and]','replace','[$or]','split','slice','forEach','shift','match','filter','conditions','push','buildExpression','DATE','operator','$eq','value','includes','$gt','add','days','format','YYYY-MM-DD','castTo','text','CAST(','field','$ne','$notIn','\x20IS\x20NULL)'];(function(_0x5185cf,_0x18e620){var _0x53a6b5=function(_0x414d58){while(--_0x414d58){_0x5185cf['push'](_0x5185cf['shift']());}};_0x53a6b5(++_0x18e620);}(_0xf506,0x1f0));var _0x6f50=function(_0x414e76,_0x196f24){_0x414e76=_0x414e76-0x0;var _0x341320=_0xf506[_0x414e76];return _0x341320;};'use strict';var _=require(_0x6f50('0x0'));var moment=require('moment');exports[_0x6f50('0x1')]=function(_0x1a1a1e){var _0x2e93e7={'conditions':[]};_0x2e93e7[_0x6f50('0x2')]=_[_0x6f50('0x3')](_0x1a1a1e,'[$or]')?'or':_0x6f50('0x4');var _0x5bfb54=_0x1a1a1e['replace'](_0x6f50('0x5'),'')[_0x6f50('0x6')](_0x6f50('0x7'),'')['split']('||');for(var _0x34697d=0x0;_0x34697d<_0x5bfb54['length'];_0x34697d++){var _0x50616b=_0x5bfb54[_0x34697d][_0x6f50('0x8')](':=');var _0xc4858e=_0x50616b[0x0];var _0x59196f=_0x50616b[_0x6f50('0x9')](0x1);_0x59196f[_0x6f50('0xa')](function(_0x416181){var _0x13c1bd=_0x416181[_0x6f50('0x8')]('[')[_0x6f50('0xb')]();var _0x4c3629=_0x416181[_0x6f50('0xc')](/\[(.*?)\]/g);_0x4c3629[_0x6f50('0xa')](function(_0x2ecdfd){var _0x10871c=_0x2ecdfd[_0x6f50('0x8')]('[')[_0x6f50('0xd')](function(_0x272726){return _0x272726['indexOf'](']')>-0x1;})['map'](function(_0x40fbf2){return _0x40fbf2[_0x6f50('0x8')](']')[0x0];})[0x0];_0x2e93e7[_0x6f50('0xe')][_0x6f50('0xf')]({'field':_0xc4858e,'operator':_0x13c1bd,'value':_0x10871c});});});}return _0x2e93e7;};exports[_0x6f50('0x10')]=function(_0x11209a,_0x30fe06,_0x45ea98){var _0x528ab6={};if(_0x30fe06===_0x6f50('0x11')){if(_0x45ea98[_0x6f50('0x12')]===_0x6f50('0x13')){_0x45ea98['operator']='$between';_0x45ea98[_0x6f50('0x14')]+=','+_0x45ea98[_0x6f50('0x14')];}else if(_[_0x6f50('0x15')]([_0x6f50('0x16'),'$lte'],_0x45ea98[_0x6f50('0x12')])){_0x45ea98['value']=moment(_0x45ea98[_0x6f50('0x14')])[_0x6f50('0x17')](0x1,_0x6f50('0x18'))[_0x6f50('0x19')](_0x6f50('0x1a'));}}if(_0x45ea98['castTo']){_0x30fe06=_0x45ea98[_0x6f50('0x1b')];_0x528ab6[_0x6f50('0x1c')]=_0x6f50('0x1d')+_0x11209a+'.'+_0x45ea98[_0x6f50('0x1e')]+'\x20AS\x20'+_0x45ea98[_0x6f50('0x1b')]+')\x20'+parseOperator(_0x45ea98[_0x6f50('0x12')]);}else{_0x528ab6['text']=_0x11209a+'.'+_0x45ea98['field']+'\x20'+parseOperator(_0x45ea98['operator']);}if(_[_0x6f50('0x15')]([_0x6f50('0x1f'),_0x6f50('0x20')],_0x45ea98['operator']))_0x528ab6[_0x6f50('0x1c')]='('+_0x528ab6[_0x6f50('0x1c')]+'\x20OR\x20'+_0x11209a+'.'+_0x45ea98[_0x6f50('0x1e')]+_0x6f50('0x21');_0x528ab6[_0x6f50('0x14')]=parseValue(_0x30fe06,_0x45ea98['operator'],_0x45ea98['value']);return _0x528ab6;};function parseOperator(_0x3dfa60){var _0x13982e;switch(_0x3dfa60){case _0x6f50('0x22'):_0x13982e=_0x6f50('0x23');break;case _0x6f50('0x20'):_0x13982e=_0x6f50('0x24');break;case _0x6f50('0x13'):_0x13982e='=\x20?';break;case'$ne':_0x13982e=_0x6f50('0x25');break;case _0x6f50('0x26'):case _0x6f50('0x27'):case _0x6f50('0x28'):_0x13982e=_0x6f50('0x29');break;case _0x6f50('0x2a'):_0x13982e='<\x20?';break;case _0x6f50('0x16'):_0x13982e=_0x6f50('0x2b');break;case _0x6f50('0x2c'):_0x13982e=_0x6f50('0x2d');break;case'$gte':_0x13982e=_0x6f50('0x2e');break;case _0x6f50('0x2f'):_0x13982e='BETWEEN\x20?\x20AND\x20?';break;}return _0x13982e;}function parseValue(_0x10cba7,_0x548f9e,_0x119cfb){var _0x2beed8={'start':undefined,'end':undefined};switch(_0x548f9e){case _0x6f50('0x22'):case _0x6f50('0x20'):_0x2beed8[_0x6f50('0x30')]=_0x119cfb[_0x6f50('0x8')](',');break;case'$substring':_0x2beed8[_0x6f50('0x30')]='%'+_0x119cfb+'%';break;case _0x6f50('0x27'):_0x2beed8[_0x6f50('0x30')]=_0x119cfb+'%';break;case _0x6f50('0x28'):_0x2beed8[_0x6f50('0x30')]='%'+_0x119cfb;break;case _0x6f50('0x2f'):var _0x397b8b=_0x119cfb['split'](',');var _0x119cfb=_0x397b8b[_0x6f50('0xb')]();var _0x417d2f=_0x397b8b[_0x6f50('0x31')]();if(_0x10cba7===_0x6f50('0x11')){_0x119cfb=moment(_0x119cfb)[_0x6f50('0x32')](0x0,!![])[_0x6f50('0x19')]();_0x417d2f=moment(_0x417d2f)[_0x6f50('0x32')](0x0,!![])['add'](0x17,'hours')[_0x6f50('0x17')](0x3b,_0x6f50('0x33'))['add'](0x3b,_0x6f50('0x34'))['format']();}_0x2beed8={'start':_0x119cfb,'end':_0x417d2f};break;default:_0x2beed8['start']=_0x119cfb;break;}return _0x2beed8;}