Built motion from commit ddca4d0d.|2.5.47
[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 _0xc8d2=['filter','indexOf','conditions','buildExpression','DATE','operator','$eq','$between','value','$gt','$lte','add','format','castTo','text','CAST(','field','includes','$ne','\x20IS\x20NULL)','$in','IN\x20?','$notIn','NOT\x20IN\x20?','<>\x20?','$substring','$startsWith','$endsWith','<\x20?','>\x20?','<=\x20?','$gte','BETWEEN\x20?\x20AND\x20?','start','pop','utcOffset','hours','seconds','moment','parseSearch','startsWith','[$or]','and','[$and]','replace','split','length','slice','forEach','shift'];(function(_0x1fae22,_0x4b7f09){var _0x4b9072=function(_0x1cc498){while(--_0x1cc498){_0x1fae22['push'](_0x1fae22['shift']());}};_0x4b9072(++_0x4b7f09);}(_0xc8d2,0x184));var _0x2c8d=function(_0x201481,_0x175102){_0x201481=_0x201481-0x0;var _0x204943=_0xc8d2[_0x201481];return _0x204943;};'use strict';var _=require('lodash');var moment=require(_0x2c8d('0x0'));exports[_0x2c8d('0x1')]=function(_0x41c438){var _0x160c21={'conditions':[]};_0x160c21['sqlOperator']=_[_0x2c8d('0x2')](_0x41c438,_0x2c8d('0x3'))?'or':_0x2c8d('0x4');var _0xca344a=_0x41c438['replace'](_0x2c8d('0x5'),'')[_0x2c8d('0x6')](_0x2c8d('0x3'),'')[_0x2c8d('0x7')]('||');for(var _0x186ee9=0x0;_0x186ee9<_0xca344a[_0x2c8d('0x8')];_0x186ee9++){var _0x83f965=_0xca344a[_0x186ee9][_0x2c8d('0x7')](':=');var _0x122443=_0x83f965[0x0];var _0x7457a8=_0x83f965[_0x2c8d('0x9')](0x1);_0x7457a8[_0x2c8d('0xa')](function(_0x427e50){var _0x338d99=_0x427e50[_0x2c8d('0x7')]('[')[_0x2c8d('0xb')]();var _0x28fb5b=_0x427e50['match'](/\[(.*?)\]/g);_0x28fb5b[_0x2c8d('0xa')](function(_0x5cc439){var _0x582a96=_0x5cc439[_0x2c8d('0x7')]('[')[_0x2c8d('0xc')](function(_0x2b54a5){return _0x2b54a5[_0x2c8d('0xd')](']')>-0x1;})['map'](function(_0x4c04f7){return _0x4c04f7[_0x2c8d('0x7')](']')[0x0];})[0x0];_0x160c21[_0x2c8d('0xe')]['push']({'field':_0x122443,'operator':_0x338d99,'value':_0x582a96});});});}return _0x160c21;};exports[_0x2c8d('0xf')]=function(_0x5f2be7,_0x9708aa,_0xe1fbf8){var _0x412c00={};if(_0x9708aa===_0x2c8d('0x10')){if(_0xe1fbf8[_0x2c8d('0x11')]===_0x2c8d('0x12')){_0xe1fbf8['operator']=_0x2c8d('0x13');_0xe1fbf8[_0x2c8d('0x14')]+=','+_0xe1fbf8[_0x2c8d('0x14')];}else if(_['includes']([_0x2c8d('0x15'),_0x2c8d('0x16')],_0xe1fbf8[_0x2c8d('0x11')])){_0xe1fbf8[_0x2c8d('0x14')]=moment(_0xe1fbf8[_0x2c8d('0x14')])[_0x2c8d('0x17')](0x1,'days')[_0x2c8d('0x18')]('YYYY-MM-DD');}}if(_0xe1fbf8[_0x2c8d('0x19')]){_0x9708aa=_0xe1fbf8[_0x2c8d('0x19')];_0x412c00[_0x2c8d('0x1a')]=_0x2c8d('0x1b')+_0x5f2be7+'.'+_0xe1fbf8[_0x2c8d('0x1c')]+'\x20AS\x20'+_0xe1fbf8[_0x2c8d('0x19')]+')\x20'+parseOperator(_0xe1fbf8[_0x2c8d('0x11')]);}else{_0x412c00[_0x2c8d('0x1a')]=_0x5f2be7+'.'+_0xe1fbf8['field']+'\x20'+parseOperator(_0xe1fbf8['operator']);}if(_[_0x2c8d('0x1d')]([_0x2c8d('0x1e'),'$notIn'],_0xe1fbf8[_0x2c8d('0x11')]))_0x412c00[_0x2c8d('0x1a')]='('+_0x412c00['text']+'\x20OR\x20'+_0x5f2be7+'.'+_0xe1fbf8[_0x2c8d('0x1c')]+_0x2c8d('0x1f');_0x412c00[_0x2c8d('0x14')]=parseValue(_0x9708aa,_0xe1fbf8[_0x2c8d('0x11')],_0xe1fbf8[_0x2c8d('0x14')]);return _0x412c00;};function parseOperator(_0x58cf73){var _0x5e5e18;switch(_0x58cf73){case _0x2c8d('0x20'):_0x5e5e18=_0x2c8d('0x21');break;case _0x2c8d('0x22'):_0x5e5e18=_0x2c8d('0x23');break;case _0x2c8d('0x12'):_0x5e5e18='=\x20?';break;case _0x2c8d('0x1e'):_0x5e5e18=_0x2c8d('0x24');break;case _0x2c8d('0x25'):case _0x2c8d('0x26'):case _0x2c8d('0x27'):_0x5e5e18='LIKE\x20?';break;case'$lt':_0x5e5e18=_0x2c8d('0x28');break;case _0x2c8d('0x15'):_0x5e5e18=_0x2c8d('0x29');break;case _0x2c8d('0x16'):_0x5e5e18=_0x2c8d('0x2a');break;case _0x2c8d('0x2b'):_0x5e5e18='>=\x20?';break;case _0x2c8d('0x13'):_0x5e5e18=_0x2c8d('0x2c');break;}return _0x5e5e18;}function parseValue(_0x184c07,_0x66ff66,_0x1eb413){var _0x140a93={'start':undefined,'end':undefined};switch(_0x66ff66){case'$in':case _0x2c8d('0x22'):_0x140a93[_0x2c8d('0x2d')]=_0x1eb413[_0x2c8d('0x7')](',');break;case _0x2c8d('0x25'):_0x140a93[_0x2c8d('0x2d')]='%'+_0x1eb413+'%';break;case _0x2c8d('0x26'):_0x140a93[_0x2c8d('0x2d')]=_0x1eb413+'%';break;case _0x2c8d('0x27'):_0x140a93[_0x2c8d('0x2d')]='%'+_0x1eb413;break;case _0x2c8d('0x13'):var _0x488e73=_0x1eb413[_0x2c8d('0x7')](',');var _0x1eb413=_0x488e73[_0x2c8d('0xb')]();var _0x448c14=_0x488e73[_0x2c8d('0x2e')]();if(_0x184c07===_0x2c8d('0x10')){_0x1eb413=moment(_0x1eb413)[_0x2c8d('0x2f')](0x0,!![])[_0x2c8d('0x18')]();_0x448c14=moment(_0x448c14)[_0x2c8d('0x2f')](0x0,!![])[_0x2c8d('0x17')](0x17,_0x2c8d('0x30'))[_0x2c8d('0x17')](0x3b,'minutes')[_0x2c8d('0x17')](0x3b,_0x2c8d('0x31'))['format']();}_0x140a93={'start':_0x1eb413,'end':_0x448c14};break;default:_0x140a93['start']=_0x1eb413;break;}return _0x140a93;}