15211d940ac5c1c538cb77ea5f183ba99e8b4dd0
[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 _0xb086=['NOT\x20IN\x20?','=\x20?','<>\x20?','$substring','$startsWith','LIKE\x20?','$lt','<\x20?','>\x20?','<=\x20?','$gte','BETWEEN\x20?\x20AND\x20?','start','$endsWith','pop','utcOffset','hours','minutes','seconds','lodash','moment','parseSearch','sqlOperator','startsWith','[$or]','and','replace','[$and]','split','length','slice','forEach','shift','match','filter','conditions','push','operator','$eq','$between','value','includes','$gt','$lte','add','days','format','YYYY-MM-DD','castTo','text','CAST(','field','$ne','$notIn','\x20IS\x20NULL)','$in','IN\x20?'];(function(_0x2b1931,_0x544a85){var _0x1977d4=function(_0x334d67){while(--_0x334d67){_0x2b1931['push'](_0x2b1931['shift']());}};_0x1977d4(++_0x544a85);}(_0xb086,0x85));var _0x6b08=function(_0x4e676e,_0x2a7c6d){_0x4e676e=_0x4e676e-0x0;var _0x336a3c=_0xb086[_0x4e676e];return _0x336a3c;};'use strict';var _=require(_0x6b08('0x0'));var moment=require(_0x6b08('0x1'));exports[_0x6b08('0x2')]=function(_0x5ee54e){var _0x840f3f={'conditions':[]};_0x840f3f[_0x6b08('0x3')]=_[_0x6b08('0x4')](_0x5ee54e,_0x6b08('0x5'))?'or':_0x6b08('0x6');var _0x141c76=_0x5ee54e[_0x6b08('0x7')](_0x6b08('0x8'),'')[_0x6b08('0x7')](_0x6b08('0x5'),'')[_0x6b08('0x9')]('||');for(var _0x1ba4e8=0x0;_0x1ba4e8<_0x141c76[_0x6b08('0xa')];_0x1ba4e8++){var _0x58cf6f=_0x141c76[_0x1ba4e8][_0x6b08('0x9')](':=');var _0x579110=_0x58cf6f[0x0];var _0x4114d5=_0x58cf6f[_0x6b08('0xb')](0x1);_0x4114d5[_0x6b08('0xc')](function(_0x133cca){var _0x369f19=_0x133cca[_0x6b08('0x9')]('[')[_0x6b08('0xd')]();var _0x134073=_0x133cca[_0x6b08('0xe')](/\[(.*?)\]/g);_0x134073[_0x6b08('0xc')](function(_0x19aef0){var _0xed709f=_0x19aef0[_0x6b08('0x9')]('[')[_0x6b08('0xf')](function(_0x3664af){return _0x3664af['indexOf'](']')>-0x1;})['map'](function(_0x45ae7a){return _0x45ae7a[_0x6b08('0x9')](']')[0x0];})[0x0];_0x840f3f[_0x6b08('0x10')][_0x6b08('0x11')]({'field':_0x579110,'operator':_0x369f19,'value':_0xed709f});});});}return _0x840f3f;};exports['buildExpression']=function(_0x33b856,_0x2bf027,_0x788016){var _0x570e57={};if(_0x2bf027==='DATE'){if(_0x788016[_0x6b08('0x12')]===_0x6b08('0x13')){_0x788016['operator']=_0x6b08('0x14');_0x788016[_0x6b08('0x15')]+=','+_0x788016[_0x6b08('0x15')];}else if(_[_0x6b08('0x16')]([_0x6b08('0x17'),_0x6b08('0x18')],_0x788016['operator'])){_0x788016[_0x6b08('0x15')]=moment(_0x788016[_0x6b08('0x15')])[_0x6b08('0x19')](0x1,_0x6b08('0x1a'))[_0x6b08('0x1b')](_0x6b08('0x1c'));}}if(_0x788016['castTo']){_0x2bf027=_0x788016[_0x6b08('0x1d')];_0x570e57[_0x6b08('0x1e')]=_0x6b08('0x1f')+_0x33b856+'.'+_0x788016['field']+'\x20AS\x20'+_0x788016[_0x6b08('0x1d')]+')\x20'+parseOperator(_0x788016[_0x6b08('0x12')]);}else{_0x570e57[_0x6b08('0x1e')]=_0x33b856+'.'+_0x788016[_0x6b08('0x20')]+'\x20'+parseOperator(_0x788016['operator']);}if(_[_0x6b08('0x16')]([_0x6b08('0x21'),_0x6b08('0x22')],_0x788016[_0x6b08('0x12')]))_0x570e57[_0x6b08('0x1e')]='('+_0x570e57['text']+'\x20OR\x20'+_0x33b856+'.'+_0x788016[_0x6b08('0x20')]+_0x6b08('0x23');_0x570e57['value']=parseValue(_0x2bf027,_0x788016[_0x6b08('0x12')],_0x788016[_0x6b08('0x15')]);return _0x570e57;};function parseOperator(_0x4b0bd5){var _0x26424c;switch(_0x4b0bd5){case _0x6b08('0x24'):_0x26424c=_0x6b08('0x25');break;case'$notIn':_0x26424c=_0x6b08('0x26');break;case _0x6b08('0x13'):_0x26424c=_0x6b08('0x27');break;case'$ne':_0x26424c=_0x6b08('0x28');break;case _0x6b08('0x29'):case _0x6b08('0x2a'):case'$endsWith':_0x26424c=_0x6b08('0x2b');break;case _0x6b08('0x2c'):_0x26424c=_0x6b08('0x2d');break;case'$gt':_0x26424c=_0x6b08('0x2e');break;case'$lte':_0x26424c=_0x6b08('0x2f');break;case _0x6b08('0x30'):_0x26424c='>=\x20?';break;case _0x6b08('0x14'):_0x26424c=_0x6b08('0x31');break;}return _0x26424c;}function parseValue(_0x3fd68e,_0x603680,_0x55ebb1){var _0x47d4f6={'start':undefined,'end':undefined};switch(_0x603680){case'$in':case _0x6b08('0x22'):_0x47d4f6[_0x6b08('0x32')]=_0x55ebb1[_0x6b08('0x9')](',');break;case _0x6b08('0x29'):_0x47d4f6[_0x6b08('0x32')]='%'+_0x55ebb1+'%';break;case _0x6b08('0x2a'):_0x47d4f6[_0x6b08('0x32')]=_0x55ebb1+'%';break;case _0x6b08('0x33'):_0x47d4f6[_0x6b08('0x32')]='%'+_0x55ebb1;break;case _0x6b08('0x14'):var _0x443251=_0x55ebb1[_0x6b08('0x9')](',');var _0x55ebb1=_0x443251[_0x6b08('0xd')]();var _0x17b29e=_0x443251[_0x6b08('0x34')]();if(_0x3fd68e==='DATE'){_0x55ebb1=moment(_0x55ebb1)[_0x6b08('0x35')](0x0,!![])[_0x6b08('0x1b')]();_0x17b29e=moment(_0x17b29e)[_0x6b08('0x35')](0x0,!![])['add'](0x17,_0x6b08('0x36'))[_0x6b08('0x19')](0x3b,_0x6b08('0x37'))['add'](0x3b,_0x6b08('0x38'))['format']();}_0x47d4f6={'start':_0x55ebb1,'end':_0x17b29e};break;default:_0x47d4f6[_0x6b08('0x32')]=_0x55ebb1;break;}return _0x47d4f6;}