ef7013095517be46717cac8bf40b0aac6448cdf2
[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 _0xc73e=['and','replace','split','length','shift','match','indexOf','conditions','buildExpression','DATE','operator','$between','value','includes','$gt','$lte','add','format','YYYY-MM-DD','castTo','text','CAST(','field','\x20AS\x20','$ne','$notIn','\x20OR\x20','$in','IN\x20?','$eq','=\x20?','<>\x20?','$substring','$startsWith','$endsWith','LIKE\x20?','$lt','<\x20?','>\x20?','<=\x20?','$gte','>=\x20?','BETWEEN\x20?\x20AND\x20?','start','pop','utcOffset','seconds','lodash','moment','sqlOperator','startsWith','[$or]'];(function(_0x4ae6ef,_0xc2af80){var _0x3cbb4e=function(_0x569ad5){while(--_0x569ad5){_0x4ae6ef['push'](_0x4ae6ef['shift']());}};_0x3cbb4e(++_0xc2af80);}(_0xc73e,0x167));var _0xec73=function(_0x1b8923,_0x11c3f3){_0x1b8923=_0x1b8923-0x0;var _0xfa31cb=_0xc73e[_0x1b8923];return _0xfa31cb;};'use strict';var _=require(_0xec73('0x0'));var moment=require(_0xec73('0x1'));exports['parseSearch']=function(_0x308e6e){var _0x32b956={'conditions':[]};_0x32b956[_0xec73('0x2')]=_[_0xec73('0x3')](_0x308e6e,_0xec73('0x4'))?'or':_0xec73('0x5');var _0x31e8cb=_0x308e6e[_0xec73('0x6')]('[$and]','')['replace']('[$or]','')[_0xec73('0x7')]('||');for(var _0x31341a=0x0;_0x31341a<_0x31e8cb[_0xec73('0x8')];_0x31341a++){var _0x5caf9b=_0x31e8cb[_0x31341a]['split'](':=');var _0x151116=_0x5caf9b[0x0];var _0x55819b=_0x5caf9b['slice'](0x1);_0x55819b['forEach'](function(_0x37dccd){var _0x173adc=_0x37dccd['split']('[')[_0xec73('0x9')]();var _0x4c9a48=_0x37dccd[_0xec73('0xa')](/\[(.*?)\]/g);_0x4c9a48['forEach'](function(_0x2490de){var _0x17b962=_0x2490de['split']('[')['filter'](function(_0x26ce6f){return _0x26ce6f[_0xec73('0xb')](']')>-0x1;})['map'](function(_0x477a6a){return _0x477a6a[_0xec73('0x7')](']')[0x0];})[0x0];_0x32b956[_0xec73('0xc')]['push']({'field':_0x151116,'operator':_0x173adc,'value':_0x17b962});});});}return _0x32b956;};exports[_0xec73('0xd')]=function(_0x428282,_0x363d69,_0x2c2c7f){var _0x402e8b={};if(_0x363d69===_0xec73('0xe')){if(_0x2c2c7f['operator']==='$eq'){_0x2c2c7f[_0xec73('0xf')]=_0xec73('0x10');_0x2c2c7f[_0xec73('0x11')]+=','+_0x2c2c7f[_0xec73('0x11')];}else if(_[_0xec73('0x12')]([_0xec73('0x13'),_0xec73('0x14')],_0x2c2c7f[_0xec73('0xf')])){_0x2c2c7f[_0xec73('0x11')]=moment(_0x2c2c7f[_0xec73('0x11')])[_0xec73('0x15')](0x1,'days')[_0xec73('0x16')](_0xec73('0x17'));}}if(_0x2c2c7f[_0xec73('0x18')]){_0x363d69=_0x2c2c7f['castTo'];_0x402e8b[_0xec73('0x19')]=_0xec73('0x1a')+_0x428282+'.'+_0x2c2c7f[_0xec73('0x1b')]+_0xec73('0x1c')+_0x2c2c7f[_0xec73('0x18')]+')\x20'+parseOperator(_0x2c2c7f[_0xec73('0xf')]);}else{_0x402e8b[_0xec73('0x19')]=_0x428282+'.'+_0x2c2c7f[_0xec73('0x1b')]+'\x20'+parseOperator(_0x2c2c7f[_0xec73('0xf')]);}if(_[_0xec73('0x12')]([_0xec73('0x1d'),_0xec73('0x1e')],_0x2c2c7f[_0xec73('0xf')]))_0x402e8b[_0xec73('0x19')]='('+_0x402e8b[_0xec73('0x19')]+_0xec73('0x1f')+_0x428282+'.'+_0x2c2c7f[_0xec73('0x1b')]+'\x20IS\x20NULL)';_0x402e8b[_0xec73('0x11')]=parseValue(_0x363d69,_0x2c2c7f[_0xec73('0xf')],_0x2c2c7f['value']);return _0x402e8b;};function parseOperator(_0x62ef1){var _0x2b3d3f;switch(_0x62ef1){case _0xec73('0x20'):_0x2b3d3f=_0xec73('0x21');break;case _0xec73('0x1e'):_0x2b3d3f='NOT\x20IN\x20?';break;case _0xec73('0x22'):_0x2b3d3f=_0xec73('0x23');break;case _0xec73('0x1d'):_0x2b3d3f=_0xec73('0x24');break;case _0xec73('0x25'):case _0xec73('0x26'):case _0xec73('0x27'):_0x2b3d3f=_0xec73('0x28');break;case _0xec73('0x29'):_0x2b3d3f=_0xec73('0x2a');break;case _0xec73('0x13'):_0x2b3d3f=_0xec73('0x2b');break;case _0xec73('0x14'):_0x2b3d3f=_0xec73('0x2c');break;case _0xec73('0x2d'):_0x2b3d3f=_0xec73('0x2e');break;case _0xec73('0x10'):_0x2b3d3f=_0xec73('0x2f');break;}return _0x2b3d3f;}function parseValue(_0x392d5a,_0x561291,_0x5f45b4){var _0x47d186={'start':undefined,'end':undefined};switch(_0x561291){case _0xec73('0x20'):case'$notIn':_0x47d186[_0xec73('0x30')]=_0x5f45b4[_0xec73('0x7')](',');break;case'$substring':_0x47d186[_0xec73('0x30')]='%'+_0x5f45b4+'%';break;case _0xec73('0x26'):_0x47d186[_0xec73('0x30')]=_0x5f45b4+'%';break;case _0xec73('0x27'):_0x47d186[_0xec73('0x30')]='%'+_0x5f45b4;break;case'$between':var _0x2a1fe9=_0x5f45b4[_0xec73('0x7')](',');var _0x5f45b4=_0x2a1fe9['shift']();var _0x5bb3e7=_0x2a1fe9[_0xec73('0x31')]();if(_0x392d5a===_0xec73('0xe')){_0x5f45b4=moment(_0x5f45b4)['utcOffset'](0x0,!![])['format']();_0x5bb3e7=moment(_0x5bb3e7)[_0xec73('0x32')](0x0,!![])[_0xec73('0x15')](0x17,'hours')['add'](0x3b,'minutes')[_0xec73('0x15')](0x3b,_0xec73('0x33'))[_0xec73('0x16')]();}_0x47d186={'start':_0x5f45b4,'end':_0x5bb3e7};break;default:_0x47d186['start']=_0x5f45b4;break;}return _0x47d186;}